Ngx-paypal for Angular 如何自定义PayPal按钮传入的收货地址
解决方案
你需要在createOrderOnClient返回的ICreateOrderRequest结构中补充shipping(自定义收货地址)和可选的application_context(地址修改权限控制)配置即可实现覆盖默认收货地址的效果,修改后的完整配置如下:
// 自定义收货地址,可替换为你业务逻辑中存储的实际地址变量 const customShippingAddress = { name: { full_name: '收件人姓名' }, address: { address_line_1: '街道地址', address_line_2: '补充地址(无则留空)', admin_area_2: '城市', admin_area_1: '省/州', postal_code: '邮编', country_code: 'CN' // 两位大写ISO 3166-1国家代码,欧元区国家填写对应代码即可 } }; this.payPalConfig = { currency: 'EUR', clientId: this.parameters.clientidpaypal, createOrderOnClient: (data) => <ICreateOrderRequest>{ intent: 'CAPTURE', // 可选配置:添加后将禁止用户在PayPal页面修改你传入的收货地址 application_context: { shipping_preference: 'SET_PROVIDED_ADDRESS' }, purchase_units: [{ amount: { currency_code: 'EUR', value: this.item.total.toString().replace(",", "."), breakdown: { item_total: { currency_code: 'EUR', value: this.item.total.toString().replace(",", ".") } } }, // 传入自定义收货地址 shipping: customShippingAddress }], } };
配置说明
shipping字段内的地址参数可直接对接你现有业务的用户地址数据,PayPal加载结账页时会自动读取该地址覆盖默认值- 不需要限制用户修改地址时,直接删除
application_context配置即可,默认状态下用户可在PayPal结账页自主调整收货地址 country_code必须使用两位大写ISO国家代码,否则会触发地址格式报错
内容的提问来源于stack exchange,提问作者Lou
相关产品推荐
相关产品推荐

