0

我在我的网站上有一个贝宝付款。看起来像这样:

app.post('/pay', (req, res) => {
    console.log(req.body);
    const create_payment_json = {
        "intent": "sale",
        "payer": {
            "payment_method": "paypal"
        },
        "redirect_urls": {
            "return_url": "http://localhost:1234/success",
            "cancel_url": "http://localhost:1234/cancel"
        },
        "transactions": [{
            "item_list": {
                "items": [{
                    "name": req.body.user_name,
                    "sku": "001",
                    "price": "25",
                    "currency": "USD",
                    "quantity": req.body.persons_count
            }]
            },
            "amount": {
                "currency": "USD",
                "total": "25"
            },
            "description": req.body.user_name + " with email " + req.body.email + " just ordered " + req.body.persons_count + " places"
    }]
    };

    paypal.payment.create(create_payment_json, function (error, payment) {
        if (error) {
            throw error;
        } else {
            res.send('on my way');
            console.log(payment);
        }
    });
})

如果我更改金额对象中的总字段(这是我想做的),我会收到 400 响应(错误请求)。我怎样才能进行这样的付款:

"amount":{
"total": req.body.persons_count * 2
}

其中req.body.persons_countvariable 是我从之前的一种表单的发布请求中获得的变量。

与该代码的斗争表明,两者pricetotal价值必须相等,但是我希望单个项目的价格与我想要获得的总金额不同。非常感谢!

顺便说一句,数量值必须等于 1。在所有其他情况下,应用程序崩溃。

4

1 回答 1

0

总金额应为物品金额、运费、税金和其他费用的总和。

在您的情况下,总计:商品价格 * 商品数量

样本,

 "transactions": [
        {
            "amount": {
                "currency": "USD",
                "total": "20",
                "details": {
                    "shipping": "1.20",
                    "tax": "1.30",
                    "subtotal": "17.50"
                }
            },
            "description": "Payment description",
            "invoice_number": "1231123524",
            "custom": "custom data",
            "item_list": {
                "items": [
                    {
                        "name": "Ground Coffee 40 oz",
                        "currency": "USD",
                        "quantity": 1,
                        "price": "7.50"
                    },
                    {
                        "name": "Granola bars",
                        "currency": "USD",
                        "quantity": 5,
                        "price": "2"
                    }
                ]
            }
        }
    ]

您也可以参考https://developer.paypal.com/docs/api/payments/v1/#payment_create

于 2019-04-25T08:51:10.103 回答