Integration Steps
The Android PhonePe SDK integration involves the following steps:
SDK Integration
Step 1: Create a PayU account
First, create a PayU account. See Register for a Merchant Account.
Step 2: Set up build.gradle
Add the following URL in the root project’s build.gradle:
allprojects {
repositories {
maven {
url "https://phonepe.mycloudrepo.io/public/repositories/phonepe-intentsdk-android"
}
}
}
Add the following dependency in your application’s build.gradle:
implementation 'in.payu:phonepe-intent:1.8.7'
Step 3: Create Callbacks Instance
PayUPhonePeCallback provides the following callback methods.
- onPaymentOptionFailure (String payuResponse, String merchantResponse): Calls when payment fails.
- onPaymentOptionSuccess (String payuResponse, String merchantResponse): Calls when payment succeeds.
- onPaymentOptionInitialisationFailure (int errorCode, String description): Called for PhonePe initialisation failure.
- onPaymentOptionInitialisationSuccess (boolean result): Callback when PhonePe is successfully initialised.
Following are error messages concerning PhonePe initialization failure.
Error Code | Error Code | Description |
---|---|---|
1 | MERCHANT_KEY_NOT_ REGISTER_FOR_PHONEPE | Merchant is not registered for PhonePe with PayU |
Create an instance of PayUPhonePeCallback similar to the following code block:
PayUPhonePeCallback payUPhonePeCallback = new PayUPhonePeCallback() {
@Override
public void onPaymentOptionFailure(String payuResponse, String merchantResponse) {
//Called when Payment gets failed.
}
@Override
public void onPaymentOptionInitialisationSuccess(boolean result) {
super.onPaymentOptionInitialisationSuccess(result);
// Merchants are advised to show PhonePe option on their UI after this callback is called.
}
@Override
public void onPaymentOptionSuccess(String payuResponse, String merchantResponse) {
//Called when Payment gets successful.
}
@Override
public void onPaymentOptionInitialisationFailure (int errorCode, String description) {
//Callback thrown in case PhonePe initialisation fails.
}
};
Step 4: Set up for Test/Sandbox merchant
If you are using the SDK with a test merchant, provide the following 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 5: Check for PhonePe availability
SDK provides the checkForPaymentAvailability method to check if PhonePe payment is available or not on the device. This method must be executed before showing PhonePe as a checkout option.
PhonePe.getInstance().checkForPaymentAvailability(Activity activity, PayUPhonePeCallback callback, String paymentOptionHash, String merchantKey, String user_credentials)
Where:
- PayUPhonePeCallback: the class to provide callbacks
- Activity : Activity
- paymentOptionHash: Payment Related Details hash
- merchantKey: PayU Merchant Key
- user_credentials: Provide user credentials or use “default”
Generate PaymentOption HashTo generate
PaymentOption
Hash refer to Generate Static Hash.Formula :-sha512(key|command|var1|salt)
where
- key=YOUR KEY
- command="payment_related_details_for_mobile_sdk" // Api Commands
- salt= YOUR SALT
- var1= default // Pass
default
value in var1
Step 6: Make Payment by PhonePe
After successful initialization of PhonePe by calling checkForPaymentAvailability method, call makePayment method to make payment.
PhonePe.getInstance().makePayment(PayUPhonePeCallback callback, Activity activity, String postData,boolean isUserCacheEnabled, View customDialogView);
Where:
- PayUPhonePeCallback: the class to provide callbacks
- Activity: activity instance
- postData: PayU postdata
- isUserCacheEnabled: To Enable/Disable User Cache
- customDialogView: Provide your Custom Progress dialog view (Optional)
Generate Payment Hash: To generate a payment hash refer to Hash Generation.
Formula :-sha512(key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||salt)
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=CASH&bankcode=PPINTENT&hash=***PAYMENT_HASH***
Step 7: 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. For more information, refer to Webhooks.
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.
Step 7.1: Create a PayU account
First, create a PayU account. See Register for a Merchant Account.
Step 7.2: Set up build.gradle
Add the following URL in the root project’s build.gradle:
allprojects {
repositories {
maven {
url "https://phonepe.mycloudrepo.io/public/repositories/phonepe-intentsdk-android"
}
}
}
Add the following dependency in your application’s build.gradle:
implementation 'in.payu:phonepe-intent:1.8.7'
Step 7.3: Create Callbacks Instance
PayUPhonePeCallback provides the following callback methods.
- onPaymentOptionFailure (String payuResponse, String merchantResponse): Calls when payment fails.
- onPaymentOptionSuccess (String payuResponse, String merchantResponse): Calls when payment succeeds.
- onPaymentOptionInitialisationFailure (int errorCode, String description): Called for PhonePe initialisation failure.
- onPaymentOptionInitialisationSuccess (boolean result): Callback when PhonePe is successfully initialised.
Following are error messages concerning PhonePe initialization failure.
Error Code | Error Code | Description |
---|---|---|
1 | MERCHANT_KEY_NOT_ REGISTER_FOR_PHONEPE | Merchant is not registered for PhonePe with PayU |
Create an instance of PayUPhonePeCallback similar to the following code block:
PayUPhonePeCallback payUPhonePeCallback = new PayUPhonePeCallback() {
@Override
public void onPaymentOptionFailure(String payuResponse, String merchantResponse) {
//Called when Payment gets failed.
}
@Override
public void onPaymentOptionInitialisationSuccess(boolean result) {
super.onPaymentOptionInitialisationSuccess(result);
// Merchants are advised to show PhonePe option on their UI after this callback is called.
}
@Override
public void onPaymentOptionSuccess(String payuResponse, String merchantResponse) {
//Called when Payment gets successful.
}
@Override
public void onPaymentOptionInitialisationFailure (int errorCode, String description) {
//Callback thrown in case PhonePe initialisation fails.
}
};
Step 7.4: Set up for Test/Sandbox merchant
If you are using the SDK with a test merchant, provide the following 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 7.5: Check for PhonePe availability
SDK provides the checkForPaymentAvailability method to check if PhonePe payment is available or not on the device. This method must be executed before showing PhonePe as a checkout option.
PhonePe.getInstance().checkForPaymentAvailability(Activity activity, PayUPhonePeCallback callback, String paymentOptionHash, String merchantKey, String user_credentials)
Where:
- PayUPhonePeCallback: the class to provide callbacks
- Activity : Activity
- paymentOptionHash: Payment Related Details hash
- merchantKey: PayU Merchant Key
- user_credentials: Provide user credentials or use “default”
Generate PaymentOption HashTo generate
PaymentOption
Hash refer to Generate Static Hash.Formula :-sha512(key|command|var1|salt)
where
- key=YOUR KEY
- command="payment_related_details_for_mobile_sdk" // Api Commands
- salt= YOUR SALT
- var1= default // Pass
default
value in var1
Step 7.6: Make Payment by PhonePe
After successful initialization of PhonePe by calling checkForPaymentAvailability method, call makePayment method to make payment.
PhonePe.getInstance().makePayment(PayUPhonePeCallback callback, Activity activity, String postData,boolean isUserCacheEnabled, View customDialogView);
Where:
- PayUPhonePeCallback: the class to provide callbacks
- Activity: activity instance
- postData: PayU postdata
- isUserCacheEnabled: To Enable/Disable User Cache
- customDialogView: Provide your Custom Progress dialog view (Optional)
Generate Payment Hash: To generate a payment hash refer to Hash Generation.
Formula :-sha512(key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||salt)
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=CASH&bankcode=PPINTENT&hash=***PAYMENT_HASH***
Step 7.7: 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. For more information, refer to Webhooks.
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.
Test the Integration
After the integration is complete, you must test the integration before you go live and start collecting payment. You can start accepting actual payments from your customers once the test is successful.
You can make test payments using one of the payment methods configured at the Checkout.
Testing checklistThings to remember while testing an integration:
- To test the integration make sure that you are making a transaction call to the test endpoint.
- Use your test key and salt for the transaction requests. For more information, refer to Access Test Key and Salt.
- Set the value of the
environment
parameters to1
.
Test UPI Intent/InApp flow
Not available in Test mode: The UPI in-app and UPI intent flow is not available in the Test mode.
Go-live Checklist
Ensure these steps before you deploy the integration in a live environment.
Collect Live Payments
After testing the integration, once you are confident that the integration is working as expected, you can switch to live mode to start accepting payments from your customers.
Watch Out!Ensure that you are using the production merchant key and salt generated in the live mode.
Checklist 1: Update Production Key and Salt
To generate the live merchant key and salt:
- Log in to the PayU Dashboard and switch to Live Mode on the menu.
- Navigate to Developers → API Keys tab.
- Copy the key and salt using the copy button.
- Replace the Test key and salt with the Production key and salt in the payment integration code and start accepting actual payments.
Checklist 2: Configure setIsProduction()
Set the value of the setIsProduction()
to true
in the payment integration code. This enables the integration to accept live payments.
Checklist 3: Configure verify payment method
Configure the Verify payment method to fetch the payment status. We strongly recommend that you use this as a back up method to handle scenarios where the payment callback is failed due to technical error.
Checklist 4: Configure Webhook
PayU recommends you to configure Webhook to receive payment responses on your server. For more information, refer to Webhooks.
During the integration, refer the Generate Static Hash for hash generation details.
Updated 3 days ago