Receipt service
The receipt service provides an implementation for printing receipts. You can register separate implementations for different receipt types.
Registration
export default async context => {
context.service.addService({
type: 'receiptService',
receiptType: 'full-receipt',
printReceipt: async req => {
// req contains: orderId, uiCultureCode
// ... send the receipt to a printer
return { status: 'Success' };
},
});
};
Receipt types
You can register a service for each receipt type independently:
| Receipt type | Description |
|---|---|
full-receipt | A full detailed receipt |
compact-receipt | A compact order confirmation receipt |
To support both types, register two separate services:
export default async context => {
context.service.addService({
type: 'receiptService',
receiptType: 'full-receipt',
printReceipt: async req => {
// print full receipt
return { status: 'Success' };
},
});
context.service.addService({
type: 'receiptService',
receiptType: 'compact-receipt',
printReceipt: async req => {
// print compact receipt
return { status: 'Success' };
},
});
};
Request parameters
The printReceipt method receives an object with the following properties:
| Property | Type | Description |
|---|---|---|
orderId | string | The order to print a receipt for |
uiCultureCode | string | Culture code for localization |
Responses
Success
return { status: 'Success' };
Error
return {
status: 'Error',
error: {
code: 'printer.offline',
message: 'The printer is not responding',
},
};