text: window.Mercadopago.setPublishableKey("TEST-33d6d38f-395c-4f24-a9e7-2267ddf4d259");
  window.Mercadopago.getIdentificationTypes();
  
  document.getElementById("paymentMethod").selectedIndex = '0';
  document.getElementById('paymentMethodId').value = '';
  document.getElementById('detalheCartao').style.display = 'none';
  
  document.getElementById('paymentMethod').addEventListener('change', function(event) {
      console.log('FORMA DE PAGAMENTO: ', event.target.value);
  
      if(event.target.value == 1) {
          
          $('#detalheCartao').fadeIn(500);
  
      } else {
  
          $('#detalheCartao').fadeOut(500);
          document.getElementById('paymentMethodId').value = 'bolbradesco';
  
      }
  });
  
  document.getElementById('cardNumber').addEventListener('change', guessPaymentMethod);
  
  function guessPaymentMethod(event) {
      cleanCardInfo();
  
      if(document.getElementById('paymentMethod').value == 1) {
          let cardnumber = document.getElementById("cardNumber").value;
          if (cardnumber.length >= 6) {
              let bin = cardnumber.substring(0,6);
              window.Mercadopago.getPaymentMethod({
                  "bin": bin
              }, setPaymentMethod);
          }
      }
  };
  
  function setPaymentMethod(status, response) {
      if (status == 200) {
          let paymentMethod = response[0];
          console.log('PAYMENT METHOD: ', paymentMethod);
          document.getElementById('paymentMethodId').value = paymentMethod.id;
  
          getIssuers(paymentMethod.id);
      } else {
          alert(`payment method info error: ${response}`);
      }
  }
  
  function getIssuers(paymentMethodId) {
      window.Mercadopago.getIssuers(
          paymentMethodId,
          setIssuers
      );
  }
      
  function setIssuers(status, response) {
      if (status == 200) {
          let issuerSelect = document.getElementById('issuer');
          issuerSelect.options.length = 0;
          response.forEach( issuer => {
              let opt = document.createElement('option');
              opt.text = issuer.name;
              opt.value = issuer.id;
              issuerSelect.appendChild(opt);
          });
      
          getInstallments(
              document.getElementById('paymentMethodId').value,
              document.getElementById('transactionAmount').value,
              issuerSelect.value
          );
      } else {
          alert(`issuers method info error: ${response}`);
      }
  }
  
  function getInstallments(paymentMethodId, transactionAmount, issuerId){
      window.Mercadopago.getInstallments({
          "payment_method_id": paymentMethodId,
          "amount": parseFloat(transactionAmount),
          "issuer_id": parseInt(issuerId)
      }, setInstallments);
  }
      
  function setInstallments(status, response){
      if (status == 200) {
          document.getElementById('installments').options.length = 0;
          response[0].payer_costs.forEach( payerCost => {
              let opt = document.createElement('option');
              opt.text = payerCost.recommended_message;
              opt.value = payerCost.installments;
              document.getElementById('installments').appendChild(opt);
          });
      } else {
          alert(`installments method info error: ${response}`);
      }
  }
  
  doSubmit = false;
  document.getElementById('paymentForm').addEventListener('submit', getCardToken);
  function getCardToken(event){
      if(document.getElementById('paymentMethod').value == 1) {
          event.preventDefault();
          if(!doSubmit){
              let $form = document.getElementById('paymentForm');
              window.Mercadopago.createToken($form, setCardTokenAndPay);
              return false;
          }
      }
  };
  
  function setCardTokenAndPay(status, response) {
      if (status == 200 || status == 201) {
          let form = document.getElementById('paymentForm');
          let card = document.createElement('input');
          card.setAttribute('name', 'token');
          card.setAttribute('type', 'hidden');
          card.setAttribute('value', response.id);
          form.appendChild(card);
          doSubmit = true;
          form.submit();
      } else {
          alert("Verify filled data!\n" + JSON.stringify(response, null, 4));
      }
  };
  
  function cleanCardInfo() {
      document.getElementById('issuer').options.length = 0;
      document.getElementById('installments').options.length = 0;
  }