1.Save the below assigned apiEndPoint value at your server for inline pay.
String apiEndPoint = "/v3/merchant/inline/pay";
-
Collect encrypted device Id from your app.
-
Call Inline Pay API along with the deviceContext. Refer this link for more details.
"deviceContext": {
"phonePeUserStatus": "VALID",
"phonePeVersionCode": 400922 // -1 if unknown
}
- Construct the checksum at your server as follows:
String checksum = sha256(base64Body + apiEndPoint + salt) + ### + saltIndex;
- Get the device Id using the below code:
try {
PhonePe.getDeviceId(this, new iDeviceIdListener() {
@Override
public void onDeviceIdAvailable(String s) {
// Get encrypted device Id using the below code
}
});
} catch (PhonePeInitException e) {
e.printStackTrace();
}
2.a Collect base64 encoded payload, checksum and apiEndPoint from your server.
b. Initiate the payment process as follows:
TransactionRequest debitRequest = new TransactionRequestBuilder()
.setData(base64Body)
.setChecksum(checksum)
.setUrl(apiEndPoint)
.build();
try {
startActivityForResult(PhonePe.getTransactionIntent(this, debitRequest), DEBIT_REQUEST_CODE);
} catch (PhonePeInitException e) {
e.printStackTrace();
}
- Override onActivityResult to listen to debit result:
private static int DEBIT_REQUEST_CODE = 777;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == DEBIT_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
/*This callback indicates only about completion of UI flow.
Inform your server to make the transaction
status call to get the status. Update your app with the
success/failure status.*/
}
else if (resultCode == Activity.RESULT_CANCELED) {
/*This callback indicates that the transaction has been cancelled by the end user.
Inform your server to make the transaction
status call to get the status. Update your app with the
failure status.*/
}
}
}
- Inform your server about the completion of the transaction flow from your app.
- Your server should make the Check Transaction Status API call to PhonePe server to check the transaction status.
- Get the result and notify your app.
- Based on the result inform the user about success or failure status of the transaction.