API Generate Receipt Document
If you want to create an etax document through your system. This guide will teach you how to use a simple Leceipt system endpoint with example code for your easy understanding.
For convenience, w e recommend that you view the sample code at https://github.com/frevation/leceipt-api-example-code.
To create an etax document, follow these steps:
1. Generate API Key
This API key will be used to connect the API to the Leceipt system. The method for generating it is in the link below.
How to generate an API Key: https://www.leceipt.com/docs/etax/api-key
2. Provide information
Provide important information in order to create documents on Leceipt. You can see examples of information on Github.
company (ผู้ขาย)
Parameters | Require | Type | Meaning |
---|---|---|---|
name |
yes |
String |
Seller Name |
buildingNumber |
yes |
String |
Address Number |
address |
yes |
String |
Address |
streetPrefix |
yes |
String |
Street name prefix, e.g. street, rd. (if you don’t want it displayed, put “”) |
streetName |
yes |
String |
Street name |
subDistrictPrefix |
yes |
String |
Sub-district name prefix, e.g. sub-district, sub-district, sub-district (if you don’t want it displayed, put “”) |
subDistrictCode |
yes |
String |
District Code |
subDistrictName |
yes |
String |
Sub-District/Sub-District Name |
districtPrefix |
yes |
String |
District name prefix, for example, district, district, khet (if you don’t want it to be displayed, put “”) |
districtCode |
yes |
String |
District Code |
districtName |
yes |
String |
District Name |
provincePrefix |
yes |
String |
Prefix of the name of the province such as province (if you do not want it to be displayed, put “”) |
provinceCode |
yes |
String |
Province Code |
provinceName |
yes |
String |
Province Name |
postcode |
yes |
String |
Postcode |
branchNumber |
yes |
String |
Branch Number |
branchText |
yes |
String |
Head Office Name |
taxNumberType |
yes |
String |
Taxpayer Type |
taxId |
yes |
String |
Taxpayer ID |
phoneCountryCode |
yes |
String |
Country Code |
phone |
yes |
String |
Telephone Number |
yes |
String |
||
unstructure |
yes |
Boolean |
Structured Address |
Example
customer
Parameters | Require | Type | Meaning |
---|---|---|---|
name |
yes |
String |
Seller name |
addressLineOne |
yes |
String |
Address |
addressLineTwo |
no |
String |
Address line 2 |
postcode |
yes |
String |
Postcode |
branchNumber |
yes |
String |
Branch number |
branchText |
yes |
String |
Head Office Name |
taxNumberType |
yes |
String |
Taxpayer Type |
taxId |
yes |
String |
Tax ID |
phoneCountryCode |
yes |
String |
Country Code |
phone |
yes |
String |
Telephone Number |
yes |
String |
||
unstructure |
yes |
Boolean |
Structured Address |
Example
items
This parameter is an array. If the document contains multiple items or services, add an Object to this array manually.
Parameters | Require | Type | Meaning |
---|---|---|---|
number |
yes |
number |
Order of goods or services |
description |
yes |
string |
Product or service details |
quantity |
yes |
number |
Number of products |
unitCode |
no |
string |
Product unit code (Refer to UNECE Recommendation No. 20 Codes for Units of Measure Used in International Trade) |
unitName |
no |
string |
Product unit name |
price |
yes |
number |
Price of goods or services |
discount |
yes |
number |
Product or service discounts |
percentVat |
yes |
number |
The tax percentage of the item includes: If it is a tax exempt item, specify -1 If it is a 0% tax item, specify 0 If it is a 7% tax item, specify 7 |
percentVatText |
no |
string |
Tax Type Name |
total |
yes |
number |
Total price of goods or services |
Example
refer
refer here refers to the reference document. If no documents are issued in lieu of the original This section is not required to be filled out.
Parameters | Require | Type | Meaning |
---|---|---|---|
typeCode |
yes |
string |
The document type code refers to , for example T03 |
typeName |
yes |
string |
Name of document type referring to e.g. Receipt/Tax Invoice |
number |
yes |
string |
Reference document number |
date |
yes |
string |
Date, month, year, time of issuing the referenced document (YYYY-MM-DDTHH:mm:ss.sssZ ISO 8601 UTC Time format) |
dateBE |
yes |
string |
Date, month, year (B.E.) the document was issued to refer to |
reasonCode |
yes |
string |
Reason |
reasonName |
yes |
string |
Name of reason |
Example
data
Parameters | Require | Type | Meaning |
---|---|---|---|
company |
yes |
object |
|
customer |
yes |
object |
|
date |
yes |
string |
Date, month, year, time of issuing receipt/tax invoice (YYYY-MM-DDTHH:mm:ss.sssZ ISO 8601 UTC Time format) |
dateBE |
yes |
string |
Date, month, year (B.E.) the receipt/tax invoice is issued |
dateCE |
no |
string |
Date, month, year (A.D.) the receipt/tax invoice was issued |
items |
yes |
array |
|
note |
no |
string |
Note that must be shown in Receipt/Tax invoice |
number |
yes |
string |
Number of Receipt/Tax invoice |
receivedBy |
yes |
string |
Payee name |
percentVat |
yes |
number |
Current VAT percentage 7 |
amountTotal |
yes |
number |
Total value of goods or services (Before Vat) |
noneVatPriceTotal |
yes |
number |
Value of goods or services exempt from all taxes |
zeroVatPriceTotal |
yes |
number |
Total value of goods or services tax 0% |
vatPriceTotal |
yes |
number |
Total value of goods or services tax 7% |
vatTotal |
yes |
number |
VAT value |
grandTotal |
yes |
number |
Total value of goods or services (after Vat) |
discount |
yes |
number |
Total discount |
reIssue |
yes |
boolean |
If issuing a document instead of the original one, specify “true” If not, specify “false” |
refer |
yes |
object |
Example
3. Send Request to Endpoint
Endpoint: https://api.leceipt.com/etax/documents/receipts Method: Post Post Send data in item 2. Go to endpoint above, it is recommended to use axios to send request for simplicity.
Example
Response:
{
createdTime: ‘2022-02-09T08:35:49.0049189Z’,
id: ‘2eac60a9-1543-450a-b34a-cd6fae8e1d86’,
status: ‘Processing’
}
Once the request has been submitted successfully, the Leceipt system will create a document. deemed to be completed.
But if you want to download the pdf file, see the next step.
4. Save FileId for Download
Endpoint: https://api.leceipt.com/etax/jobs/{id}
Method: Get
Send a get request to the endpoint above with the id taken from the response in step 3.
{
…
id: ‘bc7faa35-3109-450f-bfee-f3ea13704d8f’,
…
}
Example
Put this id at the end of the endpoint (don’t put ” around the id).
Response:
{
createdTime: ‘2022-02-03T03:31:58.9025294Z’,
fileId: ‘8af05cb9-7daa-41c5-bedf-4ee22370c3c4’,
fileSize: 312893,
id: ‘b9956a4b-cfed-4e42-b2f5-5f4aaa8ab2c3’,
lastUpdatedTime: ‘2022-02-03T03:32:12.4964502Z’,
status: ‘complete’
}
When you get a response, use fileId in the next step.
5. Download PDF file
Endpoint: https://api.leceipt.com/etax/files/{fileId}/?api-version=2021-04-22
Method: Get
Example
Use fs.createWriteStream. to create a pdf file.
If still in doubt, you can view the source code on Github provided above.