Skip to content

Commit

Permalink
Issue #396
Browse files Browse the repository at this point in the history
Corretto problema dell'invio delle notifiche di pagamento tramite AppIo.
  • Loading branch information
pintorig committed Oct 15, 2021
1 parent 0057e7f commit 3bd77f0
Show file tree
Hide file tree
Showing 27 changed files with 364 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ secimInviaTracciatoEmail=Spedito flusso Secim via Email
secimInviaTracciatoFileSystem=Salvato flusso Secim su file system
submitMessageforUserWithFiscalCodeInBody=Inviata avvisatura a backend AppIO
submitMessageforUserWithFiscalCodeInBodyScadenza=Inviato promemoria scadenza a backend AppIO
submitMessageforUserWithFiscalCodeInBodyRicevuta=Inviata ricevuta di pagamento a backend AppIO
updateApplicazione=Configura applicazione
updateOperatore=Configura operatore
updatePagamento=Configura pagamento
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Gentile ${versamento.getAnagraficaDebitore().getRagioneSociale()},

<#assign dataRichiesta = rpt.getDataMsgRichiesta()?string("yyyy-MM-dd HH:mm:ss")>
Il pagamento di "${versamento.getCausaleVersamento().getSimple()}" effettuato il ${dataRichiesta} risulta concluso con esito ${rpt.getEsitoPagamento().name()}:

Ente creditore: ${dominio.getRagioneSociale()} (${dominio.getCodDominio()})
Istituto attestante: ${rpt.getDenominazioneAttestante()} (${rpt.getIdentificativoAttestante()})
Identificativo univoco versamento (IUV): ${rpt.getIuv()}
Codice contesto pagamento (CCP): ${rpt.getCcp()}
Importo pagato: ${rpt.getImportoTotalePagato()}

Distinti saluti.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<#if rpt.getEsitoPagamento().getCodifica() = 0>
Notifica pagamento eseguito: ${rpt.getCodDominio()}/${rpt.getIuv()}/${rpt.getCcp()}
<#elseif rpt.getEsitoPagamento().getCodifica() = 1>
Notifica pagamento non eseguito: ${rpt.getCodDominio()}/${rpt.getIuv()}/${rpt.getCcp()}
<#elseif rpt.getEsitoPagamento().getCodifica() = 2>
Notifica pagamento eseguito parzialmente: ${rpt.getCodDominio()}/${rpt.getIuv()}/${rpt.getCcp()}
<#elseif rpt.getEsitoPagamento().getCodifica() = 3>
Notifica decorrenza termini pagamento: ${rpt.getCodDominio()}/${rpt.getIuv()}/${rpt.getCcp()}
<#elseif rpt.getEsitoPagamento().getCodifica() = 4>
Notifica decorrenza termini pagamento: ${rpt.getCodDominio()}/${rpt.getIuv()}/${rpt.getCcp()}
</#if>
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Background:
"""

* def tipoPendenzaDominio_appIO_apiKey = 'ABC...........'
* def tipoPendenzaDominio_appIO_apiKeyErrata = 'API_KEY_ERRATA'
* def tipoPendenzaDominio_appIO =
"""
{
Expand All @@ -73,7 +72,10 @@ Background:
abilitato: true,
"tipo": "freemarker"
},
"promemoriaRicevuta": null,
"promemoriaRicevuta": {
abilitato: true,
"tipo": "freemarker"
},
"promemoriaScadenza": null
}
}
Expand All @@ -82,6 +84,9 @@ Background:
* set configurazione_avvisaturaAppIO.promemoriaAvviso.oggetto = encodeBase64InputStream(read('classpath:configurazione/v1/msg/appio-subject-freemarker.ftl'))
* set configurazione_avvisaturaAppIO.promemoriaAvviso.messaggio = encodeBase64InputStream(read('classpath:configurazione/v1/msg/appio-body-freemarker.ftl'))

* set configurazione_avvisaturaAppIO.promemoriaRicevuta.oggetto = encodeBase64InputStream(read('classpath:configurazione/v1/msg/appio-subject-ricevuta-freemarker.ftl'))
* set configurazione_avvisaturaAppIO.promemoriaRicevuta.messaggio = encodeBase64InputStream(read('classpath:configurazione/v1/msg/appio-body-ricevuta-freemarker.ftl'))

