To merchants who have built their app on a Cordova platform, PhonePe provides a bridge to conveniently integrate PhonePe SDK for both Android. On this page, we will highlight the steps required to integrate PhonePe SDK with Cordova plugin for your app. This bridge will help you to build a seamless and responsive checkout experience for your Android application.

This integration will support the following flows:

  • **UPI Intent Flow**: In case the PhonePe app is installed, PhonePe intent flow will be launched to complete the transaction and send the response back to your app

  • **Redirection Flow**: In case the PhonePe app is not installed, PhonePe SDK will open a web-view to process transactions and give a response back to your app

## Android Project of Cordova Plug-In

  1. Add the below code to 'repositories' section of your project level build.gradle file





  1. Add the below line to the 'dependencies' section of your app build.gradle.





<!-- SNAPSHOT implementation 'phonepe.intentsdk.android.snapshot:IntentSDK:1.6.6-SNAPSHOT2’ RELEASE implementation 'phonepe.intentsdk.android.release:IntentSDK:1.6.6’ For, SDK version 1.6.5, We have compileSdkVersion: 28, minSdkVersion: 14, targetSdkVersion: 28 For, SDK version 1.6.6, We have compileSdkVersion: 29, minSdkVersion: 24, targetSdkVersion: 29 For, SDK version 1.6.7, We have compileSdkVersion: 28, minSdkVersion: 21, targetSdkVersion: 28 For, SDK version 1.6.8, We have compileSdkVersion: 28, minSdkVersion: 21, targetSdkVersion: 28 -->

For, SDK version 1.6.8

We have compileSdkVersion: 28, minSdkVersion: 21, targetSdkVersion: 28

  1. Add below lines of code inside the application tag in the AndroidManifest.xml file





  1. Add PhonePeSDKPlugin to your project (see Appendix at the end of this document).

  2. Add the OnActivityResult method in the PhonePeSDKPlugin class as per your response requirement in the cordova plug-in.

  3. Call Cordova.exec() method from your Cordova Native app to invoke the PhonePe module.

## Cordova Plug-In code

  1. In the .js file add the following to check whether PhonePe app is installed or Not:





Note

  1. Install the PhonePe PreProd app. Refer to this [link](🔗).

  2. If returns **true** then display the PhonePe option on the checkout page or if returns false then do not display the PhonePe option on the checkout page.

  1. In the .js file add the following to initiate the payment process:





  • **base64EncodedBody** - pass the encoded payload request

  • **checksum** - pass the checksum value

  • **endPoint** - pass the endpoint

  • **xCallbackUrl** - This can be “” or else you can send your custom callback URL where you will receive the server to server callback response to your custom callback URL. Once the response is received you have to validate the checksum and invalid amount. Refer to this [link](🔗) for more details.

  • ** success/error** - This is a Cordova plugin method that will receive a user interface callback response from the startPaymentTransaction method.





Note

  • If data returns **User Completed** it indicates the payment has been completed.

  • If data returns **User Cancelled** it indicates the payment has been canceled just in case if the user presses the back button or aborts the transaction.

  • Inform merchant server about the completion of the transaction flow from merchant app

  • Merchant server should check the status with server to server callback or make the Check Transaction Status API call to the PhonePe server to check the transaction status (Even for User Cancelled callback)

  • The app should get the transaction status from the backend

  • Based on the result, the merchant must inform the user about the success or failure status of the transaction

Note

Kindly maintain the parameter order sequence

## References

  • For Accept Payment API, Refer to this [link](🔗).

  • Use the Check Transaction Status API to check the status of the payment transaction. Refer to this [link](🔗).

  • For refund API, Refer to this [link](🔗).

## Appendix

**PhonePeSDKPlugin.java**