【问题标题】:PayPal Smart Buttons won't acknowledge items list. Ideas?PayPal 智能按钮不会确认项目列表。想法?
【发布时间】:2021-01-06 21:04:55
【问题描述】:

我在使用 PayPal 智能按钮界面时遇到问题。文档非常适得其反。

沙盒中的电子邮件样本不会显示项目描述/详细信息。它只显示总数。在他们网站上的一份文档中,items 块位于 purchase_units 块内。失败不会有真正的错误信息。

paypal.Buttons({
    createOrder: function (data, actions) {
        // Busy indicator.
        var spinner = document.getElementById("spinner");
        var cart = document.getElementById("vysshopcart");
        spinner.style.display = "block";
        cart.style.display = "none";
        // This function sets up the details of the transaction, including the amount and line item details.
        return actions.order.create({
            purchase_units: [{
                amount: {
                    value: "10",
                    "currency-code": "USD",
                    details: {
                        subtotal: "10",
                        shipping: "0",
                        tax: "0.00"
                    },
                    total: "10"
                }
            }],
            links: [{
                href: "http://192.168.249.20:81/virtual-yard-sale?invoice=2020092011397C1E",
                rel: "approve"
            }],
            "items": [
                {
                    "sku": "2",
                    "name": "Harry & David Snack Disk",
                    "price": "5.00",
                    "quantity": "1",
                    "category": "PHYSICAL_GOODS",
                    "currency": "USD"
                }
                , {
                    "sku": "10",
                    "name": "Raya Insulated Lunch Tote",
                    "price": "5.00",
                    "quantity": "1",
                    "category": "PHYSICAL_GOODS",
                    "currency": "USD"
                }
            ]
        });
    },
    onApprove: function (data, actions) {
        // This function captures the funds from the transaction.
        return actions.order.capture().then(function (details) {
            // This function shows a transaction success message to your buyer.
            window.location.replace("http://192.168.249.20:81/virtual-yard-sale?invoice=2020092011397C1E");
        });
    }
}).render('#paypal-button-container');

【问题讨论】:

标签: javascript paypal paypal-ipn


【解决方案1】:

看起来您在其他地方找到了答案,项目数组位于 purchase_units 中,但随后还需要 金额细分,例如

           amount: {
                currency_code: "EUR",
                value: "200.00",
                breakdown: {
                    item_total: {
                        currency_code: "EUR",
                        value: "200.00"
                    }
                }
            },

关于 onApprove 过程,如果可能,请考虑从您的服务器执行此操作和 createOrder。这是一个演示:https://developer.paypal.com/demo/checkout/#/pattern/server

您的服务器上需要两条路由,它们调用 /v2/checkout/orders API,一条用于“创建订单”,一条用于捕获它,documented here。

服务器集成更加健壮,假设您希望确保客户端(浏览器)不会与总数发生冲突,并且您会立即收到成功捕获的 API 响应,并且可以在您的服务器中将订单标记为已付款,在与客户端代码中的 actions.order.capture() 形成鲜明对比,这可能会影响您。

但对于交易量相对较低/简单的用例,更简单的仅客户端集成可能就足够了。

【讨论】:

    猜你喜欢
    • 2021-07-16
    • 2021-03-23
    • 2020-10-19
    • 2020-06-28
    • 2020-07-13
    • 2021-04-16
    • 2020-10-10
    • 2020-06-20
    • 2023-03-10
    相关资源
    最近更新 更多