使用Paypal按钮预填客户地址

时间:2019-03-18 11:20:10

标签: javascript paypal

这是我的贝宝按钮代码的样子

paypal.Buttons({
createOrder: function(data, actions) {
    // Set up the transaction
    return actions.order.create({
        purchase_units: [{
            amount: {
                value: '{{total_formatted}}',
                currency_code: '{{currency_iso}}'
            }
        }]
    });
},
style: {
    size: 'responsive',
    color: 'blue',
    shape: 'pill',
},
onApprove: function(data, actions) {
    // Capture the funds from the transaction
    return actions.order.capture().then(function(details) {
        // Show a success message to your buyer
        window.location.href = 'Some place';
    });
}
}).render('#paypal-button-container');

用户必须填写其帐单/送货地址。有什么办法可以为他预先填充吗?

预先感谢

1 个答案:

答案 0 :(得分:0)

我已经读过the docs,我认为您可以这样做,尝试一下,让我知道它是否有效

paypal.Buttons({
createOrder: function(data, actions) {
    // Set up the transaction
    return actions.order.create({
        purchase_units: [{
            amount: {
                value: '{{total_formatted}}',
                currency_code: '{{currency_iso}}'
            }
        }],
        shipping: {
          method: "United States Postal Service",
          address: {
            name: {
              give_name:"John",
              surname:"Doe"
            },
            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"
          }
        }
    });
},
style: {
    size: 'responsive',
    color: 'blue',
    shape: 'pill',
},
onApprove: function(data, actions) {
    // Capture the funds from the transaction
    return actions.order.capture().then(function(details) {
        // Show a success message to your buyer
        window.location.href = 'Some place';
    });
}
}).render('#paypal-button-container');