PHP code example of beziworld / laravel-apaczka

1. Go to this page and download the library: Download beziworld/laravel-apaczka library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

beziworld / laravel-apaczka example snippets


use Beziworld\Apaczka\Data\Address;
use Beziworld\Apaczka\Data\OrderRequest;
use Beziworld\Apaczka\Data\Parcel;
use Beziworld\Apaczka\Facades\Apaczka;

$order = new OrderRequest(
    serviceId: 41,                                       // InPost locker; ids come from serviceStructure()
    sender: new Address('ACME Shop', 'ul. Prosta 1', '00-001', 'Warszawa', email: '[email protected]', phone: '500600700'),
    receiver: new Address('Jan Kowalski', 'ul. Długa 5/3', '30-001', 'Kraków',
        email: '[email protected]', phone: '600700800', pointId: 'KRA01M'),   // locker or pickup point
    parcels: [new Parcel(length: 38, width: 64, height: 8, weight: 2.5)],
    content: 'Books',
    codAmount: 149.99,                                   // zloty; converted to grosze
    codBankAccount: '61109010140000071219812874',
    declaredValue: 200,
    pushTrackingUrl: route('apaczka.webhook'),
);

$prices = Apaczka::valuation($order);   // [41 => ['price' => 1200, 'price_gross' => 1476]] in grosze

$created = Apaczka::sendOrder($order);
$created->id;              // Apaczka order id
$created->waybillNumber;   // carrier waybill number

$pdf = Apaczka::waybill($created->id);   // label, binary PDF

Apaczka::serviceStructure();                    // services, options, parcel types
Apaczka::points('INPOST');                      // list<Point>: id, address, coordinates, cod/send/deliver
Apaczka::tracking('6800000000000');             // Tracking: service, events (newest first), isDelivered()
Apaczka::pickupHours('00-001', serviceId: 21);  // available courier windows
Apaczka::turnIn([123, 124]);                    // handover protocol, binary PDF
Apaczka::dispatchCode(123);                     // drop-off code
Apaczka::cancelOrder(123);
Apaczka::call('check_data/', ['vat_id' => 'PL5261040828']);   // any other API v2 method

use Beziworld\Apaczka\Events\TrackingStatusChanged;

Event::listen(function (TrackingStatusChanged $event): void {
    $shipment = Shipment::where('apaczka_order_id', $event->notification->orderId)->first();
    $status = $event->notification->latest()?->status;   // e.g. ON_THE_WAY, DELIVERED, RETURNED
    // ...
});