-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5778115
commit 1d6015a
Showing
18 changed files
with
751 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
prisma/migrations/20240331180158_add_lemon_squeezy_related_variables/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-- CreateTable | ||
CREATE TABLE "LemonSqueezyWebhookEvent" ( | ||
"id" SERIAL NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"eventName" TEXT NOT NULL, | ||
"processed" BOOLEAN NOT NULL DEFAULT false, | ||
"body" JSONB NOT NULL, | ||
"processingError" TEXT, | ||
|
||
CONSTRAINT "LemonSqueezyWebhookEvent_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "LemonSqueezySubscription" ( | ||
"id" SERIAL NOT NULL, | ||
"lemonSqueezyId" TEXT NOT NULL, | ||
"orderId" INTEGER NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"email" TEXT NOT NULL, | ||
"status" TEXT NOT NULL, | ||
"statusFormatted" TEXT NOT NULL, | ||
"renewsAt" TIMESTAMP(3), | ||
"endsAt" TIMESTAMP(3), | ||
"trialEndsAt" TIMESTAMP(3), | ||
"price" TEXT NOT NULL, | ||
"isUsageBased" BOOLEAN NOT NULL DEFAULT false, | ||
"isPaused" BOOLEAN NOT NULL DEFAULT false, | ||
"subscriptionItemId" INTEGER NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"planId" INTEGER NOT NULL, | ||
|
||
CONSTRAINT "LemonSqueezySubscription_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "LemonSqueezySubscription_lemonSqueezyId_key" ON "LemonSqueezySubscription"("lemonSqueezyId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "LemonSqueezySubscription" ADD CONSTRAINT "LemonSqueezySubscription_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20240401075751_add_new_field_to_sub/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `planId` on the `LemonSqueezySubscription` table. All the data in the column will be lost. | ||
- You are about to drop the column `statusFormatted` on the `LemonSqueezySubscription` table. All the data in the column will be lost. | ||
- Added the required column `customerId` to the `LemonSqueezySubscription` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "LemonSqueezySubscription" DROP COLUMN "planId", | ||
DROP COLUMN "statusFormatted", | ||
ADD COLUMN "customerId" TEXT NOT NULL; |
10 changes: 10 additions & 0 deletions
10
prisma/migrations/20240401080450_remove_some_fields/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `price` on the `LemonSqueezySubscription` table. All the data in the column will be lost. | ||
- You are about to drop the column `subscriptionItemId` on the `LemonSqueezySubscription` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "LemonSqueezySubscription" DROP COLUMN "price", | ||
DROP COLUMN "subscriptionItemId"; |
4 changes: 4 additions & 0 deletions
4
prisma/migrations/20240401080712_add_url_fields_to_ls_sub/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- AlterTable | ||
ALTER TABLE "LemonSqueezySubscription" ADD COLUMN "customerPortalUpdateSubscriptionUrl" TEXT, | ||
ADD COLUMN "customerPortalUrl" TEXT, | ||
ADD COLUMN "updatePaymentMethodUrl" TEXT; |
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20240401085643_add_variant_id/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `variantId` to the `LemonSqueezySubscription` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "LemonSqueezySubscription" ADD COLUMN "variantId" TEXT NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"use client"; | ||
import { LinkIcon, Loader2 } from "lucide-react"; | ||
import React from "react"; | ||
import { Button } from "~/components/ui/button"; | ||
import { Skeleton } from "~/components/ui/skeleton"; | ||
import { Badge } from "~/components/ui/badge"; | ||
import { api } from "~/trpc/react"; | ||
import Link from "next/link"; | ||
|
||
const Page = () => { | ||
const utils = api.useUtils(); | ||
const lemonSqueezyWebhookQuery = api.ls.getWebhook.useQuery(); | ||
const createLemonSqueezyWebhookMutation = api.ls.createLsWebhook.useMutation({ | ||
onSuccess: () => utils.ls.getWebhook.invalidate(), | ||
}); | ||
|
||
return ( | ||
<div className="space-y-4"> | ||
<h1 className="text-2xl">Lemon Squeezy setup</h1> | ||
<p className="prose"> | ||
For <b>local development</b> run the following command in your terminal:{" "} | ||
<br /> | ||
<code>npx localtunnel --port 3000 --subdomain your-domain</code> and | ||
copy resulting URL to <b>LEMON_SQUEEZY_WEBHOOK_URL</b> in your .env | ||
file. It shall look similar to this: <br /> | ||
<i>https://cascade.loca.lt/api/lemon-squeezy/webhook</i> | ||
</p> | ||
<p> | ||
For production webhook use your hosted application url e.g.: <br /> | ||
<i>https://cascade.stackonfire.com/api/lemon-squeezy/webhook</i> | ||
</p> | ||
{lemonSqueezyWebhookQuery.isLoading && ( | ||
<Skeleton className="h-[20px] w-[200px]" /> | ||
)} | ||
{lemonSqueezyWebhookQuery.data && ( | ||
<div className="space-y-2"> | ||
<div className="flex space-x-2"> | ||
<h2 className="text-lg">Webhook URL</h2> | ||
{lemonSqueezyWebhookQuery.data.attributes.url && ( | ||
<Badge variant="destructive" className="max-h-6 self-center"> | ||
{lemonSqueezyWebhookQuery.data.attributes.test_mode | ||
? "Test Mode" | ||
: "Production"} | ||
</Badge> | ||
)} | ||
</div> | ||
<div className="flex space-x-2 text-muted-foreground"> | ||
<div className="flex h-2 w-2 animate-pulse self-center rounded-full bg-green-500" />{" "} | ||
<p>{lemonSqueezyWebhookQuery.data.attributes.url}</p> | ||
<Link | ||
href="https://app.lemonsqueezy.com/settings/webhooks" | ||
target="_blank" | ||
className="self-center transition-colors hover:text-foreground" | ||
> | ||
<LinkIcon className="h-4 w-4" /> | ||
</Link> | ||
</div> | ||
<div className="flex space-x-1"> | ||
{lemonSqueezyWebhookQuery.data.attributes.events.map((event) => ( | ||
<Badge variant="outline" key={event}> | ||
{event} | ||
</Badge> | ||
))} | ||
</div> | ||
</div> | ||
)} | ||
<Button | ||
onClick={() => createLemonSqueezyWebhookMutation.mutate()} | ||
disabled={ | ||
createLemonSqueezyWebhookMutation.isPending || | ||
lemonSqueezyWebhookQuery.isLoading || | ||
!!lemonSqueezyWebhookQuery.data?.attributes.url | ||
} | ||
> | ||
{createLemonSqueezyWebhookMutation.isPending && ( | ||
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> | ||
)} | ||
Create Lemon Squeezy webhook | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Page; |
Oops, something went wrong.