Code Snippets

Android

isInitialised

Checks if current HyperSDK has been initialised. It should be used to check the HyperSDK instance state before calling process API.

/**
Checks if current sdk instance has been initialised.
*/
public boolean isInitialised;


//Example usage
if (hyperServices.isInitialised()) {
    hyperServices.process(processPayload);
} else {
  //Intialise hyperInstance
}
/**
Checks if current sdk instance has been initialised.
*/
- (Boolean)isInitialised;

//Example usage
if hyperInstance.isInitialised {
    hyperInstance.process(processPayload);
} else {
  //Intialize hyperInstance
}
/**
Checks if current sdk instance has been initialised..
*/
- (Boolean)isInitialised;

//Example usage
if ([hyperInstance isInitialised]) {
    [hyperInstance process:processPayload];
} else {
  //Intialize hyperInstance
}

UUID

Sample snippets to generate uuid-v4 string. Used in HyperSDK as [requestId]

UUID.randomUUID().toString()
NSUUID().uuidString
NSUUID.UUID.UUIDString;

Note: Swift code can be used for Android, but Objective-C can only be used with iOS).

Backpress control

Since HyperSDK is a fragment, we will need the back-press event from the current activity to trigger events required for hardware back press.

The blocking asynchronous call HyperSdkReact.onBackPressed() should be called during activity’s onBackPressed(). If the call returns true, Hyper SDK will handle the back press, else the merchant can handle it.

@Override
public void onBackPressed() {
    boolean backPressHandled = hyperServices.onBackPressed();
    if(!backPressHandled) {
        super.onBackPressed();
    }
}

The merchant also has the option of controlling backpress by calling HyperServices.onBackPressed when the UI is shown. In this case, Juspay will handle backpress, and the boolean response can be ignored.

🚧

NOTE

If the passed activity is terminated in back press (super.onBackPressed or activity.finish), in this case hyper.onBackPressed returns "true" (Shouldn't this be "false"? - Check the code.), which will cause HyperSDK ui to be removed.

Activity Result for UPI Intent switches

If the merchant wants to use UPI Intent transactions (or any other transaction which requires us to switch to a third-party app) through Juspay SDK, we will need the merchant to delegate the control to the android lifecycle event onActivityResult() so that we can correctly process the result given by that corresponding android intent. To do that, the following code snippet can be used:

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   // merchant code...
}

📘

NOTE

The above snippet can be ignored if the merchant is not overriding the onActivityResult method provided by android.

If super.onActivityResult is not accessible to the merchant, they can implement it using a similar method provided by HyperServices:

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
   hyperServices.onActivityResult(requestCode, resultCode, data);
   // merchant code...
}

🚧

Note

Merchants using ReactActivity must call the above code snippet, for the SDK to function as expected.

iOS

Declare URL Schemes for UPI Apps

Add the following properties in the App’s Info.plist file to use canOpenURL to check available UPI Apps

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>credpay</string>
        <string>phonepe</string>
        <string>paytmmp</string>
        <string>tez</string>
        <string>paytm</string>
    </array>

Did this page help you?