vasildakov/shipping

v0.1.0-alpha 2023-12-30 12:50 UTC

This package is auto-updated.

Last update: 2024-12-09 21:31:36 UTC


README

build Scrutinizer Code Quality Code Coverage Total Downloads

Features

This library is compliant with PSR-7: HTTP message interfaces, PSR-17: HTTP Factories and PSR-18: HTTP Client

Installation

Using Composer:

$ composer require vasildakov/shipping

Tests

$ ./vendor/bin/phpunit 

# with code coverage
$ ./vendor/bin/phpunit --coverage-html ./build/coverage

Configuration

...

Add your adapters configuration to a .env file in the root of your project. Make sure the .env file is added to your .gitignore so it is not checked-in the code

SPEEDY_USERNAME="username"
SPEEDY_PASSWORD="password"
SPEEDY_LANGUAGE="EN"

ECONT_USERNAME="username"
ECONT_PASSWORD="password"

Usage

Here is a simple example of how to use Shipping. As you can see, Shipping has a consistent, well thought out API. As much as possible, we try to abstract the differences between the various shipping gateways.

<?php

$econt  = Shipping::create('Econt');

$request = new GetCountriesRequest(name: 'Bul');

/** @var GetCountriesResponse $response */
$response = $econt->getCountries();
<?php

use VasilDakov\Shipping\Shipping;
use VasilDakov\Shipping\Adapter\EcontAdapter;
use VasilDakov\Shipping\Adapter\SpeedyAdapter;

// using strings
$econt  = Shipping::create('Econt');
$speedy = Shipping::create('Speedy');


// ... or using class name
$econt  = Shipping::create(EcontAdapter::class);
$speedy = Shipping::create(SpeedyAdapter::class);

Services

1 Countries

<?php

$econt  = Shipping::create('Econt');

$request = new GetCountriesRequest(name: 'Bul');

/** @var GetCountriesResponse $response */
$response = $econt->getCountries();

foreach ($response->countries as $country) {
    dump($country);
}

2 Cities

<?php
$econt  = Shipping::create('Econt');

$request = new GetCitiesRequest(isoAlpha3: 'BGR', name: null);

/** @var GetCitiesResponse $response */
$response = $econt->getCities($request);

foreach ($response->cities as $city) {
    dump($city);
}

3 Offices

<?php
$econt  = Shipping::create('Econt');

$request = new GetOfficesRequest(isoAlpha3: 'BGR', name: null);

/** @var GetCitiesResponse $response */
$response = $econt->getOffices($request);

foreach ($response->offices as $office) {
    dump($office);
}

License

Code released under the MIT license