1

I am trying to implement Shippo for estimating shipping costs during an order process. I am using Laravel 5.4 with shippo-php.

This is regarding a test environment, and I have added a Purolator Carrier in "Test-Mode".

Once the postal code is entered, an AJAX script is called to call a php function in my ShippingController to calculate the shipping cost based on the items selected for purchase.

The responses returned are always empty {} objects.

For example, the following shippo request returns {}

$address = \Shippo_Address::
    create(
        array(
             'object_purpose' => 'QUOTE',
             'name' => 'John Smith',
             'company' => 'Initech',
             'street1' => '6512 Greene Rd.',
             'city' => 'Woodridge',
             'state' => 'IL',
             'zip' => '60517',
             'country' => 'US',
             'phone' => '773 353 2345',
             'email' => 'jmercouris@iit.com',
             'metadata' => 'Customer ID 23424'
        ));

return  $address;

$address is printed to my console.log once the AJAX script completes executing.

I have tested printing out several functions, to see what the JSON response data is, and everything is just EMPTY {} - Shippo_Shipment::create() and Shippo_CarrierAccount also returns {}

What could be the issue here? Is it related to the test environment?

The purolator details I have added to my Carrier list is a Account#/PRODUCTION KEY...

How can I specify which carrier to use when searching for Rates?

jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
Borovez
  • 45
  • 2
  • 12
  • Are you trying to return these after running them through `json_encode()`? Or are you getting this back after using `var_dump($address)` – mootrichard Apr 25 '17 at 22:51

1 Answers1

1

The Shippo PHP library populates the object with JSON friendly data, so it wouldn't require an additional json_encode() to print the data out.

Without more information about how you're trying to print out the data from $address, its hard to determine why it would be empty.

In my own testing around this, the only time I returned an empty object was when I attempted to use json_encode() on it.

mootrichard
  • 3,581
  • 13
  • 25