# Koneksi API

Selamat datang di halaman Dokumentasi API. Disini telah disediakan penjelasan lengkap mengenai daftar API yang tersedia dan cara akses/penggunaan dari masing-masing API

{% hint style="info" %}
Mulai tanggal 1 November 2023 url API telah diganti. Mohon di sesuaikan ulang. 🙏
{% endhint %}

* Jika status UNPAID dalam 2 jam maka status berubah EXPIRED
* Nominal pembayaran tidak ditentukan oleh kami, pelanggan dapat memasukkan nominal berapapun
* Nominal pembayaran dihitung rate persen. Contoh 100.000 Jika Telkomsel rate 80% maka perhitngan. 100.00 / 0.80 = 125.000&#x20;
* Hit nominal dibawah 20.000 ada tambahan harga sebesar 0.07
* Rate persen setiap operator berbeda dan dapat berubah sewaktu waktu tanpa adanya pemberitahuan
* Saat ini kami hanya menerima pulsa *Telkomsel, XL/Axis, TRI, Smartfren*

#### DIRECT

1. Pelanggan melakukan checkout di situs Anda dan memilih metode pembayaran Transfer Pulsa
2. Sistem Anda melakukan request transaksi ke API kami
3. Sistem kami memberikan detail pembayaran berupa nomer hp yang harus di Transfer Pulsa
4. Pelanggan Transfer Pulsa ke nomor sesuai yang diberikan oleh kami
5. Sistem kami menerima Transfer Pulsa dari pelanggan anda
6. Dana masuk ke akun, Sistem kami mengirimkan notifikasi ke sistem anda
7. &#x20;Sistem Anda memproses notifikasi yang dikirim dan melakukan validasi pembayaran
8. Pembayaran tervalidasi, sistem Anda memproses pesanan ke pelanggan

#### REDIRECT

1. Pelanggan melakukan checkout di situs Anda dan memilih metode pembayaran Transfer Pulsa
2. Sistem Anda melakukan request transaksi ke API kami
3. Sistem kami memberikan URL pembayaran
4. Sistem Anda mengalihkan pelanggan menuju ke URL pembayaran
5. Pelanggan menyelesaikan proses Transfer Pulsa
6. Sistem kami menerima Transfer Pulsa dan penyelesaian pembayaran pelanggan Anda
7. Dana masuk ke akun dan sistem kami mengirimkan notifikasi ke sistem Anda
8. Sistem Anda memproses notifikasi yang dikirim dan melakukan validasi pembayaran
9. Pembayaran tervalidasi, sistem Anda memproses pesanan ke pelanggan


# Transaksi Baru

{% hint style="info" %}
Request nominal dibawah 20.000 dikenakan biaya tambahan sebesar 3%&#x20;

Contoh: jika rate 0.82 maka akan menjadi 0.79
{% endhint %}

<mark style="color:green;">`POST`</mark> `https://api.ilenpay.co.id/v1/transaksi/baru`

#### Headers

| Name                                            | Type   | Description |
| ----------------------------------------------- | ------ | ----------- |
| Authorization<mark style="color:red;">\*</mark> | String | Api Key     |

#### Request Body

| Name                                          | Type   | Description                            |
| --------------------------------------------- | ------ | -------------------------------------- |
| operator<mark style="color:red;">\*</mark>    | String | ( telkomsel, xl, tri, smartfren )      |
| nominal<mark style="color:red;">\*</mark>     | Int    | Nominal pembayaran                     |
| reff\_id<mark style="color:red;">\*</mark>    | String | Kode unik anda. Min 5 Max 20 karakter  |
| sign<mark style="color:red;">\*</mark>        | String | format md5()                           |
| type<mark style="color:red;">\*</mark>        | String | *( redirect / direct )*                |
| return\_url<mark style="color:red;">\*</mark> | String | URL mengalihkan pelanggan Anda kembali |

{% tabs %}
{% tab title="200: OK Respon sukses type Redirect" %}

<pre class="language-json"><code class="lang-json">{
    "data": {
        "respon": "sukses",
        "payment": "telkomsel",
        "rate": "0.82",
        "nominal": "10000",
        "reff_id": "trx68164teewfske2",
        "total_tf": "13000",
        "waktu": 1698753382,
<strong>        "type": "redirect",
</strong><strong>        "hash": "93fc85a4a2ba084f5f4850ee9ae8713d34949712",
</strong><strong>        "url_pay": "https://ilenpay.co.id/payment/93fc85a4a2ba084f5f4850ee9ae8713d34949712",
</strong>        "status": "UNPAID"
    }
}
</code></pre>

{% endtab %}

{% tab title="200: OK Respon sukses type Direct" %}

<pre class="language-json"><code class="lang-json">{
    "data": {
        "respon": "sukses",
        "payment": "telkomsel",
        "rate": "0.82",
        "nominal": "10000",
        "reff_id": "trx68164teewfske2",
        "total_tf": "13000",
        "waktu": 1698753308,
<strong>        "type": "direct",
</strong><strong>        "hash": "fd7e16c7b8c631c53685b699c6b4a5eabee285d9",
</strong><strong>        "no_center": "081286191966",
</strong>        "status": "UNPAID"
    }
}
</code></pre>

{% endtab %}
{% endtabs %}

### Contoh Untuk PHP&#x20;

<pre class="language-php"><code class="lang-php">&#x3C;?php

$api_key    = 'Production Key';
$api_user   = 'User Key';
<strong>$type       = 'direct'; // Type: direct / redirect
</strong><strong>$return_url = 'https://domain.com/riwayat/8833';
</strong>$operator   = 'telkomsel';
$nominal    = '15000';
$reff_id    = 'trx68164343fdgsfdg';
$sign       = md5($operator.'+'.$nominal.'+'.$reff_id.'+'.$api_user);

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_FRESH_CONNECT  => true,
    CURLOPT_URL            => 'https://api.ilenpay.co.id/v1/transaksi/baru',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER         => false,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => http_build_query(array(
<strong>        'type'      => $type,
</strong><strong>        'return_url'=> $return_url,
</strong>        'operator'  => $operator,
        'nominal'   => $nominal,
        'reff_id'   => $reff_id,
        'sign'      => $sign
    )),

    CURLOPT_HTTPHEADER     => array(
        'Content-Type: application/x-www-form-urlencoded',
        'Authorization: ' . $api_key
    ),
    CURLOPT_FAILONERROR    => false,
    CURLOPT_IPRESOLVE      => CURL_IPRESOLVE_V4
]);

$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
print_r(empty($error) ? $response : $error);
</code></pre>


# Konfirmasi

Api direct konfirmasi pembayaran

{% hint style="warning" %}
Hanya untuk transaksi type **DIRECT**
{% endhint %}

{% hint style="info" %}
Jika respon *sukses* maka kami akan mengirimkan notifikasi melalui url webhook yang telah anda setting.
{% endhint %}

<mark style="color:green;">`POST`</mark> `https://api.ilenpay.co.id/v1/konfirmasi/pembayaran`

#### Headers

| Name                                            | Type   | Description |
| ----------------------------------------------- | ------ | ----------- |
| Authorization<mark style="color:red;">\*</mark> | String | Api Key     |

#### Request Body

| Name                                       | Type   | Description          |
| ------------------------------------------ | ------ | -------------------- |
| reff\_id<mark style="color:red;">\*</mark> | String |                      |
| sender                                     | Int    | Nomer pengirim pulsa |

{% tabs %}
{% tab title="200: OK Respon Sukses" %}

```json
{
  "data": {
    "respon": "sukses",
    "hash": "0cac895dc4aec69e48c4e3d2e0b400c2cd2d868c",
    "reff_id": "trx68164teewfske2",
    "payment": "telkomsel",
    "rate": "0.82",
    "nominal": "10000",
    "total_tf": "13000",
    "return_url": "https://domainkamu/redirect",
    "sender": "6281238846015",
    "status": "PAID",
    "saldo_ahir": 20000
  }
}
```

{% endtab %}

{% tab title="200: OK Respon Jika Status TRX PAID" %}

```json
{
  "data": {
    "respon": "sukses",
    "pesan": "Pembayaran sudah di selesaikan reff trx8833",
    "return_url": "https://domain.com/riwayat/8833"
  }
}
```

{% endtab %}
{% endtabs %}

### Contoh Untuk PHP&#x20;

```php
<?php

$api_key    = 'Production Key';
$reff_id    = 'trx68164343'; // $_POST['reff_id'];
$sender     = '081234567828'; // $_POST['sender'];

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_FRESH_CONNECT  => true,
    CURLOPT_URL            => 'https://api.ilenpay.co.id/v1/konfirmasi/pembayaran',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER         => false,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => http_build_query(array(
        'sender'    => $sender,
        'reff_id'   => $reff_id
    )),

    CURLOPT_HTTPHEADER     => array(
        'Content-Type: application/x-www-form-urlencoded',
        'Authorization: ' . $api_key
    ),
    CURLOPT_FAILONERROR    => false,
    CURLOPT_IPRESOLVE      => CURL_IPRESOLVE_V4
]);

$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
print_r(empty($error) ? $response : $error);


```


# Cek Harga

<mark style="color:blue;">`GET`</mark> `https://api.ilenpay.co.id/v1/info/harga`

#### Query Parameters

| Name                                       | Type   | Description                     |
| ------------------------------------------ | ------ | ------------------------------- |
| operator<mark style="color:red;">\*</mark> | String | (telkomsel, xl, tri, smartfren) |
| nominal<mark style="color:red;">\*</mark>  | Int    |                                 |

#### Headers

