- Created by Seema, last modified on Dec 03, 2020
UPI SDKs enable you to create and manage different UPI workflows. The iOS UPI SDKs are designed to provide the app framework to support multiple layout and style properties.
In this article, the iOS UPI SDK integration is documented in both Swift and Objective C languages.
Prerequisites
Take care of the following prerequisites before you begin with SDK set up:
- Fusion uses an authentication token to authenticate the SDK. To know how to generate an authentication token, see SDK Authentication.
- Minimum iOS version required: 10
- Minimum Cocoapods version required: 1.9.1
Ensure you have
pay.plist
andupi.plist
files that contain configuration data necessary to set up the SDK. Contact Zeta in case if you haven't received the file.
Getting Started with iOS UPI SDK
Follow the steps below to integrate SDK:
- First, you should add the SDK to your project or app.
- Prepare the SDK set up.
- Initialize your SDK.
- Now the SDK set up is ready, to begin with, the integration process.
Step 1: Adding the SDK
The UPI SDK is compatible with apps supporting iOS with version 10 and above. To add the SDK to your project, follow these steps:
Download and extract the below zip folder containing an XCFramework for UPI SDK.
Drag & drop the XCFramework manually into your project's target.
Click Embed & sign under the XCFramework in your project's target.
Set Allow Non-modular Includes in Framework Modules to "YES" under Target > Build Settings.
Set Enable Bitcode to "NO" under Target > Build Settings.
Step 2: Setting up the SDK
Add the configuration file
A configuration file contains all the properties necessary for activating the SDK. You should add the file to your project to prepare your app to work with the SDK. You will receive the configuration file named pay.plist
and upi.plist
through email. If you haven't received the file, contact Zeta. Make sure the configuration files are available in the bundle.
Adding theme and layout files
UPI SDK and Pay SDK provide you with the capability to define the theme used by the SDK. These can be edited remotely so you won’t have to ship a new app build for changing how your view looks. You can change your theme by contacting Zeta and it will reflect on your app on the next launch.
Configure properties
To enable authentication using face recognition (Face ID), add a value to the NSfaceIdUsageDescription
(Privacy - Face ID Usage Description) with a message in the info.plist
file. Pay SDK also uses location and camera permission (if you have QR code payments enabled) to enable payments, add a value to the NSLocationWhenInUseUsageDescription
and NSCameraUsageDescription
keys in the info.plist
file.
Step 3: Initialize the SDK
To initialize the UPI and Pay SDKs, the following method calls should be made:
- Call the
[ApolloUpiSdk initializeSdk]
method. - Call the
[ApolloPaySdk initializeSdk]
method
Initialize it inside the [application didFinishLaunchingWithOptions:]
method of your Application class.
#import "AppDelegate.h" #import <ApolloPay/ApolloPaySdk.h> #import <ApolloUpi/ApolloUpiSdk.h> @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [ApolloUpiSdk initializeSdk]; [ApolloPaySdk initializeSdk]; return YES; }
Step 4: Integrating the SDK
Both Pay and UPI are stateful SDKs. Before you start using the SDK features, take care of the following:
Authenticating the SDK
For a user of your app to be able to use the UPI SDK through your app, you need to authenticate the user with the tenantAuthToken
. The tenantAuthToken
needs to be computed in your backend as it needs sensitive information to create the token. The information used to generate the tenantAuthToken
should never be compromised.
- For UPI SDK, set the
tenantAuthToken
to the UPI SDK once the user logs into your app and you have sufficient information to issue a tenantAuthToken for the user. - For PAY SDK, set the
tenantAuthToken
to the PAY SDK once the user logs into your app and you have sufficient information to issue a tenantAuthToken for the user.
To know the steps used in the generation of tenantAuthToken
, see SDK Authentication. Following is a code snippet on how to authenticate the SDKs:
[ApolloUpiSdk authenticateWithToken:token successBlock:^{} failureBlock:^(NSError *error) { }]
[ApolloPaySdk authenticateWithToken:token successBlock:^{} failureBlock:^(NSError *error) { }]
- This step has to be performed in a fresh log-in of the user or when the earlier provided
tenantAuthToken
expires. - A
tenantAuthToken
has an associated validity with it. The ideal practice is to reset a new token before it expires.
Using the SDK
Ensure that this step is performed only after you have authenticated the SDK.
For UPI SDK, after SDK authentication is completed successfully, you can initiate UPI registration flow by invoking the following method by passing the required arguments:
[ApolloUpiSdk triggerRegistrationWithPhoneNumbers:@[phoneNumber] firstName:firstName lastName:lastName emailID:email successBlock:^(NSString *vpa) { } failureBlock:^(NSError *error) { }];
For Pay SDK, there are few more steps that you need to perform before you can start making payments through the various modes offered by the SDK.
Make sure UPI registration is successful. Pay SDK will not function unless it has a valid VPA registered.
After a successful VPA registration, you will need to set up the Pay SDK by invoking the following method
[ApolloPaySdk setupWithAccountHolderID:accountHolderID successBlock:^{ } failureBlock:^(NSError *error) { }];
Here, accountHolderID is the tenant unique vector that is used to identify the tenant user uniquely.
Pay SDK APIs
You are now ready to use the Pay SDK to work with your user
Pay via QR Code/UPI ID
You can get the navigation controller instance to start the UPI payment flow by scanning the QR Code or entering the UPI ID, by invoking the following method:
UINavigationController *viewController = [ApolloPaySdk payHook];
This is a nullable method. It will return nil in case Pay SDK is not yet set up properly. So, please add a null check before presenting the navigation controller returned by this method to avoid runtime exceptions.
View your QR Code
You can get the navigation controller instance to show the QR code of the user, by invoking the following method:
UINavigationController *viewController = [ApolloPaySdk viewVpaHook];
This is a nullable method. It will return nil in case Pay SDK is not yet set up properly. So, please add a null check before presenting the navigation controller returned by this method to avoid runtime exceptions.
Request Money
You can get the navigation controller instance to start the request money flow, by invoking the following method:
UINavigationController *viewController = [ApolloPaySdk requestMoneyHook];
This is a nullable method. It will return nil in case Pay SDK is not yet set up properly. So, please add a null check before presenting the navigation controller returned by this method to avoid runtime exceptions.
Pending Requests
You can get the navigation controller instance to show the pending collect requests screen, from which the user can approve, decline received requests, or cancel the sent requests, by invoking the following method:
UINavigationController *viewController = [ApolloPaySdk viewCollectRequestsHook];
This is a nullable method. It will return nil in case Pay SDK is not yet set up properly. So, please add a null check before presenting the navigation controller returned by this method to avoid runtime exceptions.
Logout
Ensure that you logout the user by calling this API when you want to switch a user or the user logs out from the app. Failing to do this, the SDK may behave erratically later on. Here is a code snippet for the same.
[ApolloUpiSdk logout];
[ApolloPaySdk logoutWithSuccessBlock:nil failureBlock:nil];
After log out, you will have to perform all the steps starting from authentication using tenant token for SDK to function properly.
Exceptions and error codes
The following table lists the error codes, descriptions, and possible solutions. If the issue persists, contact Zeta.
UPI SDK
Error codes | Descriptions |
---|---|
1000 | Internal error |
1001 | Unauthorized error |
Pay SDK
Error codes | Descriptions |
---|---|
1000 | Internal error |
1001 | Unauthorized error |
- No labels