如何动态更改 Paypal 的结帐送货地址?

How to change Paypal's checkout shipping address dynamically?

我正在尝试在我的平台上实施贝宝结账。我已经看过 API 的文档,并且尝试了他们所说的各种方法,但由于某种原因我无法做到。现在我的代码被剪掉了。

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.",
    }
  });
}

如果你知道我想改变什么,请看下一张图片。

提前致谢!

我知道不久前有人问过这个问题。我遇到过类似的问题,并花了很多时间试图弄清楚 API 是如何工作的。 [此处][1] 的 PayPal 文档不是很清楚。对我有用的解决方案是在嵌套在 payer 对象中的 address 对象中扭曲细节:

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