Integration Details

X-DEVICE-ID header

● The deviceId header is mandatory in the /v3/merchant/otp/send, /v3/wallet/balance
and /v3/wallet/debit APIs.

● Refer to the best practices on android or iOS to generate the device Id. If integrating
on the web, use browser fingerprinting.

● Always fetch the device id from the user's device before making the API call. Do not
cache the id on the backend.

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>

Wallet top-up URL

● The top-up URL returned in /v3/wallet/topup and /v3/wallet/debit is an android
deeplink
. Do not make this call on web or iOS integrations.

● This top-up URL should not be cached.

Handling Wallet top-up URL on Android

private static final int PHONEPE_WALLET_TOPUP_REQUEST_CODE = 101;

Use startActivityForResult to launch the PhonePe App

try {
    Uri deeplink = Uri.parse(getWalletTopUpUrl()); //wallet top-up url
    Intent intent = new Intent(Intent.ACTION_VIEW, deeplink);
    startActivityForResult(intent,PHONEPE_WALLET_TOPUP_REQUEST_CODE);
  
} catch (Exception e) {
    e.printStackTrace();
}

Handle onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
    super.onActivityResult(requestCode, resultCode, data);
  
    if (requestCode == PHONEPE_WALLET_TOPUP_REQUEST_CODE) {
        /*This callback indicates only about completion of UI flow.
            Inform your server to make the wallet balance
            call to get the wallet balance.
            Call direct debit API if the balance is sufficient.*/
    }
}

Values of topupWorkflowType in the Balance & Top-up APIs

TRANSACTIONAL - Pass this enum, when the user is on the pay path. Transaction-related checks are made before top-up, so the actual debit goes through without problems.

NON_TRANSACTIONAL - To be passed when the user is on a flow like the Profile section, where there is no transaction associated with a top-up. Transaction-related checks are skipped when this enum is passed.

API Call timeouts

● The p99 latency mentioned next to each API is the max p99 latency inside PhonePe’s
network. These latencies can be configured as the API timeouts at your end after
adding an over-the-internet call latency. Make sure to add some buffer to the
internet latency.

● Note: Since /v3/wallet/balance, /v3/wallet/topup, and /v3/wallet/debit are
completely new APIs, the latencies are estimates and may change slightly.