Accept Payment

Server Side

  1. Save the below assigned value at your server
String apiEndPoint = "/v3/debit"; // Discuss with PhonePe team regarding this
  1. Construct the request body and encode in Base 64 at your server as follows:
HashMap<String, Object> data = new HashMap<>();
data.put("merchantId", <Your merchant ID>); // String. Mandatory
data.put("transactionId", <Unique transaction id>); // String. Mandatory
data.put("amount", <amount in paise>); // Integer. Mandatory

//Note: Don't pass this if you are passing userAuthToken.
data.put("merchantUserId", userId); //String. Mandatory. Needed for linking 

//Note : Used only for OTP linking flow.
data.put("userAuthToken", userId); //String. Optional. Needed for linking 

data.put("merchantOrderId", <Order Id>); // String. Optional
data.put("message", <message summarizing the transaction>); // String. Optional
 
data.put("mobileNumber", <Mobile number of the user>); // String. Optional
data.put("email", <Email of the user>); // String. Optional
data.put("shortName", <Name of the user>); // String. Optional
 
data.put("subMerchantId", <submerchant ID>); // String. ONLY if a submerchant id has been allocated to you.
 
// transactionId length should be less than 38 characters.
// merchantOrderId length should be less than 48 characters.
// Put more info as intimated. Nesting is allowed
 
String base64Body = Base64(new GSON().toJson(data));
  1. Select one of the salts shared with you and note its index. Construct the Checksum at your server as follows:
String checksum = sha256(base64Body + apiEndPoint + salt) + ### + saltIndex;

App Side

  1. Collect Base64 encoded body, checksum, apiEndPoint and transactionID from your server using an API call.
  2. Initiate the payment process as follows:
var headers = [String: String]()
headers.updateValue("<Callback URL>", forKey: "X-CALLBACK-URL")
headers.updateValue("<Callback Mode>", forKey: "X-CALL-MODE")

let debitRequest = PPSTransactionRequest(
    base64EncodedBody: <#body received by your server#>,
    apiEndPoint: <#apiEndPoint received by your server#>,
    checksum: <#checksum received by your server#>,
    headers: <#headers#>)

PhonePeSDK.shared().startPhonePeTransactionRequest(
    debitRequest,
    on: self,
    animated: true) { (debitRequest, result) in
/*
Check result.successful to check if the payment flow was successful. 
This success only indicates payment flow completion and not actual transaction status. 
You need to query your server for actual transaction status.
*/

//Check result.error for checking why the payment flow failed
 
//If you get any error, refer to the iOS Merchant Integration Document section troubleshoot for the steps to debug.

}
NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
[headers setObject:@"<Callback URL>" forKey:@"X-CALLBACK-URL"];
[headers setObject:@"<Callback Mode>" forKey:@"X-CALLBACK-MODE"];

PPSTransactionRequest * debitRequest = [[PPSTransactionRequest alloc]   
  initWithBase64EncodedBody:<#body received by your server#> 
  apiEndPoint:<#apiEndPoint received by your server#>
  checksum:<#checksum received by your server#>
  headers: <#headers#>];
    
[[PhonePeSDK shared] 
  startPhonePeTransactionRequest:transactionRequest
  onViewController:self animated:YES
  completion:^(PPSTransactionRequest * request, PPSTransactionCompletionResult * result) {

//Check result.successful to check if the payment flow was successful. This success only indicates payment flow completion and not actual transaction status. You need to query your server for actual transaction status.

//Check result.error for checking why the payment flow failed
 
//If you get any error, refer to the iOS Merchant Integration Document section troubleshoot for the steps to debug.                                           

}];
  • Inform your server about the completion of the transaction flow from your app.
  • Your server should make the Check Transaction Status call to PhonePe server to check the transaction status.
  • Get the result and notify your app.
  • Based on the result inform the user about Successful or Failed status of the transaction.

Server Side

  1. Refer to Check Transaction Status API for the server to server call to get the transaction status.
    The payment status can be Successful, Failed, Pending or any of codes. For Pending, merchants should retry until the status changes to Successful or Failed .
  2. Refer to Refund API for the reconciliation.
    There could be cases where amount gets deducted but you receive payment in pending state in the status API call.

For such cases either you can show order failed immediately and refund the amount when pending changes to success using Refund or show order placed according to your use case.