【问题标题】:PayPal onApprove not calling ajax functionPayPal onApprove 不调用 ajax 函数
【发布时间】:2021-01-30 00:56:47
【问题描述】:

我正在尝试在支付成功时向数据库添加一个布尔值。

  <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 功能不工作。它不显示任何错误或成功消息。

【问题讨论】:

    标签: javascript ajax paypal paypal-sandbox


    【解决方案1】:

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

    相反,请使用直接从服务器捕获的适当的服务器端集成,这样您就可以立即获得成功或失败的 API 响应,而无需依赖客户端来通知您发生的事情。

    为此,请在您的服务器上创建两条路由,一条用于“设置事务”,一条用于“捕获事务”,记录在此:https://developer.paypal.com/docs/checkout/reference/server-integration/

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

    【讨论】:

    • 我不明白这是怎么回事。
    • como que é o quê?
    • onde é que vou chamar a minha função do php no server integration
    • 您需要创建两条新路线。例如includes/create_payment.phpincludes/capture_payment.php?id=xxxxxxxxxxxxxxxx——或者任何适合你的东西。
    猜你喜欢
    • 2021-05-19
    • 2020-06-20
    • 2021-09-28
    • 2021-12-24
    • 2021-08-09
    • 1970-01-01
    • 2020-07-13
    • 2014-07-24
    • 1970-01-01
    相关资源
    最近更新 更多