Integration

Getting Started

Add below url in root project's build.gradle.
1
allprojects {
2
repositories {
3
maven {
4
url "https://phonepe.mycloudrepo.io/public/repositories/phonepe-intentsdk-android"
5
}
6
}
7
}
Copied!
Add below dependency in your application's build.gradle
1
implementation 'in.payu:phonepe-intent:1.6.1'
Copied!

Callbacks

PayUPhonePeCallback provides 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 w.r.t. PhonePe initialisation failure.
1
- ErrorCode : Description
2
3
- 1 : MERCHANT_KEY_NOT_REGISTER_FOR_PHONEPE // Merchant is not registered for
4
PhonePe with PayU
Copied!
Create an instance of PayUPhonePeCallback like below.
1
PayUPhonePeCallback payUPhonePeCallback = new PayUPhonePeCallback() {
2
@Override
3
public void onPaymentOptionFailure(String payuResponse, String merchantResponse) {
4
//Called when Payment gets failed.
5
}
6
7
@Override
8
public void onPaymentOptionInitialisationSuccess(boolean result) {
9
super.onPaymentOptionInitialisationSuccess(result);
10
// Merchants are advised to show PhonePe option on their UI after this callback is called.
11
}
12
13
@Override
14
public void onPaymentOptionSuccess(String payuResponse, String merchantResponse) {
15
//Called when Payment gets successful.
16
}
17
18
@Override
19
public void onPaymentOptionInitialisationFailure (int errorCode, String description) {
20
//Callback thrown in case PhonePe initialisation fails.
21
}
22
23
};
Copied!

Set up for Test/Sandbox Merchant

If you are using the SDK with a test merchant, please provide this metadata value to the manifest file else removed these lines below.
1
<application
2
<meta-data
3
android:name="payu_web_service_url"
4
android:value="https://test.payu.in" />
5
6
<meta-data
7
android:name="payu_post_url"
8
android:value="https://test.payu.in" />
9
10
</application>
Copied!

Check for PhonePe Availability

SDK provides method checkForPaymentAvailability to check if PhonePe payment is available or not on device.This method is called before showing PhonePe as a checkout option.
1
PhonePe.getInstance().checkForPaymentAvailability(Activity activity, PayUPhonePeCallback callback, String paymentOptionHash, String merchantKey, String user_credentials)
2
3
where
4
PayUPhonePeCallback : the class to provide callbacks
5
Activity : Activity
6
paymentOptionHash : Payment Related Details hash
7
merchantKey : PayU Merchant Key
8
user_credentials : Provide user credentials or use "default"
Copied!
To generate PaymentOption Hash visit here.

Make Payment by PhonePe

After successful initialisation of PhonePe by calling checkForPaymentAvailability method call makePayment method to make payment.
1
PhonePe.getInstance().makePayment(PayUPhonePeCallback callback, Activity activity, String postData,boolean isUserCacheEnabled, View customDialogView);
2
3
where
4
5
PayUPhonePeCallback : the class to provide callbacks
6
Activity : activity instance
7
postData : PayU postdata
8
isUserCacheEnabled : To Enable/Disable User Cache
9
customDialogView : Provide your Custom Progress Dialog View(Optional)
Copied!
To generate Payment Hash visit here.
Sample PostData
1
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***
Copied!
Last modified 5mo ago