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.
First, create a PayU account. For more information, refer to Register for a Merchant Account.
Add the following dependency in the application’s build.gradle.
The following is of list callback functions provided by PayU Google Pay:
onPaymentFailure (String payuResponse, String merchantResponse): Calls when payment fails
onPaymentSuccess (String payuResponse, String merchantResponse): Calls when payment succeeds
onPaymentOptionInitialisationFailure (int errorCode, String description): Called for Google Pay
errorCode: Error Code
description: 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|
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>
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.
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 instance
postData: PayU postdata
merchantKey: Your Merchant Key
loadingDialogView: ProgressDialog View
After you get the response from SDK, make sure to confirm it with the PayU server.
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