save payment method on intent creation wh received
This commit is contained in:
parent
89248e3787
commit
4ec060c14d
3 changed files with 14 additions and 1 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue