除了生成标签之外,我几乎让它完美地工作了。
我有这个代码来生成利率,它工作得很好:
//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"] );
}不过,这只会产生一个错误。我是否传递了错误的值来生成标签?我是否应该使用货件产生的价值,而不是费率?
发布于 2015-05-26 10:14:04
我是Shippo的Simon。您发布的链接实际上是费率响应,而不是交易(它是许多费率的数组,因此是长度)。
我已经快速检查了您的帐户,对于您最近的交易尝试,出现错误消息"Rate can't be purchased,原因是Shippo帐户没有有效的计费设置。“这是因为您的Shippo用户帐户没有任何信用卡信息,但您正在尝试在生产中购买标签。
您可以在此处输入有效的信用卡https://goshippo.com/user/billing/。一旦您的信用卡被保存,请求就会正常工作!
如果你有任何进一步的问题,请让我知道,总是很乐意帮助你!
https://stackoverflow.com/questions/30425203
复制相似问题