feat: integrate email event queue for payment confirmation with attachments

This commit is contained in:
Marco Pedone 2026-03-04 20:22:17 +01:00
parent 81337c852f
commit b500c7133f

View file

@ -13,6 +13,7 @@ import {
genPdfCondizioniBase64, genPdfCondizioniBase64,
genPdfRicevutaCortesiaBase64, genPdfRicevutaCortesiaBase64,
} from "../services/puppeteer.service"; } from "../services/puppeteer.service";
import { addEventToQueue } from "./event_queue.controller";
export const stripeHealthCheck = async () => { export const stripeHealthCheck = async () => {
try { try {
@ -167,34 +168,44 @@ export const whIntentSucceededHandler = async ({
}) })
.execute(); .execute();
//SERVIZIO ATTIVATO //TODO inserire gli allegati solo se si ha il pdf generato
await NewMail({ await addEventToQueue({
template: { data: {
mailType: "servizioAttivato", tipo: "email",
}, data: {
mail: { template: {
subject: "Pagamento Confermato - Acconto Infoalloggi.it", mailType: "servizioAttivato",
to: utente.email,
attachments: [
{
filename: `condizioni_contrattuali_${ordine.created_at.toISOString()}.pdf`,
//ATTENTION: hardcoded condizioni key
content: await genPdfCondizioniBase64(
"CONDIZIONI_CERCHI" as TestiEStringheStingaId,
),
encoding: "base64",
contentType: "application/pdf",
}, },
{ mail: {
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`, subject: "Pagamento Confermato - Acconto Infoalloggi.it",
content: await genPdfRicevutaCortesiaBase64(ordine.ordine_id), to: utente.email,
encoding: "base64", attachments: [
contentType: "application/pdf", {
filename: `condizioni_contrattuali_${ordine.created_at.toISOString()}.pdf`,
//ATTENTION: hardcoded condizioni key
content: await genPdfCondizioniBase64(
"CONDIZIONI_CERCHI" as TestiEStringheStingaId,
),
encoding: "base64",
contentType: "application/pdf",
},
{
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
content: await genPdfRicevutaCortesiaBase64(
ordine.ordine_id,
),
encoding: "base64",
contentType: "application/pdf",
},
],
}, },
], userId: utente.id,
},
}, },
userId: utente.id, lock_expires: new Date(Date.now() + 60 * 1000), // Lock for 1 minute
}); });
//SERVIZIO ATTIVATO
break; break;
case OrderTypeEnum.Saldo: case OrderTypeEnum.Saldo:
@ -207,24 +218,33 @@ export const whIntentSucceededHandler = async ({
isOkSaldo: true, isOkSaldo: true,
}) })
.execute(); .execute();
await NewMail({ await addEventToQueue({
template: { data: {
mailType: "pagamentoConferma", tipo: "email",
}, data: {
mail: { template: {
subject: "Pagamento Confermato - Saldo Infoalloggi.it", mailType: "pagamentoConferma",
to: utente.email,
attachments: [
{
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
content: await genPdfRicevutaCortesiaBase64(ordine.ordine_id),
encoding: "base64",
contentType: "application/pdf",
}, },
], mail: {
subject: "Pagamento Confermato - Saldo Infoalloggi.it",
to: utente.email,
attachments: [
{
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
content: await genPdfRicevutaCortesiaBase64(
ordine.ordine_id,
),
encoding: "base64",
contentType: "application/pdf",
},
],
},
userId: utente.id,
},
}, },
userId: utente.id, lock_expires: new Date(Date.now() + 60 * 1000), // Lock for 1 minute
}); });
//PAGAMENTO SALDO CONFERMATO
break; break;
case OrderTypeEnum.Consulenza: case OrderTypeEnum.Consulenza:
await trx await trx
@ -234,44 +254,61 @@ export const whIntentSucceededHandler = async ({
isOkConsulenza: true, isOkConsulenza: true,
}) })
.execute(); .execute();
await NewMail({ await addEventToQueue({
template: { data: {
mailType: "pagamentoConferma", tipo: "email",
}, data: {
mail: { template: {
subject: "Pagamento Confermato - Consulenza Infoalloggi.it", mailType: "pagamentoConferma",
to: utente.email,
attachments: [
{
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
content: await genPdfRicevutaCortesiaBase64(ordine.ordine_id),
encoding: "base64",
contentType: "application/pdf",
}, },
], mail: {
subject: "Pagamento Confermato - Consulenza Infoalloggi.it",
to: utente.email,
attachments: [
{
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
content: await genPdfRicevutaCortesiaBase64(
ordine.ordine_id,
),
encoding: "base64",
contentType: "application/pdf",
},
],
},
userId: utente.id,
},
}, },
userId: utente.id, lock_expires: new Date(Date.now() + 60 * 1000), // Lock for 1 minute
}); });
//CONSULENZA ATTIVATA
break; break;
case OrderTypeEnum.Altro: case OrderTypeEnum.Altro:
// TODO: Handle other types // TODO: Handle other types
await NewMail({ await addEventToQueue({
template: { data: {
mailType: "pagamentoConferma", tipo: "email",
}, data: {
mail: { template: {
subject: "Pagamento Confermato - Infoalloggi.it", mailType: "pagamentoConferma",
to: utente.email,
attachments: [
{
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
content: await genPdfRicevutaCortesiaBase64(ordine.ordine_id),
encoding: "base64",
contentType: "application/pdf",
}, },
], mail: {
subject: "Pagamento Confermato - Infoalloggi.it",
to: utente.email,
attachments: [
{
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
content: await genPdfRicevutaCortesiaBase64(
ordine.ordine_id,
),
encoding: "base64",
contentType: "application/pdf",
},
],
},
userId: utente.id,
},
}, },
userId: utente.id, lock_expires: new Date(Date.now() + 60 * 1000), // Lock for 1 minute
}); });
break; break;
} }