【问题标题】:Paypal Pass item sku and order reference idPaypal Pass 项目 sku 和订单参考 ID
【发布时间】:2020-04-14 08:31:14
【问题描述】:

我正在尝试使用 javascript api purchase_units 将订单发送到贝宝,但是当贝宝重定向到成功页面时,我收到错误未知 purchase_units。当我在控制台中检查 api 调用时,我在使用 purchase_units 的调用附近得到感叹号

这是我的代码

 paypal.Buttons({
        env: 'sendbox',
        style: {
            layout: 'horizontal',
            size:   'responsive',  
            shape:  'pill',        
            color:  'gold',        
            fundingicons: false,    
            tagline: false          
        },
        createOrder: function(data, actions) {
        return actions.order.create({
            purchase_units: [ {
                reference_id: "PUHF",
                description: "Some description",
                custom_id: "Something7364",
                soft_descriptor: "Great description 1",
                amount: {
                    currency_code: "USD",
                    value: "200.00",
                    breakdown: {
                        item_total: {
                            currency_code: "USD",
                            value: "200.00"
                        }
                    }
                }, items: [{
                        name: "Item 1",
                        description: "The best item ever",
                        sku: "xyz-2654",
                        unit_amount: {
                            currency_code: "USD",
                            value: "100.00"
                        },
                        quantity: "1"
                    }, {
                        name: "Item 2",
                        description: "Not bad too",
                        sku: "zdc-3942",
                        unit_amount: {
                            currency_code: "USD",
                            value: "50.00"
                        }, quantity: "2"
                    }
                ],
            }
        ]
    })}, onApprove: function(data, actions) {
            return fetch('<?= $rootPath.URL['services']['orderGet'] ?>', {
                    method: 'GET'
                }
            ).then(function(res) {
                return res.json();
            }).then(function(res) {
                window.location.href = 'pages/success.php';
            });
        }

    }).render('#paypalCheckoutContainer');

【问题讨论】:

    标签: javascript paypal paypal-sandbox


    【解决方案1】:

    我将您的 purchase_units 数组复制到一个完整的工作 HTML 示例中(下面,不要尝试在 StackOverflow 中运行它)并且没有任何问题。

    查看您的其余代码,env: sendbox 是一个错字。 onApprove 部分给我带来了麻烦,我看到那里有 PHP,但是您的代码在删除整个 onApprove 部分时有效 - 所以也许尝试不使用它进行测试然后修复它。

    <!DOCTYPE html>
    <!-- example from https://developer.paypal.com/demo/checkout/#/pattern/client -->
    
    <head>
        <!-- Add meta tags for mobile and IE -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    </head>
    
    <body>
        <!-- Set up a container element for the button -->
        <div id="paypal-button-container"></div>
    
        <!-- Include the PayPal JavaScript SDK -->
        <script src="https://www.paypal.com/sdk/js?client-id=sb&currency=USD"></script>
    
        <script>
            // Render the PayPal button into #paypal-button-container
            paypal.Buttons({
    
                // Set up the transaction
                createOrder: function(data, actions) {
                    return actions.order.create({
    
    
    // You can find a working example purchase_units at https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
      purchase_units: [ {
                    reference_id: "PUHF",
                    description: "Some description",
                    custom_id: "Something7364",
                    soft_descriptor: "Great description 1",
                    amount: {
                        currency_code: "USD",
                        value: "200.00",
                        breakdown: {
                            item_total: {
                                currency_code: "USD",
                                value: "200.00"
                            }
                        }
                    }, items: [{
                            name: "Item 1",
                            description: "The best item ever",
                            sku: "xyz-2654",
                            unit_amount: {
                                currency_code: "USD",
                                value: "100.00"
                            },
                            quantity: "1"
                        }, {
                            name: "Item 2",
                            description: "Not bad too",
                            sku: "zdc-3942",
                            unit_amount: {
                                currency_code: "USD",
                                value: "50.00"
                            }, quantity: "2"
                        }
                    ],
                }
            ]
    
      ,
      application_context: {
        brand_name: "MyBusiness",
        /*shipping_preference: 'NO_SHIPPING'*/
      }
    
    
                    }/*end of parameters to actions.order.create*/);
                },
    
                // Finalize the transaction
                onApprove: function(data, actions) {
                    return actions.order.capture().then(function(details) {
                        // Show a success message to the buyer
                        alert('Transaction completed by ' + details.payer.name.given_name + '!');
                    });
                }
    
    
            }).render('#paypal-button-container');
        </script>
    </body>

    【讨论】:

    • 运行此代码后,订单 API 在“checkout/orders/${order_id}/capture”页面上返回 NULL 数据
    • 这是 API 捕获吗?您是否尝试过客户端 javascript 捕获,只是为了查看对比是否有任何问题?由于您的问题似乎出现在捕获的那一刻,因此如果您为捕获提供示例代码,或者针对这种情况提供完整的示例 API 请求 + 响应(包括 HTTP 标头,而不仅仅是指出数据为 NULL),这将很有用.
    • 我只是使用 paypal git demo 中的代码进行服务器端集成demo.paypal.com/au/demo/…
    猜你喜欢
    • 1970-01-01
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    相关资源
    最近更新 更多