Apple Pay

The 2C2P PGW SDK allows merchants to accept payments from Apple Pay.

πŸ“˜

API Method

PGW SDK API Interface

🚧

References

SDK Payment Classes
SDK Payment Enums

Prerequisite

Refer all the steps and images from following link.

πŸ“˜

Apple Pay Prerequisite

1. Generate Payment Token

To prepare a payment token request, refer to the required parameters below.

πŸ“˜

Payment Token API

Refer to: Payment Token API

{
    "merchantID": "JT01",
    "invoiceNo": "1595219400",
    "description": "2 days 1 night hotel room",
    "amount": 10.0,
    "currencyCode": "SGD",
    "nonceStr": "a8092512-b144-41b0-8284-568bb5e9264c",
    "paymentChannel": ["DPAY"]
}

2. Receive Payment Token Response

To receive a payment token response, refer to the sample payment token response below. The response will contain the payment token ID which must be passed to the merchant application.

NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"

3. Retrieve Payment Provider Info from Payment Option Details API.

To receive a payment provider info, refer to the sample payment option detail response below.

NSArray<PaymentChannel *> *filteredPaymentChannels = [[paymentOptionDetailResponse.channels mutableCopy] filteredArrayUsingPredicate: [NSPredicate predicateWithBlock: ^BOOL(PaymentChannel *paymentChannel, NSDictionary *bindings) {
         
    return [paymentChannel.context.code.channelCode caseInsensitiveCompare: @"APPLEPAY"] == NSOrderedSame;
}]];

PaymentProvider *paymentProvider = filteredPaymentChannels.count > 0 ? filteredPaymentChannels[0].context.info.paymentProvider : nil;
let paymentProvider: PaymentProvider? = paymentOptionDetailResponse.channels.filter({ $0.context.code.channelCode == "APPLEPAY" }).first?.context.info.paymentProvider

πŸ“˜

Payment Option Detail Parameter

Payment Option Detail Request Parameter

Payment Option Detail Response Parameter

4. Construct Apple Pay Token Request

PaymentProviderRequest *paymentProviderRequest = [[[[PaymentProviderBuilder alloc] init]
                                                     paymentProvider: paymentProvider]
                                                     build];
     
[[PGWSDKHelper shared] proceedApplePayPaymentWithPaymentProviderRequest: paymentProviderRequest response: ^(ApplePayPaymentResultResponse * _Nonnull response) {
         
     if([response.responseCode isEqualToString: ApplePayPaymentResponseCode.TokenGeneratedSuccess]) {
            
       } else {
             
           //Get error response and display error.
       }
} failure: ^(NSError * _Nonnull error) {
         
     //Get error response and display error.
}];
let paymentProviderRequest: PaymentProviderRequest = PaymentProviderBuilder()
                                                     .paymentProvider(paymentProvider!)
                                                     .build()
         
PGWSDKHelper.shared.proceedApplePayPayment(paymentProviderRequest: paymentProviderRequest, { (response: ApplePayPaymentResultResponse) in
             
     if response.responseCode == ApplePayPaymentResponseCode.TokenGeneratedSuccess {
                 
     } else {
                 
           //Get error response and display error
     } 
}) { (error: NSError) in
 
     //Get error response and display error
}

5. Construct Apple Pay Payment Request

To prepare an e-wallet payment request, refer to the sample code below.

πŸ“˜

Payment Request Parameters

Refer to Payment Request API Parameters

🚧

Payment Channel Matrix

Refer to the payment channel codes for the Apple Pay e-wallet below.

Category CodeGroup CodeChannelNameCountry
DPAYCWALLETAPPLEPAYApple PayGlobal
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"APPLEPAY"];
 
PaymentRequest *paymentRequest = [[[[[[DigitalPaymentBuilder alloc] initWithPaymentCode: paymentCode]
                                     name: @"DavidBilly"]
                                     email: @"[email protected]"]
                                     token: response.token]
                                     build];
let paymentCode: PaymentCode = PaymentCode(channelCode: "APPLEPAY")

let paymentRequest: PaymentRequest = DigitalPaymentBuilder(paymentCode: paymentCode)
                                    .name("DavidBilly")
                                    .email("[email protected]")
                                    .token(response.token)
                                    .build()

6. Construct Transaction Request

To prepare a transaction request, refer to the parameters and sample code below.

πŸ“˜

Transaction Request API Parameters

Refer to: Do Payment Request API Parameters

TransactionResultRequest *transactionResultRequest = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
                                                       withPaymentRequest: paymentRequest]
                                                       build];
let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
                                                        .with(paymentRequest)
                                                        .build()

7. Execute Payment Request

To receive a transaction request response, refer to the parameters below.

πŸ“˜

Transaction Response API Parameter

Refer to: Do Payment Response API Parameters

🚧

References

Response Code
To view payment process flows based on response code, refer to: Payment Flow Response Codes

