1

I almost got it working perfectly, except for generating the labels.

I have this code to generate the rates, which works great:

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

As I go through each of the results, I assign them to variables for the different service levels and allow the user to select which shipping method they want to use. I pass the $objid to the next page to produce the label using the following code:

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

This just produces an error, though. Am I passing the wrong value to produce the label? Should I be using a value produced for the shipment rather then the rate?

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Darth Mikey D
  • 107
  • 2
  • 14
  • Hey Mike, could you also provide the error message and the entire transaction JSON response please? This would be very helpful for debugging your code. Thanks! Simon – Simon Kreuz May 25 '15 at 06:55
  • Thanks for the response. The error produced by echo( $transaction["messages"] ); only says Array. The JSON response is really long, so I posted it here: [link](http://www.eaglesnest-testserver.net/vtcustdolly/json.php) Any help is appreciated. I've never used anything like this before, and really looking forward to learning how to do this. – Darth Mikey D May 25 '15 at 15:29

1 Answers1

0

this is Simon from Shippo. The link you've posted is actually the Rates response, not the Transaction (it's an array of many Rates, thus the length).

I've quickly checked your account and for your most recent transaction attempts, there's an error message "Rate can't be purchased because the Shippo account doesn't have valid billing settings.". This is because your Shippo user account doesn't have any credit card information, but you're trying to purchase labels in production.

You can enter a valid credit card here https://goshippo.com/user/billing/. The request should work fine as soon as your credit card has been saved!

Let me know if you have any further questions, always happy to help!

Simon Kreuz
  • 575
  • 3
  • 8
  • Hi Simon. Thanks for the response. I just looked at the carriers page, and FedEx is set as test and the others are set as inactive. Is there another place to set it as test? I did move it to production temporarily to test the rates as I was getting inconsistent results in test, and wanted to make sure it returned correct results. I set the carriers back to test so I could make sure the labels portion works. Thanks for the help. – Darth Mikey D May 26 '15 at 03:01
  • Yes, I see that FedEx is now in test mode. Previously, the USPS must have been activated. Did you run another test since you've set FedEx to test mode? If so, what error/success messages did you get back? – Simon Kreuz May 26 '15 at 15:25
  • Hi Simon. I am in the test environment. I put in the following lines and got the following responses from each:echo $transaction["object_id"] returns 1fb8d19af1ee467caf6ddbcf12541c0f; echo $transaction["object_status"] returns ERROR; and echo( $transaction["messages"] ) returns Array. – Darth Mikey D May 26 '15 at 21:24
  • Hi Mike - just saw that the discounted Shippo USPS account has still been active in production. I've completely disabled it for you. Can you give it another try? If easier, feel free to reach out to me directly at simon at goshippo.com. – Simon Kreuz May 27 '15 at 03:42
  • I just tried it again with the same results. One thing I noticed is that under carriers, Parcelforce is active in test mode. I tried deactivating it, but there is no option to do this. Can you disable it for me, or how can I do this? The only one that should be active is FedEx. Thanks. – Darth Mikey D May 27 '15 at 09:59