Why choose Cashfree?
- Secure and PCI compliant: Securely collects payment details and submits them directly to Cashfree servers, removing the need for Payment Card Industry Data Security Standard (PCI DSS) compliance requirements at the merchant’s end.
- Native iOS integration: Seamlessly integrate payments into your iOS app using WKWebView without requiring third-party SDKs.
- Support for multiple payment methods: Accepts payments from over 120 payment methods including UPI Intent for direct app-to-app transfers.
Prerequisites
- Create a Cashfree Merchant Account and log in.
- Navigate to Developers > API Keys to generate your App ID and Secret Key. Learn how to generate API keys.
- Minimum iOS version is iOS 11.0 with WKWebView support.
Step 1: Create order Server-side
Create an order from your backend before processing the payment. This is a server-side operation and must not be called from the client side.- Order creation must be done through your backend as this API requires your secret key.
- Always provide a return URL when creating the order—it will be used to detect when the payment flow is complete.
Step 2: Submit form Client-side
Submit the checkout form from your app’s web view using the payment session ID obtained from Step 1.This step requires your application’s bundle ID to be whitelisted by Cashfree Payments. Please check Bundle ID Whitelisting.
Swift
Step 3: Handle redirection Client-side
Once the payment flow has ended, Cashfree Payments will redirect you to the URL specified while creating the order. Detect the URL redirection and close the web view appropriately.Swift
UPI intent from checkout
UPI Intent allows users to make direct payments through installed UPI applications without entering payment details manually. If you want to add UPI intent functionality to your custom iOS checkout integration, follow the steps below.-
Add the required UPI app schemes to your info.plist file.
You need to add the following to your info.plist to enable your app to detect installed UPI applications:swift -
Add the JSBridge functions for the checkout page to get the list of installed UPI apps and handle opening the selected UPI app.
Swift
Testing
After completing the iOS integration, verify that the payment flow works correctly:- Create a test order from your backend with a valid return URL.
- Load the checkout form in your WKWebView with the payment session ID.
- Verify that the payment page loads in the web view.
- Test the payment flow end-to-end using test credentials.
- Verify that the return URL is triggered correctly after payment completion.
- If using UPI Intent, test with actual UPI applications installed on your test device.
Sample code
Swift