[[PGWSDK shared] proceedTransactionWithTransactionResultRequest: transactionResultRequest response: ^(TransactionResultResponse * _Nonnull response) {
               
   if([response.responseCode isEqualToString: APIResponseCode.TransactionCompleted]) {
                   
        //Inquiry payment result by using invoice no.
   } else {
                   
        //Get error response and display error.
   }
} failure: ^(NSError * _Nonnull error) {
               
    //Get error response and display error.
}];
PGWSDK.shared.proceedTransaction(transactionResultRequest: transactionResultRequest, { (response: TransactionResultResponse) in

    if response.responseCode == APIResponseCode.TransactionCompleted {
             
          //Inquiry payment result by using invoice no.
    } else {
            
          //Get error response and display error
    }
}) { (error: NSError) in
        
    //Get error response and display error
}

πŸ‘

Callback for PGW Payment Authentication

Refer to: Handle PGW Payment Authentication

Full Sample Code

The following sample code demonstrates requests and parameters for each step of the process.

//Step 2: Generate payment token id.
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 3: Retrieve payment provider info from Payment Option Details API.
NSArray<PaymentChannel *> *filteredPaymentChannels = [[paymentOptionDetailResponse.channels mutableCopy] filteredArrayUsingPredicate: [NSPredicate predicateWithBlock: ^BOOL(PaymentChannel *paymentChannel, NSDictionary *bindings) {
         
    return [paymentChannel.context.code.channelCode caseInsensitiveCompare: @"APPLEPAY"] == NSOrderedSame;
}]];
     
PaymentProvider *paymentProvider = filteredPaymentChannels.count > 0 ? filteredPaymentChannels[0].context.info.paymentProvider : nil;
     
//Step 4: Construct apple pay token request.
PaymentProviderRequest *paymentProviderRequest = [[[[PaymentProviderBuilder alloc] init]
                                                     paymentProvider: paymentProvider]
                                                     build];
     
[[PGWSDKHelper shared] proceedApplePayPaymentWithPaymentProviderRequest: paymentProviderRequest response: ^(ApplePayPaymentResultResponse * _Nonnull response) {
         
     if([response.responseCode isEqualToString: ApplePayPaymentResponseCode.TokenGeneratedSuccess]) {
             
          //Step 5: Construct apple pay payment request.
          PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"APPLEPAY"];
             
          PaymentRequest *paymentRequest = [[[[[[DigitalPaymentBuilder alloc] initWithPaymentCode: paymentCode]
                                                 name: @"DavidBilly"]
                                                 email: @"[email protected]"]
                                                 token: response.token]
                                                 build];
             
          //Step 6: Construct transaction request.
          TransactionResultRequest *transactionResultRequest = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
                                                                   withPaymentRequest: paymentRequest]
                                                                   build];
                    
          //Step 7: Execute payment request.
          [[PGWSDK shared] proceedTransactionWithTransactionResultRequest: transactionResultRequest response: ^(TransactionResultResponse * _Nonnull response) {
                           
               if([response.responseCode isEqualToString: APIResponseCode.TransactionCompleted]) {
                               
                    //Inquiry payment result by using invoice no.
               } else {
                               
                    //Get error response and display error.
               }
           } failure: ^(NSError * _Nonnull error) {
                           
                //Get error response and display error.
            }];
       } else {
             
           //Get error response and display error.
       }
} failure: ^(NSError * _Nonnull error) {
         
     //Get error response and display error.
}];
//Step 2: Generate payment token id.
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
            
//Step 3: Retrieve payment provider info from Payment Option Details API.
let paymentProvider: PaymentProvider? = paymentOptionDetailResponse.channels.filter({ $0.context.code.channelCode == "APPLEPAY" }).first?.context.info.paymentProvider
         
//Step 4: Construct apple pay token request.
let paymentProviderRequest: PaymentProviderRequest = PaymentProviderBuilder()
                                                     .paymentProvider(paymentProvider!)
                                                     .build()
         
PGWSDKHelper.shared.proceedApplePayPayment(paymentProviderRequest: paymentProviderRequest, { (response: ApplePayPaymentResultResponse) in
             
     if response.responseCode == ApplePayPaymentResponseCode.TokenGeneratedSuccess {
                 
           //Step 5: Construct apple pay payment request.
           let paymentCode: PaymentCode = PaymentCode(channelCode: "APPLEPAY")
 
           let paymentRequest: PaymentRequest = DigitalPaymentBuilder(paymentCode: paymentCode)
                                                .name("DavidBilly")
                                                .email("[email protected]")
                                                .token(response.token)
                                                .build()
                 
            //Step 6: Construct transaction request.
            let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
                                                                    .with(paymentRequest)
                                                                    .build()
                 
            //Step 7: Execute payment request.
            PGWSDK.shared.proceedTransaction(transactionResultRequest: transactionResultRequest, { (response: TransactionResultResponse) in
 
                if response.responseCode == APIResponseCode.TransactionCompleted {
                         
                      //Inquiry payment result by using invoice no.
                } else {
                        
                      //Get error response and display error
                }
           }) { (error: NSError) in
                    
                //Get error response and display error
           }
     } else {
                 
           //Get error response and display error
     } 
}) { (error: NSError) in
 
     //Get error response and display error
}