简体   繁体   中英

JavaScript - Paypal API, how do I change the shipping address?

I've been trying to figure this out in the documentation, I found the address thing right here:

https://developer.paypal.com/docs/api/payments/v2/#definition-address_portable

But I have no idea how to implement that change on my Paypal checkout button, there are no examples on how to implement it, does anyone know how?

This is what my Paypal sandbox checkout looks like right now (I skipped everything below createOrder )

<script>
   paypal.Buttons({

      createOrder: function(data, actions) {

         return actions.order.create({

            purchase_units: [{
               amount: {
                  value: '<?=$total?>'
               },
                  description: '<?=$description?>'
               }]
         });
      }

      // Skipped...

</script>

use this structure of json

create_payment_json = {
                "intent": "sale",
                "payer": {
                    "payment_method": "paypal"
                },
                "transactions": [
                    {
                    "amount": {
                        "total": totalPlusTax.toFixed(2), //"30.11",
                        "currency": "USD",
                        "details": {
                            "subtotal": totalPrice, //"30.00",
                            "tax": "0.07",
                            "shipping": "0.03",
                            "handling_fee": "1.00",
                            "shipping_discount": "-1.00",
                            "insurance": "0.01"
                          }
                    },
                    "item_list": { 
                        items,
                        "shipping_address": {
                            "recipient_name": "Brian Robinson",
                            "line1": "4th Floor",
                            "line2": "Unit #34",
                            "city": "San Jose",
                            "state": "CA",
                            "phone": "12345678",
                            "postal_code": "95131",
                            "country_code": "US"
                          }
                    },
                    "description": "This is the payment description."
                }
                ],
                "redirect_urls": {
                    "return_url": "http://localhost:3000/execute",
                    "cancel_url": "http://localhost:3000/cancel"
                },
            };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM