# Tokenization

## Generate token

1. Contact NeoX to register the service.

<figure><img src="https://1419689564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFdTKNedABvGBtqJRHWA0%2Fuploads%2FKzBW6Q5YGFaUFlyH8TQG%2FScreen%20Shot%202023-05-18%20at%2009.45.48.png?alt=media&#x26;token=4487be16-c5ca-4e3d-8ae9-0baabc8331a7" alt=""><figcaption><p>Check registration status at Account information page</p></figcaption></figure>

2. Create bill with enabled `neo_TokenCreate` field.

The bill created with field `neo_TokenCreate = true` will return the token (`neo_PayToken`) after payment success via [IPN](https://docs.neox.vn/docs/payment-gateway/transaction-management/ipn). The token can be used for the next payment.

[*How to create a bill?*](https://docs.neox.vn/docs/payment-gateway/integrations/hosted-checkout)

## Next payment

1. Authentication&#x20;

Reference to [Platform Authentication](https://docs.neox.vn/docs/disbursement/integration/generate-token-api).

Using `scope = payment`

2. Pay by token API

* URL:  <https://api.neopay.vn/oapi/v2/payment/payByToken>
* Method: POST&#x20;
* Request: Content-Type: application/json

**Request Parameter**

<table><thead><tr><th width="176">Parameter</th><th width="118" align="center">Data type</th><th width="119" align="center">Required</th><th>Description</th></tr></thead><tbody><tr><td>orderId</td><td align="center">String</td><td align="center">Y</td><td>Order ID </td></tr><tr><td>orderInfo</td><td align="center">String</td><td align="center">Y</td><td>Order description</td></tr><tr><td>merchantTxnId</td><td align="center">String</td><td align="center">Y</td><td>Merchant's transaction ID (unique)</td></tr><tr><td>currency</td><td align="center">String</td><td align="center">Y</td><td>Currency (default VND)</td></tr><tr><td>amount</td><td align="center">Number</td><td align="center">Y</td><td>Bill amount</td></tr><tr><td>payToken</td><td align="center">String</td><td align="center">Y</td><td><code>neo_PayToken</code> NeoX returned </td></tr></tbody></table>

Example:

```json
{
    "orderId": "DH123232234",
    "orderInfo": "Thanh toan DH123232234",
    "merchantTxnId": "323123221434",
    "currency": "VND",
    "amount": 100000,
    "payToken": "c9291339613c4e4a80818c87cbedb483"
}
```

**Response Data**

<table><thead><tr><th>Field name</th><th width="172.33333333333331" align="center">Data type</th><th>Description</th></tr></thead><tbody><tr><td>code</td><td align="center">Number</td><td><a href="../../transaction-management/error-codes">Error code</a></td></tr><tr><td>message</td><td align="center">String</td><td>Response message</td></tr><tr><td>data</td><td align="center">Object</td><td><ul><li>orderId: String</li><li>merchantTxnId: String</li></ul></td></tr></tbody></table>

Example:

```json
{
    "code": 99,
    "message": "Order is processing",
    "data": {
        "orderId": "DH12323234234",
        "merchantTxnId": "323123221434"
    }
}
```

#### Payment result

Last result of the request will be sent via [IPN](https://docs.neox.vn/docs/payment-gateway/transaction-management/ipn).
