![](/img/trans.png)
[英]PayPal Checkout (javascript) with Smart Payment Buttons create order problem
[英]PayPal Checkout with Smart Payment Buttons (React + Redux) create order problem
每当我尝试处理付款时,我都会收到422 error: Unprocessable entity
。 当我动态地想要捕获从 redux 商店收到的购买项目详细信息时,就会出现问题。
我尝试遵循这种格式(重复): PayPal Checkout (javascript) with Smart Payment Buttons create order problem
这与 PayPal 文档中的相同: https://developer.paypal.com/docs/api/orders/v2/#definition-item
但是,这无济于事。 这是我的代码
import React, {useState, useEffect, useRef} from 'react';
import {useSelector, useDispatch} from 'react-redux'
const mapState = ({ cart }) => ({
itemsInCart: cart.itemsInCart,
total: cart.total
})
const Cart = props => {
const {itemsInCart} = useSelector(mapState);
useEffect(() => {
const itemsObj = itemsInCart.map(item => {
return {
name: item.name,
description: item.description,
unit_amount: {
currency_code: "USD",
value: item.price
},
quantity: "1"
}
})
window.paypal
.Buttons({
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [
{
description: "Your purchase details",
amount: {
currency_code: 'USD',
value: document.getElementById('totalAmount').innerHTML
},
items: itemsObj
},
],
});
}
如果我将items
属性更改为item_list
,正如我在某些文档中看到的那样,付款会通过,但不会捕获项目 object。 我不知道为什么。
如果您想将行项目捕获为 items 属性,则必须在 amount 属性中指定细分,如下所示:
purchase_units: [
{
description: "test",
amount: {
currency_code: "USD",
value: price,
breakdown: {
item_total: {
currency_code: "USD",
value: document.getElementById("totalAmount").innerHTML
}
}
这篇文章对于完整的代码示例也很有帮助: https://www.paypal-community.com/t5/REST-APIs/PayPal-Checkout-javascript-with-Smart-Payment-Buttons-create/mp/1824785#M2816
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.