【发布时间】:2021-01-03 12:24:40
【问题描述】:
我出售的商品价格和币种不同,具体取决于送货地址。
如果用户有两个地址,一个在美国,另一个在英国,他们将能够通过 PayPal 更改收货地址。当用户将地区从美国更改为英国时,PayPal 会通知我的网站,地区发生了变化,它会回复新的货币和价格,从 345 美元变为 305 英镑。
当 PayPal 收到此更新时,PayPal 会向客户显示一个错误。在网络选项卡中有更多见解,可以找到以下错误:CANNOT_MIX_CURRENCIES。但是,项目价格和总价格都转换为所需货币,因此没有“混合”货币。以下是生成错误的请求和随附的响应。
请求:PATCH -> www.sandbox.paypal.com/smart/api/order/890595684S747592L/patch
{
"data":{
"patch":[
{
"op":"replace",
"path":"/purchase_units/@reference_id=='xxx'",
"value":{
"reference_id":"xxx",
"invoice_id":"xxx",
"custom_id":1,
"description":"xxx",
"amount":{
"currency_code":"GBP",
"value":"305.00",
"breakdown":{
"item_total":{
"currency_code":"GBP",
"value":"305.00"
},
"shipping":{
"currency_code":"GBP",
"value":"0.00"
},
"tax_total":{
"currency_code":"GBP",
"value":"0.00"
},
"discount":{
"currency_code":"GBP",
"value":"0.00"
}
}
},
"items":[
{
"name":"xxx",
"sku":"xxx",
"currency":"GBP",
"quantity":1,
"category":"PHYSICAL_GOODS",
"unit_amount":{
"currency_code":"GBP",
"value":"305.00"
}
}
]
}
}
]
}
}
回复:
{
"ack":"contingency",
"contingency":"UNPROCESSABLE_ENTITY",
"data": {
"name":"UNPROCESSABLE_ENTITY",
"details":[{
"location":"body",
"issue":"CANNOT_MIX_CURRENCIES",
"description":"CANNOT_MIX_CURRENCIES"
}],
"message":"The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id":"xxx",
"links":[{
"href":"https://developer.paypal.com/docs/api/orders/v2/#error-CANNOT_MIX_CURRENCIES",
"rel":"information_link",
"method":"GET"
}]
},
"meta":{"calc":"xxx","rlog":"xxx"},
"server":"xxx"
}
以下是创建上述购买单元的请求(和响应)。
请求:POST -> POST -> www.sandbox.paypal.com/v2/checkout/orders
{
"intent":"CAPTURE",
"purchase_units":[
{
"reference_id":"xxx",
"invoice_id":"xxx",
"custom_id":1,
"description":"xxx",
"amount":{
"currency_code":"USD",
"value":"345.00",
"breakdown":{
"item_total":{
"currency_code":"USD",
"value":"345.00"
},
"shipping":{
"currency_code":"USD",
"value":"0.00"
},
"tax_total":{
"currency_code":"USD",
"value":"0.00"
},
"discount":{
"currency_code":"USD",
"value":"0.00"
}
}
},
"items":[
{
"name":"xxx",
"sku":"xxx",
"currency":"USD",
"quantity":1,
"category":"PHYSICAL_GOODS",
"unit_amount":{
"currency_code":"USD",
"value":"345.00"
}
}
]
}
],
"application_context":{
"shipping_preference":"GET_FROM_FILE"
}
}
回复:
{
"id":"xxx",
"status":"CREATED",
"links":[
{
"href":"https://api.sandbox.paypal.com/v2/checkout/orders/xxx",
"rel":"self",
"method":"GET"
},
{
"href":"https://www.sandbox.paypal.com/checkoutnow?token=xxx",
"rel":"approve",
"method":"GET"
},
{
"href":"https://api.sandbox.paypal.com/v2/checkout/orders/xxx",
"rel":"update",
"method":"PATCH"
},
{
"href":"https://api.sandbox.paypal.com/v2/checkout/orders/xxx/capture",
"rel":"capture",
"method":"POST"
}
]
}
我通过react-paypal-button-v2 npm 包使用PayPal Orders API v2。
“CANNOT_MIX_CURRENCIES”的文档提到购买单位中的所有货币必须相同,但没有提到不能更改购买单位货币。令人困惑的是,我只能在 Billing Agreements API v1 中找到这个错误(“CANNOT_MIX_CURRENCIES”)的提及。
CANNOT_MIX_CURRENCIES
货币代码无效。所有货币代码都非常匹配。对所有金额对象使用相同的货币代码。
【问题讨论】:
标签: reactjs paypal paypal-sandbox paypal-rest-sdk