====== Custom Live Rate Endpoint ======
**This snippet has been replaced.** In place of the following snippet, we now have [[v:2.0:shipping#custom_shipping_endpoint|a custom shipping endpoint]] feature in FoxyCart 2.0 that allows you to provide custom rates to your customers without needing to add custom javascript to change the way the checkout works. Please use the custom shipping endpoint instead of this snippet. This page will remain for reference.
If you have requirements outside of the live shipping rate integrations that FoxyCart currently has, whether to make use of a specific shipping carrier, or make use of functionality that we don't current support, you can use the following snippet to roll your own endpoint.
===== Requirements =====
This script requires communicating with an external script. As the cart and checkout pages where this call will happen are secured over HTTPS, to allow for the communication to happen, your endpoint needs to be secured over HTTPS as well. Without it, the requests will be blocked by the browser and customers won't see any rates.
===== Setup ======
==== Step 1: Your Endpoint ====
On your side, your endpoint will be passed a group of post values containing the customers shipping address.
* ''shipping_address_name'' Used for multiship - will contain the multiship name
* ''shipping_state'' 2 character code if auto-completed, or the name as entered
* ''shipping_country'' 2 character country code like ''US'' or ''GB''
* ''shipping_city'':
* ''shipping_postal_code''
Your endpoint should print the result out in the following format for them to be handled correctly within your store:
=== Success JSON ===
{
"ok":true,
"data": {
"shipping_results": [
{
"service_id": 57,
"price": 642.2,
"method":"FedEx",
"service_name": "International Economy"
},
{
"service_id": 56,
"price": 765.47,
"method": "FedEx",
"service_name": "International Priority"
}
]
}
}
**Note:** The ''service_id'' value needs be set to an integer.
=== Errors JSON ===
{
"ok":false,
"details": "Error Message"
}
=== Example JSONP Output ===
==== Step 2: Add javascript ====
Add the following in the “custom footer” field of the [[https://admin.foxycart.com/admin.php?ThisAction=TemplateConfig|template configuration]]'s “Add custom header and footer code to your templates” option of your store's FoxyCart administration.
{% if context == 'cart' or context == 'checkout' %}
{% endif %}
If you have created your own cart or checkout templates, ensure you've followed the steps to include the custom code placeholders as [[https://wiki.foxycart.com/v/2.0/templates/intermediate-automagicache#include_custom_code_placeholders|detailed here]]
In the above code, you'll need to update ''YOUR-ENDPOINT-URL'' to be your actual endpoint script. You have to wrap the url of your actual endpoint script in single quotes (' ').