PayPal onApprove不调用Ajax函数

问题描述

付款成功后,我正在尝试向数据库添加布尔值。

  <script>
paypal.Buttons({
  createOrder: function(data,actions) {
    // This function sets up the details of the transaction,including the amount and line item details.
    return actions.order.create({
      purchase_units: [{
        amount: {
          value: '0.01'
        }
      }]
    });
  },onApprove: function(data,actions) {
    // This function captures the funds from the transaction.
    return actions.order.capture().then(function(details) {
      // This function shows a transaction success message to your buyer.
      alert('Transaction completed by ' + details.payer.name.given_name);
      $.ajax({
        url: "includes/payment_db.PHP",success: function(data) {
          alert('Successfully called');
        },error: function(jqxhr,status,exception) {
          alert('Exception:',exception);
        }
      });
    });
  }
}).render('#paypal-button-container');
ajax功能无法正常工作。它不显示任何错误或成功消息。

解决方法

不应使用这种类型的付款流程。不要在客户端捕获数据,然后在数据库中记录信息。

相反,请使用直接从服务器捕获的正确服务器端集成,这样您就可以立即获得API成功或失败的响应,并且不依赖于客户端将发生的情况通知您。

要完成此操作,请在服务器上创建两条路由,一条用于“设置交易”,另一条用于“捕获交易”,在此处记录:https://developer.paypal.com/docs/checkout/reference/server-integration/

为获得客户的认可,请将以下JavaScript与您创建的上述两条路由配对:https://developer.paypal.com/demo/checkout/#/pattern/server