One-time purchase

Manage the orders of your product.

When a new purchase occurs, the code stores the event in a table called Order.

Here are the steps needed to support it.

Database

Add this table definition to your prisma/schema.prisma file:

schema.prisma
model Order {
  id                  Int       @id @default(autoincrement())
  email               String
  lemonOrderId        String?
  lemonProductId      String
  lemonVariantId      String?
  lemonVariantName    String?
  lemonPlanName       String?
  lemonPlanPrice      String?
  lemonSubscriptionId String?
  createdAt           DateTime  @default(now())
  updatedAt           DateTime  @updatedAt
  validUntil          DateTime?
  cancelUrl           String?
  updateUrl           String?
  status              String?
}

Push the new table to your database:

Then open the file src/app/api/webhooks/lemonsqueezy/route.ts and replace its content with this:

Lemon Squeezy

Enable the order_created order_refunded events on Lemon Squeezy, in the Webhook configuration.

Settings > Webhooks > Edit the WebHook

Now, whenever a customer buys your product, a new record will be created in the table public.Order

Last updated

Was this helpful?