1. Integration steps
This section describes how to integrate with Google Pay SDK.
Before you start with the integration, enable the payment methods that you want to offer to your customers from Dashboard > Settings > Payment methods. We enable Cards, UPI, and other payment methods by default, and we recommend that you enable other payment methods that are relevant to you.
Step 1: Create a PayU account
First, create a PayU account. For more information, refer to Register for a Merchant Account.
Step 2: Gradle dependency
Add the following dependency in the application’s build.gradle.
implementation 'in.payu:payu-gpay:3.0.0'
Step 3: Callbacks
The following is of list callback functions provided by PayU Google Pay:
onPaymentFailure (String payuResponse, String merchantResponse)
: Calls when payment failsonPaymentSuccess (String payuResponse, String merchantResponse)
: Calls when payment succeedsonPaymentOptionInitialisationFailure (int errorCode, String description)
: Called for Google Payinitialisationfailure
where:errorCode
: Error Codedescription
: Error Description
onPaymentInitialisationSuccess()
: Callback when Google Pay is successfully initialized.onGpayErrorReceived(int errorCode, String description)
: Callback when found any error while making a payment transaction.
The following are error messages when the Google Pay Payment fail:
Error Code | Error Message | Description |
---|---|---|
1 | Google Pay payment is not enabled on this merchant key | |
2 | Please check the input data. | Input Data is missing to make payments with Google Pay. |
3 | Payment APIs Error |
Step 4: Set up for Test/Sandbox Merchant
If you are using the SDK with a test merchant, provide this metadata value to the manifest file:
<application
<meta-data
android:name="payu_web_service_url"
android:value="https://test.payu.in" />
<meta-data
android:name="payu_post_url"
android:value="https://test.payu.in" />
</application>
Step 4: Check Payment Availability
Call the checkForPaymentAvailability method available in Google Pay to check if Google Pay payment is available or not on the device. The checkForPaymentAvailability method is called before showing Google Pay as a checkout option.
GPay.getInstance().checkForPaymentAvailability(Activity activity, PayUGPayCallback callback, String paymentOptionHash, String merchantKey, String user_credentials)
PayUGPayCallback : the class to provide callbacks
Activity : Activity
paymentOptionHash : Payment Related Details hash
merchantKey : PayU Merchant Key
user_credentials : Provide user credentials or use "default"
To generate PaymentOption hash, refer to Hash Generation.
Step 5: Make Payment by Google Pay
After the successful initialization of Google Pay using the checkForPaymentAvailability method, call the makePayment method to make a payment.
GPay.getInstance().makePayment(Activity activity, String postData, final PayUGPayCallback payUGPayCallback, String merchantKey, View loadingDialogView);
The PayUGPayCallback class provides the following callbacks:
Activity
: activity instancepostData
: PayU postdatamerchantKey
: Your Merchant KeyloadingDialogView
: ProgressDialog View
Sample PostData
txnid=1524122818080&productinfo=product_info&user_credentials=default&key=*****&surl=**SUCCESS_URL**&furl=**FAILURE_URL&firstname=firstname&[email protected]&amount=10&udf1=udf1&udf2=udf2&udf3=udf3&udf4=udf4&udf5=udf5&pg=UPI&bankcode=TEZ&hash=***PAYMENT_HASH***
Step 6: Verify the transaction using Webhooks
After you get the response from SDK, make sure to confirm it with the PayU server.
Remember
It is recommended to implement the PayU Webhook or backend verify call from your backend.
Webhook is a server-to-server callback. Once this feature is activated for merchants, PayU would send an S2S response, in addition to an SDK callback, to the merchant. It is recommended that the merchant process the transaction order status – based on the S2S response and not via the Browser Redirection/SDK callback response to ensure optimum translation outcomes. For more information on the Webhook implementation, refer to Web Checkout Integration Documentation > Webhooks,
Also, you can verify payment through polling, the transaction status after the SDK callback from your backend. For more information, refer to Verify the Transaction.
Updated about 1 month ago