为什么添加商品后 Paypal Checkout 返回错误?

问题描述 投票:0回答:1

我正在尝试使用 Javascript SDK 创建 PayPal 订单。如果 PayPal 不返回非描述性 400 错误,我就无法添加商品。

这个标记效果很好:

return actions.order.create({
  purchase_units: [{
    description: "Stuff",
    amount: {
      value: '57.49',
      currency_code: "CAD",
    },
  }],
  application_context: {
    brand_name: "MyBusiness",
    shipping_preference: 'NO_SHIPPING'
  }
});

此标记,我添加了金额细目,而项目则没有:

return actions.order.create({
  purchase_units: [{
    description: "Stuff",
    amount: {
      value: '57.49',
      currency_code: "CAD",
      breakdown: {
        item_total: '57.49',
      }
    },
    items: [{
      unit_amount: '57.49',
      quantity: '1',
      name: "item 1",
    }],
  }],
  application_context: {
    brand_name: "MyBusiness",
    shipping_preference: 'NO_SHIPPING'
  }
});

我正在关注此文档:

https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request

https://developer.paypal.com/docs/api/orders/v2/#definition-item

我猜我添加故障的方式不起作用。但规范暗示它是数量 -> 细分。

paypal paypal-rest-sdk
1个回答
0
投票

2024 编辑:actions.order.create 已弃用,v2/checkout/orders create 的有效负载只能从服务器发送。请参阅标准集成指南:https://developer.paypal.com/docs/checkout/standard/integrate/

application_context 也已弃用,请使用

payment_source.paypal.experience_context
代替(请参阅 API 参考

{
      "purchase_units": [{
          "description": "Stuff",
          "amount": {
            "value": "57.49",
            "currency_code": "CAD",
            "breakdown": {
              "item_total": {
                "currency_code": "CAD",
                "value": "57.49"
              },
            }
          },
          "items": [
            {
              "unit_amount": {
                "currency_code": "CAD",
                "value": "57.49"
              },
              "quantity": "1",
              "name": "item 1",
            },
          ],
        }
      ],
      "application_context": {
        "shipping_preference": 'NO_SHIPPING'
      }
}
© www.soinside.com 2019 - 2024. All rights reserved.