Hey! These docs are for version 3.2, which is no longer officially supported. Click here for the latest version, 1.0!

Prefetch (optional)

Prefetch API gets the latest business logic and keeps the SDK experience uniform for all users.
This API can be triggered any number of times and only updates assets for critical requirements.
FAQ section has answers for most queries.

👍

NOTE

To keep the SDK up to date with the latest changes, it is highly recommended to call Prefetch as early as possible (as soon as a user opens the merchant app). Prefetch is necessary to keep the payments SDK updated. Over-the-Air updates will get delayed if Prefetch is not implemented

Input

  • The Prefetch API takes a JSON object as its argument. It must contain a payload as defined below.

Integration Sample

HyperServices.preFetch(getApplicationContext(), payload);
HyperServices.preFetch(getApplicationContext(), payload);
HyperServices.preFetch(payload)
[HyperServices preFetch:payload];
HyperSdkReact.preFetch(JSON.stringify(preFetchPayload));

Payload

  • clientId is assigned by Juspay as a unique reference to static resources allocated to a merchant.
  • service is the reference to Juspay product being consumed.
  • betaAssets is a Boolean variable that enables switching between test and production resources. Allows a designated tester to receive asset updates before being pushed to all customers. Default value is 'false' (production assets).
  • requestId is a unique reference for the JSON object (used only for the JSON code).
JSONObject preFetchPayload = new JSONObject();

try {
   JSONObject innerPayload = new JSONObject();
   String clientId = "<clientID>";
   innerPayload.put("clientId", clientId);
   preFetchPayload.put("payload", innerPayload);
   
   preFetchPayload.put("service","in.juspay.hyperpay");
   
   boolean useBetaAssets = true; // false
   preFetchPayload.put("betaAssets", useBetaAssets);
} catch (JSONException e) {
   e.printStackTrace();
}

HyperServices.preFetch(this, preFetchPayload);
val preFetchPayload = JSONObject()

    try {
        val innerPayload = JSONObject()
        val clientId = "<clientID>"
        innerPayload.put("clientId", clientId)
        preFetchPayload.put("payload", innerPayload)
        preFetchPayload.put("service", "in.juspay.hyperpay")
        val useBetaAssets = true // false
        preFetchPayload.put("betaAssets", useBetaAssets)
    } catch (e: JSONException) {
        e.printStackTrace()
    }

    HyperServices.preFetch(this, preFetchPayload)
let payload = [
  "service" : "in.juspay.hyperpay",
  "payload" : [
      "clientId" : "<clientId>"
  ]
] as [String: Any]
    
Hyper.preFetch(payload)
NSDictionary *payload = @{
  @"service" : @"in.juspay.hyperpay",
  @"payload" : @{
      @"clientId" : @"<clientId>"
  }
};
 
[Hyper preFetch:payload];
{
    "requestId" : "8cbc3fad-8b3f-40c0-ae93-2d7e75a8624a", 
    "service" : "in.juspay.hyperpay",
    "payload"  : { 
        "clientId" : "<Client Id>"
    }
}

📘

Where to Call Prefetch?

  • Android: In the onCreate() method of your application's main activity
  • iOS: In application:didFinishLaunchingWithOptions method of the application's AppDelegate class
  • React
    • Class Component architecture: In componentDidMount() method
    • Function Component architecture: In useEffect() hook