CFSubsCardComponent captures and processes the card number entirely within the SDK. Your application never receives the raw card number.
This integration is suitable for non-PCI merchants. A non-PCI merchant is not certified to store, process, or transmit raw cardholder data and relies on the SDK to handle card data securely on their behalf.
The component provides auto-formatted card number input (groups of four digits), real-time card network detection with icon display, Luhn validation on every keystroke, and automatic BIN lookup after eight digits. Metadata is delivered through CFSubsCardListener. You receive only digit count, Luhn result, and BIN info, not the raw card number.
This page covers the custom card component integration only. For the full iOS Subscription Element integration, including UPI and eNach (net banking), see iOS Integration.
For merchants with raw card access (PCI-DSS certified), use
.setCardNumber() on CFCardSubs.CFCardSubsBuilder() directly instead of CFSubsCardComponent. That path follows the standard subscription card flow.Prerequisites
Complete the following tasks before you start the integration:- Create a Cashfree Merchant Account.
- Log in to the Merchant Dashboard and generate an App ID and Secret Key. Learn how to generate API keys.
- Use Cashfree iOS SDK version 2.4.0 or above.
- Set your application’s minimum deployment target to iOS 13.0 or higher.
Step 1
Create a subscription
Step 2
Open the payment page
Step 3
Confirm the payment
Step 1: Create a subscription Server-side
Create a subscription from your backend server before you process any payment.This API requires your secret key. Create subscriptions through your server only. Do not call this API directly from your mobile application.
subscription_id and a subscription_session_id. Pass both values to your iOS client to proceed with the payment.
API request for creating a subscription
API request for creating a subscription
The following example shows how to create a subscription using the Create Subscription API:A successful response returns the For the full list of request parameters and response fields, see the Create Subscription API.
subscription_id and subscription_session_id. Use these values to build the CFSubscriptionSession object in Step 2. The API returns the following response on success:Step 2: Open the payment page Client-side
After you create the subscription, set up the card component and open the payment page so the customer can provide their card details.1. Set up the SDK
The Cashfree iOS SDK is available via CocoaPods. The integration requires version 2.4.0 or above and iOS 13.0 or higher. Add the following to yourPodfile:
pod install to install the dependency.
2. Complete the payment
To complete the payment, follow these steps:- Add the
CFSubsCardComponentto your view. - Initialise the card component after the session is ready.
- Create a
CFSubscriptionSessionobject. - Conform to
CFSubsCardListenerto receive card metadata. - Set up the payment callback.
- Build the payment object and initiate the payment.
Add the card component to your view
CFSubsCardComponent is a UIView that you can add in Interface Builder or programmatically. In Interface Builder, set the custom class of a UIView to CFSubsCardComponent and connect it as an outlet:
UIView styling as needed:
Initialise the card component
CallinitializeCardComponent only after you have a valid CFSubscriptionSession. The component uses the session to authenticate BIN lookup requests.
| Parameter | Type | Required | Description |
|---|---|---|---|
session | CFSubscriptionSession | Yes | Session from your backend. |
card_listener | CFSubsCardListener | Yes | Receives metadata on every keystroke. |
hint_text | String | Yes | Placeholder text. Pass "" for the default XXXX XXXX XXXX XXXX format. |
font | UIFont? | No | Custom font. Pass nil for the system default. |
textColor | UIColor? | No | Text colour. Pass nil for the system default. |
enable_pasting | Bool | Yes | Whether the user can paste from the clipboard. |
Create a session
TheCFSubscriptionSession object holds the session context for the payment. It accepts the subscription_session_id and subscription_id obtained from Step 1, and the Cashfree environment (.SANDBOX or .PRODUCTION).
Set the environment to .SANDBOX for testing or .PRODUCTION for live payments. The following example shows how to create the session object:
Set up the CFSubsCardListener callback
Conform your view controller toCFSubsCardListener and implement cardMetaData(card_listener_response:). This callback fires on every keystroke and again after the BIN lookup completes.
CFSubsCardListenerResponse with the following top-level fields:
| Field | Type | Description |
|---|---|---|
numberOfCharacters | Int? | Number of digits entered in the card component (spaces excluded). |
message | String? | Informational message about the response. |
type | String? | Always "card_info". |
meta_data | [String: Any]? | Contains card validation and BIN data (see below). |
meta_data dictionary contains the following keys:
| Key | Type | Description |
|---|---|---|
card_length | Int | Same as numberOfCharacters; total digits entered. |
luhn_check | Bool | true if the entered card number passes the Luhn algorithm; false otherwise. |
card_bin_info | [String: Any] | Populated once 8 digits are entered. Contains BIN lookup data from the server. nil if fewer than 8 digits are entered. |
meta_data["card_bin_info"] on the next cardMetaData callback. No additional setup is required. Authentication uses the x-sub-session-id from the session provided at initialisation.
The card_bin_info dictionary returned from the BIN lookup API contains the following fields:
| Field | Description |
|---|---|
Card_bin | Bank Identification Number. |
logo | Card network logo reference. |
sub_type | Card sub-type classification. |
type | Card type classification. |
schema | Card network schema. |
brand | Card brand classification. |
bank name | Issuing bank name. |
Set up the payment callback
The SDK exposes theCFResponseDelegate protocol to receive callbacks when the subscription payment journey ends. This protocol consists of two methods:
Build the payment object and initiate payment
When the customer fills in their card details and taps the pay button, build theCFCardSubs and CFCardSubsPayment objects and call doSubsPayment() on CFPaymentGatewayService.
The CFCardSubs.CFCardSubsBuilder() supports the following methods:
| Method | Required | Description |
|---|---|---|
.setChannel(_ channel: String) | Yes (default: "link") | Payment flow type. |
.setCardComponent(_ component: CFSubsCardComponent) | Yes | Component reference; replaces .setCardNumber(). |
.setCardHolderName(_ name: String) | No | Cardholder name. |
.setCardExpiryMonth(_ month: String) | Yes | Expiry month in "MM" format. |
.setCardExpiryYear(_ year: String) | Yes | Expiry year in "YY" format. |
.setCVV(_ cvv: String) | Yes | Card CVV. |
There is no public API to read the card number out of
CFSubsCardComponent. The SDK uses it securely when doSubsPayment is called.Sample code
The following example shows a complete custom card component payment flow, including session creation, card component initialisation, metadata handling, and payment initiation.Custom card component payment sample
Custom card component payment sample
The following example demonstrates a complete non-PCI card payment integration using
CFSubsCardComponent:iOS subscription custom card component sample
iOS subscription custom card component sample
Step 3: Confirm the payment Server-side
After the SDK delivers a callback viaverifyPayment, confirm the payment status from your backend before taking any action. The SDK callback signals only that the payment flow has ended. It does not guarantee a successful payment.
Use the Fetch Details of All Payments of a Subscription API to retrieve the current payment status.
API request for fetching subscription payments
API request for fetching subscription payments
The following request fetches all payments for a subscription:A successful response returns an array of payment objects. Check the
payment_status field to determine the outcome. The API returns the following response on success:Always verify the subscription status from your backend before delivering goods or services to the customer. Proceed only when
payment_status is SUCCESS.Error codes
If a required field or object is missing when you initiate payment, the SDK returns an error through thecatch block or onError callback. The following table lists common SDK-level validation errors and when they occur.
Show error codes
Show error codes
The SDK validation errors are grouped by category as follows:
Session errors
These errors occur when theCFSubscriptionSession object or its required fields are not provided.| Error code | Message | Description |
|---|---|---|
SUBSCRIPTION_SESSION_OBJECT_MISSING | The “CFSubscriptionSession” is missing in the request. | The CFSubscriptionSession object was not passed to the payment builder. |
SUBSCRIPTION_SESSION_ID_MISSING | The “subscription_session_id” is missing in the request. | The subscription_session_id was not set on the CFSubscriptionSession builder. |
SUBSCRIPTION_ID_MISSING | The “subscription_id” is missing in the request. | The subscription_id was not set on the CFSubscriptionSession builder. |
ENVIRONMENT_MISSING | The “environment” is missing in the request. | The Cashfree environment (.SANDBOX or .PRODUCTION) was not set on the CFSubscriptionSession builder. |
Payment method object errors
These errors occur when a payment method object is absent or one of its required fields is not set.| Error code | Message | Description |
|---|---|---|
SUBSCRIPTION_CARD_OBJECT_MISSING | The “CFCardSubs” object is missing in the request. | The CFCardSubs object was not passed to the CFCardSubsPayment builder. |
Callback errors
These errors occur when the payment callback is not registered before initiating payment.| Error code | Message | Description |
|---|---|---|
CALLBACK_MISSING | The “callback” cannot be null. | setCallback was not called on CFPaymentGatewayService before doSubsPayment(). Register the callback before you initiate payment. |
Other options
The following optional configurations let you customise the payment screen behaviour.(Optional) Enable full-screen payment
(Optional) Enable full-screen payment
To present the payment flow in full screen, call
setFullScreen(true) on the payment object before you call doSubsPayment():