React Native Code Snippets

Android Hardware Back-Press Handling

Hyper SDK internally uses an android fragment for opening the bank page and will need the control to hardware back press when the bank page is active. This can be done by invoking addEventListener on the BackHandler provided by React-Native.
If the blocking asynchronous call HyperSdkReact.onBackPressed() returns true, Hyper SDK will handle the back press, else merchant can handle it.

componentDidMount() {
   BackHandler.addEventListener('hardwareBackPress', () => {
     return !HyperSdkReact.isNull() && HyperSdkReact.onBackPressed();
 componentWillUnmount() {
   BackHandler.removeEventListener('hardwareBackPress', () => null);

Note: HyperSdkReact.isNull() can also be called before calling onBackPressed() to ensure that the HyperServices object is not null.

Android Permissions Handling

Hyper SDK needs to listen to the response of permissions asked to the user for handling auto SMS reading (wherever applicable). To do so, the merchant's activity should delegate the response to Hyper SDK once it is received from the user. This can be done by adding the following snippet in merchant's react activity (MainActivity):

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
     HyperSdkReactModule.onRequestPermissionsResult(requestCode, permissions, grantResults);

Helper: Is Null

This is a helper method and can be used to check whether the HyperServices object is null at any particular moment. It is a blocking synchronous method and returns a boolean value.

var isNull: boolean = HyperSdkReact.isNull();
console.log('is HyperSDK null: ', isNull);

Is Initialised (Recommended)

This is a helper / optional method to check whether SDK has been initialised after [Initiate](doc:initiate #initiate). It returns a JS Promise with a boolean value.

HyperSdkReact.isInitialised().then((init: boolean) => {
  console.log('isInitialised:', init);