Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| v:2.0:snippets:custom_live_rate_endpoint [2014/09/22 07:59] – adam | v:2.0:snippets:custom_live_rate_endpoint [2017/04/26 07:02] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Custom Live Rate Endpoint ====== | ====== Custom Live Rate Endpoint ====== | ||
| + | |||
| + | <WRAP center round important 90%> | ||
| + | **This snippet has been replaced.** In place of the following snippet, we now have [[v: | ||
| + | </ | ||
| 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. | 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. | ||
| Line 21: | Line 25: | ||
| Your endpoint should print the result out in the following format for them to be handled correctly within your store: | Your endpoint should print the result out in the following format for them to be handled correctly within your store: | ||
| - | === Success === | + | === Success |
| <code javascript> | <code javascript> | ||
| - | | + | |
| - | " | + | " |
| - | " | + | " |
| - | { | + | { |
| - | " | + | " |
| - | " | + | " |
| - | " | + | " |
| - | " | + | " |
| - | }, | + | }, |
| - | { | + | { |
| - | " | + | " |
| - | " | + | " |
| - | " | + | " |
| - | " | + | " |
| - | } | + | } |
| - | ] | + | ] |
| - | } | + | } |
| }</ | }</ | ||
| - | === Errors === | + | <WRAP center round info 90%> |
| + | **Note:** The '' | ||
| + | </ | ||
| + | |||
| + | |||
| + | === Errors | ||
| <code javascript> | <code javascript> | ||
| Line 49: | Line 58: | ||
| }</ | }</ | ||
| + | === Example JSONP Output === | ||
| + | <code php> | ||
| + | <?php | ||
| + | // Mitigate against Rosetta Flash vulnerability: | ||
| + | header(' | ||
| + | header(' | ||
| + | $output = '/ | ||
| + | |||
| + | // Create some JSON. Preferably using your programming languages native JSON functionality, | ||
| + | $rates = '{ | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | }'; | ||
| + | |||
| + | // Output JSONP. Wrap the JSON in the callback, prepended with the comment | ||
| + | echo $output . $_GET[' | ||
| + | </ | ||
| ==== Step 2: Add javascript ==== | ==== Step 2: Add javascript ==== | ||
| - | Add the following in the "footer" section | + | Add the following in the “custom |
| <code javascript> | <code javascript> | ||
| <script type=" | <script type=" | ||
| - | FC.api.getShippingOptions(address) { | + | FC.api.getShippingOptions |
| var request_data = { | var request_data = { | ||
| ' | ' | ||
| Line 80: | Line 121: | ||
| }); | }); | ||
| }).promise(); | }).promise(); | ||
| - | } | + | }; |
| </ | </ | ||
| {% endif %}</ | {% endif %}</ | ||
| - | In the above code, you'll need to update '' | + | |
| + | <WRAP center round info 90%> | ||
| + | If you have created your own cart or checkout templates, ensure you've followed the steps to include the custom code placeholders as [[https:// | ||
| + | </ | ||
| + | |||
| + | In the above code, you'll need to update '' | ||