我几乎让它完美地工作,除了生成标签。
我有这个代码来生成费率,效果很好:
//Wait for rates to be generated
$attempts = 0;
while (($shipment["object_status"] == "QUEUED" || $shipment["object_status"] == "WAITING") && $attempts < 10)
{
$shipment = Shippo_Shipment::retrieve($shipment["object_id"]);
$attempts +=1;
}
//Get all rates for shipment.
$rates = Shippo_Shipment::get_shipping_rates(array('id'=> $shipment["object_id"]));
$json = json_decode($rates, true);
foreach ($json["results"] as $key)
{
$amount = $key["amount"];
$servicelevel = $key["servicelevel_name"];
$objid = $key["object_id"];
}
在查看每个结果时,我将它们分配给不同服务级别的变量,并允许用户选择他们想要使用的运输方式。我将 传递$objid
到下一页以使用以下代码生成标签:
//Write the object_id to a variable
$var = $shiparray[1];
$transaction = Shippo_Transaction::create(array('rate'=>$var));
echo $transaction["object_status"] ."<br>";
// Wait for carrier to create shipping label
$attempts = 0;
while (($transaction["object_status"] == "QUEUED" || $transaction["object_status"] == "WAITING") && $attempts < 10)
{
$transaction = Shippo_Transaction::retrieve($transaction["object_id"]);
$attempts += 1;
}
echo $transaction["object_status"] ."<br>";
// Retrieve label url and tracking number or error message
if ($transaction["object_status"] == "SUCCESS")
{
echo($transaction["label_url"]);
echo("\n");
echo($transaction["tracking_number"]);
}
else
{
echo( $transaction["messages"] );
}
不过,这只会产生错误。我是否传递了错误的值来生成标签?我应该使用为货件产生的价值而不是费率吗?