| Name                                            | Type | Description |
| ----------------------------------------------- | ---- | ----------- |
| Authorization<mark style="color:red;">\*</mark> |      | Api Key     |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "data": {
        "respon": "sukses",
        "operator": "smartfren",
        "rate": "0.77",
        "nominal": "20000",
        "total_tf": "Rp26,000",
        "total_tf_int": "26000"
    }
}
```

{% endtab %}
{% endtabs %}

### Contoh Untuk PHP&#x20;

```php
<?php

$api_key    = 'fb59f88534bd4c8e2559f885345trdbd81e4bd10';
$operator   = 'smartfren';
$nominal    = '20000';
$params     = array(
                'operator'  => $operator,
                'nominal'   => $nominal
            );

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_FRESH_CONNECT  => true,
    CURLOPT_URL            => 'https://api.ilenpay.co.id/v1/info/harga?' . http_build_query($params),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER         => false,
    CURLOPT_CUSTOMREQUEST  => 'GET',
    CURLOPT_HTTPHEADER     => ['Authorization: '.$api_key],
    CURLOPT_FAILONERROR    => false,
    CURLOPT_IPRESOLVE      => CURL_IPRESOLVE_V4
]);

$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
print_r(empty($error) ? $response : $error);

?>
```


# Cek Server

<mark style="color:blue;">`GET`</mark> `https://api.ilenpay.co.id/v1/info/server`

#### Headers

| Name                                            | Type   | Description |
| ----------------------------------------------- | ------ | ----------- |
| Authorization<mark style="color:red;">\*</mark> | String | Api Key     |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "data": {
        "respon": "sukses",
        "server": [
            {
                "nama": "Telkomsel",
                "rate": "0.82",
                "status": "1",
                "last_update": "1698316733"
            },
            {
                "nama": "TRI",
                "rate": "0.79",
                "status": "1",
                "last_update": "1698316733"
            },
            {
                "nama": "Smartfren",
                "rate": "0.77",
                "status": "1",
                "last_update": "1698316733"
            },
            {
                "nama": "XL/Axis",
                "rate": "0.80",
                "status": "1",
                "last_update": "1698316733"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}

### Contoh Untuk PHP&#x20;

```php
<?php

$api_key = 'fb59f88534bd4c8e2559f885345trdbd81e4bd10';

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_FRESH_CONNECT  => true,
    CURLOPT_URL            => 'https://api.ilenpay.co.id/v1/info/server',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER         => false,
    CURLOPT_CUSTOMREQUEST  => 'GET',
    CURLOPT_HTTPHEADER     => ['Authorization: '.$api_key],
    CURLOPT_FAILONERROR    => false,
    CURLOPT_IPRESOLVE      => CURL_IPRESOLVE_V4
]);

$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
print_r(empty($error) ? $response : $error);

?>
```


# Webhooks

{% hint style="info" %}
Tes apakah webhook sudah berjalan. Lakukan ping dengan URL dibawah ini. Kami akan mengirim data ke url yang telah anda settings.
{% endhint %}

> **<https://api.ilenpay.co.id/v1/webhook/ping/\\[Webhook> ID]**

```
// Contoh data yang kami kirim ke server anda.
{
  "data": {
    "webhook_id": "Tu9olJ9bLu0gDWv",
    "webhook_url": "https://ilenpay.id/webhook.php",
    "webhook_key": "alamat",
    "back_url": "https://ilenpay.id/tes-backurl.php"
  }
}
```

{% hint style="info" %}
Contoh pengiriman dari server kami
{% endhint %}

<pre><code>> POST /gass HTTP/1.1
> Host: ilenpay.co.id:3220
> X-Ilen-Delivery: pwsO51H0hfBk8iddERvp1LTasm7gG4
> X-Ilen-Signature: key=7d6f016c23d03b696e76dada91c07f178cc0af4d
> User-Agent: Ilenpay-Hookshot
<strong>> Content-Type: application/json
</strong>> Content-Length: 445
> X-Ilen-Event: create
{
  "data": {
    "hash": "e8d51bbe59f7689f82b3897a87f1e17829187391",
    "reff_id": "trx68164endo_tes",
    "payment": "telkomsel",
    "rate": "0.80",
    "nominal": "15000",
    "total_tf": "20000",
<strong>    "sender" : "6281234567898",
</strong>    "status": "PAID"
    "saldo_ahir": "576546"
  }
}

</code></pre>

{% hint style="info" %}
Contoh untuk menerima event PHP Native&#x20;
{% endhint %}

```
<?php
    $secret     = 'kodekamu';
    $post_data  = file_get_contents('php://input');
    $signature  = hash_hmac('sha1', $post_data, $secret);

    if($_SERVER['HTTP_X_ILEN_SIGNATURE'] == 'key=' . $signature){
       file_put_contents("log-ilenpay.txt", $post_data);
    }
    
?>
```


