The Blaze SDK is an easy-to-use toolkit that allows you to effortlessly integrate and utilize Breeze 1 Click Checkout & its services into your iOS app.
- iOS 12.0+
- Swift 5.0+
- Xcode 13.0+
Follow the below steps to integrate Blaze SDK into your iOS application:
BlazeSDK is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'BlazeSDK'Then run:
pod install2.1. Import the SDK and create an instance of the Blaze class in your view controller.
import BlazeSDK
class ViewController: UIViewController {
let blaze = Blaze()
}2.2. Initiate the Blaze instance.
In order to call initiate you need to perform the following steps:
Create a dictionary with the correct parameters to initiate the SDK. This is the data that will be used to initialize the SDK.
// Create the Initiate data
var initiatePayload: [String: Any] = [:]
initiatePayload["merchantId"] = "<MERCHANT_ID>"
initiatePayload["environment"] = "<ENVIRONMENT>"
initiatePayload["shopUrl"] = "<SHOP_URL>"
// Place Initiate Payload into SDK Payload
var initSDKPayload: [String: Any] = [:]
initSDKPayload["requestId"] = UUID().uuidString
initSDKPayload["service"] = "in.breeze.onecco"
initSDKPayload["payload"] = initiatePayloadNote: Obtain values for
merchantId,environmentandshopUrlfrom the Breeze team.
During the user journey the SDK will call the callback method with the result of the SDK operation. You need to implement this method in order to handle the result of the SDK operation.
func blazeCallbackHandler(event: [String: Any]) {
if let eventName = event["eventName"] as? String {
switch eventName {
// Handle various events according to your desired logic
default:
break
}
}
}Finally, call the initiate method on the Blaze instance with the payload and the callback method. The first parameter is the UIViewController context.
blaze.initiate(
context: self,
initiatePayload: initSDKPayload,
callbackFn: { event in
self.blazeCallbackHandler(event: event)
}
)Combined Example:
import BlazeSDK
import UIKit
class ViewController: UIViewController {
// Create Blaze Instance
let blaze = Blaze()
override func viewDidLoad() {
super.viewDidLoad()
initiateSDK()
}
func initiateSDK() {
// 2.2.1 Create the Initiate data
var initiatePayload: [String: Any] = [:]
initiatePayload["merchantId"] = "<MERCHANT_ID>"
initiatePayload["environment"] = "<ENVIRONMENT>"
initiatePayload["shopUrl"] = "<SHOP_URL>"
// Place Initiate Payload into SDK Payload
var initSDKPayload: [String: Any] = [:]
initSDKPayload["requestId"] = UUID().uuidString
initSDKPayload["service"] = "in.breeze.onecco"
initSDKPayload["payload"] = initiatePayload
// 2.2.3 Initiate Blaze SDK
blaze.initiate(
context: self,
initiatePayload: initSDKPayload,
callbackFn: { event in
self.blazeCallbackHandler(event: event)
}
)
}
// 2.2.2: Creating a Callback handler
func blazeCallbackHandler(event: [String: Any]) {
if let eventName = event["eventName"] as? String {
switch eventName {
// Handle various events according to your desired logic
default:
print("Received event: \(eventName)")
}
}
}
}Once the SDK is initiated, you can start processing your requests using the initialized instance of the SDK. The SDK will call the callback method with the result of the SDK operation.
Create a dictionary payload with the required parameters to process the request. The process payload differs based on the request.
// 3.1 Create SDK Process Payload
var processPayload: [String: Any] = [:]
processPayload["action"] = "<ACTION>"
// and more parameters required as per the action
// Place Process Payload into SDK Payload
var processSDKPayload: [String: Any] = [:]
processSDKPayload["requestId"] = UUID().uuidString
processSDKPayload["service"] = "in.breeze.onecco"
processSDKPayload["payload"] = processPayloadCall the process method on the Blaze instance with the process payload to start the user journey or a headless flow.
blaze.process(payload: processSDKPayload)When you are done with the SDK, call the terminate method to clean up resources.
blaze.terminate()In order to allow the SDK to launch UPI apps in UPI intent flow, you need to add the following to the Info.plist file of your iOS app:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>credpay</string>
<string>phonepe</string>
<string>paytmmp</string>
<string>tez</string>
<string>paytm</string>
<string>bhim</string>
<string>myairtel</string>
<string>slice-upi</string>
<string>ppe</string>
<string>amazonpay</string>
</array>This declares the URL schemes for UPI apps that the SDK may attempt to open. Without this configuration, iOS will not allow the SDK to check for or launch these apps.
| Scheme | App |
|---|---|
credpay |
CRED |
phonepe |
PhonePe |
paytmmp |
Paytm |
tez |
Google Pay |
paytm |
Paytm |
bhim |
BHIM |
myairtel |
Airtel Thanks |
slice-upi |
Slice |
ppe |
PhonePe (legacy) |
amazonpay |
Amazon Pay |
To run the example project, clone the repo, and run pod install from the Example directory first.
git clone https://github.com/juspay/blaze-sdk-ios.git
cd blaze-sdk-ios/Example
pod install
open BlazeSDK.xcworkspaceBlazeSDK is available under the MIT license. See the LICENSE file for more info.