Google Pay

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

📘

API Method

PGW SDK API Interface

🚧

References

SDK Payment Classes
SDK Payment Enums

Dependancies

dependencies {
 
    //2C2P PGW SDK
    implementation files("libs/PGW_SDK_ANDROID_v4.5.0.aar")
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
 
    //2C2P PGW SDK HELPER
    implementation files("libs/PGW_SDK_HELPER_ANDROID_v4.0.0.aar")
    implementation "androidx.activity:activity:1.7.0"
 
    //Google Pay
    implementation 'com.google.android.gms:play-services-wallet:19.1.0'
}

Prerequisite

Refer all the steps and images from following link.

📘

Google 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"],
    "request3DS": "Y"
}

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.

String paymentToken = "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.

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;

📘

Payment Option Detail Parameter

Payment Option Detail Request Parameter

Payment Option Detail Response Parameter

4. 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)) {  
                                
            } else {
 
                 //Get error response and display error.
            }      
       }
 
       @Override
       public void onFailure(Throwable error) {
 
            //Get error response and display error.
       }
});

5. 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 payment channel codes for the Google Pay e-wallet below.

Category CodeGroup CodeChannelNameCountry
DPAYCWALLETGOOGLEPAYGoogle PayGlobal
PaymentCode paymentCode = new PaymentCode("GOOGLEPAY");

PaymentRequest paymentRequest = new DigitalPaymentBuilder(paymentCode)
                               .setName("DavidBilly")
                               .setEmail("[email protected]")
                               .setToken(response.getToken())
                               .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 = new TransactionResultRequestBuilder(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.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
    }
});

👍

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.
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 3: 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 4: 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 5: 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 6: Construct transaction request.
               TransactionResultRequest transactionResultRequest = new TransactionResultRequestBuilder(paymentToken)
                                                                   .with(paymentRequest)
                                                                   .build();
 
               //Step 7: 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.
       }
});