Key Notes

  • Debit init call is allowed only in the ACTIVE state of the subscription.

  • Cancel/Revoke flows are only allowed after the subscription is ACTIVE.

  • Recurring debit payment will be skipped if cancellation/revoke flow is triggered after notification callback and before the Debit Execute call.

  • Recurring debit payment will succeed if Cancellation/Revoke flow is triggered after the Debit Execute call and before the Debit Execute callback.

  • If Revoke flow is triggered then cancel flow will throw an exception, and vice versa is also true.

Code Snippet to Get PhonePe App VersionCode

  1. Code Snippet to fetch the PhonePe App version code installed in the user's device.
public long getPhonePeVersionCode(Context context)
{
    String PHONEPE_PACKAGE_NAME_UAT = "com.phonepe.app.preprod";
    String PHONEPE_PACKAGE_NAME_PRODUCTION = "com.phonepe.app";
    PackageInfo packageInfo = null;
    long phonePeVersionCode = -1L;
    try {
        packageInfo = getPackageManager().getPackageInfo(PHONEPE_PACKAGE_NAME_UAT,PackageManager.GET_ACTIVITIES);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            phonePeVersionCode = packageInfo.getLongVersionCode();
        } else {
            phonePeVersionCode = packageInfo.versionCode;
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, String.format("failed to get package info for package name = {%s}, exception message = {%s}",
                PHONEPE_PACKAGE_NAME_UAT, e.getMessage()));
    }
    return  phonePeVersionCode;
}
  1. Add the below line in your AndroidManifest.xml file
<queries>
    <package android:name="com.phonepe.app" />
    <package android:name="com.phonepe.app.preprod" />
</queries>

Code Snippet to Check PhonePe App for Mandate

Method to check whether the PhonePe UPI app is installed on the android device and supports Mandate:

private boolean isUpiRegistered() {
    String phonepePackageName = "com.phonepe.app"; 
    //For PreProd app, "com.phonepe.app.preprod"
    //For Production app, "com.phonepe.app"
    Uri uri = Uri.parse(String.format("%s://%s", "upi", "mandate"));
    Intent upiUriIntent = new Intent();
    upiUriIntent.setData(uri);
    PackageManager packageManager = getApplication().getPackageManager();
    List < ResolveInfo > resolveInfoList = packageManager.queryIntentActivities(upiUriIntent, PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfoList != null) {
        for (ResolveInfo resolveInfo: resolveInfoList) {
            String packageName = resolveInfo.activityInfo.packageName;
            if (packageName != null && !packageName.isEmpty() && phonepePackageName.matches(packageName)) {
                return true;
            }
        }
    }
    return false;
}

Code Snippet to Check Supported UPI Apps for Mandate

Method to get the list of all the UPI apps installed on the android device and supports Mandate:

private ArrayList < String > getInstalledUPIApps() {
    ArrayList < String > upiList = new ArrayList < > ();
    Uri uri = Uri.parse(String.format("%s://%s", "upi", "mandate"));
    Intent upiUriIntent = new Intent();
    upiUriIntent.setData(uri);
    PackageManager packageManager = getApplication().getPackageManager();
    List < ResolveInfo > resolveInfoList = packageManager.queryIntentActivities(upiUriIntent, PackageManager.MATCH_DEFAULT_ONLY);
    if (resolveInfoList != null) {
        for (ResolveInfo resolveInfo: resolveInfoList) {
            upiList.add(resolveInfo.activityInfo.packageName);
        }
    }
    return upiList;
}

E2M Recurring : Code Snippet to invoke the app-specific Intent

Update the APP_PACKAGE** value with the package name of the UPI app selected by the user on the merchant's checkout page to launch the mandate setup.

val intent = Intent()
intent.action = Intent.ACTION_VIEW
intent.data = Uri.parse(redirectUrl)        //PhonePe Intent redirectUrl from the response.
intent.setPackage(APP_PACKAGE)                  //APP_PACKAGE will be the package name of the App selected by the user.

startActivityForResult(intent,PHONEPE_REQUEST_CODE);