feat: update Stripe integration and add settings page with health check
This commit is contained in:
parent
1a3468e7c0
commit
210ee3a9f2
7 changed files with 251 additions and 148 deletions
20
apps/infoalloggi/package-lock.json
generated
20
apps/infoalloggi/package-lock.json
generated
|
|
@ -86,7 +86,7 @@
|
||||||
"react-use": "^17.6.0",
|
"react-use": "^17.6.0",
|
||||||
"recharts": "^2.15.4",
|
"recharts": "^2.15.4",
|
||||||
"sharp": "^0.34.3",
|
"sharp": "^0.34.3",
|
||||||
"stripe": "^18.4.0",
|
"stripe": "^20.1.2",
|
||||||
"superjson": "2.2.2",
|
"superjson": "2.2.2",
|
||||||
"tailwind-merge": "3.3",
|
"tailwind-merge": "3.3",
|
||||||
"tailwind-scrollbar": "^4.0.2",
|
"tailwind-scrollbar": "^4.0.2",
|
||||||
|
|
@ -15622,9 +15622,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/qs": {
|
"node_modules/qs": {
|
||||||
"version": "6.14.0",
|
"version": "6.14.1",
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.1.tgz",
|
||||||
"integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==",
|
"integrity": "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"side-channel": "^1.1.0"
|
"side-channel": "^1.1.0"
|
||||||
|
|
@ -17861,18 +17861,18 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/stripe": {
|
"node_modules/stripe": {
|
||||||
"version": "18.4.0",
|
"version": "20.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/stripe/-/stripe-18.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/stripe/-/stripe-20.1.2.tgz",
|
||||||
"integrity": "sha512-LKFeDnDYo4U/YzNgx2Lc9PT9XgKN0JNF1iQwZxgkS4lOw5NunWCnzyH5RhTlD3clIZnf54h7nyMWkS8VXPmtTQ==",
|
"integrity": "sha512-qU+lQRRJnTxmyvglYBPE24/IepncmywsAg0GDTsTdP2pb+3e3RdREHJZjKgqCmv0phPxN/nmgNPnIPPH8w0P4A==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"qs": "^6.11.0"
|
"qs": "^6.14.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12.*"
|
"node": ">=16"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@types/node": ">=12.x.x"
|
"@types/node": ">=16"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@
|
||||||
"react-use": "^17.6.0",
|
"react-use": "^17.6.0",
|
||||||
"recharts": "^2.15.4",
|
"recharts": "^2.15.4",
|
||||||
"sharp": "^0.34.3",
|
"sharp": "^0.34.3",
|
||||||
"stripe": "^18.4.0",
|
"stripe": "^20.1.2",
|
||||||
"superjson": "2.2.2",
|
"superjson": "2.2.2",
|
||||||
"tailwind-merge": "3.3",
|
"tailwind-merge": "3.3",
|
||||||
"tailwind-scrollbar": "^4.0.2",
|
"tailwind-scrollbar": "^4.0.2",
|
||||||
|
|
|
||||||
|
|
@ -628,6 +628,7 @@ export const en: LangDict = {
|
||||||
},
|
},
|
||||||
{ href: "/area-riservata/admin/storage", title: "Storage" },
|
{ href: "/area-riservata/admin/storage", title: "Storage" },
|
||||||
{ href: "/area-riservata/admin/blacklist", title: "Black-list" },
|
{ href: "/area-riservata/admin/blacklist", title: "Black-list" },
|
||||||
|
{ href: "/area-riservata/admin/impostazioni", title: "Settings" },
|
||||||
],
|
],
|
||||||
title: "Settings",
|
title: "Settings",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -633,6 +633,7 @@ export const it: LangDict = {
|
||||||
},
|
},
|
||||||
{ href: "/area-riservata/admin/storage", title: "Allegati" },
|
{ href: "/area-riservata/admin/storage", title: "Allegati" },
|
||||||
{ href: "/area-riservata/admin/blacklist", title: "Black-list" },
|
{ href: "/area-riservata/admin/blacklist", title: "Black-list" },
|
||||||
|
{ href: "/area-riservata/admin/impostazioni", title: "Impostazioni" },
|
||||||
],
|
],
|
||||||
title: "Impostazioni",
|
title: "Impostazioni",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,87 @@
|
||||||
|
import Head from "next/head";
|
||||||
|
import { AreaRiservataLayout } from "~/components/Layout";
|
||||||
|
import type { NextPageWithLayout } from "~/pages/_app";
|
||||||
|
import { useTranslation } from "~/providers/I18nProvider";
|
||||||
|
import { api } from "~/utils/api";
|
||||||
|
|
||||||
|
const Impostazioni: NextPageWithLayout = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{t.heads.area_riservata_titolo}</title>
|
||||||
|
<meta content={t.heads.area_riservata_description} name="description" />
|
||||||
|
</Head>
|
||||||
|
|
||||||
|
<div className="mx-3 flex flex-1 flex-col gap-4 overflow-auto pt-5">
|
||||||
|
<div className="items-start justify-between md:flex">
|
||||||
|
<div className="mx-1 flex items-center">
|
||||||
|
<h3 className="font-bold text-2xl">Impostazioni</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<StripeSection />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default Impostazioni;
|
||||||
|
|
||||||
|
// export const getServerSideProps = (async (context) => {
|
||||||
|
// const access_token = context.req.cookies.access_token;
|
||||||
|
|
||||||
|
// const helpers = await TrpcAuthedFetchingIstance({ access_token });
|
||||||
|
// if (helpers) {
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// props: {
|
||||||
|
// trpcState: helpers.trpc.dehydrate(),
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// return {
|
||||||
|
// props: {},
|
||||||
|
// };
|
||||||
|
// }) satisfies GetServerSideProps;
|
||||||
|
|
||||||
|
Impostazioni.getLayout = function getLayout(page) {
|
||||||
|
return <AreaRiservataLayout>{page}</AreaRiservataLayout>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const StripeSection = () => {
|
||||||
|
const { data, isLoading } = api.stripe.health.useQuery();
|
||||||
|
if (isLoading) {
|
||||||
|
return <div>Loading...</div>;
|
||||||
|
}
|
||||||
|
console.log(data);
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border p-4">
|
||||||
|
<h4 className="mb-2 font-semibold text-lg">
|
||||||
|
Stripe Status: {data?.success ? "Sano" : "Non sano"}
|
||||||
|
</h4>
|
||||||
|
<p>Endpoint Webhook:</p>
|
||||||
|
{data?.endpoints?.data.map((endpoint) => (
|
||||||
|
<div className="mb-2" key={endpoint.id}>
|
||||||
|
<p>
|
||||||
|
ID: <code>{endpoint.id}</code>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
URL: <code>{endpoint.url}</code>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>Eventi attivi: </p>
|
||||||
|
<ul className="list-inside list-disc">
|
||||||
|
{endpoint.enabled_events.map((event) => (
|
||||||
|
<li key={event}>{event}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
<p>Versione Api: {endpoint.api_version}</p>
|
||||||
|
<p>
|
||||||
|
Stato: <code>{endpoint.status}</code>
|
||||||
|
</p>
|
||||||
|
<hr className="my-2" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
@ -6,6 +6,7 @@ import {
|
||||||
} from "~/server/api/trpc";
|
} from "~/server/api/trpc";
|
||||||
import {
|
import {
|
||||||
createIntentHandler,
|
createIntentHandler,
|
||||||
|
stripeHealthCheck,
|
||||||
whIntentCreatedHandler,
|
whIntentCreatedHandler,
|
||||||
whIntentFailedHandler,
|
whIntentFailedHandler,
|
||||||
whIntentSucceededHandler,
|
whIntentSucceededHandler,
|
||||||
|
|
@ -13,6 +14,9 @@ import {
|
||||||
import { zPagamentoId } from "~/server/utils/zod_types";
|
import { zPagamentoId } from "~/server/utils/zod_types";
|
||||||
|
|
||||||
export const stripeRouter = createTRPCRouter({
|
export const stripeRouter = createTRPCRouter({
|
||||||
|
health: publicProcedure.query(async () => {
|
||||||
|
return await stripeHealthCheck();
|
||||||
|
}),
|
||||||
createIntent: protectedProcedure
|
createIntent: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,16 @@ import { getUser } from "~/server/services/user.service";
|
||||||
|
|
||||||
const stripeApi = new Stripe(env.STRIPE_SECRET_KEY);
|
const stripeApi = new Stripe(env.STRIPE_SECRET_KEY);
|
||||||
|
|
||||||
|
export const stripeHealthCheck = async () => {
|
||||||
|
try {
|
||||||
|
const endpoints = await stripeApi.webhookEndpoints.list();
|
||||||
|
return { success: true, endpoints };
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Stripe health check failed:", e);
|
||||||
|
return { success: false, endpoints: null };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const createIntentHandler = async ({
|
export const createIntentHandler = async ({
|
||||||
paymentId,
|
paymentId,
|
||||||
}: {
|
}: {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue