Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 409
Jsh0s Avatar asked Aug 21 '26 23:08

Jsh0s


1 Answers

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"
                },
            };
like image 50
corsaro Avatar answered Aug 24 '26 14:08

corsaro