Untitled

 avatar
pixerlabs
plain_text
3 years ago
1.4 kB
1
Indexable
jQuery(document).ready(function($) {
  var $ = jQuery;

  $('.payment_process').find('.button_action').click(function(e) {
    var payment_id = $(this).attr("payment_id");
    var payment_amount = $(this).attr("payment_amount");
    e.preventDefault();
    $.ajax({
      type: 'POST',
      url: "https://vinotecabp.azurewebsites.net/webpay_init.php?action=init",
      data: {
        id: payment_id,
        amount: payment_amount
      },
      beforeSend: function(results) {
        $('.' + payment_id).find('.button_action').attr("disabled", true);
      },
      success: function(results) {
        $('.' + payment_id).find('.button_action').attr("disabled", false);
        results = $.parseJSON(results);
        if(!results.url) {
          alert("Error al obtener datos de transbank");
        } else {
          $('.' + payment_id).find('.action_form').html('<form target="_blank" name="form_' + payment_id + '" id="form_' + payment_id + '" method="POST" action="' + results.url + '"><input type="hidden" name="token_ws" value="' + results.token + '" /></form>');
          $('#form_' + payment_id).submit();
        }
      },
      error: function(results) {
        $('.' + payment_id).find('.button_action').attr("disabled", false);
        alert("Error al obtener datos de transbank");
      }
    });
  });
});