feat: enhance ComuniTable by adding nullable cap field
This commit is contained in:
parent
4f9a46d1d2
commit
572a5420c1
2 changed files with 80 additions and 67 deletions
|
|
@ -35,80 +35,91 @@ const handler = async (
|
||||||
const createCaller = t.createCallerFactory(appRouter);
|
const createCaller = t.createCallerFactory(appRouter);
|
||||||
const caller = createCaller(ctx);
|
const caller = createCaller(ctx);
|
||||||
|
|
||||||
// Handle the event
|
try {
|
||||||
switch (event.type) {
|
// Handle the event
|
||||||
case "payment_intent.created": {
|
switch (event.type) {
|
||||||
const paymentIntent = event.data.object;
|
case "payment_intent.created": {
|
||||||
const { id, metadata } = paymentIntent;
|
const paymentIntent = event.data.object;
|
||||||
|
const { id, metadata } = paymentIntent;
|
||||||
|
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
res.status(400).send("No metadata in payment intent");
|
res.status(400).send("No metadata in payment intent");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!metadata.paymentId ||
|
||||||
|
!(typeof metadata.paymentId === "string")
|
||||||
|
) {
|
||||||
|
res.status(400).send("No orderId or userId in metadata");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await caller.stripe.whIntentCreated({
|
||||||
|
paymentId: metadata.paymentId as PaymentsId,
|
||||||
|
pIntentId: id,
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!metadata.paymentId || !(typeof metadata.paymentId === "string")) {
|
case "payment_intent.succeeded": {
|
||||||
res.status(400).send("No orderId or userId in metadata");
|
const paymentIntent = event.data.object;
|
||||||
return;
|
const { id, metadata } = paymentIntent;
|
||||||
|
|
||||||
|
if (!metadata) {
|
||||||
|
res.status(400).send("No metadata in payment intent");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!metadata.paymentId ||
|
||||||
|
!(typeof metadata.paymentId === "string")
|
||||||
|
) {
|
||||||
|
res.status(400).send("No orderId or userId in metadata");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await caller.stripe.whIntentSucceeded({
|
||||||
|
paymentId: metadata.paymentId as PaymentsId,
|
||||||
|
pIntentId: id,
|
||||||
|
pm_id:
|
||||||
|
typeof paymentIntent.payment_method === "string"
|
||||||
|
? paymentIntent.payment_method
|
||||||
|
: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "payment_intent.canceled": {
|
||||||
|
const paymentIntent = event.data.object;
|
||||||
|
await caller.stripe.whIntentFailed({
|
||||||
|
pIntentId: paymentIntent.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "payment_intent.payment_failed": {
|
||||||
|
const paymentIntent = event.data.object;
|
||||||
|
await caller.stripe.whIntentFailed({
|
||||||
|
pIntentId: paymentIntent.id,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "payment_intent.processing": {
|
||||||
|
//const paymentIntent = event.data.object;
|
||||||
|
|
||||||
|
//console.log("PaymentIntent processing", paymentIntent);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await caller.stripe.whIntentCreated({
|
default:
|
||||||
paymentId: metadata.paymentId as PaymentsId,
|
//console.log(`Unhandled event type: ${event.type}`);
|
||||||
pIntentId: id,
|
break;
|
||||||
});
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "payment_intent.succeeded": {
|
|
||||||
const paymentIntent = event.data.object;
|
|
||||||
const { id, metadata } = paymentIntent;
|
|
||||||
|
|
||||||
if (!metadata) {
|
|
||||||
res.status(400).send("No metadata in payment intent");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!metadata.paymentId || !(typeof metadata.paymentId === "string")) {
|
|
||||||
res.status(400).send("No orderId or userId in metadata");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await caller.stripe.whIntentSucceeded({
|
|
||||||
paymentId: metadata.paymentId as PaymentsId,
|
|
||||||
pIntentId: id,
|
|
||||||
pm_id:
|
|
||||||
typeof paymentIntent.payment_method === "string"
|
|
||||||
? paymentIntent.payment_method
|
|
||||||
: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "payment_intent.canceled": {
|
|
||||||
const paymentIntent = event.data.object;
|
|
||||||
await caller.stripe.whIntentFailed({
|
|
||||||
pIntentId: paymentIntent.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "payment_intent.payment_failed": {
|
|
||||||
const paymentIntent = event.data.object;
|
|
||||||
await caller.stripe.whIntentFailed({
|
|
||||||
pIntentId: paymentIntent.id,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "payment_intent.processing": {
|
|
||||||
//const paymentIntent = event.data.object;
|
|
||||||
|
|
||||||
//console.log("PaymentIntent processing", paymentIntent);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
res.status(200).json({ received: true });
|
||||||
//console.log(`Unhandled event type: ${event.type}`);
|
} catch (error) {
|
||||||
break;
|
console.error("Error handling webhook event:", error);
|
||||||
|
res.status(200).json({ received: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({ received: true });
|
|
||||||
} else {
|
} else {
|
||||||
res.setHeader("Allow", "POST");
|
res.setHeader("Allow", "POST");
|
||||||
res.status(405).end("Method Not Allowed");
|
res.status(405).end("Method Not Allowed");
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ export default interface ComuniTable {
|
||||||
sigla: ColumnType<string, string, string>;
|
sigla: ColumnType<string, string, string>;
|
||||||
|
|
||||||
catasto: ColumnType<string, string, string>;
|
catasto: ColumnType<string, string, string>;
|
||||||
|
|
||||||
|
cap: ColumnType<string | null, string | null, string | null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Comuni = Selectable<ComuniTable>;
|
export type Comuni = Selectable<ComuniTable>;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue