Last active
January 15, 2023 21:37
-
-
Save dipeshhkc/720cc3e73421c3a67c5386c3cc5cf64b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import type { ActionFunction } from "@remix-run/server-runtime"; | |
import { redirect } from "@remix-run/server-runtime"; | |
import { stripeCheckout } from "~/stripe.server"; | |
import { getPriceId } from "~/types/subscription"; | |
import { getLoggedInUser } from "~/user.server"; | |
export const action: ActionFunction = async ({ request }) => { | |
const user = await getLoggedInUser(); | |
if (!user) { | |
return redirect("/"); | |
} | |
const form = await request.formData(); | |
const plan = form.get("plan") as string; | |
const priceId = getPriceId(plan)!; | |
const url = await stripeCheckout({ | |
priceId, | |
plan, | |
user, | |
}); | |
return redirect(url); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment