javascript - Paypal Express Checkout.js - 将自定义值传递到交易中

标签 javascript paypal-sandbox paypal

我正在尝试设置一个 paypal Express 实例,并将订单号从网站传递到 paypal 交易中,以便客户有一个引用。这就是他们以前的系统与 Express 的配合方式,但现在我们从头开始重建了网站,没有从 Paypal 找到任何有关自定义值的有用文档,甚至没有传递说明。

我已经尝试过PayPal Express Checkout.js - send custom parameters这两种解决方案对我的 PayPal 沙箱完全没有任何作用。 paypal提供的通知只包含账户信息和支付金额,这显然不对吧?

我已经放弃了这些文档:https://developer.paypal.com/demo/checkout/#/pattern/client

这是普通的 checkout.js 客户端结账:

<!DOCTYPE html>

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>

<body>
    <div id="paypal-button-container"></div>

    <script>
        paypal.Button.render({

            env: 'sandbox', // sandbox | production

            // PayPal Client IDs - replace with your own
            // Create a PayPal app: https://developer.paypal.com/developer/applications/create
            client: {
                sandbox:    'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R',
                production: '<insert production client id>'
            },

            // Show the buyer a 'Pay Now' button in the checkout flow
            commit: true,

            // payment() is called when the button is clicked
            payment: function(data, actions) {

                // Make a call to the REST api to create the payment
                return actions.payment.create({
                    payment: {
                        transactions: [
                            {
                                amount: { total: '0.01', currency: 'USD' }
                            }
                        ]
                    }
                });
            },

            // onAuthorize() is called when the buyer approves the payment
            onAuthorize: function(data, actions) {

                // Make a call to the REST api to execute the payment
                return actions.payment.execute().then(function() {
                    window.alert('Payment Complete!');
                });
            }

        }, '#paypal-button-container');

    </script>
</body>

我尝试形成 data 对象并将其传入,但它要么不起作用,要么根本没有发生任何事情。我还尝试添加到支付数组中,但 PayPal 沙箱端没有任何反应。

我的买家帐户收据如下所示: enter image description here

店主给我的通知是: enter image description here

如何填写红色圆圈?我需要用户刚刚购买的产品的描述,还需要将我的订单号从网站传递到 Paypal ?我确实在 PayPal 文档中找不到任何对此有帮助的内容。

有人能好心引导我走向正确的方向吗?我觉得我错过了一些简单的事情

最佳答案

我与 Paypal 交谈过,他们实际上没有这方面的直接文档,他们仍在为很多功能创建文档。

您可以在 paypal 提供的 cURL 调用示例中使用 JSON 数组

 -d'{
  "intent": "sale",
  "payer": {
  "payment_method": "paypal"
  },
  "transactions": [
  {
    "amount": {
    "total": "30.11",
    "currency": "USD",
    "details": {
      "subtotal": "30.00",
      "tax": "0.07",
      "shipping": "0.03",
      "handling_fee": "1.00",
      "shipping_discount": "-1.00",
      "insurance": "0.01"
    }
    },
    "description": "This is the payment transaction description.",
    "custom": "EBAY_EMS_90048630024435",
    "invoice_number": "48787589673",
    "payment_options": {
    "allowed_payment_method": "INSTANT_FUNDING_SOURCE"
    },
    "soft_descriptor": "ECHI5786786",
    "item_list": {
    "items": [
      {
      "name": "hat",
      "description": "Brown color hat",
      "quantity": "5",
      "price": "3",
      "tax": "0.01",
      "sku": "1",
      "currency": "USD"
      },
      {
      "name": "handbag",
      "description": "Black color hand bag",
      "quantity": "1",
      "price": "15",
      "tax": "0.02",
      "sku": "product34",
      "currency": "USD"
      }
    ],
    "shipping_address": {
      "recipient_name": "Hello World",
      "line1": "4thFloor",
      "line2": "unit#34",
      "city": "SAn Jose",
      "country_code": "US",
      "postal_code": "95131",
      "phone": "011862212345678",
      "state": "CA"
    }
    }
  }
  ],
  "note_to_payer": "Contact us for any questions on your order.",
  "redirect_urls": {
  "return_url": "https://example.com",
  "cancel_url": "https://example.com"
  }
}'

所以对于“description”:“棕色帽子”,

transactions: [
                {
                    amount: { total: $paying, currency: 'CAD' },
                    description: 'This is a test description',
                }
              ]

我不知道为什么 PayPal Express Checkout.js - send custom parameters 中提出的解决方案对我不起作用,可能是我的语法问题或缓存问题,但它今天有效! (当然...)

关于javascript - Paypal Express Checkout.js - 将自定义值传递到交易中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47463932/

相关文章:

javascript - 如何使用 ecmascript 或 SPServices 获取类型为个人或组的 SharePoint 列表字段值?

javascript - JQuery $.post 关于提交事件帮助

asp.net - 在 .net 中获取 Paypal 帐户中的总余额

ruby-on-rails - API 凭据与 paypal_permissions gem 不正确

android - 如何在改造中将 JSON 数组传递到 body 中

javascript - Select2 仅显示列表中的最后一个标签

javascript - 每个隐藏输入字段的 POST 字符串化对象

ruby-on-rails - 未定义方法 `paypal_url' 为 nil :NilClass

ios - 作为第三方商家在 iOS 上使用 PayPal 账户和信用卡进行 PayPal 支付

PHP Paypal IPN 监听器因多个项目而不是单个项目而失败