Using Lemon.js
In this guide we will go though a couple of examples how you can use Lemon.js to open Lemon Squeezy checkouts and listen for various events, directly from you app.
Add the script to your app
You can get started using Lemon.js by embedding our tiny (2.3kB) library via our CDN into the head
or body
of your page.
Buy buttons and checkout overlays
With Lemon.js on your page, you can make checkout URLs automatically open in a checkout overlay by adding lemonsqueezy-button
CSS class to your links:
Or you can open checkout URLs using the LemonSqueezy.Url.Open()
method:
This is useful if you’re generating custom checkout URLs on-the-fly using the API.
Opening other overlays
You can also load the update payment method URLs in an overlay using Lemon.js, creating a much more seamless experience inside your app.
Handling events
When a Lemon.js overlay is in use (either a checkout or an update payment method form), you can listen for certain events that happen during the form flow:
Event | Description |
---|---|
Checkout.Success | Checkout was successful |
PaymentMethodUpdate.Mounted | Payment method overlay has been loaded |
PaymentMethodUpdate.Closed | Payment method overlay has been closed |
PaymentMethodUpdate.Updated | Payment method has been updated successfully |
You can listen for these events by specifying an eventHandler
option in a LemonSqueezy.Setup()
call.
The object passed to the handler contains an event
.
Checkout.Success
events also get passed an Order object in data
so you have instant access to the order that was just created.
To learn more about Lemon.js and advanced usage read the full Lemon.js documentation.