applepayapplepayjs

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


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);

Solution

  • 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.