【问题标题】:Getting console errors while setting up client to call server side PayPal API设置客户端以调用服务器端 PayPal API 时出现控制台错误
【发布时间】:2021-03-22 14:34:01
【问题描述】:

在设置时,用于测试服务器集成的 PayPal 客户端代码,来自 https://developer.paypal.com/docs/archive/checkout/how-to/server-integration/

我的代码如下:

<html>
<head>
    <title>TEST PAYMENT</title>
</head>
<body>    
<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
  paypal.Button.render({
    env: 'sandbox', // Or 'production'
    
    // Set up the payment:
    // 1. Add a payment callback
    payment: function(data, actions) {
      // 2. Make a request to your server
      return actions.request.post('/api/paypal/create-payment')
        .then(function(res) {
            console.log(res);
          // 3. Return res.id from the response
          return res.id;
        });
    },

    // Execute the payment:
    // 1. Add an onAuthorize callback
    onAuthorize: function(data, actions) {
      // 2. Make a request to your server
      return actions.request.post('/api/paypal/execute-payment', {
        paymentID: data.paymentID,
        payerID:   data.payerID
      })
        .then(function(res) {
          // 3. Show the buyer a confirmation message.
        });
    }
  }, '#paypal-button');
</script>
</body>
</html>

当我打开页面时。

当我点击按钮时,模态窗口会显示一秒钟,然后关闭并出现以下错误。

【问题讨论】:

    标签: paypal paypal-sandbox


    【解决方案1】:

    您尝试使用的 checkout.js 集成已弃用。

    这是调用服务器的当前 JS SDK:https://developer.paypal.com/demo/checkout/#/pattern/server

    【讨论】:

    • 您能否建议一下,此服务器端集成的 PHP 示例代码是什么?官方指南真是乱七八糟。
    • 您可以使用多种 API(包括已弃用的 API),但当前的 v2/checkout/orders 'Create Order' 和 'Capture Order' 是最好的,记录在:developer.paypal.com/docs/business/checkout/…跨度>
    猜你喜欢
    • 2021-06-01
    • 2023-03-25
    • 1970-01-01
    • 2019-08-26
    • 2015-03-21
    • 2017-08-24
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多