From 89248e3787f72ac421951053d1523ba5801af290 Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Fri, 20 Feb 2026 11:42:46 +0100 Subject: [PATCH] refactor: clean up unused console logs and streamline Stripe integration --- apps/infoalloggi/src/components/checkout.tsx | 65 ------------------- apps/infoalloggi/src/lib/stripe.ts | 2 - .../src/pages/api/stripe-webhook.ts | 7 +- .../pagamento-checkout/[paymentId].tsx | 2 - .../server/controllers/stripe.controller.ts | 10 ++- 5 files changed, 8 insertions(+), 78 deletions(-) diff --git a/apps/infoalloggi/src/components/checkout.tsx b/apps/infoalloggi/src/components/checkout.tsx index 3ccb6a4..4811a95 100644 --- a/apps/infoalloggi/src/components/checkout.tsx +++ b/apps/infoalloggi/src/components/checkout.tsx @@ -63,7 +63,6 @@ const PaymentForm = ({ const handleSubmit = async (e: FormEvent) => { e.preventDefault(); - console.log("submitting payment"); if (!stripe || !elements) { return; } @@ -121,67 +120,3 @@ const PaymentForm = ({ ); }; -/* -function PaymentForm2() { - const stripe = useStripe(); - const elements = useElements(); - - const [message, setMessage] = useState(null); - const [isLoading, setIsLoading] = useState(false); - - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - - if (!stripe || !elements) { - // Stripe.js hasn't yet loaded. - // Make sure to disable form submission until Stripe.js has loaded. - return; - } - - setIsLoading(true); - - const { error } = await stripe.confirmPayment({ - elements, - confirmParams: { - // Make sure to change this to your payment completion page - return_url: "http://localhost:3000/success", - }, - }); - - // This point will only be reached if there is an immediate error when - // confirming the payment. Otherwise, your customer will be redirected to - // your `return_url`. For some payment methods like iDEAL, your customer will - // be redirected to an intermediate site first to authorize the payment, then - // redirected to the `return_url`. - if (error.type === "card_error" || error.type === "validation_error") { - setMessage(error.message || "Validation error occurred."); - } else { - setMessage("An unexpected error occurred."); - } - - setIsLoading(false); - }; - - return ( -
- - - - {message &&
{message}
} - - ); -} -*/ diff --git a/apps/infoalloggi/src/lib/stripe.ts b/apps/infoalloggi/src/lib/stripe.ts index 2e6325e..9e841fb 100644 --- a/apps/infoalloggi/src/lib/stripe.ts +++ b/apps/infoalloggi/src/lib/stripe.ts @@ -1,8 +1,6 @@ -// lib/stripe.js import Stripe from "stripe"; import { env } from "~/env"; -// This check ensures we don't accidentally run this on the client if (typeof window !== "undefined") { throw new Error("Stripe Secret Key should not be loaded on the client!"); } diff --git a/apps/infoalloggi/src/pages/api/stripe-webhook.ts b/apps/infoalloggi/src/pages/api/stripe-webhook.ts index 86c7f23..24dc0eb 100644 --- a/apps/infoalloggi/src/pages/api/stripe-webhook.ts +++ b/apps/infoalloggi/src/pages/api/stripe-webhook.ts @@ -96,15 +96,16 @@ const handler = async ( break; } case "payment_intent.processing": { - const paymentIntent = event.data.object; + //const paymentIntent = event.data.object; - console.log("PaymentIntent processing", paymentIntent); + //console.log("PaymentIntent processing", paymentIntent); break; } default: - console.log(`Unhandled event type: ${event.type}`); + //console.log(`Unhandled event type: ${event.type}`); + break; } res.status(200).json({ received: true }); diff --git a/apps/infoalloggi/src/pages/servizio/pagamento-checkout/[paymentId].tsx b/apps/infoalloggi/src/pages/servizio/pagamento-checkout/[paymentId].tsx index ce4e8a7..f610399 100644 --- a/apps/infoalloggi/src/pages/servizio/pagamento-checkout/[paymentId].tsx +++ b/apps/infoalloggi/src/pages/servizio/pagamento-checkout/[paymentId].tsx @@ -42,7 +42,6 @@ export default PagamentoPage; export const getServerSideProps = (async (context) => { const id = context.params?.paymentId; - console.log("Received paymentId:", id); if (typeof id !== "string") { console.error("Error: paymentId is not a string"); return { @@ -88,7 +87,6 @@ export const getServerSideProps = (async (context) => { }, receipt_email: paymentData.email, }); - console.log("Created payment intent with client secret:", clientSecret); if (!clientSecret) { return { diff --git a/apps/infoalloggi/src/server/controllers/stripe.controller.ts b/apps/infoalloggi/src/server/controllers/stripe.controller.ts index 94e3232..2773312 100644 --- a/apps/infoalloggi/src/server/controllers/stripe.controller.ts +++ b/apps/infoalloggi/src/server/controllers/stripe.controller.ts @@ -1,6 +1,6 @@ import { TRPCError } from "@trpc/server"; -import Stripe from "stripe"; import { env } from "~/env"; +import stripe from "~/lib/stripe"; import OrderTypeEnum from "~/schemas/public/OrderTypeEnum"; import PaymentStatusEnum from "~/schemas/public/PaymentStatusEnum"; import type { Payments, PaymentsId } from "~/schemas/public/Payments"; @@ -9,11 +9,9 @@ import { db } from "~/server/db"; import { NewMail } from "~/server/services/mailer"; import { getUser } from "~/server/services/user.service"; -const stripeApi = new Stripe(env.STRIPE_SECRET_KEY); - export const stripeHealthCheck = async () => { try { - const endpoints = await stripeApi.webhookEndpoints.list(); + const endpoints = await stripe.webhookEndpoints.list(); return { success: true, endpoints, @@ -48,7 +46,7 @@ export const createIntentHandler = async ({ .where("payments.id", "=", paymentId) .executeTakeFirstOrThrow(); - const paymentIntent = await stripeApi.paymentIntents.create({ + const paymentIntent = await stripe.paymentIntents.create({ amount: payment.amount_cent, //payment_method_configuration: "pmc_1P4NfjILe4KoQRqXYChFCTFj", automatic_payment_methods: { @@ -103,7 +101,7 @@ export const whIntentSucceededHandler = async ({ pm_id: string; }) => { try { - const paymentMethod = await stripeApi.paymentMethods.retrieve(pm_id); + const paymentMethod = await stripe.paymentMethods.retrieve(pm_id); await db.transaction().execute(async (trx) => { const payment = await trx