使用AJAX处理回调URL时出现问题

时间:2018-11-05 04:47:27

标签: forms callback payment-gateway

我正在处理一个表单,在该表单上,用户单击“提交”按钮(以进行付款)之后,该表单应该重定向到付款网关站点上的iframe以供用户进行付款;如果付款成功,则表单具有一个输入字段,其中包含要重定向到的回调URL。该窗体工作正常,除了我想编写一个if条件来检查是否已经调用了输入字段(在窗体中)中的回调,以及是否要执行其他操作。

我正在使用AJAX编写此代码,但无法正常工作。

〜请协助?

要提交到网关的表单

    <form 
   id="eazzycheckout-payment-form"
   action="https://api-test.*****************************" method="POST">
   <input type="hidden" name="custName" id="custName" value="{{ $first }} {{ $last }}">
   <input type="hidden" id="token" name="token" value="{{ $token}}">
   <input type="hidden" id="amount" name="amount" value="">
   <input type="hidden" id="orderReference" name="orderReference" value="">
   <input type="hidden" id="orderID" name="orderID" value="">
   <input type="hidden" id="merchantCode" name="merchantCode" value="*************">
   <input type="hidden" id="merchant" name="merchant" value="*************">
   <input type="hidden" id="outletCode" name="outletCode" value="0000000000">
   <input type="hidden" id="extraData" name="extraData" value="Travel_Purchase">
   <input type="hidden" id="popupLogo" name="popupLogo" value="https://**********************">
   <!-- Callback URL to redirect to after user successfully pays-->
   <input type="hidden" id="ez1_callbackurl" name="ez1_callbackurl" value=" https://***************************">
   <input type="hidden" id="expiry" name="expiry" value="{{ $newDate}}">
   <div class="card-deck payment">
   <div class="card">
      <img class="card-img-top payment" src="{{asset('assets/images-new/savi.svg')}}" alt="Card image cap">
      <div class="card-body">
         <h5 class="card-title payment">
            <button type="submit" id="submit-cg" value="Checkout" style="cursor: pointer;" class="jenga"> Make Payment </button>
         </h5>
      </div>
   </div>
   <!-- End Hidden form-->
</form>
<!-- Hidden form-->

AJAX代码,正在监听回调以执行其他一些操作

var form = $('#eazzycheckout-payment-form');

  $( "form" ).submit(function(e) {
    var type = 'jengaapi';
    var quote = $('#quote').val();
    var phone = $('#phone').val();
    //Converts to a JS object
    var type ={
      'type': type,
      'quote' : quote,
      'phone' : phone,
    };
    //console.log(type);

    //Amount
    var amount = $('#amount');
    var orderID = $('#orderID');
    var  orderRef = $('#orderReference');

    $.ajax({
        type: 'POST',
        url: 'jengaAPI',
        data: JSON.stringify(type),
        contentType: 'application/json',
        dataType: "json",
        success: function(response){
            amount.val(response.amount);
            orderID.val(response.payment_reference);
            orderRef.val(response.payment_reference);

            //Submit the form
            $('#eazzycheckout-payment-form').submit();

            //Listen if the value of input ez1_callbackurl from the form is called
            if($('#eazzycheckout-payment-form').('#ez1_callbackurl').val() == true){
                //Perform another action if the callback is called by the API
            }
        },
        failure: function(errMsg) {
             //alert('Errors');
        }
    });
  });

0 个答案:

没有答案