PHP code example of kattatzu / ship-it

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

    

kattatzu / ship-it example snippets


use Kattatzu/ShipIt/ShipIt;

$shipIt = new ShipIt('EMAIL', 'TOKEN', 'development');
// o
$shipIt = new ShipIt;
$shipIt->email('EMAIL');
$shipIt->token('TOKEN');
$shipIt->environment(ShipIt::ENV_PRODUCTION);

var_export($shipIt->getCommunes());

array:425 [▼
  0 => Commune {#208 ▼
    -data: array:10 [▼
      "id" => 1
      "region_id" => 1
      "name" => "ARICA"
      "code" => "15101"
      "is_starken" => null
      "is_chilexpress" => null
      "is_generic" => true
      "is_reachable" => true
      "couriers_availables" => {#211}
      "is_available" => false
    ]
  },
  ...
]

$shipIt->getRegions();
$shipIt->getCommunes()

$regions = $shipIt->getRegions();
echo $regions[0]->name;
// "Arica y Parinacota"

$request = new QuotationRequest([
    'commune_id' => 317,    // id de la Comuna en ShipIt
    'height' => 10,         // altura en centimetros
    'length' => 10,         // largo en centimetros
    'width' => 10,          // ancho en centimetros
    'weight' => 1          // peso en kilogramos
]);
$quotationItems = $shipIt->getQuotation($request)->getItems();

foreach($quotationItems as $item){
    echo $item->courier . "<br>";
}

$request = new QuotationRequest(...);

$quotationItems = $shipIt->getQuotation($request)->toArray();

foreach($quotationItems as $item){
    echo $item['total'] . "<br>";
}

$request = new QuotationRequest([
    'commune_id' => 317,    // id de la Comuna en ShipIt
    'height' => 10,         // altura en centimetros
    'length' => 10,         // largo en centimetros
    'width' => 10,          // ancho en centimetros
    'weight' => 1          // peso en kilogramos
]);

$quotationItem = $shipIt->getEconomicQuotation($request);
echo $quotationItem->total;

// o como array

$quotationItem = $shipIt->getEconomicQuotation($request)->toArray();
echo $quotationItem['total'];


$request = new QuotationRequest([
    'commune_id' => 317,    // id de la Comuna en ShipIt
    'height' => 10,         // altura en centimetros
    'length' => 10,         // largo en centimetros
    'width' => 10,          // ancho en centimetros
    'weight' => 1          // peso en kilogramos
]);

$quotationItem = $shipIt->getBestQuotation($request);
echo $quotationItem->total;

// o como array

$quotationItem = $shipIt->getBestQuotation($request)->toArray();
echo $quotationItem['total'];

$request = new ShippingRequest([
    'reference' => 'S000001',
    'full_name' => 'José Eduardo Rios',
    'email' => '[email protected]',
    'items_count' => 1,
    'cellphone' => '912341234',
    'is_payable' => false,
    'packing' => ShippingRequest::PACKING_NONE,
    'shipping_type' => ShippingRequest::DELIVERY_NORMAL,
    'destiny' => ShippingRequest::DESTINATION_HOME,
    'courier_for_client' => ShippingRequest::COURIER_CHILEXPRESS,
    'approx_size' => ShippingRequest::SIZE_SMALL,
    'address_commune_id' => 317,
    'address_street' => 'San Carlos',
    'address_number' => 123,
    'address_complement' => null,
]);

$response =  $shipIt->requestShipping($request);
echo $response->id; // id de la solicitud en ShipIt

$request = new ShippingRequest(...);

$response =  $shipIt->requestShipping($request)->toArray();
echo $response['id'];

$history = $shipIt->getAllShippings('2017-04-06');

// ó

$history = $shipIt->getAllShippings(Carbon::yesterday());

// ó

$history = $shipIt->getAllShippings(); // Por defecto será la fecha actual

foreach($history->getShippings() as $shipping){
    echo $shipping->id . "<br>";
}

$history = $shipIt->getAllShippings();

foreach($history->toArray() as $shipping){
    echo $shipping['id'] . "<br>";
}

$shipping = $shipIt->getShipping(136107);
echo $shipping->reference;

// o como array

$shipping = $shipIt->getShipping(136107)->toArray();
echo $shipping['reference'];

$url = $shipIt->getTrackingUrl('chilexpress', 72626262);

// o

$url = ShipIt::getShipping(136097)->getTrackingUrl()

$size = $shipIt->getPackageSize($width = 14, $height = 23, $length = 45);

Resultado: Grande (50x50x50cm)

'providers' => [
    ...
    Kattatzu\ShipIt\Providers\ShipItServiceProvider::class,
],
'aliases' => [
    ...
    'ShipIt' => Kattatzu\ShipIt\Facades\ShipItFacade::class,
]

$shipping = ShipIt::getShipping(136107);
$regions = ShipIt::getRegions();
$communes = ShipIt::getCommunes()
$url = ShipIt::getTrackingUrl('chilexpress', 72626262);
$size = ShipIt::getPackageSize(14, 23, 45);

$regions = shipit_regions();
$communes = shipit_communes();
$shippings = shipit_shippings('2017-06-01');
$shipping = shipit_shipping(12322);
$quotationItems = shipit_quotation($request);
$quotationItem = shipit_best_quotation($request);
$quotationItem = shipit_economic_quotation($request);
$response = shipit_send_shipping($request);
$url = shipit_tracking_url('starken', 23312332);
$size = shipit_package_size(14, 23, 45);

protected $listen = [
    'Kattatzu\ShipIt\Events\ShipItCallbackPostEvent' => [
        'App\Listeners\ShipItCallbackPostListener',
    ],
    'Kattatzu\ShipIt\Events\ShipItCallbackPutEvent' => [
        'App\Listeners\ShipItCallbackPutListener',
    ],
];
bash
php artisan vendor:publish --provider="Kattatzu\ShipIt\Providers\ShipItServiceProvider"