shipmate/shipmate-php-sdk

1.1 2024-05-17 13:06 UTC

This package is auto-updated.

Last update: 2024-09-06 10:55:05 UTC


README

这个官方支持的SDK为PHP应用程序提供了访问Shipmate API的接口。

Shipmate是英国和爱尔兰商家的运输自动化平台,可用于生成运输标签和跟踪与商家有账户的多个承运人的包裹,在一个平台上完成。这减少了集成工作量,同时通过仅需要定期使用一个平台进行关键运输交互来简化日常操作,并能进行规模化运营。

要使用此SDK,您需要一个有效的Shipmate账户 - 如果您还没有访问权限,请访问Shipmate网站了解可用的账户类型并开设账户。

此SDK使用Shipmate API版本1.2,并提供对所有功能的接口,包括

  • 创建运输
  • 标签打印
  • 递送服务
  • 跟踪事件
  • SKU库存
  • 自定义字段

安装

composer require shipmate/shipmate-php-sdk

配置

要访问Shipmate API,您需要配置环境和API密钥。

您可以在Shipmate订阅中请求预发布/沙箱账户,或作为开发合作伙伴。

在Shipmate网络门户中为您的应用程序注册API密钥,并按以下方式配置SDK

// Create an instance of Shipmate Service
$shipmate = new ShipmateService();

// Set the API key
$shipmate->setApiKey('YOUR_SHIPMATE_API_KEY');

// Set the Access Token
$shipmate->setApiToken('YOUR_SHIPMATE_API_TOKEN');

// Set the Environment
$shipmate->setEnvironment(Environment::STAGING); // if setEnvironment is not called then production URL will be used by default in requests.

使用SDK

创建运输对象 - 英格兰大陆 - 1个包裹 - 必要属性

// Create an instance of the Shipment class
$shipment = new Shipment();
	
// Set properties for the Shipment
$shipment->setShipmentReference('123456789');
$shipment->setOrderReference("987654321");

// Create an instance of the Address class for the to_address
$toAddress = new Address();
$toAddress->setName('Mr Shipmate Test');
$toAddress->setLine1('Friar Gate Studios');
$toAddress->setLine2('Ford Street');
$toAddress->setLine3('TEST LABEL - DO NOT DELIVER');
$toAddress->setCity('Derby');
$toAddress->setPostcode('DE1 1EE');
$toAddress->setCountry('GB');
$toAddress->setTelephone('01332460888');
$toAddress->setEmailAddress('support@shipmate.co.uk');

// Add the toAddress to the Shipment 
$shipment->setToAddress($toAddress);

$shipment->setDeliveryInstructions('Leave with receptionist');

// Create an instance of the Parcel class
$parcel = new Parcel();
$parcel->setReference('56789');
$parcel->setWeight(450);
$parcel->setWidth(20);
$parcel->setLength(20);
$parcel->setDepth(20);
$parcel->setValue(14.99);

// Add the Parcel object to the parcels array of the Shipment object
$shipment->addParcel($parcel);

在Shipmate账户中创建运输

$shipmentResponse = $shipmate->createShipment($shipment);

访问运输标签

$shipmentResponse[0]->ZPL(); // get label of parcel 1

打印标签

$shipmate->printLabels('SHIPMENT_ID', 'SHIPMATE_USER_ID');

获取递送服务

$deliveryServices = $shipmate->getDeliveryServices();

获取跟踪事件

$shipmentTrackingEvents = $shipmate->getEventsByShipment(‘SHIPMENT_REFERENCE’);

$parcelTrackingEvents = $shipmate->getEventsByParcel(‘PARCEL_TRACKING_REFERENCE’);

创建SKU对象 - 必要属性

$sku = new SKU();
$sku->setSku('6776929224');
$sku->setProductName('Blue Shipmate T-shirt (Cotton), size Large');
$sku->setTariffCode('6109100010');
$sku->setTariffDescription('Mens T-shirts (Cotton)');
$sku->setCountryOfOrigin('GB');
$sku->setValueExVat('20.82');
$sku->setVatRate('20.0');
$sku->setValueIncVat('24.99');
$sku->setGrossWeight(350);
$sku->setNetWeight(350);
$sku->setWidth(200);
$sku->setLength(200);
$sku->setDepth(20);
$sku->setIsStockedItem(true);
$sku->setInStock(true);
$sku->setItemHandling('Packable');

将SKU添加到Shipmate账户

$shipmate->createSKU($sku);

获取Shipmate账户上的所有SKU

$shipmate->getSKUs();

创建自定义字段对象

// Create a new instance of the CustomField class
$customField = new CustomField();

// Set properties for the Custom Field 
$customField->setName('Insurance Cover Value');
$customField->setKey('SHIPMENT_INSURANCE_COVER_VALUE');
$customField->setEntity('SHIPMENT');
$customField->setDataType('NUMERIC');
$customField->setSource('DIRECT');
$customField->setDefaultValue('0');

// Create a new instance of the DataValidationRules class
$dataValidationRules = new DataValidationRules();
$dataValidationRules->setNumericType('DECIMAL');
$dataValidationRules->setMaxValue(200.00);

// Add Data Validation Rules to the Custom Field
$customField->setDataValidationRules($dataValidationRules);

将自定义字段添加到Shipmate账户

$shipmate->createCustomField($customField);

获取所有自定义字段

$shipmate->getCustomFields();

许可

此SDK的使用提供在MIT许可证下。请参阅LICENSE以获取详细信息。

LICENSE

版权所有2024 Shipmate Systems Limited

在此,免费许可任何获得此软件及其相关文档副本(“软件”)的人士,在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向软件提供副本的个人这样做,前提是遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何形式的保证,无论是明示的、暗示的,还是基于适用法律、特定用途或不侵权,包括但不限于适销性、特定用途的适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任承担责任,无论是基于合同、侵权或其他方式,由此软件或其使用或任何其他方式产生的。