From 4ec060c14d9349677d46e81805c321b631e0badd Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Fri, 20 Feb 2026 11:52:14 +0100 Subject: [PATCH] save payment method on intent creation wh received --- apps/infoalloggi/src/pages/api/stripe-webhook.ts | 4 ++++ apps/infoalloggi/src/server/api/routers/stripe.ts | 2 ++ .../src/server/controllers/stripe.controller.ts | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/infoalloggi/src/pages/api/stripe-webhook.ts b/apps/infoalloggi/src/pages/api/stripe-webhook.ts index 24dc0eb..202eb39 100644 --- a/apps/infoalloggi/src/pages/api/stripe-webhook.ts +++ b/apps/infoalloggi/src/pages/api/stripe-webhook.ts @@ -53,6 +53,10 @@ const handler = async ( await caller.stripe.whIntentCreated({ paymentId: metadata.paymentId as PaymentsId, pIntentId: id, + pm_id: + typeof paymentIntent.payment_method === "string" + ? paymentIntent.payment_method + : "", }); break; diff --git a/apps/infoalloggi/src/server/api/routers/stripe.ts b/apps/infoalloggi/src/server/api/routers/stripe.ts index ba4a345..fd43f4f 100644 --- a/apps/infoalloggi/src/server/api/routers/stripe.ts +++ b/apps/infoalloggi/src/server/api/routers/stripe.ts @@ -33,12 +33,14 @@ export const stripeRouter = createTRPCRouter({ z.object({ paymentId: zPagamentoId, pIntentId: z.string(), + pm_id: z.string(), }), ) .query(async ({ input }) => { return await whIntentCreatedHandler({ paymentId: input.paymentId, pIntentId: input.pIntentId, + pm_id: input.pm_id, }); }), whIntentFailed: publicProcedure diff --git a/apps/infoalloggi/src/server/controllers/stripe.controller.ts b/apps/infoalloggi/src/server/controllers/stripe.controller.ts index 2773312..1af66ef 100644 --- a/apps/infoalloggi/src/server/controllers/stripe.controller.ts +++ b/apps/infoalloggi/src/server/controllers/stripe.controller.ts @@ -79,13 +79,20 @@ export const createIntentHandler = async ({ export const whIntentCreatedHandler = async ({ pIntentId, paymentId, + pm_id, }: { pIntentId: Payments["intent_id"]; paymentId: PaymentsId; + pm_id: string; }) => { + const paymentMethod = await stripe.paymentMethods.retrieve(pm_id); return await db .updateTable("payments") - .set({ intent_id: pIntentId, paymentstatus: PaymentStatusEnum.processing }) + .set({ + intent_id: pIntentId, + paymentstatus: PaymentStatusEnum.processing, + paymentmethod: paymentMethod.type, + }) .where("id", "=", paymentId) .returning("id") .execute();