Simple Laravel package to integrate ESC/POS Print Driver for PHP.
Via Composer
$ composer require charlieuki/receiptprinter
I have set up a simple app based on Laravel 7 to serve as a demo.
Execute the following command to publish the config used by this package:
$ php artisan vendor:publish --tag=receiptprinter.config
Edit the config file located at config/receiptprinter.php
as follows:
- Set
connector_type
to:windows
if you are using Windows as your web server.cups
if you are using Linux or Mac as your web server.network
if you are using a network printer.
- Set
connector_descriptor
to:- the printer name if your
connector_type
is eitherwindows
orcups
- the IP address or Samba URI, e.g:
smb://192.168.0.5/PrinterName
if yourconnector_type
isnetwork
- the printer name if your
- Set
connector_port
to the open port for the printer, only if yourconnector_type
isnetwork
Include the library:
use charlieuki\ReceiptPrinter\ReceiptPrinter as ReceiptPrinter;
Then use any one of these two functions to send "print" command to the printer.
printReceipt()
printRequest()
use charlieuki\ReceiptPrinter\ReceiptPrinter as ReceiptPrinter;
...
// Set params
$mid = '123123456';
$store_name = 'YOURMART';
$store_address = 'Mart Address';
$store_phone = '1234567890';
$store_email = 'yourmart@email.com';
$store_website = 'yourmart.com';
$tax_percentage = 10;
$transaction_id = 'TX123ABC456';
$currency = 'Rp';
$image_path = 'logo.png';
// Set items
$items = [
[
'name' => 'French Fries (tera)',
'qty' => 2,
'price' => 65000,
],
[
'name' => 'Roasted Milk Tea (large)',
'qty' => 1,
'price' => 24000,
],
[
'name' => 'Honey Lime (large)',
'qty' => 3,
'price' => 10000,
],
[
'name' => 'Jasmine Tea (grande)',
'qty' => 3,
'price' => 8000,
],
];
// Init printer
$printer = new ReceiptPrinter;
$printer->init(
config('receiptprinter.connector_type'),
config('receiptprinter.connector_descriptor')
);
// Set store info
$printer->setStore($mid, $store_name, $store_address, $store_phone, $store_email, $store_website);
// Set currency
$printer->setCurrency($currency);
// Add items
foreach ($items as $item) {
$printer->addItem(
$item['name'],
$item['qty'],
$item['price']
);
}
// Set tax
$printer->setTax($tax_percentage);
// Calculate total
$printer->calculateSubTotal();
$printer->calculateGrandTotal();
// Set transaction ID
$printer->setTransactionID($transaction_id);
// Set logo
// Uncomment the line below if $image_path is defined
//$printer->setLogo($image_path);
// Set QR code
$printer->setQRcode([
'tid' => $transaction_id,
]);
// Print receipt
$printer->printReceipt();
use charlieuki\ReceiptPrinter\ReceiptPrinter as ReceiptPrinter;
...
// Set params
$mid = '123123456';
$store_name = 'YOURMART';
$store_address = 'Mart Address';
$store_phone = '1234567890';
$store_email = 'yourmart@email.com';
$store_website = 'yourmart.com';
$tax_percentage = 10;
$transaction_id = 'TX123ABC456';
$currency = 'Rp';
$image_path = 'logo.png';
// Init printer
$printer = new ReceiptPrinter;
$printer->init(
config('receiptprinter.connector_type'),
config('receiptprinter.connector_descriptor')
);
// Set store info
$printer->setStore($mid, $store_name, $store_address, $store_phone, $store_email, $store_website);
// Set currency
$printer->setCurrency($currency);
// Set request amount
$printer->setRequestAmount($request_amount);
// Set transaction ID
$printer->setTransactionID($transaction_id);
// Set logo
// Uncomment the line below if $image_path is defined
//$printer->setLogo($image_path);
// Set QR code
$printer->setQRcode([
'tid' => $transaction_id,
'amount' => $request_amount,
]);
// Print payment request
$printer->printRequest();
Please see the changelog for more information on what has changed recently.
Please see contributing.md for details and a todolist.
If you discover any issues, please post the details on the issue tracker.
- Mike42 for the awesome PHP ESC/POS Print Driver library
MIT. Please see the license file for more information.