1

我几乎让它完美地工作,除了生成标签。

我有这个代码来生成费率,效果很好:

//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"] );
}

不过,这只会产生错误。我是否传递了错误的值来生成标签?我应该使用为货件产生的价值而不是费率吗?

4

1 回答 1

0

这是七宝的西蒙。您发布的链接实际上是 Rates 响应,而不是 Transaction(它是许多 Rates 的数组,因此是长度)。

我已经快速检查了您的帐户,对于您最近的交易尝试,有一条错误消息“无法购买费率,因为 Shippo 帐户没有有效的计费设置。”。这是因为您的 Shippo 用户帐户没有任何信用卡信息,但您正在尝试购买生产中的标签。

您可以在此处输入有效的信用卡https://goshippo.com/user/billing/。保存您的信用卡后,该请求应该可以正常工作!

如果您有任何进一步的问题,请告诉我,随时乐意为您提供帮助!

于 2015-05-26T02:14:04.070 回答