charlieuki / receipt-printer

Laravel package to integrate ECS/POS Print Driver for PHP
Other
131 stars 46 forks source link

Laravel issue #17

Open matiasdiaz21 opened 3 years ago

matiasdiaz21 commented 3 years ago

"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": "->" } ] }

charlieuki commented 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?

jumarjuaton commented 3 years ago

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:

  1. Create a Laravel project from scratch with command: composer create-project laravel/laravel app-name-here
  2. Create a db and update your .envconfiguration with the db details.
  3. cdto app-name-here directory then run php artisan migrate
  4. Download and install the receipt-printer package: composer require charlieuki/receiptprinter
  5. Execute this command to create the config file: php artisan vendor:publish --tag=receiptprinter.config
  6. Add the necessary config details. If your printer is on your network and on Windows, make sure sharing is enabled in the Printer Properties. See screenshot: Screenshot 2021-11-09 173341
  7. Create a controller. php artisan make:controller PrintController
  8. Add these code (which is same in the example repo) in 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`
hamza-saqib commented 2 years ago

what the purpose of migrating if there is nothing to store or there is it ?