SDK Setup

In this part we will talk about how you can integrate iOS SDK and initiate payment:

Quick Links

anchor image
Copied !

Prerequisites :

  • XCode 12.5 or newer
  • Cocoapod
  • Onboarded on PhonePe as a Merchant (Given a MerchantID, Client Secret and version to generate the o-auth token )

iOS PG SDK setup

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

  • The PhonePePayment SDK is available through CocoaPods [Refer to this link ], Latest Phonepe iOS SDK Version: 4.0.1.
  • To install it, simply add the following line to your Podfile:
pod 'PhonePePayment'

then run :

pod install

Import the framework in your project using “import PhonePePayment”

Remove the “DirectPaymentSDK” from your project if you have already integrated and want to migrate to CocoaPods.

import PhonePePayment

iOS PG App Side Implementation

Step 1. In your Info.plist, create or append a new Array type node LSApplicationQueriesSchemes to append the following values:

<key>LSApplicationQueriesSchemes</key> <array> <string>ppemerchantsdkv1</string> <string>ppemerchantsdkv2</string> <string>ppemerchantsdkv3</string> <string>paytmmp</string> <string>gpay</string> <string>credpay</string> <string>amazonpay</string> <string>bhim</string> </array>

Step 2. Create DeepLink Schema

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)

URLScheme should match the below conditions :

  • Only Alphabets (lower and upper case) and numbers are allowed.
  • We can allow special characters only like dot and Hyphen
  • The name should always start with alphabets.
  • The schema should be correct to redirect the app otherwise it will not redirect back to the merchant app.

To Enable Debug Logs

Update the PPPayment.enableDebugLogs = true or enableLogging flag to true in startPG method.

Environment :

  • .Production for Live
  • .Sandbox for Sandbox testing

Step 3. Initialize the PG SDK

let ppPayment = PPPayment(environment: .production, flowId: "FLOW_ID", merchantId: "MERCHANT_ID")
Parameter NameTypeDescription
environmentEnum.production for Production
.sandbox for PreProd
flowIdStringPass the merchant user Id or the unique string (UUID().uuidString) for every init for analytics purposes.
merchantIdStringThe merchant Id provided by PhonePe
enableLoggingBoolean[Optional Parameter]
– True
(To enable the SDK logs)
– False
(To disable the SDK logs)
Note: In Prod, make sure to set as False.
  • Initialize the PPPayment with the environment and pass the PhonePe generate orderId and token which was received in response of Create order API from your backend. SDK will handle the request & get back the response.
  • After the payment is complete and a callback is received back to your app on the completionHandler, Check the status of the transaction with your backend.
anchor image
Copied !

Example :

public func startCheckoutFlow(merchantId: String, orderId: String, token: String, appSchema: appSchema, on viewController: UIViewController, completion: @escaping PhonePePayment.PPTransactionCompletion) Example: ppPayment.startCheckoutFlow(merchantId: merchantId, orderId: orderId, token: token, appSchema: appSchema, on: vc) { _, state in print(state) }
Parameter NameTypeDescription
merchantIdStringProvided by PhonePe
orderIdStringThe PhonePe Order ID received in the Create Order API response.
tokenStringThe order token received in the Create Order API response.
In your appdelegate, check for a 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 = PPPayment.checkDeeplink(url, options: options) if handled { // Phonepe is handling this, no need for any processing return true } //Process your own deeplinks here return true }

After the method calls, you will get the control in the completion block.

Once the redirection back to the merchant app then back to the Order Status API /check for webhook response accordingly update the original status to Users.

anchor image
Copied !

Step 1. Fetch Auth Token

Merchants to check whether the valid Auth Token is present already. If not, the Fetch Auth Token API should be called to get the valid Auth Token.

Step 2. Call the Create Order API

Merchants should call Create Order API for Order creation with the valid Auth Token from the merchant Backend side by passing the required details. PhonePe backend will pass the Order Token in response to the merchant Backend.

Step 3. Pass the Order Token and Order ID to frontend

Merchant should pass the Order Token and Order ID received in the Create Order API response to the frontend application which will further passed to the SDK method: ppPayment.startCheckoutFlow.

Step 4. Check the payment status

Once the payment is completed, merchants should check with the backend server if the Webhook has been received or not.

  • If not, merchants should call the Order Status API to fetch the current payment status.
  • If the status is terminal status like: COMPLETED or FAILED, the the order status can be updated accordingly.
  • If incase, the status is PENDING, then merchants should call the Order Status API at regular intervals like every 15 secs or 30 secs or 1min once till the terminal status is reached.
anchor image
Copied !
  • 4.0.1 – Added support for three more UPI Apps – CRED, AMAZON, BHIM.