{% extends './vista/template/payment/credit_card.twig' %}
{% block scripts_before %}
  <script src="https://assets.pagseguro.com.br/checkout-sdk-js/rc/dist/browser/pagseguro.min.js"></script>
{% endblock %}

{% block initForm %}
  {{ parent() }}
  <input type="text" class="hidden" name="creditcard_public_key" id="creditcard_public_key" value={{ pagseguroPublicKey }}>
{% endblock %}

{% block script_before_send %}
    let card = PagSeguro.encryptCard({
      publicKey: atob(data['creditcard_public_key']),
      holder: data['creditcard_name'],
      number: data['creditcard_ccno'].replace(/\s/g, ''),
      expMonth: data['expire'].substring(0, 2),
      expYear: data['expire'].substring(3, 7),
      securityCode: data['creditcard_cccvd']
    });

    data['encryptedCard'] = card.encryptedCard;
{% endblock %}