10

While trying to setup Apple Pay in an iOS app we've run into an issue with the API and pre-filling information. Our user flow allows the user to manually set their address, email and phone prior to paying with Apple Pay, so we want to be sure to fill the Apple Pay prompt with their inputs if they decide to do so.

According to the development guide, this should be as simple as setting these values in the request.shippingContact. However, when we do this, the values are ignored.

Is there something the documentation is not telling us?

PKContact *contact = [[PKContact alloc] init];  
contact.emailAddress = @"john@appleseed.com";
contact.phoneNumber = [[CNPhoneNumber alloc] initWithStringValue:@"5555555"];

NSPersonNameComponents *name = [[NSPersonNameComponents alloc] init];
name.givenName = @"John";
name.familyName = @"Appleseed";
contact.name = name;

request.billingContact = contact;
request.shippingContact = contact;
request.requiredBillingAddressFields = PKAddressFieldAll;
request.requiredShippingAddressFields = PKAddressFieldEmail | PKAddressFieldPhone;

Apple Pay Sample

Nathan Taylor
  • 23,720
  • 17
  • 90
  • 152
  • Did you find a solution to this Nathan? – James Anderson Aug 25 '16 at 14:51
  • @JamesAnderson what version of Xcode/iOS are you using? Could you please clarify what is your environment and what is the problem (billing address is missing or email is missing)? Can't reproduce the bug at Xcode 8 beta 6 / iOS Simulator 9-10. – Roman Ermolov Aug 28 '16 at 22:20

1 Answers1

3

As mentioned in the documentation we need to validate the address values properly. We should pass valid address with valid postal code, see code below.

PKContact *contact = [[PKContact alloc] init];

NSPersonNameComponents *name = [[NSPersonNameComponents alloc] init];
name.givenName = @"John";
name.familyName = @"Appleseed";

contact.name = name;

CNMutablePostalAddress *address = [[CNMutablePostalAddress alloc] init];
address.street = @"1234 Laurel Street";
address.city = @"Atlanta";
address.state = @"GA";
address.postalCode = @"30303";

Also check:


NOTE

Address information can come from a wide range of sources in iOS. Always validate the information before you use it.

Arun Ammannaya
  • 4,565
  • 11
  • 14