Pay with Apple Pay

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:

  1. WLW SDK - Check to ensure that Payment Type of Apple Pay is returned on the retrieveTransactionMetaData (Discovery) request.

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

  3. Apple Pay - Authorize the Payment with iOS / Apple Pay.

  4. Apple Pay - A Payment Token Is created when a payment is authorized.

  5. WLW SDK – Populate the PDExtendedPaymentInstrument field in the PDUpdateTransactionRequest request with the Payment Token returned from Apple Pay. WLW will provide the specific key to be used for this Key / Value Pair. The token.paymentMethod.displayName that comes back from Apple Pay will look something like "AMEX 1004". Your application must populate the key DISPLAY_NAME with this value. In addition, your application must send the token.paymentData as metadata APPLE_PAYMENT_DATA. This field must use NSUTF8StringEncoding.

  6. 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:

#pragma mark - PKPaymentAuthorizationViewControllerDelegate

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
didAuthorizePayment:(PKPayment *)payment
completion:(void (^)(PKPaymentAuthorizationStatus
status))completion {

    PKPaymentToken *token = payment.token;

    PDSubmitPaymentTendersRequest *request = self.pendingApplePayRequest;
    PDExtendedPaymentInstrument *extendedPaymentInstrument = [request.extendedPaymentInstruments lastObject];

    NSMutableArray *extendedPaymentTenderData = [NSMutableArray new];

    NSArray *displayName = [token.paymentMethod.displayName componentsSeparatedByString:@" "];

    PDExtendedPaymentTenderData *card_name = [PDExtendedPaymentTenderData new];
    card_name.extendedPaymentTenderDataKey = @"CARD_TYPE";
    card_name.extendedPaymentTenderDataValue = [displayName objectAtIndex:0]; // split this into card type and last 4
    [extendedPaymentTenderData addObject:card_name];

    PDExtendedPaymentTenderData *card_last4 = [PDExtendedPaymentTenderData new];
    card_last4.extendedPaymentTenderDataKey = @"LAST4";
    card_last4.extendedPaymentTenderDataValue = [displayName objectAtIndex:1]; // split this into card type and last 4
    [extendedPaymentTenderData addObject:card_last4];

    NSError *error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:token.paymentData options:kNilOptions error:&error];
    NSLog(@"Payment Data json %@", json);

    PDExtendedPaymentTenderData *paymentData = [PDExtendedPaymentTenderData new];
    paymentData.extendedPaymentTenderDataKey = @"APPLE_PAYMENT_DATA";
    paymentData.extendedPaymentTenderDataValue = [[NSString alloc] initWithData:token.paymentData encoding:NSUTF8StringEncoding];
    [extendedPaymentTenderData addObject:paymentData];

    extendedPaymentInstrument.extendedPaymentTenderData = [NSArray arrayWithArray:extendedPaymentTenderData];

    [self.ruleEngineCoordinator submitPaymentTenders:request];

End-to-End Flow

Apple provides a helpful end-to-end flow diagram on this Apple Pay support site: Getting Started with Apple Pay