Zomars/cal 748 paid bookings are failing (#1335)
* E2E video adjustments * Adds test to add Stripe integration * Type fix * WIP: Payment troubleshooting * Paid bookings shouldn't be confirmed by default * Runs stripe test only if installed * BookingListItem Adjustments * Pending paid bookings should be unconfirmed * Attempt to fix paid bookings * Type fixes * Type fixes * Tests fixes * Adds paid booking to seeder * Moves stripe tests to own file * Matches app locale to Stripe's * Fixes minimun price for testing * Stripe test fixes * Fixes stripe frame test * Added some Stripe TODOs
This commit is contained in:
1 parent
ca405743fb
commit
21103580f7
19 files changed
+201
-51
No files matched your search
@@ -1,9 +1,8 @@
|
||||
import { CardElement, useStripe, useElements } from "@stripe/react-stripe-js";
|
||||
import { StripeCardElementChangeEvent } from "@stripe/stripe-js";
|
||||
import { CardElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
||||
import stripejs, { StripeCardElementChangeEvent, StripeElementLocale } from "@stripe/stripe-js";
|
||||
import { useRouter } from "next/router";
|
||||
import { stringify } from "querystring";
|
||||
import React, { useState } from "react";
|
||||
import { SyntheticEvent } from "react";
|
||||
import React, { SyntheticEvent, useEffect, useState } from "react";
|
||||
|
||||
import { PaymentData } from "@ee/lib/stripe/server";
|
||||
|
||||
@@ -12,7 +11,7 @@ import { useLocale } from "@lib/hooks/useLocale";
|
||||
|
||||
import Button from "@components/ui/Button";
|
||||
|
||||
const CARD_OPTIONS = {
|
||||
const CARD_OPTIONS: stripejs.StripeCardElementOptions = {
|
||||
iconStyle: "solid" as const,
|
||||
classes: {
|
||||
base: "block p-2 w-full border-solid border-2 border-gray-300 rounded-md shadow-sm dark:bg-black dark:text-white dark:border-black focus-within:ring-black focus-within:border-black sm:text-sm",
|
||||
@@ -29,7 +28,7 @@ const CARD_OPTIONS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
} as const;
|
||||
|
||||
type Props = {
|
||||
payment: {
|
||||
@@ -47,18 +46,23 @@ type States =
|
||||
| { status: "ok" };
|
||||
|
||||
export default function PaymentComponent(props: Props) {
|
||||
const { t } = useLocale();
|
||||
const { t, i18n } = useLocale();
|
||||
const router = useRouter();
|
||||
const { name, date } = router.query;
|
||||
const [state, setState] = useState<States>({ status: "idle" });
|
||||
const stripe = useStripe();
|
||||
const elements = useElements();
|
||||
|
||||
const { isDarkMode } = useDarkMode();
|
||||
|
||||
useEffect(() => {
|
||||
elements?.update({ locale: i18n.language as StripeElementLocale });
|
||||
}, [elements, i18n.language]);
|
||||
|
||||
if (isDarkMode) {
|
||||
CARD_OPTIONS.style.base.color = "#fff";
|
||||
CARD_OPTIONS.style.base.iconColor = "#fff";
|
||||
CARD_OPTIONS.style.base["::placeholder"].color = "#fff";
|
||||
CARD_OPTIONS.style!.base!.color = "#fff";
|
||||
CARD_OPTIONS.style!.base!.iconColor = "#fff";
|
||||
CARD_OPTIONS.style!.base!["::placeholder"]!.color = "#fff";
|
||||
}
|
||||
|
||||
const handleChange = async (event: StripeCardElementChangeEvent) => {
|
||||
|
||||
@@ -64,7 +64,11 @@ export async function handlePayment(
|
||||
data: {
|
||||
type: PaymentType.STRIPE,
|
||||
uid: uuidv4(),
|
||||
bookingId: booking.id,
|
||||
booking: {
|
||||
connect: {
|
||||
id: booking.id,
|
||||
},
|
||||
},
|
||||
amount: selectedEventType.price,
|
||||
fee: paymentFee,
|
||||
currency: selectedEventType.currency,
|
||||
|
||||
@@ -6,7 +6,7 @@ import stripe from "@ee/lib/stripe/server";
|
||||
|
||||
import { CalendarEvent } from "@lib/calendarClient";
|
||||
import { IS_PRODUCTION } from "@lib/config/constants";
|
||||
import { HttpError } from "@lib/core/http/error";
|
||||
import { HttpError as HttpCode } from "@lib/core/http/error";
|
||||
import { getErrorFromUnknown } from "@lib/errors";
|
||||
import EventManager from "@lib/events/EventManager";
|
||||
import prisma from "@lib/prisma";
|
||||
@@ -31,6 +31,7 @@ async function handlePaymentSuccess(event: Stripe.Event) {
|
||||
booking: {
|
||||
update: {
|
||||
paid: true,
|
||||
confirmed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -97,7 +98,7 @@ async function handlePaymentSuccess(event: Stripe.Event) {
|
||||
|
||||
await prisma.booking.update({
|
||||
where: {
|
||||
id: payment.bookingId,
|
||||
id: booking.id,
|
||||
},
|
||||
data: {
|
||||
references: {
|
||||
@@ -106,6 +107,11 @@ async function handlePaymentSuccess(event: Stripe.Event) {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
throw new HttpCode({
|
||||
statusCode: 200,
|
||||
message: `Booking with id '${booking.id}' was paid and confirmed.`,
|
||||
});
|
||||
}
|
||||
|
||||
type WebhookHandler = (event: Stripe.Event) => Promise<void>;
|
||||
@@ -117,15 +123,15 @@ const webhookHandlers: Record<string, WebhookHandler | undefined> = {
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
if (req.method !== "POST") {
|
||||
throw new HttpError({ statusCode: 405, message: "Method Not Allowed" });
|
||||
throw new HttpCode({ statusCode: 405, message: "Method Not Allowed" });
|
||||
}
|
||||
const sig = req.headers["stripe-signature"];
|
||||
if (!sig) {
|
||||
throw new HttpError({ statusCode: 400, message: "Missing stripe-signature" });
|
||||
throw new HttpCode({ statusCode: 400, message: "Missing stripe-signature" });
|
||||
}
|
||||
|
||||
if (!process.env.STRIPE_WEBHOOK_SECRET) {
|
||||
throw new HttpError({ statusCode: 500, message: "Missing process.env.STRIPE_WEBHOOK_SECRET" });
|
||||
throw new HttpCode({ statusCode: 500, message: "Missing process.env.STRIPE_WEBHOOK_SECRET" });
|
||||
}
|
||||
const requestBuffer = await buffer(req);
|
||||
const payload = requestBuffer.toString();
|
||||
@@ -137,7 +143,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
await handler(event);
|
||||
} else {
|
||||
/** Not really an error, just letting Stripe know that the webhook was received but unhandled */
|
||||
throw new HttpError({
|
||||
throw new HttpCode({
|
||||
statusCode: 202,
|
||||
message: `Unhandled Stripe Webhook event type ${event.type}`,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user