diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/ReceiptPDFTemplate.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/ReceiptPDFTemplate.java index 04de2d9e..4ebf8dc4 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/ReceiptPDFTemplate.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/ReceiptPDFTemplate.java @@ -15,6 +15,7 @@ @JsonInclude(Include.NON_NULL) public class ReceiptPDFTemplate { + private String serviceCustomerId; private Transaction transaction; private User user; private Cart cart; diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/Transaction.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/Transaction.java index f406eef1..b56743ce 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/Transaction.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/model/template/Transaction.java @@ -11,7 +11,6 @@ @JsonInclude(Include.NON_NULL) public class Transaction { - private String id; private String timestamp; private String amount; private PSP psp; diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImpl.java index 4086feba..d64fbd4c 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImpl.java @@ -86,8 +86,8 @@ public class BuildTemplateServiceImpl implements BuildTemplateService { @Override public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTemplate) throws TemplateDataMappingException { return ReceiptPDFTemplate.builder() + .serviceCustomerId(getServiceCustomerId(bizEvent)) .transaction(Transaction.builder() - .id(getId(bizEvent)) .timestamp(getTimestamp(bizEvent)) .amount(getAmount(bizEvent)) .psp(getPsp(bizEvent)) @@ -134,23 +134,11 @@ public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTempla .build(); } - private String getId(BizEvent event) throws TemplateDataMappingException { - if ( - event.getTransactionDetails() != null && - event.getTransactionDetails().getTransaction() != null && - event.getTransactionDetails().getTransaction().getIdTransaction() != 0L - ) { - return String.valueOf(event.getTransactionDetails().getTransaction().getIdTransaction()); - } - if (event.getPaymentInfo() != null) { - if (event.getPaymentInfo().getPaymentToken() != null) { - return event.getPaymentInfo().getPaymentToken(); - } - if (event.getPaymentInfo().getIUR() != null) { - return event.getPaymentInfo().getIUR(); - } + private String getServiceCustomerId(BizEvent event) throws TemplateDataMappingException { + if (event.getId() != null) { + return event.getId(); } - throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.TRANSACTION_ID), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode()); + throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.SERVICE_CUSTOMER_ID), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode()); } private String getTimestamp(BizEvent event) throws TemplateDataMappingException { diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/utils/TemplateDataField.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/utils/TemplateDataField.java index 025ee329..c7b74800 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/utils/TemplateDataField.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/utils/TemplateDataField.java @@ -2,7 +2,7 @@ public class TemplateDataField { public static final String ERROR_MAPPING_MESSAGE = "Error mapping bizEvent data to template, missing property %s"; - public static final String TRANSACTION_ID = "transaction.id"; + public static final String SERVICE_CUSTOMER_ID = "serviceCustomerId"; public static final String TRANSACTION_TIMESTAMP = "transaction.timestamp"; public static final String TRANSACTION_AMOUNT = "transaction.amount"; public static final String TRANSACTION_RRN = "transaction.rrn"; diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImplTest.java index c2ce635e..fe47fb2b 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImplTest.java @@ -127,9 +127,9 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE); assertNotNull(receiptPdfTemplate); + assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction(); - assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId()); assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp()); assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount()); assertEquals(PSP_LOGO, transaction.getPsp().getLogo()); @@ -217,9 +217,9 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE); assertNotNull(receiptPdfTemplate); + assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction(); - assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId()); assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp()); assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount()); assertEquals(PSP_LOGO, transaction.getPsp().getLogo()); @@ -307,9 +307,9 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, PARTIAL_TEMPLATE); assertNotNull(receiptPdfTemplate); + assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction(); - assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId()); assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp()); assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount()); assertEquals(PSP_LOGO, transaction.getPsp().getLogo()); @@ -378,9 +378,9 @@ void mapTemplateWithoutTransactionDetailsSuccess() throws Exception { ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE); assertNotNull(receiptPdfTemplate); + assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction(); - assertEquals(PAYMENT_TOKEN, transaction.getId()); assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp()); assertEquals(FORMATTED_AMOUNT, transaction.getAmount()); assertEquals(PSP_LOGO, transaction.getPsp().getLogo()); @@ -449,9 +449,9 @@ void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Excepti ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE); assertNotNull(receiptPdfTemplate); + assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction(); - assertEquals(IUR, transaction.getId()); assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp()); assertEquals(FORMATTED_AMOUNT, transaction.getAmount()); assertEquals(PSP_LOGO, transaction.getPsp().getLogo()); @@ -526,7 +526,7 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception { .amount(AMOUNT_LONG) .fee(FEE_LONG) .rrn(RRN) - .authorizationCode(AUTH_CODE) + .numAut(AUTH_CODE) .creationDate(DATE_TIME_TIMESTAMP_ZONED) .psp(TransactionPsp.builder() .businessName(PSP_NAME) @@ -538,9 +538,9 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception { ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE); assertNotNull(receiptPdfTemplate); + assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction(); - assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId()); assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp()); assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount()); assertEquals(PSP_LOGO, transaction.getPsp().getLogo()); @@ -616,7 +616,7 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception .amount(AMOUNT_LONG) .fee(FEE_LONG) .rrn(RRN) - .authorizationCode(AUTH_CODE) + .numAut(AUTH_CODE) .creationDate(DATE_TIME_TIMESTAMP_ZONED) .psp(TransactionPsp.builder() .businessName(PSP_NAME) @@ -628,9 +628,9 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE); assertNotNull(receiptPdfTemplate); + assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction(); - assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId()); assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp()); assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount()); assertEquals(PSP_LOGO, transaction.getPsp().getLogo()); @@ -706,7 +706,7 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exceptio .amount(AMOUNT_LONG) .fee(FEE_LONG) .rrn(RRN) - .authorizationCode(AUTH_CODE) + .numAut(AUTH_CODE) .creationDate(DATE_TIME_TIMESTAMP_ZONED) .psp(TransactionPsp.builder() .businessName(PSP_NAME) @@ -718,9 +718,9 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exceptio ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE); assertNotNull(receiptPdfTemplate); + assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction(); - assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId()); assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp()); assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount()); assertEquals(PSP_LOGO, transaction.getPsp().getLogo()); @@ -759,6 +759,7 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exceptio @Test void mapTemplateLeastAmountOfInfoSuccess() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -794,17 +795,17 @@ void mapTemplateLeastAmountOfInfoSuccess() { } @Test - void mapTemplateNoTransactionIdError() { + void mapTemplateNoServiceCustomerIdError() { BizEvent event = new BizEvent(); TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); - assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_ID), e.getMessage()); + assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.SERVICE_CUSTOMER_ID), e.getMessage()); } @Test void mapTemplateNoTransactionTimestampError() { - BizEvent event = BizEvent.builder().paymentInfo(PaymentInfo.builder().IUR(IUR).build()).build(); + BizEvent event = BizEvent.builder().id(BIZ_EVENT_ID).paymentInfo(PaymentInfo.builder().IUR(IUR).build()).build(); TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); @@ -814,6 +815,7 @@ void mapTemplateNoTransactionTimestampError() { @Test void mapTemplateNoTransactionAmountError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -828,6 +830,7 @@ void mapTemplateNoTransactionAmountError() { @Test void mapTemplateNoPspError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -843,6 +846,7 @@ void mapTemplateNoPspError() { @Test void mapTemplateNoPspNameError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -861,6 +865,7 @@ void mapTemplateNoPspNameError() { @Test void mapTemplateNoPspCompanyNameError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -880,6 +885,7 @@ void mapTemplateNoPspCompanyNameError() { @Test void mapTemplateNoPspAddressError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -899,6 +905,7 @@ void mapTemplateNoPspAddressError() { @Test void mapTemplateNoPspCityError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -918,6 +925,7 @@ void mapTemplateNoPspCityError() { @Test void mapTemplateNoPspProvinceError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -937,6 +945,7 @@ void mapTemplateNoPspProvinceError() { @Test void mapTemplateNoPspBuildingNumberError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -956,6 +965,7 @@ void mapTemplateNoPspBuildingNumberError() { @Test void mapTemplateNoPspPostalCodeError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -975,6 +985,7 @@ void mapTemplateNoPspPostalCodeError() { @Test void mapTemplateNoPspLogoError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -999,6 +1010,7 @@ void mapTemplateNoPspLogoError() { @Test void mapTemplateNoRrnError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) .amount(AMOUNT_WITHOUT_CENTS) @@ -1022,6 +1034,7 @@ void mapTemplateNoRrnError() { @Test void mapTemplateNoUserDataFullNameError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -1041,6 +1054,7 @@ void mapTemplateNoUserDataFullNameError() { @Test void mapTemplateNoUserDataTaxCodeError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -1063,6 +1077,7 @@ void mapTemplateNoUserDataTaxCodeError() { @Test void mapTemplateNoCartItemRefNumberTypeError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -1086,6 +1101,7 @@ void mapTemplateNoCartItemRefNumberTypeError() { @Test void mapTemplateNoCartItemRefNumberValueError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -1112,6 +1128,7 @@ void mapTemplateNoCartItemRefNumberValueError() { @Test void mapTemplateNoCartItemDebtorTaxCodeValueError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -1139,6 +1156,7 @@ void mapTemplateNoCartItemDebtorTaxCodeValueError() { @Test void mapTemplateNoCartItemPayeeTaxCodeValueError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) @@ -1169,6 +1187,7 @@ void mapTemplateNoCartItemPayeeTaxCodeValueError() { @Test void mapTemplateNoCartItemAmountValueError() { BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() .IUR(IUR) .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)