2025-08-07 14:50:40 +02:00
|
|
|
import { z } from "zod/v4";
|
2025-08-04 17:45:44 +02:00
|
|
|
import {
|
2025-08-28 18:27:07 +02:00
|
|
|
createTRPCRouter,
|
|
|
|
|
protectedProcedure,
|
|
|
|
|
publicProcedure,
|
2025-08-04 17:45:44 +02:00
|
|
|
} from "~/server/api/trpc";
|
|
|
|
|
import {
|
2025-08-28 18:27:07 +02:00
|
|
|
createIntentHandler,
|
2026-01-14 12:02:03 +01:00
|
|
|
stripeHealthCheck,
|
2025-08-28 18:27:07 +02:00
|
|
|
whIntentCreatedHandler,
|
|
|
|
|
whIntentFailedHandler,
|
|
|
|
|
whIntentSucceededHandler,
|
2025-08-04 17:45:44 +02:00
|
|
|
} from "~/server/controllers/stripe.controller";
|
|
|
|
|
import { zPagamentoId } from "~/server/utils/zod_types";
|
|
|
|
|
|
|
|
|
|
export const stripeRouter = createTRPCRouter({
|
2026-01-14 12:02:03 +01:00
|
|
|
health: publicProcedure.query(async () => {
|
|
|
|
|
return await stripeHealthCheck();
|
|
|
|
|
}),
|
2025-08-28 18:27:07 +02:00
|
|
|
createIntent: protectedProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
paymentId: zPagamentoId,
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.mutation(async ({ input }) => {
|
|
|
|
|
return await createIntentHandler({
|
|
|
|
|
paymentId: input.paymentId,
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
whIntentCreated: publicProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
paymentId: zPagamentoId,
|
2025-08-29 16:18:32 +02:00
|
|
|
pIntentId: z.string(),
|
2025-08-28 18:27:07 +02:00
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.query(async ({ input }) => {
|
|
|
|
|
return await whIntentCreatedHandler({
|
|
|
|
|
paymentId: input.paymentId,
|
2025-08-29 16:18:32 +02:00
|
|
|
pIntentId: input.pIntentId,
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
whIntentFailed: publicProcedure
|
|
|
|
|
.input(z.object({ pIntentId: z.string() }))
|
|
|
|
|
.query(async ({ input }) => {
|
|
|
|
|
return await whIntentFailedHandler({
|
|
|
|
|
pIntentId: input.pIntentId,
|
2025-08-28 18:27:07 +02:00
|
|
|
});
|
|
|
|
|
}),
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
whIntentSucceeded: publicProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
paymentId: zPagamentoId,
|
2025-08-29 16:18:32 +02:00
|
|
|
pIntentId: z.string(),
|
2025-08-28 18:27:07 +02:00
|
|
|
pm_id: z.string(),
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.query(async ({ input }) => {
|
|
|
|
|
return await whIntentSucceededHandler({
|
|
|
|
|
paymentId: input.paymentId,
|
|
|
|
|
pIntentId: input.pIntentId,
|
2025-08-29 16:18:32 +02:00
|
|
|
pm_id: input.pm_id,
|
2025-08-28 18:27:07 +02:00
|
|
|
});
|
|
|
|
|
}),
|
2025-08-04 17:45:44 +02:00
|
|
|
});
|
2026-01-12 17:08:23 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Credit Card integration guide
|
|
|
|
|
https://docs.stripe.com/payments/cards
|
|
|
|
|
|
|
|
|
|
Google Pay integration guide
|
|
|
|
|
https://docs.stripe.com/google-pay
|
|
|
|
|
|
|
|
|
|
SEPA Direct Debit integration guide
|
|
|
|
|
https://docs.stripe.com/payments/sepa-debit/accept-a-payment
|
|
|
|
|
|
|
|
|
|
Bank Transfers integration guide
|
|
|
|
|
https://docs.stripe.com/payments/bank-transfers
|
|
|
|
|
|
|
|
|
|
Satispay integration guide
|
|
|
|
|
https://docs.stripe.com/payments/satispay
|
|
|
|
|
*/
|