Skip to content

Commit

Permalink
[PAGOPA-1921] fix: resolved bug on paaInviaRT duplicated send (#46)
Browse files Browse the repository at this point in the history
* [PAGOPA-1921] fix: add iuv-domainId filter for paaInviaRT send
* [PAGOPA-1921] fix: resolved bug on null metadata
  • Loading branch information
andrea-deri authored Jul 4, 2024
1 parent 121b0d3 commit d7d74b1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ public void sendKoPaaInviaRtToCreditorInstitution(String payload) {
commonFields.getStationId());

/*
For each RPT extracted from session data, is necessary to generate a single paaInviaRT SOAP request.
For each RPT extracted from session data that is required by paSendRTV2, is necessary to generate a single paaInviaRT SOAP request.
Each paaInviaRT generated will be autonomously sent to creditor institution in order to track each RPT.
*/
for (RPTContentDTO rpt : sessionData.getAllRPTs()) {
List<RPTContentDTO> rpts = extractRequiredRPTs(sessionData, cachedMapping.getIuv(), cachedMapping.getFiscalCode());
for (RPTContentDTO rpt : rpts) {

// Generating the paaInviaRT payload from the RPT
String paymentOutcome = "Annullato da WISP"; // TODO change this with one of the following -> https://pagopa.atlassian.net/wiki/spaces/PN5/pages/913244345/WISP-Converter?focusedCommentId=1002078407
Expand Down Expand Up @@ -206,10 +207,11 @@ public void sendOkPaaInviaRtToCreditorInstitution(String payload) {
} else {

/*
For each RPT extracted from session data, is necessary to generate a single paaInviaRT SOAP request.
For each RPT extracted from session data that is required by paSendRTV2, is necessary to generate a single paaInviaRT SOAP request.
Each paaInviaRT generated will be autonomously sent to creditor institution in order to track each RPT.
*/
for (RPTContentDTO rpt : sessionData.getAllRPTs()) {
List<RPTContentDTO> rpts = extractRequiredRPTs(sessionData, receipt.getCreditorReferenceId(), receipt.getFiscalCode());
for (RPTContentDTO rpt : rpts) {

// generate the header for the paaInviaRT SOAP request. This object is different for each generated request
IntestazionePPT intestazionePPT = generateHeader(
Expand Down Expand Up @@ -326,6 +328,11 @@ From station identifier (the common one defined, not the payment reference), ret
return isSuccessful;
}

private List<RPTContentDTO> extractRequiredRPTs(SessionDataDTO sessionData, String iuv, String creditorInstiutionId) {
return sessionData.getAllRPTs().stream()
.filter(rpt -> rpt.getIuv().equals(iuv) && rpt.getRpt().getDomain().getDomainId().equals(creditorInstiutionId))
.toList();
}

private CtRicevutaTelematica generateRTContentForKoReceipt(RPTContentDTO rpt, Map<String, ConfigurationKeyDto> configurations, Instant now, String paymentOutcome) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public List<CtDatiSingoloPagamentoRT> toCtDatiSingoloPagamentoRTListForOkRT(CtRe
@Mapping(source = "ctReceiptV2.paymentDateTime", target = "dataEsitoSingoloPagamento")
@Mapping(source = "ctReceiptV2.receiptId", target = "identificativoUnivocoRiscossione")
@Mapping(source = "ctTransferPAReceiptV2.remittanceInformation", target = "causaleVersamento")
@Mapping(target = "datiSpecificiRiscossione", expression = "java(extractMetadata(ctTransferPAReceiptV2.getMetadata().getMapEntry()))")
@Mapping(target = "datiSpecificiRiscossione", expression = "java(ctTransferPAReceiptV2.getMetadata() != null ? extractMetadata(ctTransferPAReceiptV2.getMetadata().getMapEntry()) : \"\")")
@Mapping(source = "ctReceiptV2.fee", target = "commissioniApplicatePSP")
public abstract CtDatiSingoloPagamentoRT toCtDatiSingoloPagamentoRTForOkRT(CtTransferPAReceiptV2 ctTransferPAReceiptV2, CtReceiptV2 ctReceiptV2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void sendOkReceipt_notSent() throws Exception {
// mocking RPT retrieve
RPTRequestEntity rptRequestEntity = RPTRequestEntity.builder()
.primitive("nodoInviaRPT")
.payload(TestUtils.zipAndEncode(TestUtils.getRptPayload(false, STATION_ID, "100.00", "datispec")))
.payload(TestUtils.zipAndEncode(TestUtils.getRptPayload(false, STATION_ID, "77777777777", "48111111112222222", "100.00", "datispec")))
.build();
when(rptRequestRepository.findById(anyString())).thenReturn(Optional.of(rptRequestEntity));

Expand Down Expand Up @@ -406,12 +406,12 @@ void sendKoReceipt_notSent() throws Exception {
setConfigCacheStoredData("/creditorinstitution/station", 2);

// mocking decoupler cached keys
when(cacheRepository.read(anyString(), any())).thenReturn("wisp_nav2iuv_123456IUVMOCK1");
when(cacheRepository.read(anyString(), any())).thenReturn("wisp_{pa}_48111111112222222");

// mocking RPT retrieve
RPTRequestEntity rptRequestEntity = RPTRequestEntity.builder()
.primitive("nodoInviaRPT")
.payload(TestUtils.zipAndEncode(TestUtils.getRptPayload(false, STATION_ID, "100.00", "datispec")))
.payload(TestUtils.zipAndEncode(TestUtils.getRptPayload(false, STATION_ID, "{pa}", "48111111112222222", "100.00", "datispec")))
.build();
when(rptRequestRepository.findById(anyString())).thenReturn(Optional.of(rptRequestEntity));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,26 @@ public static String getInnerRptPayload(boolean bollo, String amount, String dat
.replaceAll("\\{amount}", amount);
}

public static String getRptPayload(boolean bollo, String station, String amount, String datiSpecificiRiscossione) {
public static String getRptPayload(boolean bollo, String station, String pa, String iuv, String amount, String datiSpecificiRiscossione) {
if (datiSpecificiRiscossione == null) {
datiSpecificiRiscossione = "9/tipodovuto_7/datospecifico";
}
String rpt = TestUtils.loadFileContent(bollo ? "/requests/rptBollo.xml" : "/requests/rpt.xml");
String rptreplace = rpt
.replace("{datiSpecificiRiscossione}", datiSpecificiRiscossione)
.replace("{pa}", pa)
.replace("{iuv}", iuv)
.replaceAll("\\{amount}", amount);
String nodoInviaRPT = TestUtils.loadFileContent("/requests/nodoInviaRPT.xml");
return nodoInviaRPT
.replace("{station}", station)
.replace("{rpt}", Base64.getEncoder().encodeToString(rptreplace.getBytes(StandardCharsets.UTF_8)));
}

public static String getRptPayload(boolean bollo, String station, String amount, String datiSpecificiRiscossione) {
return getRptPayload(bollo, station, "{pa}", "123456IUVMOCK1", amount, datiSpecificiRiscossione);
}

public static String getRptNullIbanPayload(String station, String amount, String datiSpecificiRiscossione) {
if (datiSpecificiRiscossione == null) {
datiSpecificiRiscossione = "9/tipodovuto_7/datospecifico";
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/requests/paSendRTV2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<transferCategory>0101100IM</transferCategory>
<metadata>
<mapEntry>
<key>keytest</key>
<key>datiSpecificiRiscossione</key>
<value>1</value>
</mapEntry>
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/requests/rpt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dataEsecuzionePagamento>{dataEsecuzionePagamento}</dataEsecuzionePagamento>
<importoTotaleDaVersare>{amount}</importoTotaleDaVersare>
<tipoVersamento>{tipoVersamento}</tipoVersamento>
<identificativoUnivocoVersamento>123456IUVMOCK1</identificativoUnivocoVersamento>
<identificativoUnivocoVersamento>{iuv}</identificativoUnivocoVersamento>
<codiceContestoPagamento>{ccp}</codiceContestoPagamento>
<firmaRicevuta>0</firmaRicevuta>
<datiSingoloVersamento>
Expand Down

0 comments on commit d7d74b1

Please sign in to comment.