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 android app.
Follow the below steps to integrate Blaze SDK into your android application:
1.1. Include the repository for SDK Resolution to your project's settings.gradle.kts
or settings.gradle
file.
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// jitpack repository for Blaze SDK resolution
maven {
url = uri("https://jitpack.io")
}
}
}
1.2. Add Breeze SDK as an dependency to your app modules's build.gradle file
dependencies {
// ... rest of your app dependencies
// Add Blaze SDK as a dependency
implementation 'com.github.juspay:blaze-sdk-android:0.0.2-alpha'
}
2.1. Create an instance of the Blaze
class in your application class.
val blaze = Blaze()
2.2. Initiate the Blaze instance. Preferably in the onCreate
method of your application class.
In order to call initiate you need to perform the following steps:
Create a Json with correct parameters to initiate the SDK. This is the data that will be used to initialize the SDK.
// Create a JSONObject for the Initiate data
val initiatePayload = JSONObject()
initiatePayload.put("merchantId", "<MERCHANT_ID>")
initiatePayload.put("environment", "<ENVIRONMENT>")
initiatePayload.put("shopUrl", "<SHOP_URL>")
// Place Initiate Payload into SDK Payload
val initSDKPayload = JSONObject()
initSDKPayload.put("requestId", "<UNIQUE_RANDOM_ID>")
initSDKPayload.put("service", "in.breeze.onecco")
initSDKPayload.put("payload", initiatePayload)
Note: Obtain values for merchantId
, environment
and shopUrl
from the Breeze team.
Refer to schemas for understanding what keys mean.
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.
fun blazeCallbackHandler (event: JSONObject) {
val eventName = event.getString("eventName")
val eventData = event.getJSONObject("eventData")
when(eventName) {
// Handle various events according your desired logic
}
}
Finally, call the initiate method on the Blaze instance with the payload and the callback method. The first parameter is the context of the application.
blaze.initiate(this, initSDKPayload, ::blazeCallbackHandler)
Combined Example:
class MyApplication : Application() {
// Create Blaze Instance
val blaze = Blaze()
override fun onCreate() {
super.onCreate()
// 2.2 Initiate
// 2.2.1 Create a JSONObject for the Initiate data
val initiatePayload = JSONObject()
initiatePayload.put("merchantId", "<MERCHANT_ID>")
initiatePayload.put("environment", "<ENVIRONMENT>")
initiatePayload.put("shopUrl", "<SHOP_URL>")
// Place Initiate Payload into SDK Payload
val initSDKPayload = JSONObject()
initSDKPayload.put("requestId", "<UNIQUE_RANDOM_ID>")
initSDKPayload.put("service", "in.breeze.onecco")
initSDKPayload.put("payload", initiatePayload)
// 2.2.3 Initiate Blaze SDK
blaze.initiate(this, initSDKPayload, ::blazeCallbackHandler)
}
}
// 2.2.2: Creating a Callback handler
fun blazeCallbackHandler (event: JSONObject) {
val eventName = event.getString("eventName")
val eventData = event.getJSONObject("eventData")
when(eventName) {
// Handle various events according your desired logic
}
}
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 Json payload with the required parameters to process the request. The process payload differs based on the request. Refer to schemas sections to understand what kind of data is required for different requests
// 3.1 Create SDK Process Payload
// Create a JSONObject for the Process data
val processPayload = JSONObject()
processPayload.put("action", "<ACTION>")
// and more parameters required as per the action
// Place Process Payload into SDK Payload
val processSDKPayload = JSONObject()
processSDKPayload.put("requestId", "<UNIQUE_RANDOM_ID>")
processSDKPayload.put("service", "in.breeze.onecco")
processSDKPayload.put("payload", processPayload)
Call the process method on the Blaze instance with the process payload to start the user journey or a headless flow.
blaze.process(processSDKPayload)
For making the hardware back button work as expected, you need to call the handleBackPress
method on the Blaze instance.
The method should be called in the onBackPressed
method of the activity.
This method returns a boolean value which indicates if you need to handle back press or not.
override fun onBackPressed() {
if (!blaze.handleBackPress()) {
super.onBackPressed()
}
}
This section contains optional steps required to be implemented only if you are overriding the life cycle events of your activity.
onActivityResult
In order to handle results of App Switches in cases like UPI Intent transactions, you need to call super.onActivityResult() if available, if not you can make same function call on Blaze Instance.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// If super.onActivityResult is available use following:
super.onActivityResult(requestCode, resultCode, data)
// In case super.onActivityResult is NOT available please use following:
blaze.onActivityResult(requestCode, resultCode, data)
}
onRequestPermissionsResult
In order to handle results of Permission Request results for cases like OTP Reading, you need to call super.onRequestPermissionsResult() in your onRequestPermissionsResult lifeCycle hook, if available, if not you can make same function call on Blaze Instance.
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
// If super.onRequestPermissionsResult is available use following:
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
// In case super.onActivityResult is NOT available please use following:
blaze.onRequestPermissionsResult(requestCode, permissions, grantResults)
}