【问题标题】:PayPal Checkout SDK breakdown object raising errorPayPal Checkout SDK 分解对象引发错误
【发布时间】:2021-11-15 11:44:29
【问题描述】:

我正在尝试在我正在开发的店面中使用 PayPal Checkout SDK 处理付款。我正在尝试为所有订单添加 10 美元的运费。查看 SDK documentation 我相信我需要使用 amountbreakdown 对象。

代码

      createOrder: (data, actions) => {
        return actions.order.create({
          purchase_units: [{
            amount: {
              breakdown: {
                item_total: {currency_code: "USD", value: "32"},
                shipping: {currency_code: "USD", value: "10"}
              }
            }
          }]
        })
      }

错误

Uncaught Error: /v2/checkout/orders returned status 400 (Corr ID: 46c2d60c192b).

{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"46c2d60c192b","details":[{"field":"/purchase_units/@reference_id=='default'/amount/value","value":"","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field / parameter is missing."}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-MISSING_REQUIRED_PARAMETER","rel":"information_link","encType":"application/json"}]}

【问题讨论】:

    标签: typescript paypal checkout


    【解决方案1】:

    金额本身需要一个 value 和 currency_code,与任何提供细分的额外对象分开。

    请参阅this documentation 的第 6 个项目符号中的完整示例:

    createOrder: function(data, actions) {
          return actions.order.create({
             "purchase_units": [{
                "amount": {
                  "currency_code": "USD",
                  "value": "100",
                  "breakdown": {
                    "item_total": {  /* Required when including the `items` array */
                      "currency_code": "USD",
                      "value": "100"
                    }
                  }
                },
                "items": [
                  {
                    "name": "First Product Name", /* Shows within upper-right dropdown during payment approval */
                    "description": "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
                    "unit_amount": {
                      "currency_code": "USD",
                      "value": "50"
                    },
                    "quantity": "2"
                  },
                ]
              }]
          });
        },
    

    【讨论】:

      猜你喜欢
      • 2020-10-30
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2015-12-28
      • 2018-04-27
      • 2011-08-17
      • 2017-05-31
      • 2021-10-25
      相关资源
      最近更新 更多