# Integration guide

## 1. Install library

Add to dependencies:

```java
ninepay_sdk_flutter: ^1.0.5
```

## 2. Init SDK

| Parameter    | Explain                                                                                                                                                          |
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| merchantCode | This is the code of the partner when integrating the SDK                                                                                                         |
| secretKey    | Key connect to API 9Pay                                                                                                                                          |
| uId          | User identifier using merchant's account, optional, can be null                                                                                                  |
| flavorEnv    | Using environment, there are 2 environments, sandbox (test code environment) and production (actual running environment), see the table below for configuration. |
| colorCode    | The color code that the merchant wants to use on the buttons in the SDK, hex color code and not the # character, for example 15AE62                              |

## 3. List of constants config SDK

| Key                        | Explain                                                                    |
| -------------------------- | -------------------------------------------------------------------------- |
| EnvironmentKey.SANDBOX     | flavorEnv environment Sandbox                                              |
| EnvironmentKey.PRODUCTION  | flavorEnv environment Production                                           |
| PaymentMethod.DEFAULT      | Payment using all methods (used in the openPaymentOnSDK function).         |
| PaymentMethod.WALLET       | Payment using method 9Pay Ewallet (used in the openPaymentOnSDK function). |
| PaymentMethod.ATM\_CARD    | Payment using method inland card (used in the openPaymentOnSDK function).  |
| PaymentMethod.CREDIT\_CARD | Payment using method credit card (used in the openPaymentOnSDK function).  |

## **4.** Technical Diagram

<figure><img src="/files/RmgqcIxSc2PEgom8lYq4" alt=""><figcaption></figcaption></figure>

### **4.1 Example init SDK**

```dart
late final NinepaySdkFlutter? ninepaySdkFlutter;

@override
  void initState() {
    ninepaySdkFlutter = NinepaySdkFlutter(
      merchantCode: 'merchant_code',
      secretKey: 'secret_key',
      uId: null,
      flavorEnv: NinepayEnv.STAGING,
      colorCode: '15AE62', // Color hex
    );
ninepaySdkFlutter.onEvent().listen((event) {
      // Get type event
      if (kDebugMode) {
        print('LISTEN SUCCESS ${event["name_event"]}');
      }
      String typeEvent = event['name_event'];

      switch (typeEvent) {
        case 'backToAppFrom':
          showToast(event.toString());
          break;
        case 'sdkDidComplete':
          showToast('sdkDidComplete');
          print(event);
          break;
        case 'getInfoSuccess':
          showToast('GET INFO SUCCESS ${event['data']}');
          break;
        case 'onError':
          showToast(event['message']);
          // map {"error_code": errorCode, "message": message}
          break;
        case 'onLogoutSuccessful':
          showToast('Đăng xuất thành công!');
          break;
        case 'onCloseSDK':
          showToast('onCloseSDK');
          break;
      }
    });

    super.initState();
  }
  
  @override
  void dispose() {
    // cancel listener
    ninepaySdkFlutter.cancel();
    super.dispose();
  }
```

```javascript
// Json callback from getInfoSuccess:

{
  "balance": "1505549",
  "phone": "0971999999",
  "name": "NGUYEN VAN A",
  "statusKyc": "2"
}
```

### **4.2 Open fucntion SDK 9Pay**

```typescript
// Open SDK Action.
ninepaySdkFlutter.openSDKWithAction(action: NinepayActions.LOGIN);
```

| Name action   | Function                                |
| ------------- | --------------------------------------- |
| LOGIN         | Login                                   |
| HISTORY       | Transaction history                     |
| TRANSFER      | Money transfer and withdrawal functions |
| DEPOSIT       | Deposit to 9Pay Ewallet                 |
| QR            | Function scan QR code                   |
| BILLING       | Billing (electric, water...)            |
| TOPUP         | Topup phone                             |
| PHONE\_CARD   | Buy phone card                          |
| DATA\_CARD    | Buy data card 4G                        |
| SERVICE\_CARD | Buy service card                        |

{% tabs %}
{% tab title="Deposit" %}

<figure><img src="/files/rcpPxSqDtAJnhjWOLSgE" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Transfer" %}

<figure><img src="/files/gtWevk79VjiXnASfvLzx" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Topup phone" %}

<figure><img src="/files/rSEUQeewsjevPPfrUJL2" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Service card" %}

<figure><img src="/files/ynRFt2ZgkIIMtY0q9ALu" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Billing" %}

<figure><img src="/files/WcG4c5bz9wiVLgv3ltu9" alt="" width="360"><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

### **4.3 Function Payment  order merchant**

{% code overflow="wrap" %}

```java
String urlPayment = "" // Url payment was created from backend
bool isShowResultScreen = true // show result screen when payment complete
// Method payment

// PaymentMethod.WALLET
// PaymentMethod.ATM_CARD
// PaymentMethod.CREDIT_CARD
// PaymentMethod.DEFAULT

ninepaySdkFlutter.openPaymentOnSDK(urlPayment, PaymentMethod.DEFAULT, isShowResultScreen);
```

{% endcode %}

### **4.4 Get user info**&#x20;

<figure><img src="https://lh4.googleusercontent.com/i0RQRU8xWxQKCNSZoG7j7Tvmy_SZ4UhfmjpBtL0cYidKzvvN5AzvSHknRUxt2qXLP1DH9rjjj0cXfa0oRN0qzLANh7qSdSgOIhUg-HGh_cM41xLJUMeOAlrPVI901cYLPLUk4cugjP0ribrGXpmSXIM" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```java
ninepaySdkFlutter.getUserInfo();

// Data will callback from getInfoSuccess listener
// Json data infomation:
// Phone number login, balance, eKYC status, full name of user.
```

{% endcode %}

### **4.5 Logout**

```java
ninepaySdkFlutter.logout(); // Logout user was logged
```

### **4.6 Close screen SDK**

```java
ninepaySdkFlutter.close();
```

## **5. Data test sandbox**

| Type                                      | Details                                                                                                                                                                      |
| ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Account Ewallet 9Pay SDK                  | 0912365431                                                                                                                                                                   |
| Password (Account Ewallet 9Pay SDK)       | 123123                                                                                                                                                                       |
| OTP (Account Ewallet 9Pay SDK)            | 123456                                                                                                                                                                       |
| Bank information used to link and deposit | <p>Bank: Agribank</p><p>Number card: 9704 0000 0000 0018</p><p>Account holder: Nguyen Van A</p><p>Issuance date: 03/07</p><p>OTP: otp</p><p><br></p>                         |
| International card                        | <p>Account holder: NGUYEN VAN A</p><p>Number card:</p><ul><li>4005555555000009 (Visa)</li><li>5200000000001005 (MasterCard)</li></ul><p>Expiration: 05/25</p><p>CVV: 123</p> |

## **6. List error code SDK**

Error will return callback from `onError` when init SDK.

| Code | Type                                                        |
| ---- | ----------------------------------------------------------- |
| 403  | Not login                                                   |
| 2001 | Error validate information order                            |
| 2002 | Error payment order merchant                                |
| 2003 | Error getting bank information and payment card SDK support |
| 2004 | Error decoding returned data                                |
| 2005 | Unknown error                                               |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.9pay.vn/flutter-9pay-sdk/integration-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
