Apple Pay
The 2C2P PGW SDK allows merchants to accept payments from Apple Pay.
API Method
References
1. Prerequisite
Refer all the steps and images from following link.
2. 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"]
}
3. 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"
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
let paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
4. Retrieve Payment Provider Info from Payment Option Details API.
To receive a payment provider info, refer to the sample payment option detail response below.
Payment Option Detail 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;
let paymentProvider: PaymentProvider? = paymentOptionDetailResponse.channels.filter({ $0.context.code.channelCode == "APPLEPAY" }).first?.context.info.paymentProvider
Map<String, dynamic>? paymentProvider = paymentOptionDetailResponse['channels'].firstWhere((f) => f['context']?['code']?['channelCode'] == PaymentChannelCode.channel.applePay, orElse: () => null)?['context']?['info']?['paymentProvider'];
let paymentProvider = paymentOptionDetailResponse?.channels?.find((element: any) => {
return element?.context?.code?.channelCode == 'APPLEPAY';
})?.context?.info?.paymentProvider;
5. 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]) {
//Construct google pay payment request.
} 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 {
//Construct google pay payment request.
} else {
//Get error response and display error
}
}) { (error: NSError) in
//Get error response and display error
}
PGWSDKHelper().proceedApplePayPayment(paymentProvider!, null, (response) {
if (response['responseCode'] == ApplePayPaymentResponseCode.tokenGeneratedSuccess) {
//Construct google pay payment request.
} else {
//Get error response and display error
}
}, (error) {
//Get error response and display error
});
await RTNPGW.proceedApplePayPayment(JSON.stringify(paymentProvider), null).then(async (response: string) => {
let applePayPaymentResultResponse = JSON.parse(response);
if (applePayPaymentResultResponse?.responseCode == ApplePayPaymentResponseCode.tokenGeneratedSuccess) {
//Construct google pay payment request.
} else {
//Get error response and display error
}
}).catch ((error: Error) => {
//Get error response and display error
});
6. 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 below payment channel codes from Digital Payment
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()
Map<String, dynamic> paymentCode = {
'channelCode': 'APPLEPAY'
};
Map<String, dynamic> paymentRequest = {
'name': 'DavidBilly',
'email': '[email protected]',
'token': response['token']
};
let paymentCode = {
'channelCode': 'APPLEPAY'
};
let paymentRequest = {
'name': 'DavidBilly',
'email': '[email protected]',
'token': applePayPaymentResultResponse?.token
};
7. 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()
Map<String, dynamic> transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
let transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
8. 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
}
PGWSDK().proceedTransaction(transactionResultRequest, (response) {
if (response['responseCode'] == APIResponseCode.transactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}, (error) {
//Get error response and display error.
});
await RTNPGW.proceedTransaction(JSON.stringify(transactionResultRequest)).then((response: string) => {
let transactionResultResponse = JSON.parse(response);
if (transactionResultResponse?.responseCode == APIResponseCode.transactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}).catch ((error: Error) => {
//Get error response and display error
});
9. Initiate Transaction Status Inquiry
To retrieve transaction details and status, merchants must initiate the Transaction Status Inquiry API. Refer to the sample code below.
Transaction Status Inquiry API
Refer to: Transaction Status Inquiry API
Full Sample Code
The following sample code demonstrates requests and parameters for each step of the process.
//Step 1: Generate payment token.
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
//Step 2: 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 3: 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 4: 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 5: Construct transaction request.
TransactionResultRequest *transactionResultRequest = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
withPaymentRequest: paymentRequest]
build];
//Step 6: 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 1: Generate payment token.
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
//Step 2: 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 3: 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 4: 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 5: Construct transaction request.
let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
.with(paymentRequest)
.build()
//Step 6: 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
}
//Step 1: Generate payment token.
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
//Step 2: Retrieve payment provider info from Payment Option Details API.
Map<String, dynamic>? paymentProvider = paymentOptionDetailResponse['channels'].firstWhere((f) => f['context']?['code']?['channelCode'] == PaymentChannelCode.channel.applePay, orElse: () => null)?['context']?['info']?['paymentProvider'];
//Step 3: Construct apple pay token request.
PGWSDKHelper().proceedApplePayPayment(paymentProvider!, null, (response) {
if (response['responseCode'] == ApplePayPaymentResponseCode.tokenGeneratedSuccess) {
//Step 4: Construct apple pay payment request.
Map<String, dynamic> paymentCode = {
'channelCode': 'APPLEPAY'
};
Map<String, dynamic> paymentRequest = {
'name': 'DavidBilly',
'email': '[email protected]',
'token': response['token']
};
//Step 5: Construct transaction request.
Map<String, dynamic> transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
//Step 6: Execute payment request.
PGWSDK().proceedTransaction(transactionResultRequest, (response) {
if (response['responseCode'] == APIResponseCode.transactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}, (error) {
//Get error response and display error.
});
} else {
//Get error response and display error
}
}, (error) {
//Get error response and display error
});
//Step 1: Generate payment token.
let paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
//Step 2: Retrieve payment provider info from Payment Option Details API.
let paymentProvider = paymentOptionDetailResponse?.channels?.find((element: any) => {
return element?.context?.code?.channelCode == 'APPLEPAY';
})?.context?.info?.paymentProvider;
//Step 3: Construct apple pay token request.
await RTNPGW.proceedApplePayPayment(JSON.stringify(paymentProvider), null).then(async (response: string) => {
let applePayPaymentResultResponse = JSON.parse(response);
if (applePayPaymentResultResponse?.responseCode == ApplePayPaymentResponseCode.tokenGeneratedSuccess) {
//Step 4: Construct apple pay payment request.
let paymentCode = {
'channelCode': 'APPLEPAY'
};
let paymentRequest = {
'name': 'DavidBilly',
'email': '[email protected]',
'token': applePayPaymentResultResponse?.token
};
//Step 5: Construct transaction request.
let transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
//Step 6: Execute payment request.
await RTNPGW.proceedTransaction(JSON.stringify(transactionResultRequest)).then((response: string) => {
let transactionResultResponse = JSON.parse(response);
if (transactionResultResponse?.responseCode == APIResponseCode.transactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}).catch ((error: Error) => {
//Get error response and display error
});
} else {
//Get error response and display error
}
}).catch ((error: Error) => {
//Get error response and display error
});
Updated 26 days ago