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({
paymentId: metadata.paymentId as PaymentsId,
pIntentId: id,
pm_id:
typeof paymentIntent.payment_method === "string"
? paymentIntent.payment_method
: "",
});
break;

View file

@ -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

View file

@ -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();