iOS Integration
Zoho Payments mobile SDK allows you to integrate directly with your iOS mobile app to collect payments from your customers.
Note: The minimum deployment iOS version for the ZohoPayments SDK is iOS 15.
Install Zoho Payments SDK
First, you’ll have to add the Zoho Payments SDK to your iOS app to initiate the integration.
To install the SDK to your iOS project:
- Open your project in Xcode.
- Select your project.pbxproj file, go to the Package Dependencies tab, and click Add Package Dependency.
- Enter the URL: https://github.com/zoho/zpayments-ios-sdk in the search bar to fetch the Zoho Payments package.
- Set the dependency rule to Exact Version and specify the latest SDK version, 1.0.0. This ensures that only the tested and approved version is used.
- Click Add Package.
Once added, import ZohoPayments
into your Swift files to integrate the checkout widget within your app.
Integrate Checkout Widget
Zoho Payments provides a native iOS SDK for embedding payments into your iOS app using SwiftUI and UIKit. You can integrate the checkout widget by initializing the SDK and invoking it with the required payment session details.
Initialize SDK
First, initialize the SDK using your API key and account ID, and provide a delegate from your app to process the payment results.
class PaymentController
{
var checkout: ZohoPaymentsCheckout? = nil
init()
{
checkout = ZohoPayCheckout(apiKey: Secrets.apiKey, accountId: Secrets.accId, domain: .IN, withCheckoutDelegate: self)
}
}
extension PaymentController: ZohoPaymentsCheckoutDelegate
{
func onPaymentSuccess(paymentId: String, signature: String)
{
//Handle Success case
}
func onPaymentFailure(code: String, message: String)
{
// Handle Failure case
}
}
If you’re facing any errors while processing payments via mobile app, refer to the error messages to identify and resolve the issue.
Specify the domain as IN, since this integration is currently available only in India.
public enum ZohoPayDomain {
case IN
}
Create Payment Session
Create a payment session to obtain the paymentSessionId
. To do this:
- Collect the payment details, such as the amount, currency, etc.
- Call the Payment Session Create API.
The API will return a paymentSessionId
. Use this ID to invoke the checkout widget and initiate the payment process.
Invoke Checkout Widget
Invoke the checkout widget from your app to initiate the payment process. Use the CheckoutOptions
with your paymentSessionId
and other parameters such as name, invoice number, and payment method.
UIKit
If you’re using UIKit (Storyboard, XIB, or UIViewController), invoke the checkout widget using the following function:
func open(on viewController: UIViewController, with options: CheckoutOptions)
SwiftUI
If you’re using SwiftUI, invoke the checkout widget using the following function:
func open(with options: CheckoutOptions)
The payment parameters for CheckoutOptions
and the supported payment methods are listed below:
Parameter | Description |
---|---|
paymentSessionId |
A unique identifier created for each payment session. Learn how to create a payment session. |
description |
Description of the payment session. The maximum length of the description can be 500 characters. |
invoiceNumber |
Invoice number of the payment session. The maximum length of the invoice number can be 50 characters. |
referenceNumber |
Reference number for the payment. |
name |
Name of the customer. |
email |
Email address of the customer. |
phone |
Phone number associated with the customer. |
paymentMethod |
Type of payment method (e.g., Cards, Net Banking, or UPI). |
Choose your preferred payment method from the below listed enums to receive payments from customers.
public enum PaymentMethod
{
case card
case netBanking
case upi
}
extension PaymentController
{
func openCheckout(viewController: UIViewController)
{
let options = CheckoutOptions(paymentSessionId: "1234567890",
description: "description of this payment",
invoiceNumber: "Inv_01",
referenceNumber: "Ref_01",
name: "Patricia Boyle",
email: "pboyle@zylker.com",
phone: "9898xxxxxx",
paymentMethod: .card)
// UIKit
checkout.open(on: viewController, with: options)
// SwiftUI
checkout.open(with: options)
}
}
Confirm Payment
After payment completion, the SDK returns the paymentId
and signature
via the ZohoPaymentsCheckoutDelegate
. You can confirm the payment on your server and update your system accordingly.
Verify Payment Status
Use the Payment Retrieve API with the paymentId
returned in the success callback to verify the transaction status. Update your system based on the status returned (success, failure, or pending).