npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hyper-sdk-expo-plugin

v1.0.0

Published

An Expo config plugin for automating Android & iOS integration changes for [`hyper-sdk-react`](https://www.npmjs.com/package/hyper-sdk-react) with apps using Expo.

Downloads

178

Readme

hyper-sdk-expo-plugin

An Expo config plugin for automating Android & iOS integration changes for hyper-sdk-react with apps using Expo.

Installation

npm install hyper-sdk-expo-plugin
OR
yarn add hyper-sdk-expo-plugin

Note: Please install hyper-sdk-react before doing this.

npm install hyper-sdk-react

Uses

Step-1: Inputs

Expo config plugin takes some parameters which are needed to setup hyper-sdk-react.

Add following parameters in app.json

{
  "expo": {
    // Others
    "extra": {
      // ...
      "clientId": "<clientId shared by Juspay team>", // Mandatory
      "hyperSDKVersion": "2.1.33", // Optional: Override for base SDK version present in plugin (the newer version among both would be considered)
      "juspayMavenUrls": [
        "https://maven.juspay.in/jp-build-packages/hyper-sdk/"
      ] // Optional
    },
    "plugins": [
      // Other plugins
      "hyper-sdk-expo-plugin"
    ]
    // ...
  }
}

Step-2:

The expo config plugin is configured to execute while running npx expo prebuild OR npx expo prebuild --clean

Note: You must run npx expo prebuild --clean after making any change in plugin parameters defined in app.json.

Step-3:

  • For IOS, go inside iOS folder and run pod install to install pods.

Use APIs exposed by hyper-sdk-react here

hyper-sdk-react

Exposed APIs

type HyperSdkReactType = {
  HyperEvent: string;
  preFetch(data: string): void;
  createHyperServices(): void;
  initiate(data: string): void;
  process(data: string): void;
  processWithActivity(data: string): void;
  terminate(): void;
  onBackPressed(): boolean;
  isNull(): boolean;
  isInitialised(): Promise<boolean>;
  updateBaseViewController(): void;
};

const { HyperSdkReact } = NativeModules;

export default HyperSdkReact as HyperSdkReactType;

Import HyperSDK

import HyperSdkReact from 'hyper-sdk-react';

Step-0: PreFetch

To keep the SDK up to date with the latest changes, it is highly recommended to call preFetch as early as possible. It takes a stringified JSON as its argument.

HyperSdkReact.preFetch(JSON.stringify(preFetchPayload));

Step-1: Create HyperServices Object

This method creates an instance of HyperServices class in the React Bridge Module on which all the HyperSDK APIs / methods are triggered. It internally uses the current activity as an argument.

Note: This method is mandatory and is required to call any other subsequent methods from HyperSDK.

HyperSdkReact.createHyperServices();

Step-2: Initiate

This method should be called on the render of the host screen. This will boot up the SDK and start the Hyper engine. It takes a stringified JSON as its argument which will contain the base parameters for the entire session and remains static throughout one SDK instance lifetime.

Initiate is an asynchronous call and its result (whether success or failure) is provided in the Hyper Event listener, later discussed in step-4.

Note: It is highly recommended to initiate SDK from the order summary page (at least 5 seconds before opening your payment page) for seamless user experience.

HyperSdkReact.initiate(JSON.stringify(initiatePayload));

Step-3: Process

This API should be triggered for all operations required from HyperSDK. The operation may be related to:

  • Displaying payment options on your payment page
  • Performing a transaction
  • User's payment profile management

The result of the process call is provided in the Hyper Event listener, later discussed in step-4.

HyperSdkReact.process(JSON.stringify(processPayload));

If any of the react-native library is impacting the UI/UX, please use processWithActivity instead, which starts a new Activity for opening the Payment Page, isolated of react native.

HyperSdkReact.processWithActivity(JSON.stringify(processPayload));

Step-4: Listen to events from HyperSDK

Hyper SDK Native Module will be emitting all the relevant events to JS via RCTDeviceEventEmitter and JavaScript modules can then register to receive events by invoking addListener on the NativeEventEmitter class in the componentDidMount() method with the event name 'HyperEvent' (You can use the HyperSdkReact.HyperEvent as well). The listener will return a stringified JSON response (resp).

The following events should be handled here:

  • show_loader: To show a loader for the processing state.
  • hide_loader: To hide the previously shown loader.
  • initiate_result: Result of initiate done in step-2.
  • process_result: Result of the process operation done in step-3.

Note: The listener can be removed when the React component unmounts in componentWillUnmount() method.

 componentDidMount() {
   ...
   const eventEmitter = new NativeEventEmitter(NativeModules.HyperSdkReact);
   this.eventListener = eventEmitter.addListener(HyperSdkReact.HyperEvent, (resp) => {
     var data = JSON.parse(resp);
     var event: string = data.event || '';
     switch (event) {
       case 'show_loader':
         // show some loader here
         break;

       case 'hide_loader':
         // hide the loader
         break;

       case 'initiate_result':
         var payload = data.payload || {};
         console.log('initiate_result: ', payload);
         // merchant code
         ...
         break;

       case 'process_result':
         var payload = data.payload || {};
         console.log('process_result: ', payload);
         // merchant code
         ...
         break;

       default:
         console.log('Unknown Event', data);
     }
     ...
   });
   ...
 }

 componentWillUnmount() {
   ...
   this.eventListener.remove();
   ...
 }

Step-5: 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.

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

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

 componentWillUnmount() {
   ...
   BackHandler.removeEventListener('hardwareBackPress', () => null);
   ...
 }

Step-6: 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):

  @Override
  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
      if (HyperSdkReactModule.getPermissionRequestCodes().contains(requestCode)) {
          HyperSdkReactModule.onRequestPermissionsResult(requestCode, permissions, grantResults);
      } else {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);
      }
  }

Step-7: Terminate

This method shall be triggered when HyperSDK is no longer required.

HyperSdkReact.terminate();

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);

Optional: Is Initialised

This is a helper / optional method to check whether SDK has been initialised after step-2. It returns a JS Promise with a boolean value.

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

Optional: Update Base ViewController - Only for iOS

This is an optional method to update the base view controller in case if any new view controller is presented over top view controller after the SDK initiation. This method should be called before making HyperSdkReact.process() call.

HyperSdkReact.updateBaseViewController();

Optional: Support for adding merchant views

This sections helps to attach custom views inside designated sections in the payment page. You will need to register the component to be attached under one of the following names, based on where the component is attached.

  1. JuspayHeaderAttached
  2. JuspayHeader
  3. JuspayFooter
  4. JuspayFooterAttached

You can follow the below syntax to attach the component.

HyperSdkReact.notifyAboutRegisterComponent(HyperSdkReact.JuspayHeaderAttached)
AppRegistry.registerComponent(HyperSdkReact.JuspayHeaderAttached, () => CustomComponent);

Please note component must be registered before calling process call of the sdk.

Note: In iOS we are not able to infer the height of the component being rendered. Therefore the component must fire HyperSdkReact.updateMerchantViewHeight(<section_name>, <height>);

For example

HyperSdkReact.updateMerchantViewHeight(HyperSdkReact.JuspayHeader, 200);

If your view dynamically computes height. Height can be obtained by adding the following property to the root of component registered

  onLayout={(event) => {
        const { height } = event.nativeEvent.layout;
        HyperSdkReact.updateMerchantViewHeight(HyperSdkReact.JuspayHeader, height);
      }}

License

hyper-sdk-expo-plugin is distributed under AGPL-3.0-only license.