定制 always-open/shipengine 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

always-open/shipengine

最新稳定版本:v3.2.1

Composer 安装命令:

composer require always-open/shipengine

包简介

Wrapper around ShipEngine API

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.

统计信息

  • 总下载量: 3.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 5
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-02