Setting Up SDK
CocoaPods
In your pod file add the following linepod 'CashfreePG', '2.2.4'
. Ensure you are using the latest version of the SDK. Install the package using pod install
.
To provide UPI payments on iOS you will also need to enable the following permissions in your app. Open the info.plist
file and add the below content.
Step 1: Creating a Subscription
The first step in the Subscription Checkout integration is to create a subscription. You need to do this before any payment can be processed. You can add an endpoint to your server which creates this subscription and is used for communication with your frontend.Subscription creation must happen from your backend (as this API uses your secret key). Please do not call this directly from your mobile application. You can use below-mentioned backend SDKs
Once you create subscription, you will get the
subscription_id
and subscription_session_id
Step 2: Opening the Subscription Checkout Payment Page
Once the subscription is created, the next step is to open the payment page so the customer can make the payment. To complete the payment, we can follow the following steps:- Create a
CFSubscriptionSession
object. - Create a
CFSubscriptionPayment
object. - Set payment callback.
- Initiate the payment using the payment object created from [step 2]
Create a Session
This object contains essential information about the subscription, including the subscription session ID (subscription_session_id
) and subscription ID (subscription_id
) obtained from creation step. It also specifies the environment (sandbox or production).
Create Subscription Payment Object
UseCFSubscriptionPaymentBuilder
to create the payment object. This object accepts a CFSubscriptionSession
, like the one created in the previous step.
Setup callback
You need to set up callback handlers to handle events after payment processing. The callback implementsCFResponseDelegate
to handle payment responses and errors.
It can be initialized in viewDidLoad
by calling CFPaymentGatewayService.getInstance().setCallback(self)
or call it before calling startSubscription
.
- onError: Handles payment failures by displaying an alert with error details
- verifyPayment: Called when payment needs merchant verification, shows status alert to user
Step 3: Sample Code
Step 4: Confirming the Payment
After the payment is completed, you need to confirm whether the payment was successful by checking the subscription status. Once the payment finishes, the user will be redirected back to your activity.You must always verify payment status from your backend. Before delivering the goods or services, please ensure you call check the subscription status from your backend. Ensure you check the subscription status from your server endpoint.