vasildakov / shipping
Shipping Library
v0.1.0-alpha
2023-12-30 12:50 UTC
Requires
- php: >=8.1
- eventsauce/object-hydrator: dev-main
- jms/serializer: ^3.29
- laminas/laminas-hydrator: ^4.15
- selective/transformer: dev-master
- vasildakov/econt: dev-main
- vasildakov/speedy: ^1.0@alpha
- vlucas/phpdotenv: ^5.6
Requires (Dev)
- friendsofphp/php-cs-fixer: dev-master
- php-coveralls/php-coveralls: dev-master
- phpmd/phpmd: dev-master
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: dev-master
- squizlabs/php_codesniffer: 4.0.x-dev
- symfony/var-dumper: 7.1.x-dev
- theseer/phpdox: dev-master
- vimeo/psalm: 4.x-dev
This package is auto-updated.
Last update: 2024-12-09 21:31:36 UTC
README
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