-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from kevinreber/fix-stripe-webhook
Debugging Stripe Webhook
- Loading branch information
Showing
6 changed files
with
179 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
import { | ||
redirect, | ||
type LoaderFunctionArgs, | ||
MetaFunction, | ||
type MetaFunction, | ||
} from "@remix-run/node"; | ||
import { authenticator } from "~/services/auth.server"; | ||
import { requireUserLogin } from "~/services/auth.server"; | ||
import { stripeCheckout } from "~/services/stripe.server"; | ||
import { loader as UserLoaderData } from "../root"; | ||
import { Logger } from "~/utils/logger.server"; | ||
|
||
export const meta: MetaFunction< | ||
typeof loader, | ||
{ root: typeof UserLoaderData } | ||
> = ({ matches }) => { | ||
const userMatch = matches.find((match) => match.id === "root"); | ||
const username = | ||
userMatch?.data?.userData?.username || | ||
userMatch?.data?.userData?.name || | ||
"Checkout"; | ||
|
||
return [{ title: `Checkout | ${username}` }]; | ||
}; | ||
|
||
export const loader = async ({ request }: LoaderFunctionArgs) => { | ||
const user = (await authenticator.isAuthenticated(request, { | ||
failureRedirect: "/", | ||
})) as { id: string }; | ||
const user = await requireUserLogin(request); | ||
|
||
Logger.info({ | ||
message: "[checkout.tsx]: Starting checkout process", | ||
metadata: { userId: user.id }, | ||
}); | ||
|
||
const url = await stripeCheckout({ | ||
userId: user.id, | ||
}); | ||
|
||
return redirect(url); | ||
}; | ||
|
||
export const meta: MetaFunction< | ||
typeof loader, | ||
{ root: typeof UserLoaderData } | ||
> = ({ data, params, matches }) => { | ||
// Incase our Profile loader ever fails, we can get logged in user data from root | ||
const userMatch = matches.find((match) => match.id === "root"); | ||
const username = userMatch?.data.data?.username || userMatch?.data.data?.name; | ||
Logger.info({ | ||
message: "[checkout.tsx]: Redirecting to Stripe checkout", | ||
metadata: { checkoutUrl: url }, | ||
}); | ||
|
||
return [{ title: `Checkout | ${username}` }]; | ||
return redirect(url); | ||
}; |
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
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.
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