CarrierService API not making request to "callback_url" to get dynamic Shipping method rates.

mukesh2
Shopify Partner
2 0 0


First thing first, i have created a free acount of 14 days on shopify and made an app with scopes "read_orders,read_products,write_products,write_shipping,write_content,write_products".

I am making an APP to integrate with shopify using CarrierService API.
I did all the steps provided in the documentation of CarrierService API at 
https://help.shopify.com/api/reference/carrierservice
With the help of API code i have added a shipping method and my code is like : 
#####################################################
$services_array = array(
                    "carrier_service"=>array(
                        'active'=>true,
                        'name'=>'Endertech Carrier Demo',
                        "callback_url"=> "https://mydomain.com/rates.php",
                        "service_discovery"=> true,
                        'carrier_service_type'=>'api'
                    )
                );
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept:application/json','Content-Type: application/json','X-Shopify-Access-Token: '.$accessToken));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($services_array));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($curl);
curl_close ($curl);
###########################################################

and adding "carrier_service" is working fine. 
For rate to be calculated dynamically i have code  

#######################################################
// log the raw request -- this makes debugging much easier
$filename = time();

$input = file_get_contents('php://input');

file_put_contents($filename.'-input', $input);

// parse the request
$rates = json_decode($input, true);

// log the array format for easier interpreting
file_put_contents($filename.'-debug', print_r($rates, true));

// total up the cart quantities for simple rate calculations
$quantity = 0;
foreach($rates['rate']['items'] as $item) {
    $quantity =+ $item['quantity'];
}

// use number_format because shopify api expects the price to be "25.00" instead of just "25"

// overnight shipping is 5.50 per item
$overnight_cost = number_format($quantity * 5.50, 2, '', '');
// regular shipping is 2.75 per item
$regular_cost = number_format($quantity * 2.75, 2, '', '');

// overnight shipping is 1 to 2 days after today
$on_min_date = date('Y-m-d H:i:s O', strtotime('+1 day'));
$on_max_date = date('Y-m-d H:i:s O', strtotime('+2 days'));

// regular shipping is 3 to 7 days after today
$reg_min_date = date('Y-m-d H:i:s O', strtotime('+3 days'));
$reg_max_date = date('Y-m-d H:i:s O', strtotime('+7 days'));

// build the array of line items using the prior values
$output = array('rates' => array(
    array(
        'service_name' => 'Endertech Overnight',
        'service_code' => 'ETON',
        'total_price' => $overnight_cost,
        'currency' => 'USD',
        'min_delivery_date' => $on_min_date,
        'max_delivery_date' => $on_max_date
    ),
    array(
        'service_name' => 'Endertech Regular',
        'service_code' => 'ETREG',
        'total_price' => $regular_cost,
        'currency' => 'USD',
        'min_delivery_date' => $reg_min_date,
        'max_delivery_date' => $reg_max_date
    )
));

// encode into a json response
$json_output = json_encode($output);

// log it so we can debug the response
file_put_contents($filename.'-output', $json_output);

// send it back to shopify
print $json_output;

###################################################


i.e when shopify will make a request, it will go to callback_url assigned vlaue "" but shopify is not making any request to callback_url assigned vlaue. This is main issue i am facing. 

Another thing that comes in my mind
1) Do we need the store that will install the APP should be on a paid plan?
2) Do we need the development store which is used to make APP should be on a paid plan?
3) Also is it necessasry, Its Shopify plan is paid annually.
4) Do we need Advanced Shopify plan or higher or i can use this service with 14 days DEMO also.

What parameters or setting in my store needs to be corrected, so that when there is any checkout on store which  installed my APP will get my custom rate generated by "rates.php" code. Please help. 

Thanks in advance.

Replies 2 (2)
Don
Shopify Staff
Shopify Staff
2462 173 336

Hi there Mukesh!

Don here from Shopify!

I just wanted to let you know that I had moved your query here to our API forum thread instead as you will be much more likely to get a helpful response in this forum. 🙂

Hopefully, some fellow partners or developers will be able to provide some advice on your API query that we wouldn't be able to give from support ourselves.

All the best!


Regards,
Don

Don | Social Care @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

mukesh2
Shopify Partner
2 0 0

Thanks, Don. Let some one guide me to get my query resolved.