Receipt Print
Receipt Print is a smart receipt printing service provided by Alibaba Cloud IoT Platform. It offers ready-to-use printing templates, allowing you to print receipts quickly without using complex printing commands. This document describes how to use the Receipt Print service.
Prerequisites
-
Your device is connected to Alibaba Cloud IoT Platform. For more information, see device connection.
-
The Receipt Print service is activated. For more information, see activate service.
Procedure
To use the Receipt Print service, you first create a project and a receipt template in the console, and then make an API call with the required printing parameters.
|
Step |
Description |
|---|---|
|
Projects provide resource isolation. Receipt Print provides services at the project level. You can create different projects for various application scenarios to isolate devices and data across projects. |
|
|
Create and download a receipt printing template in the console. |
|
|
Call the Receipt Print service API with the required printing parameters to start the print job. |
Step 1: Create a project
-
Log on to the IoT Platform console. In the left-side navigation pane, choose Value-added Services.
-
On the Value-added Services page, find the Receipt Print service and click Go to Service.
-
In the left-side navigation pane, choose Project Management.
-
On the Project Management page, click Create Project or Associate Project.
-
Create Project: Create a new project. In the dialog box, configure the following parameters and click OK.
Parameter
Description
Project name/Product name
The project name must be unique within the instance. It can be up to 32 characters long and can contain Chinese characters, uppercase and lowercase letters, digits, and underscores (_).
Source of product for the project
A project must be bound to a specific product.
-
Create a new product along with the project: Automatically creates a product in IoT Platform that has the same name as the project.
-
Create a project from an existing product: Select an existing product.
If you select this option, we recommend using the name of the existing product as the Project Name for easier matching and identification.
Project description
Enter a description for the project, such as background information. The description can be up to 500 characters long and can contain Chinese characters, uppercase and lowercase letters, digits, and underscores (_). Each Chinese character counts as two characters.
-
-
Associate Project: Reuse an existing project from another service. In the panel, configure the following parameters.
Parameter
Description
Other services
Currently, you can only associate projects from the Voice Broadcasting Service.
Project list
Select the specific project that you want to use.
-
-
Click OK. After the project is created or associated, you are returned to the project list.
In the project list, you can view the project ID and perform operations such as editing, configuring, and disabling projects.
-
View project ID: The unique identifier of a project. It is a required parameter for API calls.
-
Edit project: Click Edit to modify the project description. The project name and the associated product source cannot be modified.
-
Configure project: Click Configure to go to the project details page for the Receipt Print service.
-
Step 2: Create a template
-
On the Project Management page, find the target project and click Configure in the Actions column.
-
On the Template Management page, click Create Template, set the parameters, and then click Finish.
Parameter
Description
Select scene
Base templates are provided for different printing scenarios, including Sales, Takeaway, and Kitchen. Select a scenario based on your requirements.
NoteYou cannot modify template parameters in the console. Instead, you must pass the required printing parameters in the API call.
Template name
Set a name for the template that is easy for you to identify. The name can be up to 32 characters long and can contain Chinese characters, letters, digits, and underscores (_).
Template identifier
Set a unique identifier for the template, which is used in API calls.Template specification
Select a specification based on your printer: 58mm or 80mm. -
Click Data Template to view the printing parameters and download the template to your local machine.
The data template is a JSON-formatted sample for receipt printing. When making an API call, replace the placeholder values in the JSON sample with your business data to print dynamic content.
-
The data template for the Sales template is in JSON format. The following table describes the mapping between the parameters and the content on the printed receipt.
Parameter
Description
orderTabelThe order details table. The value is an array where each object represents a line item on the receipt.nameItem name.numberQuantity.
pricePrice.
totalTotal price for the line item.
orderTimeThe order time displayed at the top of the receipt.
totalPriceTotal price.PaidInAmount paid.
giveChange
Change.
title
The title of the receipt. -
The data template for the Takeaway template is in JSON format. The following table describes the parameters.
Parameter
Description
orderTabelThe order details table. The value is an array where each object represents a line item on the receipt.nameItem name.numberQuantity.
pricePrice.
totalTotal price for the line item.
orderTimeThe order time displayed at the top of the receipt.
address
Address.
phone
Phone number.
priceTotal price.distributionFee
Delivery fee.
shopNameThe shop name displayed at the top of the receipt.
title
The title of the receipt.
status
The payment status displayed at the top of the receipt. -
The data template for the Kitchen template is in JSON format. The following table describes the parameters.
Parameter
Description
orderTabelThe order details table. The value is an array where each object represents a line item on the receipt.nameItem name.numberQuantity.
totalTotal quantity.
deskNo
The table number displayed at the top of the receipt.
orderTimeThe order time displayed at the top of the receipt.
orderNoThe order number displayed at the top of the receipt.remarkRemarks.
title
The title of the receipt.
-
Step 3: Make an API call
This section describes how to obtain key API parameters. For the complete API reference, see PrintByTemplate.
-
ParamsJsonString: The printing parameters. Construct the data as described in the preceding sections. The following code provides an example:
{ "orderTable":[ { "number":"1", "price":"32.00", "name":"GP-3120TU" } ], "total":"4", "orderTime":"2021-01-25 10:20:00", "totalPrice":"98.00", "paidIn":"100.00", "giveChange":"2.00", "title":"XX Specialty Store" } -
ProjectCode: The project ID. On the Project Management page, find the ID in the Project ID column and click Copy.
-
TemplateBizCode: The template identifier. On the Template Management page for the project, find this value in the Template Identifier column.