Developer Center

CreateInvoice

Create a new invoice according to the specified parameters.

Method / Endpoint

POST/ {{API_URL}} Billing/CreateInvoice

İstek Parametreleri

Parameter Name Type Requirement Description
user_id Integer Yes ID Number of the Customer to Create Invoice
notification Boolean No Notification Sending Status
notes String No Invoice Note (For staff to see)
status String No Invoice Status. Values it can take: "unpaid',' "pending',' "paid',' "refunded',' "cancelled'. Default: "unpaid"
formalize Boolean No Invoice Formalization Status.
formalize_file String No The formalization file must contain a URL.
You can also specify a directory path if using the internal API.

(The transmitted file will be automatically copied to the system).
created_at String No Invoice Creation Date. Format: YYYY-MM-DD HH:ii:ss
Default: The date of the request is considered valid.
due_date String Yes Invoice Payment Due Date. Format: YYYY-MM-DD HH:ii:ss
payment_date String No Invoice Paid Date. Format: YYYY-MM-DD HH:ii:ss
Required if the invoice status is "paid" or "pending".
refund_date String No Invoice Refund Date. Format: YYYY-MM-DD HH:ii:ss
Required if the invoice status is "refunded".
currency String Yes The currency of the invoice. Format: ISO 4217. For example: USD, EUR, GBP
payment_method String No Payment Method Name
payment_method_data Object No Payment Method Data
payment_method_commission Double No Payment Method Commission Amount
payment_method_commission_rate Double No Payment Method Commission Rate
send_bill_to_address Double No Cost of Sending Invoices to the Address
exchange Double No Current Exchange Rate
discounts Object No Discounts
discounts.type String Yes Discount Type. "promotion", "coupon", "dealership"
discounts.sequence Integer Yes It must be the same as the "sequence" information you set in the invoice item.
discounts.rate Double No Discount Percentage. Default: 0
discounts.amount Double Yes Applied Discount Amount
discounts.description String Yes Discount Name: Coupon code, Promotion name, etc.
discounts.dkey String No If the discount type is "dealership", information on which product or product group the dealership discount is obtained from.
items Object Yes Invoice Items
items.sequence Integer Yes Invoice Item Sequence Number
items.description String Yes Invoice Item Description
items.quantity Integer No Invoice Item Quantity. Default : 1
items.amount Double Yes Invoice Item Unit Price
items.total Double No Invoice Item Total Amount. Default: Unit Price
items.order_id Integer No The product/service ID number to which the invoice item is linked. This information can be obtained from the "id" field in the "users_products" table in the database.
items.due_date String No If the invoice item is linked to a product/service, it must have the same end date as the product/service. Format: YYYY-MM-DD HH:ii:ss
items.attributes Object No If the invoice item is linked to a product/service, it contains information about the purchase or renewal of the linked product/service.

External Sample

curl --location 'https://example.com/api/Billing/CreateInvoice' \
--header 'Content-Type: application/json' \
--header 'Apikey: [YOUR_API_KEY]' \
--data '{
    "user_id": 22,
    "notification": false,
    "notes": "I created this invoice with API",
    "status": "unpaid",
    "formalize": false,
    "formalize_file": null,
    "created_at": "2023-12-13 16:25:00",
    "due_date": "2023-12-20 23:59:59",
    "payment_date": null,
    "refund_date": null,
    "currency": "USD",
    "payment_method": null,
    "payment_method_data": [],
    "payment_method_commission": 0,
    "payment_method_commission_rate": 0,
    "send_bill_to_address": 0,
    "exchange": null,
    "items": [
        {
            "sequence": 1,
            "description": "test description 1",
            "quantity": 1,
            "amount": 100,
            "total": 100,
            "order_id": 0,
            "due_date": null,
            "attributes": {
                "sample1": "Example test 1"
            }
        },
        {
            "sequence": 2,
            "description": "Sample Web Hosting (#123) (example.com) (2023-11-20 - 2023-12-20)",
            "quantity": 1,
            "amount": 143.23,
            "total": 143.23,
            "order_id": 123,
            "due_date": "2023-12-20 23:59:59",
            "attributes": {
                "event": "ExtendOrderPeriod"
            }
        }
    ],
    "discounts": [
        {
            "type": "promotion",
            "description": "Test Promotion 1",
            "sequence": 1,
            "rate": 5,
            "amount": 1
        },
        {
            "type": "coupon",
            "description": "AE1Q2CDF3",
            "sequence": 2,
            "rate": 20,
            "amount": 28.646
        }
    ]
}'

Internal Sample

Helper::Load("Api");
try {
    $result = Api::Billing()->CreateInvoice([
        'user_id'                        => 22,
        'notification'                   => false,
        'notes'                          => 'I created this invoice with API',
        'status'                         => 'unpaid',
        'formalize'                      => false,
        'formalize_file'                 => NULL,
        'created_at'                     => '2023-12-13 16:25:00',
        'due_date'                       => '2023-12-20 23:59:59',
        'payment_date'                   => NULL,
        'refund_date'                    => NULL,
        'currency'                       => 'USD',
        'payment_method'                 => NULL,
        'payment_method_data'            => [],
        'payment_method_commission'      => 0,
        'payment_method_commission_rate' => 0,
        'send_bill_to_address'           => 0,
        'exchange'                       => NULL,
        'items'                          => [
            [
                'sequence'    => 1,
                'description' => 'test description 1',
                'quantity'    => 1,
                'amount'      => 100,
                'total'       => 100,
                'order_id'    => 0,
                'due_date'    => NULL,
                'attributes'  => [
                    'sample1' => 'Example test 1',
                ],
            ],
            [
                'sequence'    => 2,
                'description' => 'Sample Web Hosting (#123) (example.com) (2023-11-20 - 2023-12-20)',
                'quantity'    => 1,
                'amount'      => 143.22999999999999,
                'total'       => 143.22999999999999,
                'order_id'    => 123,
                'due_date'    => '2023-12-20 23:59:59',
                'attributes'  => [
                    'event' => 'ExtendOrderPeriod',
                ],
            ],
        ],
        'discounts'                      => [
            [
                'type'        => 'promotion',
                'description' => 'Test Promotion 1',
                'sequence'    => 1,
                'rate'        => 5,
                'amount'      => 1,
            ],
            [
                'type'        => 'coupon',
                'description' => 'AE1Q2CDF3',
                'sequence'    => 2,
                'rate'        => 20,
                'amount'      => 28.646000000000001,
            ],
        ],
    ]);
    print_r($result);
}
catch (Exception $e)
{
    echo 'Error: '.$e->getMessage();
}

Sample JSON Response

{
    "status": "successful",
    "data": {
        "id": 468,
        "number": "#468",
        "user": {
            "id": 22,
            "lang": "en",
            "type": "corporate",
            "identity": "11111111111",
            "company_name": "ABC LLC",
            "company_tax_number": "12345",
            "company_tax_office": "XTESTX",
            "name": "Mark",
            "surname": "Roberson",
            "full_name": "Mark Roberson",
            "email": "[email protected]",
            "phone": "19142426349",
            "address": {
                "country_code": "US",
                "country_name": "United States",
                "city": "New York",
                "state": "Mount Kisco",
                "detail": "1159 Lake Forest Drive",
                "zipcode": "10549"
            }
        },
        "taxation_type": "exclusive",
        "notes": "I created this invoice with API",
        "created_at": "2023-12-13 16:25:00",
        "due_date": "2023-12-20 23:59:59",
        "payment_date": "0000-00-00 00:00:00",
        "refund_date": "0000-00-00 00:00:00",
        "status": "unpaid",
        "formalize": false,
        "local": false,
        "taxfree": false,
        "formalize_file": null,
        "exchange_rate": 1,
        "currency": "USD",
        "tax_rate": 0,
        "subtotal": 243.229999999999989768184605054557323455810546875,
        "tax": 0,
        "total": 213.58400000000000318323145620524883270263671875,
        "payment_method": "None",
        "payment_method_data": [],
        "payment_method_commission": 0,
        "payment_method_commission_rate": 0,
        "send_bill_to_address": 0,
        "share": {
            "token": "bGI1UlRBVXpPL3lmZThpTmM1Zy9pdXhoZldFa3E1cUdNQmRSVWJCV0ROMD0=",
            "link": "https://example.com/en/invoice?token=bGI1UlRBVXpPL3lmZThpTmM1Zy9pdXhoZldFa3E1cUdNQmRSVWJCV0ROMD0="
        },
        "discounts": [
            {
                "type": "coupon",
                "item_id": 571,
                "rate": 20,
                "description": "AE1Q2CDF3",
                "amount": 28.6460000000000007958078640513122081756591796875
            },
            {
                "type": "promotion",
                "item_id": 570,
                "rate": 5,
                "description": "Test Promotion 1",
                "amount": 1
            }
        ],
        "items": [
            {
                "id": 570,
                "owner_id": 468,
                "description": "test description 1",
                "quantity": 1,
                "tax_exempt": false,
                "amount": 100,
                "total": 100,
                "order_id": 0,
                "due_date": "2023-12-20 23:59:59",
                "attributes": {
                    "sample1": "Example test 1"
                }
            },
            {
                "id": 571,
                "owner_id": 468,
                "description": "Sample Web Hosting (#123) (example.com) (2023-11-20 - 2023-12-20)",
                "quantity": 1,
                "tax_exempt": false,
                "amount": 143.229999999999989768184605054557323455810546875,
                "total": 143.229999999999989768184605054557323455810546875,
                "order_id": 123,
                "due_date": "2023-12-20 23:59:59",
                "attributes": {
                    "event": "ExtendOrderPeriod"
                }
            }
        ]
    }
}

Response Parameters

Parameter Name Type Description
status String Action Status "successful" or "error"
message String Error message if action status is "error"
data Object Transmits the same data as "getInvoice".
GetInvoices UpdateInvoice

Do you have any questions?

Feel free to contact us
Contact Us
Copyright © 2024. All Rights Reserved.
Join Our Discord Channel
Top