PHP code example of omnibus / offline

1. Go to this page and download the library: Download omnibus/offline 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/ */

    

omnibus / offline example snippets




mnibus\Model\{Address, Parcel, Shipment};
use Omnibus\Offline\OfflineGatewayFactory;

// No carrier and no network: the shop's own rates (grams => cents) and a tracking number typed by hand.
$gateway = (new OfflineGatewayFactory())->create([
    'rates' => [['service' => 'courier', 'label' => 'Courier', 'bands' => [1000 => 690, 30000 => 1290]]],
    'tracking_url' => 'https://www.laposte.fr/outils/suivre-vos-envois?code={number}',
]);
$shipment = new Shipment(
    new Address('The shop', ['1 rue de Rivoli'], '75001', 'Paris', 'FR'),
    new Address('Camille Durand', ['12 rue des Juifs'], '67000', 'Strasbourg', 'FR'),
    [new Parcel(500)],
    options: ['tracking_number' => '6A12345678901'],
);
echo $gateway->rate($shipment)[0]->amount, "\n";        // 690
echo $gateway->ship($shipment)->trackingNumber, "\n";   // 6A12345678901

$gateway = (new OfflineGatewayFactory())->create($options);   // the options below