Paypal API V2 创建订单格式错误的请求

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

尝试创建订单时,我不断收到格式错误的请求。我的 json 看起来像这样。

{
   "intent":"CAPTURE",
   "purchase_units":[
      {
         "items":[
            {
               "name":"Heartless",
               "description":"Short sleeve tshirt 230gram of 100% cotton, Heartless print on front empty back.",
               "quantity":2,
               "unit_amount":{
                  "currency_code":"EUR",
                  "value":25.0
               }
            },
            {
               "name":"NASCAR",
               "description":"Short sleeve tshirt 230gram of 100% cotton, NASCAR car print on front empty back.",
               "quantity":1,
               "unit_amount":{
                  "currency_code":"EUR",
                  "value":25.0
               }
            }
         ],
         "amount":{
            "currency_code":"EUR",
            "value":"75"
         },
         "custom_id":65
      }
   ],
   "application_context":{
      "return_url":"https://localhost:3000/order/success",
      "cancel_url":"https://localhost:3000/cancel"
   }
}

这里是api的文档。 https://developer.paypal.com/docs/api/orders/v2/#orders_create 我期待着大家的回答。预先感谢!

编辑

{
   "intent":"CAPTURE",
   "purchase_units":[
      {
         "items":[
            {
               "name":"Heartless",
               "description":"Short sleeve tshirt 230gram of 100% cotton, Heartless print on front empty back.",
               "quantity":2,
               "unit_amount":{
                  "currency_code":"EUR",
                  "value":25.0
               }
            },
            {
               "name":"NASCAR",
               "description":"Short sleeve tshirt 230gram of 100% cotton, NASCAR car print on front empty back.",
               "quantity":1,
               "unit_amount":{
                  "currency_code":"EUR",
                  "value":25.0
               }
            }
         ],
         "amount":{
            "currency_code":"EUR",
            "value":"75",
            "breakdown":{
               "item_total":{
                  "currency_code":"EUR",
                  "value":"75"
               }
            }
         },
         "custom_id":65
      }
   ],
   "application_context":{
      "return_url":"https://localhost:3000/order/success",
      "cancel_url":"https://localhost:3000/cancel"
   }
}

这是我的错误:

"status": "success",
  "url": {
    "name": "INVALID_REQUEST",
    "message": "Request is not well-formed, syntactically incorrect, or violates schema.",
    "debug_id": "94d5cca2ed833",
    "details": [
      {
        "location": "body",
        "issue": "MALFORMED_REQUEST_JSON",
        "description": "The request JSON is not well formed."
      }
    ],
    "links": [
      {
        "href": "https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON",
        "rel": "information_link",
        "encType": "application/json"
      }
    ]
  }
}

添加“故障”时,此错误没有改变我之前也遇到过这个问题,但在文档中看到它不是必需的

json paypal
1个回答
0
投票

该错误不是格式错误的请求。错误为 UNPROCESSABLE_ENTITY、ITEM_TOTAL_REQUIRED。

当purchase_unit包含

items
数组时,它还必须包含细分金额(
amount.breakdown.item_total.value
amount.breakdown.item_total.currency_code
)。

金额总计必须与细分项目总计加上任何其他总计相匹配,并且 item_total 必须对应于 items 数组的总计。

© www.soinside.com 2019 - 2024. All rights reserved.