---
page_source: https://docs.juspay.io/upi-inapp/flutter/interaction-with-sdk/initiating-the-sdk
page_title: Initiating the SDK
---


## Initiating the SDK



To initialise the SDK, client needs to call the `initiate` SDK API. The initiate api call boots up the SDK and makes it ready for all other operations

Follow the below steps to make an initiate SDK call:


### Step 1 Import HyperSDK


Import the HyperSDK namespace to get access to HyperServices class in your code



#### Code Snippets: -

#### Flutter Code Snippet:

```flutter
import 'package:flutter/material.dart';
import 'package:hypersdk/hypersdk.dart';
import 'package:flutter/services.dart';
import './screens/home.dart';

void main() {
  final hyperSDK = HyperSDK();
  runApp(MyApp(hyperSDK: hyperSDK));
}

class MyApp extends StatelessWidget {
  // Create Juspay Object
  // // block:start:create-hyper-sdk-instance
  final HyperSDK hyperSDK;
  // // block:end:create-hyper-sdk-instance
  const MyApp({Key? key, required this.hyperSDK}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [
  SystemUiOverlay.bottom
]);
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomeScreen(
        hyperSDK: hyperSDK,
      ),
    );
  }
}
```



### Step 2 Create an instance of HyperServices


The SDK exposes the `HyperServices` class. Create an object of this class for all upcoming operations



#### Code Snippets: -

#### Flutter Code Snippet:

```flutter
import 'package:flutter/material.dart';
import 'package:hypersdk/hypersdk.dart';
import 'package:flutter/services.dart';
import './screens/home.dart';

void main() {
  final hyperSDK = HyperSDK();
  runApp(MyApp(hyperSDK: hyperSDK));
}

class MyApp extends StatelessWidget {
  // Create Juspay Object
  // // block:start:create-hyper-sdk-instance
  final HyperSDK hyperSDK;
  // // block:end:create-hyper-sdk-instance
  const MyApp({Key? key, required this.hyperSDK}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [
  SystemUiOverlay.bottom
]);
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomeScreen(
        hyperSDK: hyperSDK,
      ),
    );
  }
}
```



### Step 3 Create Initiate payload


Initiate API takes two parameters as input. One of the parameter is a JSON object referred as `InitiatePayload`. This payload contains certain key value pairs used by the SDK to perform a successful initiate

Refer to the following table for information about the description and sample payload.



#### Code Snippets: -

#### Flutter Code Snippet:

```flutter
var initiatePayload = {
        {
          // block:start:generatingRequestId
          "requestId": const Uuid().v4(),
          // block:end:generatingRequestId
          "service": "in.juspay.hyperapi",
          "payload": {
            "action": "initiate",
            "merchantKeyId": "<Merchant Key Id>",
            "clientId": "<Client Id>",
            "signature": "<Generated signature for signature payload>",
            "signaturePayload": {
              "merchant_id": "stock",
              "customer_id": "abcde12345",
              "timestamp": "1668389349848"
            }
            "environment": "sandbox",
            "upiEnvironment": "sandbox"
            "issuingPsp": "YES_BIZ",
            "shouldCreateCustomer": true,
            "logLevel": 1
          }
        }
      };
```



###   Initiate Parameters



## Request Payload
- **RequestId**:
  - Description: Unique uuid-v4 string
  - Value: $requestId
  - Tags: String, Mandatory
- **Service**:
  - Description: Value: in.juspay.hyperapi
  - Tags: String, Mandatory
