diff --git a/StripeService.ts b/StripeService.ts index 06d712e..728197d 100644 --- a/StripeService.ts +++ b/StripeService.ts @@ -35,11 +35,13 @@ export class StripeService { mode: "payment", success_url: `${process.env.FRONTEND_URL}?success=true`, cancel_url: `${process.env.FRONTEND_URL}?canceled=true`, - metadata: { - userId: userId, - }, }); + await this.pool.query( + "update credits set credits = credits + 10 where userId = $1", + [userId] + ); + return stripePromise.url || ""; } @@ -61,10 +63,6 @@ export class StripeService { if (event.type === "checkout.session.completed") { const session = event.data.object; console.log("Fulfilling order", session); - await this.pool.query( - "update credits set credits = credits + 10 where userId = $1", - [session.metadata!.userId] - ); console.log("Order fulfilled successfully"); // Log when the order is fulfilled successfully return { statusCode: "200", body: "Order fulfilled" };