贝宝订单创建:状态 422,尽管值匹配但金额不匹配错误

PayPal Orders Create: Status 422, amount mismatch error despite matching values

我收到来自 paypal 的 422 UNPROCESSABLE_ENTITY 错误,表明我的 amount->valuebreakdown 值不匹配,但据我所知它们不匹配'吨。请求正文如下:

"amount": {
  "currency_code": "USD",
  "value": 5,
  "breakdown": {
    "item_total": {
      "value": 10,
      "currency_code": "USD",
      "discount": {
        "value": 5,
        "currency_code": "USD"
      }
    }
  }
}

错误消息说 amount->valueShould equal item_total + tax_total + shipping + handling + insurance - shipping_discount - discount.

既然我没有shipping/handling/insurance/etc,不就是5(amount) = 10(item_total) - 5(discount)吗?我在这里错过了什么?

此外,以防万一,我的采购单位中只有一件商品:

"items": [
  {
    "name": "...",
    "unit_amount": {
      "value": 10,
      "currency_code": "USD"
    },
    "quantity": 1,
    "category": "DIGITAL_GOODS"
  }
]

discountwrong place 这里:

"breakdown": {
   "item_total": {
     "value": 10,
     "currency_code": "USD",
     "discount": {
       "value": 5,
       "currency_code": "USD"
     }
   }
 }

将它移出 item_total(它作为未知字段被忽略),并移到它所属的父 breakdown 对象中。

对于 PHP 那将是:

$request->body = [
        'intent' => 'CAPTURE',
        'purchase_units' => [
            [
                'invoice_id' => 'some-id',
                'amount' => [
                    'value' => 15,
                    'currency_code' => 'EUR',
                    'breakdown' => [
                        'shipping' => [
                            'value' => 5,
                            'currency_code' => 'EUR',
                        ],
                        'item_total' => [
                            'value' => 10,
                            'currency_code' => 'EUR',
                        ]
                    ],
                ],
            ],
        ],
        'application_context' => [
            'cancel_url' => $cancelUrl,
            'return_url' => $returnUrl,
        ],
    ];