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 03592092..f406eef1 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 @@ -19,4 +19,5 @@ public class Transaction { private String authCode; private PaymentMethod paymentMethod; private boolean requestedByDebtor; + private boolean processedByPagoPA; } 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 5ba36e47..e2fc2bd6 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 @@ -17,10 +17,7 @@ import java.time.LocalDateTime; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Locale; -import java.util.Map; +import java.util.*; public class BuildTemplateServiceImpl implements BuildTemplateService { @@ -30,6 +27,8 @@ public class BuildTemplateServiceImpl implements BuildTemplateService { private static final String BRAND_LOGO_MAP_ENV_KEY = "BRAND_LOGO_MAP"; private static final String PSP_CONFIG_FILE_JSON_FILE_NAME = "psp_config_file.json"; + private static final String PAGO_PA_CHANNEL_IO = "IO"; + private static final String PAGO_PA_CHANNEL_IO_PAY = "IO-PAY"; /** * Hide from public usage. @@ -77,6 +76,7 @@ public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTempla .build()) .authCode(getAuthCode(bizEvent)) .requestedByDebtor(partialTemplate) + .processedByPagoPA(getProcessedByPagoPA(bizEvent)) .build()) .user(partialTemplate ? null : @@ -324,6 +324,18 @@ private String getOrThrow(LinkedHashMap map, String key, String return value; } + public boolean getProcessedByPagoPA(BizEvent event){ + if(event.getTransactionDetails() != null && event.getTransactionDetails().getWallet() != null){ + String onboardingChannel = event.getTransactionDetails().getWallet().getOnboardingChannel(); + return onboardingChannel != null && + (onboardingChannel.equals(PAGO_PA_CHANNEL_IO) || + onboardingChannel.equals(PAGO_PA_CHANNEL_IO_PAY) + ); + } + + return false; + } + private String currencyFormat(String value) { BigDecimal valueToFormat = new BigDecimal(value); NumberFormat numberFormat = NumberFormat.getInstance(Locale.ITALY); 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 2bc9dd5d..84ae652c 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 @@ -58,6 +58,9 @@ class BuildTemplateServiceImplTest { private static final String MODEL_TYPE_NOTICE_TEXT = "codiceAvviso"; private static final String MODEL_TYPE_IUV_TEXT = "IUV"; private static final String DATE_TIME_TIMESTAMP_FORMATTED = "12 aprile 2023, 16:32:27"; + private static final String PAGO_PA_CHANNEL_IO = "IO"; + private static final String PAGO_PA_CHANNEL_IO_PAY = "IO-PAY"; + private static final String NOT_PAGO_PA_CHANNEL = "NOT_PAGO_PA_CHANNEL"; private BuildTemplateServiceImpl buildTemplateService; @BeforeEach @@ -70,7 +73,7 @@ void setUp() throws Exception { } @Test - void mapTemplateAllFieldsSuccessCompleteTemplate() throws Exception { + void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .debtorPosition(DebtorPosition.builder() @@ -99,7 +102,10 @@ void mapTemplateAllFieldsSuccessCompleteTemplate() throws Exception { .IUR(IUR) .build()) .transactionDetails(TransactionDetails.builder() - .wallet(WalletItem.builder().info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build()).build()) + .wallet(WalletItem.builder() + .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build()) + .onboardingChannel(PAGO_PA_CHANNEL_IO) + .build()) .transaction(Transaction.builder() .idTransaction(ID_TRANSACTION) .grandTotal(GRAND_TOTAL_LONG) @@ -138,6 +144,7 @@ void mapTemplateAllFieldsSuccessCompleteTemplate() throws Exception { assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder()); assertEquals(AUTH_CODE, transaction.getAuthCode()); assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertTrue(transaction.isProcessedByPagoPA()); it.gov.pagopa.receipt.pdf.generator.model.template.UserData userData = receiptPdfTemplate.getUser().getData(); assertEquals(PAYER_VALID_CF, userData.getTaxCode()); @@ -156,7 +163,97 @@ void mapTemplateAllFieldsSuccessCompleteTemplate() throws Exception { } @Test - void mapTemplateAllFieldsSuccessPartialTemplate() throws Exception { + void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Exception { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .debtorPosition(DebtorPosition.builder() + .iuv(IUV) + .modelType(MODEL_TYPE_IUV_CODE) + .build()) + .creditor(Creditor.builder() + .companyName(COMPANY_NAME) + .officeName(OFFICE_NAME) + .build()) + .psp(Psp.builder() + .idPsp(ID_PSP) + .psp(PSP_NAME) + .build()) + .debtor(Debtor.builder() + .fullName(DEBTOR_FULL_NAME) + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build()) + .paymentInfo(PaymentInfo.builder() + .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) + .paymentToken(PAYMENT_TOKEN) + .amount(AMOUNT_WITHOUT_CENTS) + .fee(FEE_WITH_SINGLE_DIGIT_CENTS) + .remittanceInformation(REMITTANCE_INFORMATION) + .IUR(IUR) + .build()) + .transactionDetails(TransactionDetails.builder() + .wallet(WalletItem.builder() + .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build()) + .onboardingChannel(PAGO_PA_CHANNEL_IO_PAY) + .build()) + .transaction(Transaction.builder() + .idTransaction(ID_TRANSACTION) + .grandTotal(GRAND_TOTAL_LONG) + .amount(AMOUNT_LONG) + .fee(FEE_LONG) + .rrn(RRN) + .authorizationCode(AUTH_CODE) + .creationDate(DATE_TIME_TIMESTAMP_ZONED) + .psp(TransactionPsp.builder() + .businessName(PSP_NAME) + .build()) + .build()) + .build()) + .eventStatus(BizEventStatusType.DONE) + .build(); + ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE); + + assertNotNull(receiptPdfTemplate); + + 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()); + assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount()); + assertEquals(PSP_NAME, transaction.getPsp().getName()); + assertEquals(PSP_CITY, transaction.getPsp().getCity()); + assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName()); + assertEquals(PSP_POSTAL_CODE, transaction.getPsp().getPostalCode()); + assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress()); + assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber()); + assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince()); + assertEquals(RRN, transaction.getRrn()); + assertEquals(BRAND, transaction.getPaymentMethod().getName()); + assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo()); + assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder()); + assertEquals(AUTH_CODE, transaction.getAuthCode()); + assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertTrue(transaction.isProcessedByPagoPA()); + + it.gov.pagopa.receipt.pdf.generator.model.template.UserData userData = receiptPdfTemplate.getUser().getData(); + assertEquals(PAYER_VALID_CF, userData.getTaxCode()); + assertEquals(PAYER_FULL_NAME, userData.getFullName()); + + it.gov.pagopa.receipt.pdf.generator.model.template.Cart cart = receiptPdfTemplate.getCart(); + assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial()); + assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount()); + assertEquals(DEBTOR_FULL_NAME, cart.getItems().get(0).getDebtor().getFullName()); + assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode()); + assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject()); + assertEquals(OFFICE_NAME, cart.getItems().get(0).getPayee().getName()); + assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getTaxCode()); + assertEquals(MODEL_TYPE_IUV_TEXT, cart.getItems().get(0).getRefNumber().getType()); + assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue()); + } + + @Test + void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exception { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .debtorPosition(DebtorPosition.builder() @@ -185,7 +282,10 @@ void mapTemplateAllFieldsSuccessPartialTemplate() throws Exception { .IUR(IUR) .build()) .transactionDetails(TransactionDetails.builder() - .wallet(WalletItem.builder().info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build()).build()) + .wallet(WalletItem.builder() + .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build()) + .onboardingChannel(NOT_PAGO_PA_CHANNEL) + .build()) .transaction(Transaction.builder() .idTransaction(ID_TRANSACTION) .grandTotal(GRAND_TOTAL_LONG) @@ -224,6 +324,7 @@ void mapTemplateAllFieldsSuccessPartialTemplate() throws Exception { assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder()); assertEquals(AUTH_CODE, transaction.getAuthCode()); assertEquals(PARTIAL_TEMPLATE, transaction.isRequestedByDebtor()); + assertFalse(transaction.isProcessedByPagoPA()); it.gov.pagopa.receipt.pdf.generator.model.template.User user = receiptPdfTemplate.getUser(); assertNull(user); @@ -294,6 +395,7 @@ void mapTemplateWithoutTransactionDetailsSuccess() throws Exception { assertNull(transaction.getPaymentMethod().getAccountHolder()); assertNull(transaction.getAuthCode()); assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertFalse(transaction.isProcessedByPagoPA()); it.gov.pagopa.receipt.pdf.generator.model.template.UserData userData = receiptPdfTemplate.getUser().getData(); assertEquals(PAYER_VALID_CF, userData.getTaxCode());