Code Snippets

All HyperSDK and related code snippets.

isInitialised

Checks if current HyperSDK has been initialized. 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;

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.
hyperServices.onBackPressed() should be called during activity’s onBackPressed(). If the result is true, HyperSDK will consume the hardware back press.

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

In case the merchant wants to control backpress, they can call hyperServices.onBackPressed only when the UI is shown and Juspay can handle backpress. They can ignore the boolean response.

🚧

NOTE

If the passed activity is terminated in back press (super.onBackPressed or activity.finish), in this case hyper.onBackPressed returns true, 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.

Handling Permission Results

Juspay SDK uses permissions in various flows (Example OTP Auto Read), we will need the merchant to delegate the control to the android lifecycle event onRequestPermissionsResult() so that we can correctly process the result given by that corresponding permission request. To do that, the following code snippet can be used:

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    // Merchant code
}

📘

Note

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

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

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    hyperServices.onRequestPermissionsResult(requestCode, permissions, grantResults);
    // Merchant code
}

🚧

Note

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


What’s Next
Did this page help you?