cognito/couriersplease
Composer 安装命令:
composer require cognito/couriersplease
包简介
Couriers Please API
README 文档
README
Interact with the Couriers Please API
Installation
Installation is very easy with composer:
composer require cognito/couriersplease
Setup
Get a business account at Couriers Please and request API access
Usage
<?php
$couriersplease = new \Cognito\CouriersPlease\CouriersPlease('Your API Key', 'Your Account Number', $testmode);
// Create a shipment
$shipment = $couriersplease->newShipment()
->setFrom(new \Cognito\CouriersPlease\Address([
'name' => 'Joe Tester',
'lines' => [
'11 MyStreetname Court',
],
'suburb' => 'MySuburb',
'state' => 'QLD',
'postcode' => '4503',
'country' => 'AU',
]))
->setTo(new \Cognito\CouriersPlease\Address([
'name' => 'Mary Tester',
'lines' => [
'10 ReceiverStreetname St',
],
'suburb' => 'HerSuburb',
'state' => 'NSW',
'postcode' => '2430',
'country' => 'AU',
'phone' => '035555XXXX',
'email' => 'mary@XXXXX.com.au',
]))
->setInsuranceType('INS2')
->addParcel(new \Cognito\CouriersPlease\Parcel([
'item_reference' => 'pkg1',
'length' => 5,
'height' => 4,
'width' => 45,
'weight' => 0.55,
'value' => 200,
]))
->addParcel(new \Cognito\CouriersPlease\Parcel([
'item_reference' => 'pkg2',
'length' => 12,
'height' => 12,
'width' => 20,
'weight' => 1.55,
'value' => 50,
]));
// Get costing for the shipment for the various Couriers Please products available
$itemQuotes = $shipment->getQuotes();
foreach ($itemQuotes as $quote) {
var_dump($quote->product_id);
var_dump($quote->product_type);
var_dump($quote->price_inc_gst);
}
// Set details about the shipment and lodge it
$shipment->shipment_reference = 'OurInternalID';
$shipment->customer_reference_1 = 'INV #12345';
$shipment->customer_reference_2 = '';
$shipment->product_id = 'L44'; // The Couriers Please product returned in the Quote
$shipment->delivery_instructions = 'Leave in a dry place out of the sun';
$shipment->lodgeShipment();
var_dump($shipment->shipment_id);
// Print the labels for all the parcels in a shipment
if ($shipment->shipment_id) {
$label = $shipment->getLabel();
if ($label) {
while(ob_get_level()) {
ob_get_clean();
}
header('Content-Type: application/pdf');
die($label);
}
}
// Or to print the label from the api by consignment number
$label = $couriersplease->printLabels($consignment_number);
if ($label) {
while(ob_get_level()) {
ob_get_clean();
}
header('Content-Type: application/pdf');
die($label);
}
// Cancel the shipment
$shipment->cancelShipment();
// Or to cancel from the api by consignment number
$couriersplease->deleteShipment($consignment_number);
// Book a driver to pick up
$pickup = $couriersplease->newPickup([
'contact_name' => 'Sender Contact Name',
'contact_email' => 'Sender Email Address',
'pickup_address' => new \Cognito\CouriersPlease\Address([
'name' => 'Sender Contact Name',
'business_name' => 'Sender Business Name',
'lines' => [
'Sender Address Line 1',
'Sender Address Line 2',
],
'suburb' => 'Sender Address Suburb',
'state' => 'Sender Address State',
'postcode' => 'Sender Address Postcode',
'phone' => 'Sender Address Phone',
'country' => 'Sender Address Country',
'email' => 'Sender Email ',
],
'deliver_address' => new \Cognito\CouriersPlease\Address([
'name' => 'Receiver Contact Name',
'business_name' => 'Receiver Business Name',
'lines' => [
'Receiver Address Line 1',
'Receiver Address Line 2',
],
'suburb' => 'Receiver Address Suburb',
'state' => 'Receiver Address State',
'postcode' => 'Receiver Address Postcode',
'phone' => 'Receiver Address Phone',
'country' => 'Receiver Address Country',
'email' => 'Receiver Email ',
]);
]);
$pickup->addParcel(new \Cognito\CouriersPlease\Parcel([
'item_reference' => 'pkg1',
'length' => 5,
'height' => 4,
'width' => 45,
'weight' => 0.55,
'value' => 200,
]))
->addParcel(new \Cognito\CouriersPlease\Parcel([
'item_reference' => 'pkg2',
'length' => 12,
'height' => 12,
'width' => 20,
'weight' => 1.55,
'value' => 50,
]));
$job_number = $pickup->bookPickup();
cognito/couriersplease 适用场景与选型建议
cognito/couriersplease 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 152 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cognito/couriersplease 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cognito/couriersplease 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 152
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-10