kmuharam / tamex-php
本项目是TAMEX v2 REST API的PHP集成
1.0.0
2023-03-28 01:02 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- phpunit/phpunit: ^9.0
README

TAMEX PHP
TAMEX REST API集成,适用于您的PHP应用程序。
探索文档
查看演示 · 报告错误 · 请求功能
关于项目
本项目是TAMEX v2 REST API的PHP集成。
(返回顶部)
支持

(返回顶部)
入门
您可以通过Composer安装此包。
您可以从这里查看和下载TAMEX 2.7 API文档。
先决条件
在您开始使用此包之前,您需要联系TAMEX销售以获取测试
和实时
API密钥。
安装
composer require kmuharam/tamex-php
(返回顶部)
用法
快速开始
在下面的代码中,您将找到API支持的三种操作的示例实现。
<?php namespace MyAwesomeApp\Shipments\Services; use Kmuharam\Tamex\Requests\CreateShipmentRequest; use Kmuharam\Tamex\Requests\PrintWaybillRequest; use Kmuharam\Tamex\Requests\ShipmentStatusRequest; use Kmuharam\Tamex\Responses\CreateShipmentResponse; use Kmuharam\Tamex\Responses\PrintWaybillResponse; use Kmuharam\Tamex\Responses\ShipmentStatusResponse; class MyTamexServices { /** * @var \Kmuharam\Tamex\Services\TamexServices */ protected TamexServices $services; /** * @var boolean */ protected bool $shoudWeGoLive = false; /** * @var string */ protected string $testingApiKey = 'mytesingapikey'; /** * @var string */ protected string $liveApiKey = 'myliveapikey'; /** * Create a new instance of My Tamex Services. * * @return void */ public function __construct() { $this->shoudWeGoLive = false; // or true depending on your environment settings $this->services = new TamexServices($this->shoudWeGoLive); } /** * Create shipment request. * * @return \Kmuharam\Tamex\Responses\CreateShipmentResponse */ public function create(): CreateShipmentResponse { $createShipmentRequest = new CreateShipmentRequest(); $createShipmentRequest->apiKey = $this->shoudWeGoLive ? $this->liveApiKey : $this->testingApiKey; $createShipmentRequest->packType = '2'; // 1: Delivery, 2: Pickup $createShipmentRequest->packVendorId = 'My store name'; $createShipmentRequest->packReciverName = 'Receiver name'; $createShipmentRequest->packReciverPhone = '+966500000000'; $createShipmentRequest->packReciverCountry = 'SA'; $createShipmentRequest->packReciverCity = 'City name'; $createShipmentRequest->packReciverStreet = '26th St.'; $createShipmentRequest->packDesc = '1 item(s), weight: 3KG , price: 1200SAR.'; $createShipmentRequest->packNumPcs = 1; $createShipmentRequest->packWeight = 3; $createShipmentRequest->packCodAmount = '0'; $createShipmentRequest->packCurrencyCode = 'SAR'; $createShipmentRequest->packSenderName = 'My store name'; $createShipmentRequest->packSenderPhone = '+966500000000'; $createShipmentRequest->packSendCountry = 'SA'; $createShipmentRequest->packSendCity = 'City name'; $createShipmentRequest->packSenderStreet = '12th St., Example neighborhood, building No. 1, house No. 1'; $createShipmentRequest->packDimension = '10:10:10'; // width x height x length $response = $this->services->createShipment($createShipmentRequest); return $response; } /** * Track shipment status. * * @param string $packAWB * * @return \Kmuharam\Tamex\Responses\ShipmentStatusResponse */ public function shipmentStatus(string $packAWB): ShipmentStatusResponse { $shipmentStatusRequest = new ShipmentStatusRequest(); $shipmentStatusRequest->apiKey = $this->shoudWeGoLive ? $this->liveApiKey : $this->testingApiKey; $shipmentStatusRequest->packAWB = $packAWB; $response = $this->services->shipmentStatus($shipmentStatusRequest); return $response; } /** * Print shipment waybill. * * @param string $packAWB * * @return \Kmuharam\Tamex\Responses\PrintWaybillResponse */ public function printWaybill(string $packAWB): PrintWaybillResponse { $printWaybillRequest = new PrintWaybillRequest(); $printWaybillRequest->apiKey = $this->shoudWeGoLive ? $this->liveApiKey : $this->testingApiKey; $printWaybillRequest->packAWB = $packAWB; $response = $this->services->printWaybill($printWaybillRequest); return $response; } }
有关请求负载应如何查看的更多信息,请参阅以下链接
预期响应
创建运输响应
<?php // ... // contains original response received from the API $response->raw; // operation status code // 0 = Return tmxAWB, // 90001 = Error in Json Record Format, // 90003 = API KEY NOT AUTORIZED, // 90004 = ERROR Contact Support $response->code; // operation status text // 0 = Operation Success, // 90001 = JSON, // 90003 = Authorization, // 90004 = System $response->data; // airway bill code $response->tmxAWB; // returns true if shipment creation failed $response->hasError(); // returns true if shipment creation succeeded $response->created(); // array wrapping response properties and methods // [ // 'error' => $this->hasError(), // 'created' => $this->created(), // 'code' => $this->code, // 'data' => $this->data, // 'tmxAWB' => $this->tmxAWB, // ] $response->response(); // ...
运输状态响应
<?php // ... // contains original response received from the API $response->raw; // operation status code // 0 = Return tmxAWB, // 90001 = Error in Json Record Format, // 90003 = API KEY NOT AUTORIZED, // 90004 = ERROR Contact Support $response->code; // operation status text // 0 = Operation Success, // 90001 = JSON, // 90003 = Authorization, // 90004 = System $response->data; // airway bill code $response->awb; // status message code $response->status; // Status update date and time $response->updateOn; // status message string $response->message; // returns true if shipment creation failed $response->hasError(); // returns true if shipment exists $response->exists(); // array wrapping response properties and methods // [ // 'error' => $this->hasError(), // 'exists' => $this->exists(), // 'code' => $this->code, // 'data' => $this->data, // 'awb' => $this->awb, // 'status' => $this->status, // 'updateOn' => $this->updateOn, // 'message' => $this->message, // ] $response->response(); // ...
打印运单响应
<?php // ... // contains original response received from the API $response->raw; // operation status code // 0 = Return tmxAWB, // 90001 = Error in Json Record Format, // 90003 = API KEY NOT AUTORIZED, // 90004 = ERROR Contact Support $response->code; // operation status text // 0 = Operation Success, // 90001 = JSON, // 90003 = Authorization, // 90004 = System $response->data; // waybill pdf as base64 string $response->contents; // returns true if shipment creation failed $response->hasError(); // returns true if shipment exists $response->exists(); // array wrapping response properties and methods // [ // 'error' => $this->hasError(), // 'exists' => $this->exists(), // 'code' => $this->code, // 'data' => $this->data, // 'contents' => $this->contents, // ] $response->response(); // ...
(返回顶部)
路线图
- 添加对webhooks的支持
- 在muharam.dev添加文档页面
请参阅开放问题以获取提议的功能(和已知问题的)完整列表。
(返回顶部)
贡献
贡献使开源社区成为一个如此令人惊叹的学习、灵感和创造的地方。您做出的任何贡献都备受赞赏。
如果您有改进此项目的建议,请fork存储库并创建一个pull request。您也可以简单地通过带有“增强”标签的问题来提出建议。别忘了给项目加星!再次感谢!
- 分支项目
- 创建您的功能分支(
git checkout -b feature/AmazingFeature
) - 提交您的更改(
git commit -m 'Add some AmazingFeature'
) - 推送到分支(
git push origin feature/AmazingFeature
) - 打开Pull Request
(返回顶部)
许可证
在MIT许可证下分发。有关更多信息,请参阅LICENSE.md
。
(返回顶部)
联系方式
Khalid Muharam - devel@muharam.dev
项目链接: https://github.com/kmuharam/tamex-php
(返回顶部)