Reputation: 11
I am sending this request:
{ "carrier_service":
{ "name": "Test Provider",
"callback_url": "callback_url",
"format": "json",
"service_discovery": true,
"rate": {
"origin": {
"country": "CA",
"postal_code": "K1S4J3",
"province": "ON",
"city": "Ottawa",
"name": "test name",
"address1": "520 Cambridge Street South",
"address2": "asas",
"address3": "sdsdsd",
"phone": "32323323434",
"fax": "3434343434",
"address_type": "sdsdsd",
"company_name": "test"
},
"destination": {
"country": "CA",
"postal_code": "K1S 3T7",
"province": "ON",
"city": "Ottawa",
"name": "Jason Normore",
"address1": "520 Cambridge Street South Apt. 5",
"address2": null,
"address3": null,
"phone": "7097433959",
"fax": null,
"address_type": null,
"company_name": null
},
"items": [
{
"name": "My Product 3",
"sku": "sdsdsdsd",
"quantity": 1,
"grams": 1000,
"price": 2000,
"vendor": "TestVendor",
"requires_shipping": true,
"taxable": true,
"fulfillment_service": "manual"
}
],
"currency": "CAD"
}
}
}
it's saying you already have Test Provider set up for this shop But when I remove carrier and make request once again it shows only
{"carrier_services":[{"active":true,"id":116379,"name":"Test Provider","service_discovery":true,"carrier_service_type":"api"}]}
But i need to get response like described here http://docs.shopify.com/api/carrierservice
{
"rates": [
{
"service_name": "canadapost-overnight",
"service_code": "ON",
"total_price": "1295",
"currency": "CAD",
"min_delivery_date": "2013-04-12 14:48:45 -0400",
"max_delivery_date": "2013-04-12 14:48:45 -0400"
},
{
"service_name": "fedex-2dayground",
"service_code": "1D",
"total_price": "2934",
"currency": "USD",
"min_delivery_date": "2013-04-12 14:48:45 -0400",
"max_delivery_date": "2013-04-12 14:48:45 -0400"
},
{
"service_name": "fedex-2dayground",
"service_code": "1D",
"total_price": "2934",
"currency": "USD",
"min_delivery_date": "2013-04-12 14:48:45 -0400",
"max_delivery_date": "2013-04-12 14:48:45 -0400"
}
]
}
Upvotes: 1
Views: 1020
Reputation: 991
Give the CarrierService API docs another read.
This part is used to SET UP your carrier service; usually when the merchant installs your app:
https://help.shopify.com/api/reference/carrierservice#create
Then, assuming the store has the CarrierServices API permissions, Shopify will send you something like the following, when a customer is going through checkout:
{
"rate": {
"origin": {
"country": "CA",
"postal_code": "K1S4J3",
"province": "ON",
"city": "Ottawa",
"name": null,
"address1": "520 Cambridge Street South",
"address2": null,
"address3": null,
"phone": null,
"fax": null,
"address_type": null,
"company_name": null
},
"destination": {
"country": "CA",
"postal_code": "K1S 3T7",
"province": "ON",
"city": "Ottawa",
"name": "Jason Normore",
"address1": "520 Cambridge Street South Apt. 5",
"address2": null,
"address3": null,
"phone": "7097433959",
"fax": null,
"address_type": null,
"company_name": null
},
"items": [
{
"name": "My Product 3",
"sku": null,
"quantity": 1,
"grams": 1000,
"price": 2000,
"vendor": "TestVendor",
"requires_shipping": true,
"taxable": true,
"fulfillment_service": "manual"
}
],
"currency": "CAD"
}
}
Note that it's not a regular _POST, rather a stream - with PHP you access that by:
file_get_contents('php://input');
.. you use THAT to calculate your rates, then return them in the format:
{
"rates": [
{
"service_name": "canadapost-overnight",
"service_code": "ON",
"total_price": "1295",
"currency": "CAD",
"min_delivery_date": "2013-04-12 14:48:45 -0400",
"max_delivery_date": "2013-04-12 14:48:45 -0400"
},
{
"service_name": "fedex-2dayground",
"service_code": "2D",
"total_price": "2934",
"currency": "USD",
"min_delivery_date": "2013-04-12 14:48:45 -0400",
"max_delivery_date": "2013-04-12 14:48:45 -0400"
},
{
"service_name": "fedex-priorityovernight",
"service_code": "1D",
"total_price": "3587",
"currency": "USD",
"min_delivery_date": "2013-04-12 14:48:45 -0400",
"max_delivery_date": "2013-04-12 14:48:45 -0400"
}
]
}
.. and as long as the checkout hasn't timed out, the customer should see the rates returned.
Upvotes: 2