Search code examples
angularpaypalpaypal-sandbox

How to change Paypal's checkout shipping address dynamically?


I'm trying to implement the paypal checkout in my platform. I already saw the API's documentation and I tryied various ways they said to do it, but I couldn't make it for some reason. Right now my code is in snipped.

payment: (data, actions) => {
  return actions.payment.create({
    address_details:{
      street_number: "123",
      street_name: "Test address"       
    },
    address_portable:{
      postal_code:"4590-555",
      country_code:"PT"
    },
    payment: {
      transactions: [
        { 
          amount: { 
            total: this.TotalPrice, 
            currency: 'EUR' 
          } 
        },
      ],
      note_to_payer: "Contact us for any questions on your order.",
    }
  });
}

For you have an idea what I wanna change, please take a look at the next image. Shipping address

Thank you in advance!


Solution

  • I know this was asked a while ago. I've had a similar problem and spent a lot of time trying to work out how the API all works. The PayPal doc [here][1] isn't very clear. The solution that worked for me was to warp the details inside an address object nested in a payer object:

    payment: (data, actions) => {
      return actions.payment.create({
        payer : {
        address :{
        address_details:{
          street_number: "123",
          street_name: "Test address"       
        },
        address_portable:{
          postal_code:"4590-555",
          country_code:"PT"
        }
        }
        },
        payment: {
          transactions: [
            { 
              amount: { 
                total: this.TotalPrice, 
                currency: 'EUR' 
              } 
            },
          ],
          note_to_payer: "Contact us for any questions on your order.",
        }
      });
    }
    
    
      [1]: https://developer.paypal.com/docs/api/orders/v2/#definition-payer