Skip to main content
Cashfree’s iOS SDK provides a streamlined payment solution that integrates the payment gateway into your iOS applications through a WebView-based checkout implementation, supporting iOS deployment target 11 and above.

Key benefits

The iOS SDK offers the following advantages for your payment integration:
  • Simplified integration: Provides a pre-built SDK that delivers an optimised payment experience for iOS applications.
  • Secure and compliant: Securely handles payment processing with built-in security measures managed by the SDK.
  • Multiple integration methods: Supports both Swift Package Manager (recommended) and CocoaPods for easy installation.

Prerequisites

Ensure you complete the following tasks before starting the integration: The iOS integration consists of three essential steps:

Step 1

Create an order

Step 2

Open the payment page

Step 3

Confirm the payment
The step-by-step guide for each step of the integration process is as follows:

Step 1: Create an order Server-side

To integrate the Cashfree Payment Gateway, you must first create an order. Complete this step before you process any payments. Configure an endpoint on your server to handle order creation. You can’t call this API from the client-side.
Create orders through your server as this API requires your secret key. Don’t call it directly from your mobile application.
API request for creating an order
Here’s a sample request for creating an order using your desired backend language. Cashfree offers backend SDKs to simplify the integration process.
After successfully creating an order, you will receive a unique order_id and payment_session_id that you need for subsequent steps. You can view the complete API request and response for /orders in the Create Order API.

Step 2: Open the payment page Client-side

Web Checkout is a streamlined payment solution that integrates Cashfree’s payment gateway into your iOS app through the SDK. This implementation uses a WebView to provide a secure, feature-rich payment experience. Your customers are presented with a familiar web interface where they can enter their payment details and complete their transaction seamlessly. All payment logic, UI components, and security measures are managed by the SDK, eliminating the need for complex custom implementation.

1. Set up the SDK

Swift Package Manager (recommended)
The recommended way to integrate the Cashfree iOS SDK is by using Swift Package Manager. You can do this through the Xcode interface. To add the Cashfree iOS SDK to your project, follow these steps:
  1. Open your project in Xcode.
  2. Go to File > Add Package Dependencies.
  3. Enter the repository address: https://github.com/cashfree/core-ios-sdk.git.
  4. Select the version rule (Recommended: Up to Next Major Version).
  5. Choose the products you need:
    • CashfreePG—Complete Payment Gateway SDK (recommended)
    • CashfreePGCoreSDK—Core payment processing
    • CashfreePGUISDK—UI components
    • CashfreeAnalyticsSDK—Analytics and tracking
    • CFNetworkSDK—Networking layer
CocoaPods
In your pod file add the following line pod 'CashfreePG', '2.4.0'. Install the package using pod install.
iOS configuration
To provide UPI payments on iOS you need to enable the following permissions in your app. Open the info.plist file and add the below content:

2. Complete the payment

To complete the payment, follow these steps:
  1. Create a CFSession object.
  2. Create a Web Checkout Payment object.
  3. Set payment callback.
  4. Initiate the payment using the payment object created.

Create a session

This object contains essential information about the order, including the payment session ID (payment_session_id) and order ID (order_id) obtained from Step 1. It also specifies the environment (sandbox or production).

Create a web checkout payment object

Use CFWebCheckoutPayment to create the payment object. This object accepts a CFSession, like the one created in the previous step.

Setup callback

Set up callback handlers to handle events after payment processing. The callback implements CFResponseDelegate to handle payment responses and errors. Initialise it in viewDidLoad by calling CFPaymentGatewayService.getInstance().setCallback(self).
  • onError: Handles payment failures by displaying an alert with error details
  • verifyPayment: Called when payment needs merchant verification, shows status alert to user
Make sure to set the callback at activity’s onCreate as this also handles the activity restart cases.

Sample code

Step 3: Confirm the payment Server-side

After the customer completes the payment, you must confirm the payment status. Once the payment finishes, the user redirects back to your activity. To verify an order you can call our /pg/orders endpoint from your backend. You can also use our SDK to achieve the same.
Always verify the order status before you deliver services to the customer. You can use the Get Order API for this. An order is successful when the order_status is PAID.

Testing

After you integrate the checkout functionality, verify that it opens the Cashfree-hosted payment page. Follow these steps to test:
  1. Click the checkout button.
  2. Verify you’re redirected to the Cashfree Checkout payment page.

Error codes

To confirm the error returned in your iOS application, you can view the error codes that are exposed by the SDK.
CashfreeError is an Enum that inherits Foundations Error class. The following are some of the error codes that are exposed by the SDK:

Affiliate partner program

As a developer building payment experiences for your clients, you can earn additional income while providing them with industry-leading payment solutions.

Join the Cashfree affiliate partner program and get rewarded every time your clients use Cashfree.

What you get:

  • Earn up to 0.25% commission on every transaction.
  • Become a trusted fintech partner for your clients.
  • Access to a dedicated partner manager for expert support.

What your clients get:

  • Instant activation and go live in minutes.
  • Industry-best success rate across all payment modes.
  • Effortless acceptance of international payments in 140+ currencies.

Get started today. Become a partner now.