# MOBILEMONEY

## Payin by MOBILEMONEY

**Step 1:** Get the "prepay\_id" from the API response. Each transaction should create a unique prepay\_id.

<mark style="color:green;">`POST`</mark> `https://gateway-test.pagsmile.com/trade/create`

This endpoint allows you to submit a payin by MOBILEMONEY in Kenya.

#### Headers

| Name                                            | Type   | Description                                |
| ----------------------------------------------- | ------ | ------------------------------------------ |
| Content-Type<mark style="color:red;">\*</mark>  | string | application/json; chartset=UTF-8           |
| Authorization<mark style="color:red;">\*</mark> | string | Basic Base($app\_*id:$security\_*&#x6B;ey) |

#### Request Body

<table><thead><tr><th width="277">Name</th><th width="166">Type</th><th>Description</th></tr></thead><tbody><tr><td>app_id<mark style="color:red;">*</mark></td><td>string</td><td><p>created app's id at dashboard</p><p>- Max. 32 chars -</p></td></tr><tr><td>method<mark style="color:red;">*</mark></td><td>string</td><td>Fixed value: MOBILEMONEY</td></tr><tr><td>out_trade_no<mark style="color:red;">*</mark></td><td>string</td><td>ID given by the merchant in their system<br>- Max. 64 chars - </td></tr><tr><td>notify_url<mark style="color:red;">*</mark></td><td>string</td><td>Where Pagsmile will send notification to</td></tr><tr><td>timestamp<mark style="color:red;">*</mark></td><td>string</td><td>yyyy-MM-dd HH:mm:ss<br>- Max. 19 chars -</td></tr><tr><td>subject<mark style="color:red;">*</mark></td><td>string</td><td><p>payment reason or item title</p><p>- Max. 128 chars -</p></td></tr><tr><td>order_amount<mark style="color:red;">*</mark></td><td>string</td><td>payment amount<br>- 10 ~ 50,000 KES<br>(Only Integer) -</td></tr><tr><td>order_currency<mark style="color:red;">*</mark></td><td>string</td><td>Fixed value: KES</td></tr><tr><td>content</td><td>string</td><td><p>payment reason detail or item detail</p><p>- Max. 255 chars -</p></td></tr><tr><td>buyer_id<mark style="color:red;">*</mark></td><td>string</td><td>merchant user's id</td></tr><tr><td>version<mark style="color:red;">*</mark></td><td>string</td><td>Fixed value: 2.0</td></tr><tr><td>trade_type<mark style="color:red;">*</mark></td><td>string</td><td>Fixed value: WEB</td></tr><tr><td>customer.email<mark style="color:red;">*</mark></td><td>string</td><td>User's email</td></tr><tr><td>customer.phone<mark style="color:red;">*</mark></td><td>string</td><td>User's phone</td></tr></tbody></table>

{% tabs %}
{% tab title="200 submit successfully" %}

```
{
    "code": "10000",
    "msg": "Success",
    "out_trade_no": "out***300",
    "trade_no": "20240***34",
    "web_url": "https://checkout.pagsmile.com?prepay_id=UloyV0l3NFFyW***DTT0=-645a8F4c",
    "prepay_id": "UloyV0l3NFFyW***DTT0=-645a8F4c"
}
```

{% endtab %}

{% tab title="400 duplicate out\_trade\_no" %}

```
{
    "code": "40002",
    "msg": "Business Failed",
    "sub_code": "duplicate-out_trade_no",
    "sub_msg": "out_trade_no is duplicate"
}
```

{% endtab %}
{% endtabs %}

## Example

```
curl --location --request POST 'https://gateway-test.pagsmile.com/trade/create' \
--header 'Authorization: Basic MTYyNTgyOTIxNDUzMTY2Mzg6UGFnc21pbGVfc2tfZDUwMWQ1ZGNkNTI5OGQ5N2MwNmUzYjI4YjA2OWZjZmY3NDU5ZjY2NzNiMjFjMTFlYTY3NDM5MDgzOTZkOTYxNQ==' \
--header 'Content-Type: application/json' \
--data-raw '{
    * "app_id": "1649***56",
    * "out_trade_no": "out***3300",
    * "order_currency": "KES",
    * "method": "MOBILEMONEY",
    * "order_amount": "100",
    * "subject": "pagsmile test ",
      "content": "pagsmile test ",
    * "trade_type": "WEB",
    * "timestamp": "2024-07-04 18:50:42",
    * "notify_url": "http://demo.gemini-tiger.cn/callback/success",
    * "buyer_id": "buyer52023",
    * "version": "2.0",
    * "customer" : {
    *     "email": "gabrz000@gmail.com",
    *     "phone": "254******000"
      }
}
```

**Step 2:** Initialize the SDK using setPublishableKey method by providing the necessary parameters.

```
Pagsmile.setPublishableKey({
        app_id: "166****044", //Use your own app_id taken from the dashboard. 
        public_key: "Pagsmile_sk_47****59728d70e9a", //Use your own key taken from the dashboard.
        env: "sandbox",
        region_code: "EAK",
        prepay_id:
          "UloyV0l3NFFyW***DTT0=-645a8F4c",
      })
        .then((clientInstance) => {
          console.log("successfully initiated!");
          document
            .getElementById("submit-pay")
            .addEventListener("click", function (e) {
              clientInstance
                .createOrder()
                .then((res) => {
                  console.log("res: ", res);
                })
                .catch((err) => {
                  console.log("Error: ", err);
                });
            });
        })
        .catch((err) => {
          console.log("Error: ", err);
        });

```

**Step 3:** Use createOrder method of clientInstance; the user may need to enter OTP, (SDK automatically triggers OTP prompt)

**Step 4:** Analyse the response

```
{
 status: "success",        // successfully created order
 query: true,              // use backend query for transaction status
 auth_type: "STK_PROMPT",  // user needs to confirm the transaction on mobile app
}
```

{% hint style="info" %}
Note:  **162\*\*\*\*\*\*\*\*\*\*\*\*38** is pagsmile's test app id for sandbox, and **MTYyNTgyOTIxNDUzMTY2Mzg6UGFnc21pbGVfc2tfZDUwMWQ1ZGNkNTI5OGQ5N2MwNmUzYjI4YjA2OWZjZmY3NDU5ZjY2NzNiMjFjMTFlYTY3NDM5MDgzOTZkOTYxNQ==** is authorization token associated with the test app id.&#x20;
{% endhint %}

{% hint style="danger" %}
Please use your own **app\_id** and generate your own **authorization token** when testing.
{% endhint %}
