captain-courier / cidr
快递集成,一劳永逸!
0.1.0
2013-09-04 14:14 UTC
Requires
- php: >=5.5.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-23 14:59:59 UTC
README
Cidr的目标很简单,使与快递合作变得容易。
Cidr将能够
- 提供快递最便宜的报价
- 以最低的自定义程度创建/查看/删除/跟踪特定快递的运输请求
- 获取运单
当前功能
- 与ParcelForce和P4D快递创建运输
安装
Cidr源代码可以从github下载,或者可以通过添加以下内容到composer.json文件中作为依赖项来添加:
{
....
"require": {
....
"captain-courier/cidr": "*"
}
}
设置
在项目目录中创建一个名为res/credentials.yml的文件。它看起来可能像这样
ParcelForce:
username: <insert here>
password: <insert here>
P4D:
username: <insert here>
apiKey: <insert here>
在此处替换<insert here>
为您自己的用户名/密码/api密钥。如果您不需要某个快递,则不要将其添加到credentials.yml文件中。例如,如果您只需要ParcelForce,则credentials.yml文件可能看起来像这样
ParcelForce:
username: <insert here>
password: <insert here>
在测试Cidr时,建议使用测试凭据而不是生产凭据。P4D提供无需注册的测试凭据,只需访问http://www.p4d.co.uk/v2/api。
测试
Cidr使用Travis进行测试,可在此处找到。可以通过运行以下命令在本地测试Cidr:
phpunit --configuration=phpunit.xml src/
用法
以下是一个使用ParcelForce创建运输的示例
use Cidr\Cidr;
use Cidr\CidrRequest;
use Cidr\CidrResponse;
// creates a new Cidr object
// the cidr object provides capabilities, which are objects that can only
// perform 1 task for 1 courier such as creating a consignment for ParcelForce.
$cidr = new Cidr();
$capability = $cidr->getCapability("ParcelForce", "CreateConsignment");
$request = new CidrRequest(...);
// submits the request to the courier[s] and returns a Cidr\CidrResponse object.
// response has a context properties which is different depending on the status of the response.
$response = $capability->submitCidrRequest($request);
// checks the request was successful, and prints out the assigned consignment number.
// if the request failed, it prints out the response context to get an idea why it has failed.
if (CidrResponse::STATUS_SUCCESS === $response->getStatus()) {
// gets the consignment number assigned for the created shipment
$consignmentNumber = $response->getResponseContext();
print "consignment number is '${consignmentNumber}'\n";
exit(0);
} else {
print "request failed\n";
print_r($response->getResponseContext());
exit(1);
}