- **Payload**:
  - Description: Parameters required to call Hyper SDK API
  - Value:
    - **Action**:
      - Description: Operation to be performed in the SDK. Should be initiate for this call.
      - Value: Value: initiate
      - Tags: String, Mandatory
    - **ClientId**:
      - Description: Client Id assigned by juspay. Usual convention is merchant_id
      - Value: Example: stock
      - Tags: String, Mandatory
    - **Environment**:
      - Description: Environment to be used for the session. Accepted values are 'sandbox' or 'production'
      - Value: Example: sandbox
      - Tags: String, Mandatory
    - **IssuingPsp**:
      - Description: Bank on which the merchant has been onboarded.
      - Value: Example: YES_BIZ
      - Tags: String, Mandatory
    - **MerchantKeyId**:
      - Description: Key ID to identify the public-private key pair used for signature generation.
      - Value: Example: 1234
      - Tags: String, Mandatory
    - **Signature**:
      - Description: Generated signature for signature payload. See signature generation process in pre-requisites section.
      - Tags: String, Mandatory
    - **SignaturePayload**:
      - Description: Signature payload is a stringified JSON of the details mentioned in the below table.
      - Value:
        - **Merchant_id**:
          - Description: Unique identifier associated with an account created by juspay.
          - Value: Example: stock
          - Tags: String, Mandatory
        - **Customer_id**:
          - Description: Any unique reference associated with your customer.
          - Value: Example: abcde12345
          - Tags: String, Mandatory
        - **Timestamp**:
          - Description: Time when request is created in milliseconds.
          - Value: Example: 1665996901100
          - Tags: String, Mandatory
      - Tags: String, Mandatory
    - **ShouldCreateCustomer**:
      - Description: Value: true
      - Tags: Boolean, Mandatory
  - Tags: JSON, Mandatory


## Response Payload
- **RequestId**:
  - Description: Unique uuid-v4 string
  - Value: $requestId
  - Tags: String, Mandatory
- **Service**:
  - Description: Value: in.juspay.hyperapi
  - Tags: String, Mandatory
- **Payload**:
  - Description: Parameters required to call Hyper SDK API
  - Value:
    - **Action**:
      - Description: Operation performed in the SDK.
      - Value: Value: initiate
      - Tags: String
    - **Status**:
      - Description: Status of the Operation.
      - Value: Possible values : SUCCESS / FAILURE
      - Tags: String
  - Tags: JSON, Mandatory



> **Note**
> [Click here](../miscellaneous/additional-parameters) for additional initiate parameters





#### Code Snippets: -

#### Flutter Code Snippet:

```flutter
{
  "requestId": "8cbc3fad-8b3f-40c0-ae93-2d7e75a8624a",
  "service": "in.juspay.hyperapi",
  "payload": {
    "action": "initiate",
    "merchantKeyId": "<Merchant Key Id>",
    "clientId": "<Client Id>",
    "signature": "<Generated signature for signature payload>",
    "signaturePayload": "<Stringified signature payload>",
    "environment": "sandbox",
    "upiEnvironment": "sandbox"
    "issuingPsp": "YES_BIZ",
    "shouldCreateCustomer": true,
    "logLevel": 1
  }
}

"signaturePayload": {
  "merchant_id": "stock",
  "customer_id": "abcde12345",
  "timestamp": "1668389349848"
}
```



### Step 4 Create CallbackHandler


During its lifecycle, SDK emits multiple events to communicate about the transaction status. All of these events are received by an instance of `HyperPaymentsCallbackAdapter`.

This callback handler is passed as the second argument to the initiate API call.



#### Code Snippets: -

#### Flutter Code Snippet:

```flutter
void hyperSDKCallbackHandler(MethodCall methodCall) {
    switch (methodCall.method) {

      // block:start:show-loader
      case "show_loader":
        // Show some Loader
        break;
      // block:end:show-loader

      // block:start:hide-loader
      case "hide_loader":
        // Hide Loader
        break;
      // block:end:hide-loader

      // block:start:initiate-result
      case "initiate_result":
      // Get the response
        var args = {};
        try {
          args = json.decode(methodCall.arguments);
        } catch (e) {
          print(e);
        }
        //Merchant handling
        break;
      // block:end:initiate-result

      // block:start:process-result
      case "process_result":
      // Get the response
        var args = {};
        try {
          args = json.decode(methodCall.arguments);
        } catch (e) {
          print(e);
        }
        //Merchant handling
        break;
      // block:end:process-result

      // block:start:log-stream
      case "log_stream":
        // print data
        break;
      // block:end:log-stream

      // block:start:session-expiry
      case "session_expiry":
        // Handle Session Expiry
        break;
      // block:end:session-expiry

  }
```



### Step 5 Call initiate


The final step is to call the `Initiate SDK API`.

The initiate method takes two parameters: `InitiatePayload` and `HyperPaymentsCallbackAdapter`. Use the functions created in the above steps to create the parameters

> **Warning**
> Initiate is a fire-and-forget call. For every HyperService instance you should **call initiate only once.** 





#### Code Snippets: -

#### Flutter Code Snippet:

```flutter
await widget.hyperSDK.initiate(initiatePayload, hyperSDKCallbackHandler);
```
