使用 stripe.js 的网页版 Apple Pay,填充弹出窗口

Apple Pay on web using stripe.js, populating the popup

我正在测试 Apple Pay JS,它可以正常工作。但是,我想用其他一些字段填充确认弹出窗口(要求接受购买的弹出窗口),例如用户名或地址。文档说可以做到,但是没有例子。这是我指的代码:

var request = {
countryCode: 'US',
currencyCode: 'USD',
supportedNetworks: ['visa', 'masterCard'],
merchantCapabilities: ['supports3DS'],
total: { label: 'Your Label', amount: '10.00' },
}
var session = new ApplePaySession(1, request);

据我所知,您无法使用 JavaScript API 将联系信息写入 Apple Pay sheet,只能读取用户输入的值。预先设定的值来自 phone 来自为用户之前的 Apple Pay 会话输入的详细信息,无论是在网络上还是在应用程序中,然后由设备保存到钱包中。

您可以从传递给 onshippingcontactselected function, with everything being returned in the event passed to the onpaymentauthorized 函数的事件中读取 部分 联系方式。

这绝对可以做到。

PaymentRequest object allows you to include a shippingContact object that is a shipping dictionary. The available fields are listed on their PaymentContact 页面。

所以您的 PaymentRequest 看起来像

var request = {
countryCode: 'US',
currencyCode: 'USD',
supportedNetworks: ['visa', 'masterCard'],
merchantCapabilities: ['supports3DS'],
total: { label: 'Your Label', amount: '10.00' },
shippingContact: {
  givenName: 'Martin', familyName: 'Whosebug',
  addressLines: ['123 Main St', 'Apt: 5'],
  locality: 'Whoville',
  administrativeArea: 'FL',
  postalCode: '43210',
  country: 'US'
}  
}
var session = new ApplePaySession(1, request);

当您将此信息传递给 PaymentRequest 时,该地址将显示在付款表中。它不会将联系人添加到他们的联系人列表中,他们仍然可以用自己的联系人覆盖它,但该地址将默认显示在薪资表中。