Open matiasdiaz21 opened 3 years ago
Sorry I am unable to reproduce this issue; if possible you can create a simple Laravel app repo to reproduce your issue?
Hello @matiasdiaz21,
I've tested this one on Laravel 8.69.0 with PHP 8.0.12 and it's working just fine. All you need to do is:
composer create-project laravel/laravel app-name-here
.env
configuration with the db details. cd
to app-name-here
directory then run php artisan migrate
composer require charlieuki/receiptprinter
php artisan vendor:publish --tag=receiptprinter.config
php artisan make:controller PrintController
<?php
namespace App\Http\Controllers;
use App\Http\Controllers; use charlieuki\ReceiptPrinter\ReceiptPrinter as ReceiptPrinter;
class PrinterController extends Controller { public function test() { // 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';
// 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);
// 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 qr code
$printer->setQRcode([
'tid' => $transaction_id,
]);
// Print receipt
$printer->printReceipt();
}
}
9. Add the routes to your `route/web.php` file:
`use App\Http\Controllers\PrinterController;`
`Route::get('/print/test', [PrintController::class, 'test']);`
10. Check your localhost if it's working. e.g url: `http://localhost:8080/print/test`
what the purpose of migrating if there is nothing to store or there is it ?
"Malformed UTF-8 characters, possibly incorrectly encoded when y use NetworkPrinter" on laravel 6.0.4 and PHP 7.2.
{ "message": "Malformed UTF-8 characters, possibly incorrectly encoded", "exception": "InvalidArgumentException", "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Http\JsonResponse.php", "line": 75, "trace": [ { "file": "C:\laragon\www\sistema_facturacion\vendor\symfony\http-foundation\JsonResponse.php", "line": 50, "function": "setData", "class": "Illuminate\Http\JsonResponse", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Http\JsonResponse.php", "line": 31, "function": "__construct", "class": "Symfony\Component\HttpFoundation\JsonResponse", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php", "line": 445, "function": "__construct", "class": "Illuminate\Http\JsonResponse", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php", "line": 191, "function": "prepareJsonResponse", "class": "Illuminate\Foundation\Exceptions\Handler", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\app\Exceptions\Handler.php", "line": 49, "function": "render", "class": "Illuminate\Foundation\Exceptions\Handler", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php", "line": 51, "function": "render", "class": "App\Exceptions\Handler", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 132, "function": "handleException", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php", "line": 41, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Routing\Middleware\SubstituteBindings", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Auth\Middleware\Authenticate.php", "line": 43, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Auth\Middleware\Authenticate", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php", "line": 76, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\VerifyCsrfToken", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php", "line": 49, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\View\Middleware\ShareErrorsFromSession", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php", "line": 56, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Session\Middleware\StartSession", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php", "line": 37, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php", "line": 66, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Cookie\Middleware\EncryptCookies", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 105, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Routing\Router.php", "line": 682, "function": "then", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Routing\Router.php", "line": 657, "function": "runRouteWithinStack", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Routing\Router.php", "line": 623, "function": "runRoute", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Routing\Router.php", "line": 612, "function": "dispatchToRoute", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php", "line": 176, "function": "dispatch", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 130, "function": "Illuminate\Foundation\Http\{closure}", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php", "line": 21, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\TransformsRequest", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php", "line": 21, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\TransformsRequest", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php", "line": 27, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\ValidatePostSize", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php", "line": 62, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\fideloper\proxy\src\TrustProxies.php", "line": 57, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 171, "function": "handle", "class": "Fideloper\Proxy\TrustProxies", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php", "line": 105, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php", "line": 151, "function": "then", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php", "line": 116, "function": "sendRequestThroughRouter", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "C:\laragon\www\sistema_facturacion\public\index.php", "line": 55, "function": "handle", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" } ] }