php 如何创建一个贝宝订单与默认值的帐单和航运

k3bvogb1  于 2023-03-28  发布在  PHP
关注(0)|答案(1)|浏览(138)

我需要预先填写我的贝宝付款表格与帐单地址和送货地址。我能够完成送货细节,但不是帐单。

paypal.Buttons({
    createOrder: function(data, actions) {
        return actions.order.create({
            purchase_units: [{
                reference_id: "PUHF",
                description: "Sporting Goods",
                custom_id: "CUST-HighFashions",
                soft_descriptor: "HighFashions",
                amount: {
                    currency_code: "USD",
                    value: "220.00",
                    breakdown: {
                        item_total: {
                            currency_code: "USD",
                            value: "180.00"
                        },
                        discount: {
                            currency_code: "USD",
                            value: "10.00"
                        },
                        shipping: {
                            currency_code: "USD",
                            value: "30.00"
                        },
                        handling: {
                            currency_code: "USD",
                            value: "10.00"
                        },
                        tax_total: {
                            currency_code: "USD",
                            value: "20.00"
                        },
                        shipping_discount: {
                            currency_code: "USD",
                            value: "10.00"
                        }
                    }
                },
                items: [{
                    name: "T-Shirt",
                    description: "Green XL",
                    sku: "sku01",
                    unit_amount: {
                         currency_code: "USD",
                         value: "90.00"
                    },
                    tax: {
                        currency_code: "USD",
                        value: "10.00"
                    },
                    quantity: "1",
                    category: "PHYSICAL_GOODS"
                },
                    {
                    name: "Shoes",
                    description: "Running, Size 10.5",
                    sku: "sku02",
                    unit_amount: {
                         currency_code: "USD",
                         value: "45.00"
                    },
                    tax: {
                        currency_code: "USD",
                        value: "5.00"
                    },
                    quantity: "2",
                    category: "PHYSICAL_GOODS"
                }
                ],
                shipping: {
                    method: "United States Postal Service",
            name: {
            full_name: "John Doe"
                    },
                    address: {
                        address_line_1: "123 Townsend St",
                        address_line_2: "Floor 6",
                        admin_area_2: "San Francisco",
                        admin_area_1: "CA",
                        postal_code: "94107",
                        country_code: "US"
                    }
                }
            }]
        })
    },
    // Call your server to finalize the transaction
    onApprove: function(data, actions) {
        return fetch('/demo/checkout/api/paypal/order/' + data.orderID + '/capture/', {
            method: 'post'
        }).then(function(res) {
            return res.json();
        }).then(function(orderData) {
            // Three cases to handle:
            //   (1) Recoverable INSTRUMENT_DECLINED -> call actions.restart()
            //   (2) Other non-recoverable errors -> Show a failure message
            //   (3) Successful transaction -> Show confirmation or thank you

            // This example reads a v2/checkout/orders capture response, propagated from the server
            // You could use a different API or structure for your 'orderData'
            var errorDetail = Array.isArray(orderData.details) && orderData.details[0];

            if (errorDetail && errorDetail.issue === 'INSTRUMENT_DECLINED') {
                return actions.restart(); // Recoverable state, per:
                // https://developer.paypal.com/docs/checkout/integration-features/funding-failure/
            }

            if (errorDetail) {
                var msg = 'Sorry, your transaction could not be processed.';
                if (errorDetail.description) msg += '\n\n' + errorDetail.description;
                if (orderData.debug_id) msg += ' (' + orderData.debug_id + ')';
                return alert(msg); // Show a failure message (try to avoid alerts in production environments)
            }

            // Successful capture! For demo purposes:
            console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
            var transaction = orderData.purchase_units[0].payments.captures[0];
            alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');

            // Replace the above to show a success message within this page, e.g.
            // const element = document.getElementById('paypal-button-container');
            // element.innerHTML = '';
            // element.innerHTML = '<h3>Thank you for your payment!</h3>';
            // Or go to another URL:  actions.redirect('thank_you.html');
        });
    }
}).render('#paypal-button-container')

我需要填充账单细节。我尝试的一切都失败了,我发现贝宝文档非常不清楚。
有人能提供一点帮助吗?
我已经尝试了下面的代码,它不工作

payer: {
                  email_address: 'customer@domain.com',
                  phone: {
                    phone_number: {
                        national_number: '4543433243',
                    }
                  },
                  name: {
                    given_name: 'PayPal',
                    surname: 'Customer',
                  },
                  address: {
                    address_line_1: '123 ABC Street',
                    address_line_2: 'Apt 2',
                    admin_area_2: 'San Jose',
                    admin_area_1: 'CA',
                    postal_code: '95121',
                    country_code: 'US',
                  },
                },
rsaldnfx

rsaldnfx1#

actions.order.create(action.order.capture(已过时,不应使用。有关从后端创建和捕获订单的信息,请参阅standard checkout integration guide。node.js的示例代码在那里,当然,任何环境都可以用于实现这两种途径,包括PHP。
payer对象也已弃用,因此请勿使用该对象。可以在payment_source.paypal对象中发送账单信息,请参见此处。如果付款人使用现有PayPal帐户,则不会使用该对象。

相关问题