Custom shipping Integration

chesterpchesterp Member
Hi Guys,

Iam exploring how to use custom shipping endpoint,I dont have any experience yet in working with custom shipping endpoint. I wonder if this class

https://github.com/Foxy/foxy-shipping-endpoint-php/blob/master/README.md#example-usage

Is this applicable to a certain api like NIppon express API or do I need to build the same class as above?
https://www.nittsu.com/

What do you suggest in this scenario the client wants to pass on Nippons preferred shipping rates to the customer.
These are the three shipping options they want to offer:
- 2 day
- Express Saver
- Priority Overnight

I cant seem to find a good documentation on how to work with custom shipping endpoint.

Thank you

Comments
  • fc_adamfc_adam FoxyCart Team
    @chesterp,

    Thanks for posting. The shipping endpoint helper library you linked to there is designed to be included on your shipping endpoint script and assist with creating and returning rates in the format that our systems expect. You don't have to use them if you don't want to - but it helps simplify the process a little.

    It's not designed with any specific API in mind - it's essentially just designed to make adding the rates easier. For your use case of integrating with the Nippon Express API - your endpoint would still need to communicate with their API and get the rates returned. You would use the address as it's included within the shipping payload passed to your custom shipping endpoint - which you can see an example of here: https://wiki.foxycart.com/v/2.0/shipping#custom_shipping_endpoint

    Once you get the reply back from their API with the rates, you would loop through each of the returned rates, and using the helper library, add rates for each one using the details received. Then you'd call the output function as shown in the example code on the Github readme you linked to so the rates are output back to the cart/checkout.

    Does that help clarify how the pieces would work together?
  • @fc_adam

    Thank you for your response.

    I tried to setup a custom enpoint so I can test how the ShippingResponse works without any api integration. I just want to see how to pass data and what data to be passed back by foxycart.

    On my script I have this

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

    $modx->log(modX::LOG_LEVEL_ERROR,'================RAW POST===============',$rawPost);

    $cart_details = json_decode($rawPost, true);

    $modx->log(modX::LOG_LEVEL_ERROR,'================CART DETAILS===============',$cart_details);

    $rates = new ShippingResponse($cart_details);
    I tried to log the $rawPost and $cart_details but it is returning empty. I assumed that the endpoint will run once the cart is loaded on the page.

    I checked my log and no log is being print, I assumed that rawPost and $cart_details will be printed out.

    So my question is, Is this correct

    $rawPost = file_get_contents('php://input');
    Is that the correct argument to pass on file_get_contents?
  • fc_adamfc_adam FoxyCart Team
    @chesterp,

    The custom shipping endpoint is hit when live shipping rates are requested for a store that has that endpoint set in the shipping settings.

    In terms of the code - the sample endpoint code on the Github readme is correct in terms of it being a working example of an endpoint.

    To confirm - you've got your endpoint script configured for the custom shipping endpoint, and you've entered a shipping address in the cart or checkout for a cart that has live rate shippable products?
  • @fc_adam

    I chose Live shipping rate on Foxycart category and enter a custom-shipping url with a script in it.
    https://www.screencast.com/t/tDLByr8Vu

    On the cart im getting this.
    https://www.screencast.com/t/7ENvJrr0x3vq

    But I know the custom shippign script runs because Im seeing my test text that I printed on log on the custom shipping script.

    My problem is $rawPost and $cart_details var is empty when I tried to print it out on log. I just want to see what data is being received by the script from these sample variables of the ShippingResponse class.
  • fc_adamfc_adam FoxyCart Team
    @chesterp,

    Thanks for the screenshots. I've just checked the logs for your development store, and based on the logs the payload for the current cart details are being passed over as it should.

    I wonder if ModX is intercepting the incoming request and handling the body for you. Are you running your endpoint within ModX? If so - you may need to get the POST body from the request using whatever methods ModX provide for getting that.
  • @fc_adam

    Thank you, I removed other modx log code, put the script outside modx and just make it a stand alone php file. And it worked, I saw some shipping options now on the cart.

    Is there any way I can print the cart_details or the raw post data on foxycart log?
  • fc_adamfc_adam FoxyCart Team
    @chesterp,

    I'm glad you were able to get it working! We trim the log returned so you probably won't be able to view the whole value on the Foxy error log. Your best bet will be to write to a file from your script and save the post body to that to view it.

    If you're just looking for a sample of the payload - we do have that on our wiki here: https://wiki.foxycart.com/v/2.0/shipping#custom_shipping_endpoint
  • @fc_adam

    Thank you sir for your help.
  • fc_adamfc_adam FoxyCart Team
    Happy to help! :smile:
Sign In or Register to comment.