* def debitoreNoAuthAppIO =
"""
{
Expand Down Expand Up @@ -352,7 +357,7 @@ Given url backofficeBaseurl
And path '/eventi'
And param idA2A = idA2A
And param idPendenza = idPendenza
And param tipoEvento = 'submitMessageforUserWithFiscalCodeInBody'
And param tipoEvento = 'submitMessageforUserWithFiscalCodeInBodyRicevuta'
And param messaggi = true
And headers gpAdminBasicAutenticationHeader
When method get
Expand Down Expand Up @@ -380,7 +385,7 @@ And match response.risultati[0] ==
"componente": "API_BACKEND_IO",
"categoriaEvento": "INTERFACCIA",
"ruolo": "CLIENT",
"tipoEvento": "submitMessageforUserWithFiscalCodeInBody",
"tipoEvento": "submitMessageforUserWithFiscalCodeInBodyRicevuta",
"sottotipoEvento": "##null",
"esito": "OK",
"sottotipoEsito": "201",
Expand Down
13 changes: 13 additions & 0 deletions jars/core/src/main/java/it/govpay/core/utils/CtReceiptUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
import it.govpay.bd.anagrafica.AnagraficaManager;
import it.govpay.bd.model.Dominio;
import it.govpay.bd.model.Notifica;
import it.govpay.bd.model.NotificaAppIo;
import it.govpay.bd.model.Pagamento;
import it.govpay.bd.model.Promemoria;
import it.govpay.bd.model.Rpt;
import it.govpay.bd.model.SingoloVersamento;
import it.govpay.bd.model.TipoVersamentoDominio;
import it.govpay.bd.model.Versamento;
import it.govpay.bd.pagamento.NotificheAppIoBD;
import it.govpay.bd.pagamento.PagamentiBD;
import it.govpay.bd.pagamento.PromemoriaBD;
import it.govpay.bd.pagamento.RptBD;
Expand Down Expand Up @@ -555,6 +557,17 @@ public static Rpt acquisisciRT(String codDominio, String iuv, PaSendRTReq ctRt,
log.error("Errore durante la lettura dei dati della RT: ", e.getMessage(),e);
}
}

//schedulo l'invio della notifica APPIO
if(tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaRicevutaAbilitato()) {
log.debug("Creo notifica avvisatura ricevuta tramite App IO...");
NotificaAppIo notificaAppIo = new NotificaAppIo(rpt, versamento, it.govpay.model.NotificaAppIo.TipoNotifica.RICEVUTA, configWrapper);
log.debug("Creazione notifica avvisatura ricevuta tramite App IO completata.");
NotificheAppIoBD notificheAppIoBD = new NotificheAppIoBD(versamentiBD);
notificheAppIoBD.setAtomica(false); // riuso connessione
notificheAppIoBD.insertNotifica(notificaAppIo);
log.debug("Inserimento su DB notifica avvisatura ricevuta tramite App IO completata.");
}

// Aggiornamento dello stato del pagamento portale associato all'RPT
// Long idPagamentoPortale = rpt.getIdPagamentoPortale();
Expand Down
13 changes: 13 additions & 0 deletions jars/core/src/main/java/it/govpay/core/utils/RtUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@
import it.gov.digitpa.schemas._2011.pagamenti.CtRichiestaPagamentoTelematico;
import it.govpay.bd.BDConfigWrapper;
import it.govpay.bd.model.Notifica;
import it.govpay.bd.model.NotificaAppIo;
import it.govpay.bd.model.Pagamento;
import it.govpay.bd.model.Promemoria;
import it.govpay.bd.model.Rpt;
import it.govpay.bd.model.SingoloVersamento;
import it.govpay.bd.model.TipoVersamentoDominio;
import it.govpay.bd.model.Versamento;
import it.govpay.bd.pagamento.NotificheAppIoBD;
import it.govpay.bd.pagamento.PagamentiBD;
import it.govpay.bd.pagamento.PromemoriaBD;
import it.govpay.bd.pagamento.RptBD;
Expand Down Expand Up @@ -668,6 +670,17 @@ public static Rpt acquisisciRT(String codDominio, String iuv, String ccp, byte[]
}
}

//schedulo l'invio della notifica APPIO
if(tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaRicevutaAbilitato()) {
log.debug("Creo notifica avvisatura ricevuta tramite App IO...");
NotificaAppIo notificaAppIo = new NotificaAppIo(rpt, versamento, it.govpay.model.NotificaAppIo.TipoNotifica.RICEVUTA, configWrapper);
log.debug("Creazione notifica avvisatura ricevuta tramite App IO completata.");
NotificheAppIoBD notificheAppIoBD = new NotificheAppIoBD(versamentiBD);
notificheAppIoBD.setAtomica(false); // riuso connessione
notificheAppIoBD.insertNotifica(notificaAppIo);
log.debug("Inserimento su DB notifica avvisatura ricevuta tramite App IO completata.");
}

// Aggiornamento dello stato del pagamento portale associato all'RPT
// Long idPagamentoPortale = rpt.getIdPagamentoPortale();
if(idPagamentoPortale != null) {
Expand Down
46 changes: 35 additions & 11 deletions jars/core/src/main/java/it/govpay/core/utils/appio/AppIOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import org.slf4j.Logger;

import it.govpay.bd.configurazione.model.PromemoriaAvvisoBase;
import it.govpay.bd.configurazione.model.PromemoriaRicevutaBase;
import it.govpay.bd.configurazione.model.PromemoriaScadenza;
import it.govpay.bd.model.Dominio;
import it.govpay.bd.model.Rpt;
import it.govpay.bd.model.TipoVersamentoDominio;
import it.govpay.bd.model.Versamento;
import it.govpay.core.beans.EsitoOperazione;
Expand All @@ -26,7 +29,7 @@

public class AppIOUtils {

public static NewMessage creaNuovoMessaggioAvvisoPagamento(Logger log, Versamento versamento, TipoVersamentoDominio tipoVersamentoDominio, PromemoriaAvvisoBase configurazionePromemoriaAvviso, BigDecimal timeToLive) throws GovPayException {
public static NewMessage creaNuovoMessaggioAvvisoPagamento(Logger log, Versamento versamento, Dominio dominio, TipoVersamentoDominio tipoVersamentoDominio, PromemoriaAvvisoBase configurazionePromemoriaAvviso, BigDecimal timeToLive) throws GovPayException {
String appIOMessaggio = tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaAvvisoMessaggio();
String appIOOggetto = tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaAvvisoOggetto();
String appIOTipo = tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaAvvisoTipo();
Expand All @@ -43,11 +46,11 @@ public static NewMessage creaNuovoMessaggioAvvisoPagamento(Logger log, Versament
appIOTipo = configurazionePromemoriaAvviso.getTipo();
}

NewMessage messageWithCF = AppIOUtils.getPostMessage(log, appIOTipo, appIOOggetto, appIOMessaggio, timeToLive, versamento, true);
NewMessage messageWithCF = AppIOUtils.getPostMessage(log, appIOTipo, appIOOggetto, appIOMessaggio, timeToLive, versamento, null, dominio, true);
return messageWithCF;
}

public static NewMessage creaNuovoMessaggioScadenzaPagamento(Logger log, Versamento versamento, TipoVersamentoDominio tipoVersamentoDominio, PromemoriaScadenza configurazionePromemoriaScadenza, BigDecimal timeToLive) throws GovPayException {
public static NewMessage creaNuovoMessaggioScadenzaPagamento(Logger log, Versamento versamento, Dominio dominio, TipoVersamentoDominio tipoVersamentoDominio, PromemoriaScadenza configurazionePromemoriaScadenza, BigDecimal timeToLive) throws GovPayException {
String appIOMessaggio = tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaScadenzaMessaggio();
String appIOOggetto = tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaScadenzaOggetto();
String appIOTipo = tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaScadenzaTipo();
Expand All @@ -64,11 +67,32 @@ public static NewMessage creaNuovoMessaggioScadenzaPagamento(Logger log, Versame
appIOTipo = configurazionePromemoriaScadenza.getTipo();
}

NewMessage messageWithCF = AppIOUtils.getPostMessage(log, appIOTipo, appIOOggetto, appIOMessaggio, timeToLive, versamento, false);
NewMessage messageWithCF = AppIOUtils.getPostMessage(log, appIOTipo, appIOOggetto, appIOMessaggio, timeToLive, versamento, null, dominio, false);
return messageWithCF;
}

public static NewMessage creaNuovoMessaggioRicevutaPagamento(Logger log, Versamento versamento, Rpt rpt, Dominio dominio, TipoVersamentoDominio tipoVersamentoDominio, PromemoriaRicevutaBase configurazionePromemoriaRicevuta, BigDecimal timeToLive) throws GovPayException {
String appIOMessaggio = tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaRicevutaMessaggio();
String appIOOggetto = tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaRicevutaOggetto();
String appIOTipo = tipoVersamentoDominio.getAvvisaturaAppIoPromemoriaRicevutaTipo();

boolean usaConfigurazioneSistema = true;

if(appIOMessaggio != null && appIOOggetto != null && appIOTipo != null) {
usaConfigurazioneSistema = false;
}

if(usaConfigurazioneSistema) {
appIOMessaggio = configurazionePromemoriaRicevuta.getMessaggio();
appIOOggetto = configurazionePromemoriaRicevuta.getOggetto();
appIOTipo = configurazionePromemoriaRicevuta.getTipo();
}

NewMessage messageWithCF = AppIOUtils.getPostMessage(log, appIOTipo, appIOOggetto, appIOMessaggio, timeToLive, versamento, rpt, dominio, false);
return messageWithCF;
}

public static NewMessage getPostMessage(Logger log, String tipo, String oggetto, String messaggio, BigDecimal timeToLive, Versamento versamento, boolean includePaymentData) throws GovPayException {
public static NewMessage getPostMessage(Logger log, String tipo, String oggetto, String messaggio, BigDecimal timeToLive, Versamento versamento, Rpt rpt, Dominio dominio, boolean includePaymentData) throws GovPayException {
NewMessage message = new NewMessage();

if(timeToLive != null)
Expand All @@ -77,8 +101,8 @@ public static NewMessage getPostMessage(Logger log, String tipo, String oggetto,
message.setFiscalCode(versamento.getAnagraficaDebitore().getCodUnivoco());
MessageContent content = new MessageContent();

String subject = trasformazioneSubject(log, versamento, tipo, oggetto);
String markdown = trasformazioneMarkdown(log, versamento, tipo, messaggio);
String subject = trasformazioneSubject(log, versamento, rpt, dominio, tipo, oggetto);
String markdown = trasformazioneMarkdown(log, versamento, rpt, dominio, tipo, messaggio);

content.setSubject(subject);
content.setMarkdown(markdown);
Expand Down Expand Up @@ -124,7 +148,7 @@ public static NewMessage getPostMessage(Logger log, String tipo, String oggetto,
}


public static String trasformazioneSubject(Logger log, Versamento versamento, String tipoTemplate, String templateTrasformazione) throws GovPayException {
public static String trasformazioneSubject(Logger log, Versamento versamento, Rpt rpt, Dominio dominio, String tipoTemplate, String templateTrasformazione) throws GovPayException {
log.debug("Generazione del Subject della Notifica AppIO tramite template freemarker ...");
String name = "TrasformazioneSubjectAppIO";
try {
Expand All @@ -139,7 +163,7 @@ public static String trasformazioneSubject(Logger log, Versamento versamento, St
//log.debug("Template: "+ new String(template) );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Map<String, Object> dynamicMap = new HashMap<String, Object>();
TrasformazioniUtils.fillDynamicMapSubjectMessageAppIO(log, dynamicMap, ContextThreadLocal.get(), versamento);
TrasformazioniUtils.fillDynamicMapSubjectMessageAppIO(log, dynamicMap, ContextThreadLocal.get(), versamento, rpt, dominio);
TrasformazioniUtils.convertFreeMarkerTemplate(name, template , dynamicMap , baos );
// assegno il json trasformato
log.debug("Generazione del Subject della Notifica AppIO tramite template freemarker completata con successo.");
Expand All @@ -154,7 +178,7 @@ public static String trasformazioneSubject(Logger log, Versamento versamento, St
}
}

public static String trasformazioneMarkdown(Logger log, Versamento versamento, String tipoTemplate, String templateTrasformazione) throws GovPayException {
public static String trasformazioneMarkdown(Logger log, Versamento versamento, Rpt rpt, Dominio dominio, String tipoTemplate, String templateTrasformazione) throws GovPayException {
log.debug("Generazione del Markdown della Notifica AppIO tramite template freemarker ...");
String name = "TrasformazioneMarkdownAppIO";
try {
Expand All @@ -169,7 +193,7 @@ public static String trasformazioneMarkdown(Logger log, Versamento versamento, S
//log.debug("Template: "+ new String(template) );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Map<String, Object> dynamicMap = new HashMap<String, Object>();
TrasformazioniUtils.fillDynamicMapMarkdownMessageAppIO(log, dynamicMap, ContextThreadLocal.get(), versamento);
TrasformazioniUtils.fillDynamicMapMarkdownMessageAppIO(log, dynamicMap, ContextThreadLocal.get(), versamento, rpt, dominio);
TrasformazioniUtils.convertFreeMarkerTemplate(name, template , dynamicMap , baos );
// assegno il json trasformato
log.debug("Generazione del Markdown della Notifica AppIO tramite template freemarker completata con successo.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
import org.slf4j.MDC;

import it.govpay.bd.BDConfigWrapper;
import it.govpay.bd.anagrafica.AnagraficaManager;
import it.govpay.bd.configurazione.model.AppIOBatch;
import it.govpay.bd.configurazione.model.AvvisaturaViaAppIo;
import it.govpay.bd.configurazione.model.Giornale;
import it.govpay.bd.configurazione.model.PromemoriaAvvisoBase;
import it.govpay.bd.configurazione.model.PromemoriaRicevutaBase;
import it.govpay.bd.configurazione.model.PromemoriaScadenza;
import it.govpay.bd.model.Configurazione;
import it.govpay.bd.model.Dominio;
import it.govpay.bd.model.NotificaAppIo;
import it.govpay.bd.model.Rpt;
import it.govpay.bd.model.TipoVersamentoDominio;
import it.govpay.bd.model.Versamento;
import it.govpay.bd.pagamento.EventiBD;
Expand All @@ -45,6 +49,7 @@ public class InviaNotificaAppIoThread implements Runnable{
public static final String SWAGGER_OPERATION_GET_PROFILE = "getProfile";
public static final String SWAGGER_OPERATION_POST_MESSAGE_AVVISO_PAGAMENTO = "submitMessageforUserWithFiscalCodeInBody";
public static final String SWAGGER_OPERATION_POST_MESSAGE_SCADENZA_PAGAMENTO = "submitMessageforUserWithFiscalCodeInBodyScadenza";
public static final String SWAGGER_OPERATION_POST_MESSAGE_RICEVUTA_PAGAMENTO = "submitMessageforUserWithFiscalCodeInBodyRicevuta";


private IContext ctx = null;
Expand Down Expand Up @@ -84,6 +89,8 @@ public void run() {
AppIoClient clientPostMessage = null;
boolean postMessage = false;
Versamento versamento = null;
Rpt rpt = null;
Dominio dominio = null;
BDConfigWrapper configWrapper = new BDConfigWrapper(this.ctx.getTransactionId(), true);
NotificheAppIoBD notificheBD = null;
try {
Expand Down Expand Up @@ -117,6 +124,8 @@ public void run() {
if(profile.isSenderAllowed()) { // spedizione abilitata procedo
postMessage = true;
versamento = this.notifica.getVersamento(configWrapper);
rpt = this.notifica.getRpt(configWrapper);
dominio = AnagraficaManager.getDominio(configWrapper, this.notifica.getCodDominio());
} else { // termino il processo indicando che la notifica non verra' spedita
clientGetProfile.getEventoCtx().setDescrizioneEsito("Utente non abilitato alla spedizione della notifica");
this.aggiornaNotificaAnnullata(notificheBD, "Utente non abilitato alla spedizione della notifica");
Expand Down Expand Up @@ -193,6 +202,7 @@ public void run() {
azione = SWAGGER_OPERATION_POST_MESSAGE_SCADENZA_PAGAMENTO;
break;
case RICEVUTA:
azione = SWAGGER_OPERATION_POST_MESSAGE_RICEVUTA_PAGAMENTO;
break;
}

Expand All @@ -218,13 +228,15 @@ public void run() {
switch (this.tipo) {
case AVVISO:
PromemoriaAvvisoBase promemoriaAvviso = this.avvisaturaViaAppIo.getPromemoriaAvviso() != null ? this.avvisaturaViaAppIo.getPromemoriaAvviso() : new PromemoriaAvvisoBase();
messageWithCF = AppIOUtils.creaNuovoMessaggioAvvisoPagamento(log, versamento, this.tipoVersamentoDominio, promemoriaAvviso, this.appIo.getTimeToLive());
messageWithCF = AppIOUtils.creaNuovoMessaggioAvvisoPagamento(log, versamento, dominio, this.tipoVersamentoDominio, promemoriaAvviso, this.appIo.getTimeToLive());
break;
case SCADENZA:
PromemoriaScadenza promemoriaScadenza = this.avvisaturaViaAppIo.getPromemoriaScadenza() != null ? this.avvisaturaViaAppIo.getPromemoriaScadenza() : new PromemoriaScadenza();
messageWithCF = AppIOUtils.creaNuovoMessaggioScadenzaPagamento(log, versamento, this.tipoVersamentoDominio, promemoriaScadenza, this.appIo.getTimeToLive());
messageWithCF = AppIOUtils.creaNuovoMessaggioScadenzaPagamento(log, versamento, dominio, this.tipoVersamentoDominio, promemoriaScadenza, this.appIo.getTimeToLive());
break;
case RICEVUTA:
PromemoriaRicevutaBase promemoriaRicevuta = this.avvisaturaViaAppIo.getPromemoriaRicevuta() != null ? this.avvisaturaViaAppIo.getPromemoriaRicevuta() : new PromemoriaRicevutaBase();
messageWithCF = AppIOUtils.creaNuovoMessaggioRicevutaPagamento(log, versamento, rpt, dominio, this.tipoVersamentoDominio, promemoriaRicevuta, this.appIo.getTimeToLive());
break;
}

Expand Down

0 comments on commit 3bd77f0

Please sign in to comment.