# Create Invoice

## Creating a new Invoice

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

```
curl --location -g --request POST '{{BASE_URL}}/v2/create-invoice' \
--header 'Authorization: Bearer {{API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "api Invoice test",
    "invoice_number": "1234",
    "subject":   "API test",
    "description": "Rent for Q1",
    "amount": 30,
    "currency_name": "USD",
    "items": {
		"1": {
			"name": "Test Item 1",
            "Quantity":"1",
			"price": 10
		},
		"2": {
			"name": "Test Item 2",
			"price": 20
		}
	}
}'
```

{% endtab %}

{% tab title="JavaScript" %}

```
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer {{API_KEY}}");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "name": "api Invoice test",
  "invoice_number": "1234",
  "subject": "API test",
  "description": "Rent for Q1",
  "amount": 30,
  "currency_name": "USD",
  "items": {
    "1": {
      "name": "Test Item 1",
      "Quantity": "1",
      "price": 10
    },
    "2": {
      "name": "Test Item 2",
      "price": 20
    }
  }
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("{{BASE_URL}}/v2/create-invoice", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

{% endtab %}

{% tab title="Node.js" %}

```
var request = require('request');
var options = {
  'method': 'POST',
  'url': '{{BASE_URL}}/v2/create-invoice',
  'headers': {
    'Authorization': 'Bearer {{API_KEY}}',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "name": "api Invoice test",
    "invoice_number": "1234",
    "subject": "API test",
    "description": "Rent for Q1",
    "amount": 30,
    "currency_name": "USD",
    "items": {
      "1": {
        "name": "Test Item 1",
        "Quantity": "1",
        "price": 10
      },
      "2": {
        "name": "Test Item 2",
        "price": 20
      }
    }
  })

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

{% endtab %}

{% tab title="PHP" %}

```
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '%7B%7BBASE_URL%7D%7D/v2/create-invoice',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "name": "api Invoice test",
    "invoice_number": "1234",
    "subject":   "API test",
    "description": "Rent for Q1",
    "amount": 30,
    "currency_name": "USD",
    "items": {
		"1": {
			"name": "Test Item 1",
            "Quantity":"1",
			"price": 10
		},
		"2": {
			"name": "Test Item 2",
			"price": 20
		}
	}
}',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer {{API_KEY}}',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}

{% tab title="Python" %}

```
import requests
import json

url = "{{BASE_URL}}/v2/create-invoice"

payload = json.dumps({
  "name": "api Invoice test",
  "invoice_number": "1234",
  "subject": "API test",
  "description": "Rent for Q1",
  "amount": 30,
  "currency_name": "USD",
  "items": {
    "1": {
      "name": "Test Item 1",
      "Quantity": "1",
      "price": 10
    },
    "2": {
      "name": "Test Item 2",
      "price": 20
    }
  }
})
headers = {
  'Authorization': 'Bearer {{API_KEY}}',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

{% endtab %}
{% endtabs %}

| Field           | Description                                                    | Example                                                                                                      |
| --------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| name            | Name of your customer                                          | "API Invoice test"                                                                                           |
| invoice\_number | The number of the invoice (optional). Can accept any character | "1234"                                                                                                       |
| subject         | Subject as you'd like it to appear                             | "API test"                                                                                                   |
| description     | Description of items in the invoice                            | "Rent for Q1"                                                                                                |
| amount          | The amount as a string                                         | "100.05"                                                                                                     |
| currency\_name  | The ISO-4217 currency                                          | "USD"                                                                                                        |
| items           | List of items in JSON format                                   | { "1": { "name": "Test Item 1", "Quantity":"1", "price": 10 }, "2": { "name": "Test Item 2", "price": 20 } } |

## Create an invoice.

<mark style="color:green;">`POST`</mark> `https://merchant.fcfpay.com/api/v2/create-invoice`

Creates a new invoice.

#### Request Body

| Name                                          | Type    | Description                         |
| --------------------------------------------- | ------- | ----------------------------------- |
| name<mark style="color:red;">\*</mark>        | string  | Name of your customer               |
| invoice\_number                               | string  | The invoice number                  |
| amount<mark style="color:red;">\*</mark>      | decimal | The amount                          |
| description<mark style="color:red;">\*</mark> | string  | Description of items in the invoice |
| subject                                       | String  | Subject as you'd like it to appear  |

{% tabs %}
{% tab title="200 Order successfully created" %}

```javascript
{
    "success": true,
    "data": {
        "checkout_page_url": "https://checkout.fcfpay.com/pay/JDJ5JDEwJG1rVldXaGVtTVZsTHZUbjkxUFJmSE9QQURvQzVjUDlucU9zQVEyUWo5SWNGRWs0Lkx3bFRP",
        "payment_status": "waiting"
    },
    "message": "Invoice successfully created. Waiting for the payment."
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid API Key" %}

```javascript
{
    "success": false,
    "data": [],
    "message": "Merchant Authentication problem!"
}
```

{% endtab %}
{% endtabs %}

After order creation, our system will send you a checkout page URL. You should redirect your customers to that URL.

If you send information about items, this will be displayed on the checkout page:

<figure><img src="https://1945871046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3ZdalD0o3BV7ztrYg74F%2Fuploads%2FgK8mnbv486em1QpBYxqb%2Fimage.png?alt=media&#x26;token=d42f8878-164c-4c79-a19d-62a96539e70e" alt=""><figcaption></figcaption></figure>
