always-open / shipengine
Wrapper around ShipEngine API
Installs: 2 546
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- php: ^8.0.0|^8.1.0
- always-open/laravel-request-logger: ^2.1
- guzzlehttp/guzzle: ^7.4
- illuminate/contracts: ^9.0|^10.0
- illuminate/support: ^9.0|^10.0
- spatie/data-transfer-object: ^3.7
- spatie/laravel-package-tools: ^1.9.2
- symfony/property-access: ^6.0
- symfony/serializer: ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.1
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
- 3.x-dev
- v3.2.1
- v3.2.0
- v3.1.1
- v3.1.0
- v3.0.2
- v3.0.1
- v3.0.0
- 2.x-dev
- v2.3.0
- v2.2.1
- v2.1.1
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- v0.9.1
- v0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- v0.5.1
- v0.5.0
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.0
- v0.1.0
- dev-feature/add-local-limit-to-config
- dev-main
- dev-feature/add-warehouse-endpoints
This package is auto-updated.
Last update: 2024-10-14 10:06:35 UTC
README
Wrapper around ShipEngine API
Installation
You can install the package via composer:
composer require always-open/shipengine
You can publish the config file with:
php artisan vendor:publish --tag="shipengine-config"
This is the contents of the published config file:
return [ /* |-------------------------------------------------------------------------- | ShipEngine configurations |-------------------------------------------------------------------------- | | API Key used to authenticate with ShipEngine APIs. | https://www.shipengine.com/docs/auth/ | */ 'credentials' => [ 'key' => env('SHIP_ENGINE_API_KEY'), ], /* |-------------------------------------------------------------------------- | ShipEngine configurations |-------------------------------------------------------------------------- | | Values used to set configuration of ShipEngine API integration. | */ 'endpoint' => [ 'version' => env('SHIP_ENGINE_API_VERSION', 'v1'), 'base' => env('SHIP_ENGINE_ENDPOINT', 'https://api.shipengine.com/'), ], 'retries' => env('SHIP_ENGINE_RETRIES', 1), 'response' => [ 'as_object' => env('SHIP_ENGINE_RESPONSE_AS_OBJECT', false), 'page_size' => env('SHIP_ENGINE_RESPONSE_PAGE_SIZE', 50), ], 'timeout' => 'PT10S', ];
Usage
Config
To use the ShipEngine wrapper you must first instantiate a new instance.
By default, the config information is read out of the config file but can be overridden on the fly. This can be done when instantiating a new instance, which will impact all subsequent calls, or when making the call.
// Use default config settings from `config/shipengine.php` $shipengine = new AlwaysOpen\ShipEngine\ShipEngine(); // Override config which will impact all calls made with this instance $config = new \AlwaysOpen\ShipEngine\ShipEngineConfig(['asObject' => true]); $custom_shipengine = new AlwaysOpen\ShipEngine\ShipEngine($config); // Override config on a single specific call $shipengine->listShipments(config: ['asObject' => true]);
Making calls
To make calls to the ShipEngine API you must have credentials setup within ShipEngine itself. Those API credentials will then be used by this library to handle the calls and responses.
NOTE: This library is still in the 0.x.x stages and not all endpoints are fully mapped. We are working towards 100% coverage of existing API endpoints.
Method names should match documentation names of API endpoints from official ShipEngine API Docs.
Example calls
Here is a sample of how to get a listing of shipments as well as the difference between asObject => false
and asObject => true
.
$shipengine = new AlwaysOpen\ShipEngine\ShipEngine(); $shipengine->listShipments(); //[ // "shipments" => [ // [ // "shipment_id" => "se-123456789", // "carrier_id" => "se-123456", // ... // ], // [...], // ], // "total" => 12, // "page" => 1, // "pages" => 1, // "links" => [ // "first" => [ // "href" => "https://api.shipengine.com/v1/shipments?page=1&page_size=25", // ], // "last" => [ // "href" => "https://api.shipengine.com/v1/shipments?page=1&page_size=25", // ], // "prev" => [], // "next" => [], // ], //]; $shipengine->listShipments(config: ['asObject' => true]); // [ // "shipments" => [ // AlwaysOpen\ShipEngine\DTO\Shipment {#4070 // +shipment_id: "se-123456789", // +carrier_id: "se-123456", // ... // ], // [...], // ], // "total" => 12, // "page" => 1, // "pages" => 1, // "links" => [ // "first" => [ // "href" => "https://api.shipengine.com/v1/shipments?page=1&page_size=25", // ], // "last" => [ // "href" => "https://api.shipengine.com/v1/shipments?page=1&page_size=25", // ], // "prev" => [], // "next" => [], // ], //];
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.