Google Pay
The 2C2P PGW SDK allows merchants to accept payments from Google 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"],
"request3DS": "Y"
}
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.
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
val paymentToken = "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 Parameter
PaymentChannel paymentChannel = paymentOptionDetailResponse.getChannels().stream().filter((channel) -> channel.getContext().getCode().getChannelCode().equalsIgnoreCase("GOOGLEPAY")).findAny().orElse(null);
PaymentProvider paymentProvider = paymentChannel != null ? paymentChannel.getContext().getInfo().getPaymentProvider() : null;
val paymentProvider = paymentOptionDetailResponse.channels.find {
it.context.code.channelCode.equals("GOOGLEPAY", ignoreCase = true)
}?.context?.info?.paymentProvider
Map<String, dynamic>? paymentProvider = paymentOptionDetailResponse['channels'].firstWhere((f) => f['context']?['code']?['channelCode'] == PaymentChannelCode.channel.googlePay, orElse: () => null)?['context']?['info']?['paymentProvider'];
let paymentProvider = paymentOptionDetailResponse?.channels?.find((element: any) => {
return element?.context?.code?.channelCode == 'GOOGLEPAY';
})?.context?.info?.paymentProvider;
5. Construct Google Pay Token Request
PaymentProviderRequest paymentProviderRequest = new PaymentProviderBuilder(getActivity())
.setPaymentProvider(paymentProvider)
.build();
PGWSDKHelper.getInstance().proceedGooglePayPayment(paymentProviderRequest, new PaymentResultResponseCallback<GooglePayPaymentResultResponse>() {
@Override
public void onResponse(GooglePayPaymentResultResponse response) {
if (response.getResponseCode().equalsIgnoreCase(GooglePayPaymentResponseCode.TokenGeneratedSuccess)) {
//Construct google pay payment request.
} else {
//Get error response and display error.
}
}
@Override
public void onFailure(Throwable error) {
//Get error response and display error.
}
});
val paymentProviderRequest = PaymentProviderBuilder(activity).apply {
paymentProvider(paymentProvider)
}.build()
PGWSDKHelper.getInstance().proceedGooglePayPayment(paymentProviderRequest, object : PaymentResultResponseCallback<GooglePayPaymentResultResponse> {
override fun onResponse(response: GooglePayPaymentResultResponse) {
if (response.responseCode == GooglePayPaymentResponseCode.TokenGeneratedSuccess) {
//Construct google pay payment request.
} else {
//Get error response and display error.
}
}
override fun onFailure(error: Throwable) {
//Get error response and display error.
}
})
PGWSDKHelper().proceedGooglePayPayment(paymentProvider!, null, GooglePayAPIEnvironment.production, (response) {
if (response['responseCode'] == GooglePayPaymentResponseCode.tokenGeneratedSuccess) {
//Construct google pay payment request.
} else {
//Get error response and display error
}
}, (error) {
//Get error response and display error
});
await RTNPGW.proceedGooglePayPayment(JSON.stringify(paymentProvider), null, GooglePayAPIEnvironment.production).then(async (response: string) => {
let googlePayPaymentResultResponse = JSON.parse(response);
if (googlePayPaymentResultResponse?.responseCode == GooglePayPaymentResponseCode.tokenGeneratedSuccess) {
//Construct google pay payment request.
} else {
//Get error response and display error
}
}).catch ((error: Error) => {
//Get error response and display error
});
6. Construct Google 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 = new PaymentCode("GOOGLEPAY");
PaymentRequest paymentRequest = new DigitalPaymentBuilder(paymentCode)
.setName("DavidBilly")
.setEmail("[email protected]")
.setToken(response.getToken())
.build();
val paymentCode = PaymentCode("GOOGLEPAY")
val paymentRequest = DigitalPaymentBuilder(paymentCode).apply {
name("DavidBilly")
email("[email protected]")
token(response.token)
}.build()
Map<String, dynamic> paymentCode = {
'channelCode': 'GOOGLEPAY'
};
Map<String, dynamic> paymentRequest = {
'name': 'DavidBilly',
'email': '[email protected]',
'token': response['token']
};
let paymentCode = {
'channelCode': 'GOOGLEPAY'
};
let paymentRequest = {
'name': 'DavidBilly',
'email': '[email protected]',
'token': googlePayPaymentResultResponse?.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 = new TransactionResultRequestBuilder(paymentToken)
.with(paymentRequest)
.build();
val transactionResultRequest = TransactionResultRequestBuilder(paymentToken).apply {
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.getInstance().proceedTransaction(transactionResultRequest, new APIResponseCallback<TransactionResultResponse>() {
@Override
public void onResponse(TransactionResultResponse response) {
if (response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateRedirect) || response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateFullRedirect)) {
String redirectUrl = response.getData(); //Open WebView
} else if (response.getResponseCode().equals(APIResponseCode.TransactionCompleted)) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error
}
}
@Override
public void onFailure(Throwable error) {
//Get error response and display error
}
});
PGWSDK.getInstance().proceedTransaction(transactionResultRequest, object : APIResponseCallback<TransactionResultResponse> {
override fun onResponse(response: TransactionResultResponse) {
if (response.responseCode == APIResponseCode.TransactionAuthenticateRedirect || response.responseCode == APIResponseCode.TransactionAuthenticateFullRedirect) {
val redirectUrl = response.data //Open WebView
} else if (response.responseCode == APIResponseCode.TransactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}
override fun onFailure(error: Throwable) {
//Get error response and display error.
}
})
PGWSDK().proceedTransaction(transactionResultRequest, (response) {
if (response['responseCode'] == APIResponseCode.transactionAuthenticateRedirect || response['responseCode'] == APIResponseCode.transactionAuthenticateFullRedirect) {
String redirectUrl = response['data']; //Open WebView
} else 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.transactionAuthenticateRedirect || transactionResultResponse?.responseCode == APIResponseCode.transactionAuthenticateFullRedirect) {
let redirectUrl = transactionResultResponse?.data; //Open WebView
} else 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
});
Callback for PGW Payment Authentication
Refer to: Handle PGW Payment Authentication
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.
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
//Step 2: Retrieve payment provider info from Payment Option Details API.
PaymentChannel paymentChannel = paymentOptionDetailResponse.getChannels().stream().filter((channel) -> channel.getContext().getCode().getChannelCode().equalsIgnoreCase("GOOGLEPAY")).findAny().orElse(null);
PaymentProvider paymentProvider = paymentChannel != null ? paymentChannel.getContext().getInfo().getPaymentProvider() : null;
//Step 3: Construct google pay token request.
PaymentProviderRequest paymentProviderRequest = new PaymentProviderBuilder(getActivity())
.setPaymentProvider(paymentProvider)
.build();
PGWSDKHelper.getInstance().proceedGooglePayPayment(paymentProviderRequest, new PaymentResultResponseCallback<GooglePayPaymentResultResponse>() {
@Override
public void onResponse(GooglePayPaymentResultResponse response) {
if (response.getResponseCode().equalsIgnoreCase(GooglePayPaymentResponseCode.TokenGeneratedSuccess)) {
//Step 4: Construct google pay payment request.
PaymentCode paymentCode = new PaymentCode("GOOGLEPAY");
PaymentRequest paymentRequest = new DigitalPaymentBuilder(paymentCode)
.setName("DavidBilly")
.setEmail("[email protected]")
.setToken(response.getToken())
.build();
//Step 5: Construct transaction request.
TransactionResultRequest transactionResultRequest = new TransactionResultRequestBuilder(paymentToken)
.with(paymentRequest)
.build();
//Step 6: Execute payment request.
PGWSDK.getInstance().proceedTransaction(transactionResultRequest, new APIResponseCallback<TransactionResultResponse>() {
@Override
public void onResponse(TransactionResultResponse response) {
if (response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateRedirect) || response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateFullRedirect)) {
String redirectUrl = response.getData(); //Open WebView
} else if (response.getResponseCode().equals(APIResponseCode.TransactionCompleted)) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error
}
}
@Override
public void onFailure(Throwable error) {
//Get error response and display error
}
});
} else {
//Get error response and display error.
}
}
@Override
public void onFailure(Throwable error) {
//Get error response and display error.
}
});
//Step 1: Generate payment token.
val paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
//Step 2: Retrieve payment provider info from Payment Option Details API.
val paymentProvider = paymentOptionDetailResponse.channels.find {
it.context.code.channelCode.equals("GOOGLEPAY", ignoreCase = true)
}?.context?.info?.paymentProvider
//Step 3: Construct google pay token request.
val paymentProviderRequest = PaymentProviderBuilder(activity).apply {
paymentProvider(paymentProvider)
}.build()
PGWSDKHelper.getInstance().proceedGooglePayPayment(paymentProviderRequest, object : PaymentResultResponseCallback<GooglePayPaymentResultResponse> {
override fun onResponse(response: GooglePayPaymentResultResponse) {
if (response.responseCode == GooglePayPaymentResponseCode.TokenGeneratedSuccess) {
//Step 4: Construct google pay payment request.
val paymentCode = PaymentCode("GOOGLEPAY")
val paymentRequest = DigitalPaymentBuilder(paymentCode).apply {
name("DavidBilly")
email("[email protected]")
token(response.token)
}.build()
//Step 5: Construct transaction request.
val transactionResultRequest = TransactionResultRequestBuilder(paymentToken).apply {
with(paymentRequest)
}.build()
//Step 6: Execute payment request.
PGWSDK.getInstance().proceedTransaction(transactionResultRequest, object : APIResponseCallback<TransactionResultResponse> {
override fun onResponse(response: TransactionResultResponse) {
if (response.responseCode == APIResponseCode.TransactionAuthenticateRedirect || response.responseCode == APIResponseCode.TransactionAuthenticateFullRedirect) {
val redirectUrl = response.data //Open WebView
} else if (response.responseCode == APIResponseCode.TransactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}
override fun onFailure(error: Throwable) {
//Get error response and display error.
}
})
} else {
//Get error response and display error.
}
}
override fun onFailure(error: Throwable) {
//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.googlePay, orElse: () => null)?['context']?['info']?['paymentProvider'];
//Step 3: Construct google pay payment request.
PGWSDKHelper().proceedGooglePayPayment(paymentProvider!, null, GooglePayAPIEnvironment.production, (response) {
if (response['responseCode'] == GooglePayPaymentResponseCode.tokenGeneratedSuccess) {
//Step 4: Construct google pay payment request.
Map<String, dynamic> paymentCode = {
'channelCode': 'GOOGLEPAY'
};
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.transactionAuthenticateRedirect || response['responseCode'] == APIResponseCode.transactionAuthenticateFullRedirect) {
String redirectUrl = response['data']; //Open WebView
} else 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 == 'GOOGLEPAY';
})?.context?.info?.paymentProvider;
//Step 3: Construct google pay payment request.
await RTNPGW.proceedGooglePayPayment(JSON.stringify(paymentProvider), null, GooglePayAPIEnvironment.production).then(async (response: string) => {
let googlePayPaymentResultResponse = JSON.parse(response);
if (googlePayPaymentResultResponse?.responseCode == GooglePayPaymentResponseCode.tokenGeneratedSuccess) {
//Step 4: Construct google pay payment request.
let paymentCode = {
'channelCode': 'GOOGLEPAY'
};
let paymentRequest = {
'name': 'DavidBilly',
'email': '[email protected]',
'token': googlePayPaymentResultResponse?.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.transactionAuthenticateRedirect || transactionResultResponse?.responseCode == APIResponseCode.transactionAuthenticateFullRedirect) {
let redirectUrl = transactionResultResponse?.data; //Open WebView
} else 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 about 2 months ago