Pay with Apple Pay
Last updated: Aug 15th, 7:25am
From the WLW perspective, paying with Apple Pay is the same as enabling a user to pay with any other supported tender within a mobile wallet experience. However, as described here, iOS/Apple Pay imposes some additional steps to enable Apple Pay as a payment type:
WLW SDK - Check to ensure that Payment Type of Apple Pay is returned on the
retrieveTransactionMetaData (Discovery)
request.Apple Pay - If Apple Pay is a supported tender, then use the appropriate iOS commands to check whether the user has a device that supports Apple Pay and if they have card types that your processor supports.
Apple Pay - Authorize the Payment with iOS / Apple Pay.
Apple Pay - A Payment Token Is created when a payment is authorized.
WLW SDK – Populate the
PDExtendedPaymentInstrument
field in thePDUpdateTransactionRequest
request with the Payment Token returned from Apple Pay. WLW will provide the specific key to be used for this Key / Value Pair. Thetoken.paymentMethod.displayName
that comes back from Apple Pay will look something like "AMEX 1004". Your application must populate the keyDISPLAY_NAME
with this value. In addition, your application must send the token.paymentData as metadataAPPLE_PAYMENT_DATA
. This field must useNSUTF8StringEncoding
.WLW Platform – As with any other supported tender, the WLW Platform leverages the Payment Token returned from Apple Pay to process the transaction for the appropriate Payment Provider and then returns the appropriate response code.
Here is an example of how to set metadata while paying with Apple Pay:
1#pragma mark - PKPaymentAuthorizationViewControllerDelegate23- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller4didAuthorizePayment:(PKPayment *)payment5completion:(void (^)(PKPaymentAuthorizationStatus6status))completion {78 PKPaymentToken *token = payment.token;910 PDSubmitPaymentTendersRequest *request = self.pendingApplePayRequest;11 PDExtendedPaymentInstrument *extendedPaymentInstrument = [request.extendedPaymentInstruments lastObject];1213 NSMutableArray *extendedPaymentTenderData = [NSMutableArray new];1415 NSArray *displayName = [token.paymentMethod.displayName componentsSeparatedByString:@" "];1617 PDExtendedPaymentTenderData *card_name = [PDExtendedPaymentTenderData new];18 card_name.extendedPaymentTenderDataKey = @"CARD_TYPE";19 card_name.extendedPaymentTenderDataValue = [displayName objectAtIndex:0]; // split this into card type and last 420 [extendedPaymentTenderData addObject:card_name];2122 PDExtendedPaymentTenderData *card_last4 = [PDExtendedPaymentTenderData new];23 card_last4.extendedPaymentTenderDataKey = @"LAST4";24 card_last4.extendedPaymentTenderDataValue = [displayName objectAtIndex:1]; // split this into card type and last 425 [extendedPaymentTenderData addObject:card_last4];2627 NSError *error;28 NSDictionary* json = [NSJSONSerialization JSONObjectWithData:token.paymentData options:kNilOptions error:&error];29 NSLog(@"Payment Data json %@", json);3031 PDExtendedPaymentTenderData *paymentData = [PDExtendedPaymentTenderData new];32 paymentData.extendedPaymentTenderDataKey = @"APPLE_PAYMENT_DATA";33 paymentData.extendedPaymentTenderDataValue = [[NSString alloc] initWithData:token.paymentData encoding:NSUTF8StringEncoding];34 [extendedPaymentTenderData addObject:paymentData];3536 extendedPaymentInstrument.extendedPaymentTenderData = [NSArray arrayWithArray:extendedPaymentTenderData];3738 [self.ruleEngineCoordinator submitPaymentTenders:request];39}
End-to-End Flow
Apple provides a helpful end-to-end flow diagram on this Apple Pay support site: Getting Started with Apple Pay