承接 reachship/reachship-php-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

reachship/reachship-php-sdk

最新稳定版本:v0.0.9-alpha

Composer 安装命令:

composer require reachship/reachship-php-sdk

包简介

PHP library for the ReachShip API.

README 文档

README

A PHP library built on the ReachShip API.

Getting Started

Install ReachShip PHP SDK via Composer:

composer require reachship/reachship-php-sdk

Class Objects

  • ReachshipRequestBuilder - This class provides methods to build request body for various ReachShip API Services.

Instantiate Request Builder Class

<?php 
require_once dirname(__FILE__) . '/vendor/autoload.php';

// Create Instance.
$builder = new ReachshipRequestBuilder();
$request = $builder->ratesRequest();

// From Address.
$request->shipFrom()->setCityLocality('Cupertino');
$request->shipFrom()->setStateProvince('CA');
$request->shipFrom()->setPostalCode('95014');
$request->shipFrom()->setCountryCode('US');

// To Address.
$request->shipTo()->setCityLocality('Austin');
$request->shipTo()->setStateProvince('TX');
$request->shipTo()->setPostalCode('78756');
$request->shipTo()->setCountryCode('US');

// Add Items.
// Item 1.
$request->item()->setLength(1);
$request->item()->setWidth(2);
$request->item()->setHeight(3);
$request->item()->setDimensionUnit('IN');
$request->item()->setWeight(4);
$request->item()->setWeightUnit('LB');
$request->items()->addItem($request->item()->getObject());

// Item 2.
$request->item()->setLength(5);
$request->item()->setWidth(6);
$request->item()->setHeight(7);
$request->item()->setDimensionUnit('IN');
$request->item()->setWeight(8);
$request->item()->setWeightUnit('LB');
$request->items()->addItem($request->item()->getObject());

// Specify Carriers.
$request->ratesOptions()->setCarriers(["UPS", "USPS"]);

// Get JSON.
error_log(print_r($request->getRequestJSON(), true));

/*
Above statement will print the following.
{
    "rates_options": {
        "carriers": [
            "UPS",
            "USPS"
        ]
    },
    "shipment": {
        "ship_from": {
            "city_locality": "Cupertino",
            "state_province": "CA",
            "postal_code": "95014",
            "country_code": "US"
        },
        "ship_to": {
            "city_locality": "Austin",
            "state_province": "TX",
            "postal_code": "78756",
            "country_code": "US"
        },
        "packages": [
            {
                "length": {
                    "value": 1,
                    "unit": "IN"
                },
                "width": {
                    "value": 2,
                    "unit": "IN"
                },
                "height": {
                    "value": 3,
                    "unit": "IN"
                },
                "weight": {
                    "value": 4,
                    "unit": "LB"
                }
            },
            {
                "length": {
                    "value": 5,
                    "unit": "IN"
                },
                "width": {
                    "value": 6,
                    "unit": "IN"
                },
                "height": {
                    "value": 7,
                    "unit": "IN"
                },
                "weight": {
                    "value": 8,
                    "unit": "LB"
                }
            }
        ]
    }
}
*/
// Get JSON.
$requestBody = $request->getRequestJSON();

// Get Token.
$tokenResponse = ReachshipAPIClient::getToken("reachship_client_id", "reachship_client_secret", "sandbox");

// Token.
$token = $tokenResponse['token'];

// Get Rates.
$ratesResponse = ReachshipAPIClient::getRates($token, $requestBody, 'sandbox' );

// Response as PHP Array.
$responseBody = $ratesResponse['message'];

error_log(print_r($responseBody, true));
/*
    Array
    (
        [0] => stdClass Object
            (
                [companyName] => STAMPS_USPS
                [serviceName] => USPS Priority Mail
                [estimatedDelivery] => 1-3 business days
                [totalBaseCharge] => 22.04
                [totalChargeWithTaxes] => 22.04
                [currency] => USD
                [reachshipAccountIdentifier] => stamps-3
                [serviceCode] => US-PM
            )
        [1] => stdClass Object
            (
                [companyName] => UPS
                [serviceName] => UPS Next Day Air Saver
                [serviceCode] => 13
                [estimatedDelivery] => 1 business day
                [totalBaseCharge] => 304.74
                [totalChargeWithTaxes] => 304.74
                [currency] => USD
                [reachshipAccountIdentifier] => ups-sandbox
            )
    )
*/

Examples

For more examples, refer to /examples folder

Contributing

Contributions, enhancements, and bug-fixes are welcome! Open an issue on GitHub and submit a pull request.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2023-01-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固