save payment method on intent creation wh received

This commit is contained in:
Marco Pedone 2026-02-20 11:52:14 +01:00
parent 89248e3787
commit 4ec060c14d
3 changed files with 14 additions and 1 deletions

View file

@ -53,6 +53,10 @@ const handler = async (
await caller.stripe.whIntentCreated({ await caller.stripe.whIntentCreated({
paymentId: metadata.paymentId as PaymentsId, paymentId: metadata.paymentId as PaymentsId,
pIntentId: id, pIntentId: id,
pm_id:
typeof paymentIntent.payment_method === "string"
? paymentIntent.payment_method
: "",
}); });
break; break;

View file

@ -33,12 +33,14 @@ export const stripeRouter = createTRPCRouter({
z.object({ z.object({
paymentId: zPagamentoId, paymentId: zPagamentoId,
pIntentId: z.string(), pIntentId: z.string(),
pm_id: z.string(),
}), }),
) )
.query(async ({ input }) => { .query(async ({ input }) => {
return await whIntentCreatedHandler({ return await whIntentCreatedHandler({
paymentId: input.paymentId, paymentId: input.paymentId,
pIntentId: input.pIntentId, pIntentId: input.pIntentId,
pm_id: input.pm_id,
}); });
}), }),
whIntentFailed: publicProcedure whIntentFailed: publicProcedure

View file

@ -79,13 +79,20 @@ export const createIntentHandler = async ({
export const whIntentCreatedHandler = async ({ export const whIntentCreatedHandler = async ({
pIntentId, pIntentId,
paymentId, paymentId,
pm_id,
}: { }: {
pIntentId: Payments["intent_id"]; pIntentId: Payments["intent_id"];
paymentId: PaymentsId; paymentId: PaymentsId;
pm_id: string;
}) => { }) => {
const paymentMethod = await stripe.paymentMethods.retrieve(pm_id);
return await db return await db
.updateTable("payments") .updateTable("payments")
.set({ intent_id: pIntentId, paymentstatus: PaymentStatusEnum.processing }) .set({
intent_id: pIntentId,
paymentstatus: PaymentStatusEnum.processing,
paymentmethod: paymentMethod.type,
})
.where("id", "=", paymentId) .where("id", "=", paymentId)
.returning("id") .returning("id")
.execute(); .execute();