# Create Bill

There are 2 ways when creating a bill. Both ways will generate a bill under a collection of your choice.

## Authentication

LeanX uses **Auth Token** to authenticate in each request's header.

{% hint style="info" %}
**Auth Token** can be retrieved in your portal dashboard under **API** page.
{% endhint %}

**Request Header**

{% code overflow="wrap" %}

```json
{
    "auth-token": "LP-0D7C06DE-MM|7394e58e-edee-4c42-9ca5-bcbc449f1b9f|2141df4a3cb633d5ce8683bb0c55067e5caebfbe07390dde277dc455bcc95c91723a81b5e565c7c02d68fb84e396722563016bf99e576a4b8cdbe4423fbf226b"
}
```

{% endcode %}

## Option 1 : Payment Page

This will create a bill and return a link to our LeanX Payment page.

HTTP Method: <mark style="color:yellow;">POST</mark>

```
https://api.leanx.dev/api/v1/merchant/create-bill-page
```

**Query**

| Query       | Type   | Description      |
| ----------- | ------ | ---------------- |
| invoice\_no | String | Your bill number |

**Request Body**

```json
{
    "collection_uuid": "CL-C0D7F54A90-LNP",
    "amount": 10.00,
    "redirect_url": "https://www.yourdomain.com/return-page",
    "callback_url": "https://www.yourdomain.com/api-callback-url",
    "full_name": "John Doe",
    "email": "johndoe@email.com",
    "phone_number": "0123456789",
}
```

**Attributes**

<table><thead><tr><th width="251">Property</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>collection_uuid<mark style="color:red;">*</mark></td><td>String</td><td>Your <a data-mention href="../collection">collection</a> UUID</td></tr><tr><td>amount<mark style="color:red;">*</mark></td><td>Decimal (10,2)</td><td>Total amount to be paid in MYR</td></tr><tr><td>callback_url</td><td>String</td><td>Your callback URL</td></tr><tr><td>redirect_url<mark style="color:red;">*</mark></td><td>String</td><td>Your redirect URL</td></tr><tr><td>full_name<mark style="color:red;">*</mark></td><td>String</td><td>Name of the payer</td></tr><tr><td>email<mark style="color:red;">*</mark></td><td>String</td><td>Email of the payer</td></tr><tr><td>phone_number<mark style="color:red;">*</mark></td><td>String</td><td>Mobile number of the payer</td></tr></tbody></table>

**Response**

```json
{
    "response_code": 2000,
    "description": "SUCCESS",
    "app_version": "/api/v1",
    "talk_to_server_before": "2024-03-27T21:46:07.403797",
    "data": {
        "collection_uuid": "CL-AUTH-35775712FA-LNP",
        "redirect_url": "https://payment.leanx.dev/collection?id=CL-AUTH-35775712FA-LNP&fullname=puteri balqis&email=puteri.balqis@gmail.com&phone_number=0112459822&invoice_no=speedmart-87654432&description=test description&amount=119.0&redirect_url=aHR0cHMlM0EvL2xlYW5pcy5jb20ubXk=&callback_url=https%3A//api.leanx.dev/api/v1/callback-url/callback-redirect%3F_uuid%3D2f49c906-4a1f-4cb4-bf46-949f9f77a6ce%26order_id%3DNone",
        "old_redirect_url": "https://portal.leanx.dev/pay/collections/CL-AUTH-35775712FA-LNP?fullname=puteri balqis&email=puteri.balqis@gmail.com&phone_number=0112459822&invoice_no=speedmart-87654432&description=test description&amount=119.0&redirect_url=aHR0cHMlM0EvL2xlYW5pcy5jb20ubXk=&callback_url=https%3A//api.leanx.dev/api/v1/callback-url/callback-redirect%3F_uuid%3D2f49c906-4a1f-4cb4-bf46-949f9f77a6ce%26order_id%3DNone",
        "bill_no": "speedmart-87654432"
    },
    "breakdown_errors": "",
    "token": ""
}
```

## Option 2 : Without Payment Page

This will create a bill and return a link straight to the payment service that you chose through `payment_service_id.`

{% hint style="info" %}
Payment Service? Go to [payment-service](https://docs.leanx.io/api-docs/cloud-payment/payment-service "mention") to learn more about them and how to get their values.
{% endhint %}

HTTP Method: <mark style="color:yellow;">POST</mark>

```
https://api.leanx.dev/api/v1/merchant/create-bill-silent
```

**Request Body**

```json
{
    "collection_uuid": "CL-C0D7F54A90-LNP",
    "amount": 10.00,
    "redirect_url": "https://www.yourdomain.com/return-page",
    "callback_url": "https://www.yourdomain.com/api-callback-url",
    "full_name": "John Doe",
    "email": "johndoe@email.com",
    "phone_number": "0123456789",
    "payment_service_id": 33,
    "invoice_ref" : "INV202311280001"
}
```

**Attributes**

<table><thead><tr><th width="258">Property</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>collection_uuid<mark style="color:red;">*</mark></td><td>String</td><td>Your <a data-mention href="../collection">collection</a> UUID</td></tr><tr><td>amount<mark style="color:red;">*</mark></td><td>Decimal (10,2)</td><td>Total amount to be paid in MYR</td></tr><tr><td>callback_url<mark style="color:red;">*</mark></td><td>String</td><td>Your callback URL</td></tr><tr><td>redirect_url</td><td>String</td><td>Your redirect URL</td></tr><tr><td>full_name<mark style="color:red;">*</mark></td><td>String</td><td>Name of the payer</td></tr><tr><td>email<mark style="color:red;">*</mark></td><td>String</td><td>Email of the payer</td></tr><tr><td>phone_number<mark style="color:red;">*</mark></td><td>String</td><td>Mobile number of the payer</td></tr><tr><td>payment_service_id<mark style="color:red;">*</mark></td><td>Number</td><td>The <a data-mention href="../payment-service">payment-service</a> ID</td></tr><tr><td>invoice_ref<mark style="color:red;">*</mark></td><td>String</td><td>Merchant Invoice Reference</td></tr></tbody></table>

**Response**

```json
{
  "response_code": 2000,
  "description": "SUCCESS",
  "app_version": "/api/v1",
  "talk_to_server_before": "2023-01-31T14:28:30.842232",
  "data": {
    "bill_no": "EXAMPLE-BILL-001",
    "transaction_invoice_no": "FPX1700639540AlnAnAy0",
    "redirect_url": "https://www.yourdomain.com/return-page"
  }
}
```
