'Shopify Custom Carrier Service Error : Your cart has been updated and the items you added can’t be shipped to your address
I've create a shopify app using Codeigniter 4. It's a carrier service app. The carrier service is created successfully and I can see it in my development store in settings under manage rates but I'm getting error while checking out. It says - Your cart has been updated and the items you added can’t be shipped to your address. Remove the items to complete your order. Below is the code to create the carrier service:
$response = $client->post(
"carrier_services",
[
"carrier_service" => [
'active' => true,
"name" => "Faast Delivery",
"callback_url" => "https://app.faastdelivery.com/shopify/rate",
"service_discovery" => true,
]
]
);
And here is my callback function.
public function rate(){
// 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' => 'Faast Delivery',
'service_code' => 'FSTD',
'total_price' => $overnight_cost,
"description" => "This is the fastest option by far",
'currency' => 'EUR',
'min_delivery_date' => $on_min_date,
'max_delivery_date' => $on_max_date
),
array(
'service_name' => 'Faast Delivery',
'service_code' => 'FSTD',
'total_price' => $regular_cost,
"description" => "This is the fastest option by far",
'currency' => 'EUR',
'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
header('Content-Type: application/json');
echo $json_output;
// return $json_output;
}
Thanks in advance.
Solution 1:[1]
I guess and from my experience that your response took more than 10 secs and for that, a message was returned instead.
please refer to the below timeout period for each request per min:
- RPM under 1500: read timeout will be 10 seconds
- RPM between 1500 and 3000: read timeout will be 5 seconds
- RPM over 3000: read timeout will be 3 seconds
Refrence: Dynamic Timeout for CarrierService API Rate Requests
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hussain Sabba |
