Apple使用stripe.js在网上付费,填充弹出窗口(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);

I am testing the Apple Pay JS, I have it working completely. However, I would like to populate the confirmation popup (the one that asks to accept the purchase) with some other fields, like user's name or address. The documentation says it can be done, but there are no examples. Here is the code I am referring to:

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

最满意答案

这当然可以做到。

PaymentRequest对象允许您包含shippingContact对象,该对象是送货字典。 可用字段列在PaymentContact页面上。

所以你的PaymentRequest看起来像

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

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

This can most certainly be done.

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

So your PaymentRequest will look like

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

When you pass this information to the PaymentRequest, that address will show up in the Paysheet. It will not add the contact to their list of contacts, and they can still overwrite it with their own contacts, but that address will be what shows in the Paysheet by default.

更多推荐