将详细信息添加到 PayPal Checkout 购买(如标题)

时间:2021-06-30 20:00:17

标签: javascript paypal

我的网站上目前有一家由 PayPal 提供支持的数字商店。我正在尝试为我的购买添加标题,以便客户在查看交易历史记录时知道购买了什么。我试图在 PayPal Checkout 文档中找出方法,但我不太明白其中的内容以及如何实现它。

function paypal_render(price, tier) {
    paypal.Buttons({
        style : {
            color: 'blue',

        },
        createOrder: function (data, actions) {
            return actions.order.create({
                purchase_units : [{
                    amount: {
                        currency_code: 'USD',
                        value: ''+price
                    },
                }],
                application_context: {
                    shipping_preference: "NO_SHIPPING",
                },
                item: {
                    title: "PEANUTS LAB - TIER " + tier + "DONATION",
                }
            });
        },
        onApprove: function (data, actions) {
            return actions.order.capture().then(function (details) {
                console.log(details)
            })
        }
    }).render('#paypal');
}

以下是当前脚本中沙盒顺序的样子: enter image description here

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您链接到了一个商品对象的定义,但您需要提供一个数组,其中包含键为 items 的商品对象,如 purchase_unit 对象的详细说明。 >

v2/checkout/orders 创建的根 API 架构是 documented here

这是一个完整的示例,其中包含一个项目并包括所需的金额明细。

{
  "intent": "CAPTURE",
  "purchase_units": [
    {
      "amount": {
        "currency_code": "USD",
        "value": "500",
        "breakdown": {
          "item_total": {
            "currency_code": "USD",
            "value": "500"
          }
        }
      },
      "items": [
        {
          "name": "Name of Item #1 (can be viewed in the upper-right dropdown during payment approval)",
          "description": "Optional description; item details will also be in the completed paypal.com transaction view",
          "unit_amount": {
            "currency_code": "USD",
            "value": "500"
          },
          "quantity": "1"
        }
      ]
    }
  ]
}

任何与 API 架构不对应的字段都将被忽略,如您问题的示例