SDK Integration


  1. XCode 11 or newer
  2. Swift 5 or Objective-C codebase.
  3. Onboarded on PhonePe as a Merchant (Given a MerchantID, & Saltkeys to generate the checksum on your servers)

Steps to Integrate SDK

The DirectPaymentSDK framework is needed for the SDK to work for both PreProd (Testing) and Production (Deployment) environments.

  1. The framework and PhonePe PreProd iOS App can be found here. Download the SDK and App.

  2. Drag and drop the framework under your main project. Go to your Project Settings -> General tab and make sure that both the framework is added to the Frameworks, Libraries & Embedded Content section (With Embed & Sign selected) as shown in the below screenshot.

App Side

  1. In your Info.plist, create or append a new Array type node LSApplicationQueriesSchemes to append the following values:
  1. Add PhonePeAppId key with value as string in your app’s Info.plist as shown in the below screenshot for analytics purposes.
    To Get AppId: Share the Apple Team Id with the integration team to generate the AppId to be used.
  1. Create a URLType for your app (Deeplink), if not already present.
    For example, we have used: iOSIntentIntegration. (You can create your own identifier for your app)
  1. Using the Payload from your server, create a DPSTransactionRequest object, with callbackURL as the URLType in the step above.

  2. Initialize the PhonePeDPSDK and pass the DPSTransactionRequest object to the SDK. After the payment is complete and callback is received back to your app on the completionHandler, check the status of the transaction with your backend.

let request : DPSTransactionRequest = DPSTransactionRequest (
    body : base64EncodedString,
    apiEndPoint : service,
    checksum : payloadChecksum,
    headers : nil,
    callBackURL : callBackURL

PhonePeDPSDK.init (environment: .uat, enableLogging: true)
.startPhonePeTransactionRequest ( transactionRequest: request, on: self, animated: true )
    result in print ("Completion:---------------------")
    var text = "" 
    text = text + "Successful: \(result.isSuccessful)\n" 
    text = text + "Message: \(result.message ?? " ")\n" 
    text = text + "Status Code: \(String(describing: result.statusCode))\n" 
    print ("result := \(text)")
  1. Set the environment as .uat to test in the PreProd environment. While moving to the Production, set the environment as .production.

  2. In your AppDelegate, check for callback from the PhonePe app and if found, pass it to the SDK.

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    let handled = PhonePeDPSDK.checkDeeplink(url, options: options)
    if handled {
       // Phonepe is handling this, no need for any processing
       return true
   //Process your own deeplinks here
   return true

Server Side

  1. Save the below assigned value at your server
String apiEndPoint = "/v4/debit";
  1. Construct the request body and encode it 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
data.put("paymentScope", "PHONEPE"); // String. 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("subMerchant", <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.
// merchantUserId length should be less than 64 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 X-verify at your server as follows:
String checksum = sha256(base64Body + apiEndPoint + salt) + ### + saltIndex;
  1. Once the payment is completed, please call the Check Transaction Status API to validate the response received via App. You can call the Check Transaction Status at regular intervals to fetch the response from the PhonePe server in case a response is not received in the application even after 10 minutes of initiating the application.

  2. The payment status can be Successful, Failed, Pending or any of the codes. For Pending, you should retry until the status changes to Successful or Failed.