【问题标题】:How to change total according to item quantity如何根据项目数量更改总计
【发布时间】:2019-09-09 01:26:11
【问题描述】:

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

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_count 变量是我从之前的一种表单的发布请求中获得的变量。

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

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

【问题讨论】:

    标签: node.js paypal-rest-sdk


    【解决方案1】:

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

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

    样本,

     "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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多