Using EasyPost With Laravel 8

241 Views Asked by At

Guys I'm brand new to laravel and easypost. I'm putting together an ecommerce store but I need to show the customer shipping rates that must be passed on to the total price. So far, the test payments work in the bummen99 cart, but I'm really struggling to show the rates.

What is the procedure to do this? I imagine you build a controller for the Easypost rates, but how do you implement it on the checkout page with the products in question. Any help is much appreciated.

Dane

1

There are 1 best solutions below

1
Justin Hammond On

I have an example of an EasyPost UI built on Laravel. You can see an example of how to pull out the rates from a shipment here which is inside a controller (your assumption is correct), then you assign the rates to a variable and return that to your view which in your example would be your "checkout page". On my project, you can see the rates on the view as an example of how to do that there. Feel free to checkout the rest of the project for more inspiration on how to use Laravel and EasyPost hand-in-hand!

TLDR:

You'll want to create a shipment following the EasyPost docs and the rates will be returned in the response under the rates key.

  1. Create an EasyPost shipment via a controller (using input from a form most likely
  2. On the response of that shipment create call, there will be a rates key with all the rates
  3. Return that JSON to your checkout view and you'll see the rates (if present) on your page.