Sometimes you may want to fetch and show in your application how much a certain customer would pay before they enter the checkout, taking into consideration things like location, discounts and tax ID validation.
This is easy to do on Lemon Squeezy with a single API call.
Because accessing the Lemon Squeezy requires an API key that provides programatic access to your store, you should never query our API directly in the client (e.g. a browser). Always build a wrapper around the API so your secret API key can stay private.
If you haven't already, make sure to read through our Developer Guide, which takes you through setting up a full integration from creating products and syncing customer data in your application.
How to preview a checkout using the API
Here's an example request:
In this request you can add information about the customer and order so you can get a proper estimate of their payment. Add in the details—for example, location, tax ID and discount code—in
checkout_data. This will generate a specific checkout price preview based on your customer's data.
In the response, you will see the usual Checkout object but with extra data in
data.attributes.preview, which will look like this:
This preview object contains monetary values which you can then use to display pricing in your page: currency (taken from the product), subtotal, tax, discount total and total. All values are based on the price you set on your product variant combined with the data you provide in
checkout_data in the request.
You can see a full explanation of each value in the Checkout docs.
Now you can display a price like this in your application: