diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/InfoTransaction.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/InfoTransaction.java new file mode 100644 index 00000000..e3ea1ab7 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/InfoTransaction.java @@ -0,0 +1,19 @@ +package it.gov.pagopa.receipt.pdf.generator.entity.event; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.*; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +public class InfoTransaction { + + private String brand; + private String brandLogo; + private String clientId; + private String paymentMethodName; + private String type; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/Transaction.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/Transaction.java index ba860247..d0c89a83 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/Transaction.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/Transaction.java @@ -22,4 +22,5 @@ public class Transaction { private String numAut; private String accountCode; private TransactionPsp psp; + private String origin; } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/TransactionDetails.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/TransactionDetails.java index a04fda77..ebb16b9a 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/TransactionDetails.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/TransactionDetails.java @@ -14,4 +14,5 @@ public class TransactionDetails { private User user; private Transaction transaction; private WalletItem wallet; + private InfoTransaction info; } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/User.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/User.java index 87c437bc..d46e719c 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/User.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/entity/event/User.java @@ -12,6 +12,8 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class User { private String fullName; + private String name; + private String surname; private UserType type; private String fiscalCode; private String notificationEmail; 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 7203375a..b53cadaf 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 @@ -6,18 +6,7 @@ import it.gov.pagopa.receipt.pdf.generator.entity.receipt.enumeration.ReasonErrorCode; import it.gov.pagopa.receipt.pdf.generator.exception.PdfJsonMappingException; import it.gov.pagopa.receipt.pdf.generator.exception.TemplateDataMappingException; -import it.gov.pagopa.receipt.pdf.generator.model.template.Cart; -import it.gov.pagopa.receipt.pdf.generator.model.template.Debtor; -import it.gov.pagopa.receipt.pdf.generator.model.template.Item; -import it.gov.pagopa.receipt.pdf.generator.model.template.PSP; -import it.gov.pagopa.receipt.pdf.generator.model.template.PSPFee; -import it.gov.pagopa.receipt.pdf.generator.model.template.Payee; -import it.gov.pagopa.receipt.pdf.generator.model.template.PaymentMethod; -import it.gov.pagopa.receipt.pdf.generator.model.template.ReceiptPDFTemplate; -import it.gov.pagopa.receipt.pdf.generator.model.template.RefNumber; -import it.gov.pagopa.receipt.pdf.generator.model.template.Transaction; -import it.gov.pagopa.receipt.pdf.generator.model.template.User; -import it.gov.pagopa.receipt.pdf.generator.model.template.UserData; +import it.gov.pagopa.receipt.pdf.generator.model.template.*; import it.gov.pagopa.receipt.pdf.generator.service.BuildTemplateService; import it.gov.pagopa.receipt.pdf.generator.utils.ObjectMapperUtils; import it.gov.pagopa.receipt.pdf.generator.utils.TemplateDataField; @@ -31,12 +20,7 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import java.util.Collections; -import java.util.Date; -import java.util.TimeZone; -import java.util.LinkedHashMap; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -87,7 +71,9 @@ public class BuildTemplateServiceImpl implements BuildTemplateService { * {@inheritDoc} */ @Override - public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTemplate, Receipt receipt) throws TemplateDataMappingException { + public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean isGeneratingDebtor, Receipt receipt) throws TemplateDataMappingException { + boolean requestedByDebtor = getRequestByDebtor(isGeneratingDebtor, bizEvent); + return ReceiptPDFTemplate.builder() .serviceCustomerId(getServiceCustomerId(bizEvent)) .transaction(Transaction.builder() @@ -101,10 +87,10 @@ public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTempla .accountHolder(getPaymentMethodAccountHolder(bizEvent)) .build()) .authCode(getAuthCode(bizEvent)) - .requestedByDebtor(partialTemplate) + .requestedByDebtor(requestedByDebtor) .processedByPagoPA(getProcessedByPagoPA(bizEvent)) .build()) - .user(partialTemplate ? + .user(requestedByDebtor ? null : User.builder() .data(UserData.builder() @@ -228,6 +214,16 @@ private String getPaymentMethodAccountHolder(BizEvent event) { } private String getUserFullName(BizEvent event) throws TemplateDataMappingException { + if ( + event.getTransactionDetails() != null && + event.getTransactionDetails().getUser() != null && + event.getTransactionDetails().getUser().getName() != null && + event.getTransactionDetails().getUser().getSurname() != null + ) { + return String.format("%s %s", + event.getTransactionDetails().getUser().getName(), + event.getTransactionDetails().getUser().getSurname()); + } if (event.getPayer() != null && event.getPayer().getFullName() != null) { return event.getPayer().getFullName(); } @@ -235,6 +231,13 @@ private String getUserFullName(BizEvent event) throws TemplateDataMappingExcepti } private String getUserTaxCode(BizEvent event) throws TemplateDataMappingException { + if ( + event.getTransactionDetails() != null && + event.getTransactionDetails().getUser() != null && + event.getTransactionDetails().getUser().getFiscalCode() != null + ) { + return event.getTransactionDetails().getUser().getFiscalCode(); + } if (event.getPayer() != null && event.getPayer().getEntityUniqueIdentifierValue() != null) { return event.getPayer().getEntityUniqueIdentifierValue(); } @@ -347,8 +350,41 @@ private String getOrThrow(LinkedHashMap map, String key, String return value; } - public boolean getProcessedByPagoPA(BizEvent event) { - return event.getIdPaymentManager() != null && !event.getIdPaymentManager().isBlank(); + private boolean getProcessedByPagoPA(BizEvent event) { + if (event.getTransactionDetails() != null) { + if (event.getTransactionDetails().getTransaction() != null && + event.getTransactionDetails().getTransaction().getOrigin() != null) { + return true; + } + if (event.getTransactionDetails().getInfo() != null && + event.getTransactionDetails().getInfo().getClientId() != null) { + return true; + } + } + return false; + } + + private boolean getRequestByDebtor(boolean isGeneratingDebtor, BizEvent event) { + if (isGeneratingDebtor) { + String debtorFiscalCode = event.getDebtor().getEntityUniqueIdentifierValue(); + + String fiscalCodeFromPayer = event.getPayer() != null ? event.getPayer().getEntityUniqueIdentifierValue() : null; + String fiscalCodeFromUser = event.getTransactionDetails() != null && event.getTransactionDetails().getUser() != null ? + event.getTransactionDetails().getUser().getFiscalCode() : null; + //Check if payer's and user's fiscal codes exist + if (fiscalCodeFromPayer == null && fiscalCodeFromUser == null) { + return true; + } + //Check if payer's fiscal code exists and is different from debtor's + if (fiscalCodeFromPayer != null && !fiscalCodeFromPayer.equals(debtorFiscalCode)) { + return true; + } + //Check if user's fiscal code exists and is different from debtor's + if (fiscalCodeFromUser != null && !fiscalCodeFromUser.equals(debtorFiscalCode)) { + return true; + } + } + return false; } private String currencyFormat(String value) { @@ -372,6 +408,7 @@ private String dateFormatZoned(String date) throws TemplateDataMappingException SimpleDateFormat dateFormat = new SimpleDateFormat(RECEIPT_DATE_FORMAT, Locale.ITALY); return dateFormat.format(parsed); } + private String dateFormat(String date) { DateTimeFormatter simpleDateFormat = DateTimeFormatter.ofPattern(RECEIPT_DATE_FORMAT).withLocale(Locale.ITALY); return LocalDateTime.parse(date).format(simpleDateFormat); @@ -392,6 +429,6 @@ private String formatFullName(String fullName, String fiscalCode) { return null; } - return fullName.replaceAll("[,;:/]+", " "); + return fullName.replaceAll("[,;:/]+", " "); } } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java index e7936dbc..68c8a1c4 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java @@ -79,7 +79,7 @@ public PdfGeneration generateReceipts(Receipt receipt, BizEvent bizEvent, Path w pdfGeneration.setDebtorMetadata(PdfMetadata.builder().statusCode(ALREADY_CREATED).build()); return pdfGeneration; } - PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt, PAYER_TEMPLATE_SUFFIX, false, workingDirPath); + PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt, PAYER_TEMPLATE_SUFFIX, true, workingDirPath); pdfGeneration.setDebtorMetadata(generationResult); return pdfGeneration; } @@ -166,9 +166,9 @@ public boolean verifyAndUpdateReceipt(Receipt receipt, PdfGeneration pdfGenerati return result; } - private PdfMetadata generateAndSavePDFReceipt(BizEvent bizEvent, Receipt receipt, String templateSuffix, boolean partialTemplate, Path workingDirPath) { + private PdfMetadata generateAndSavePDFReceipt(BizEvent bizEvent, Receipt receipt, String templateSuffix, boolean isGeneratingDebtor, Path workingDirPath) { try { - ReceiptPDFTemplate template = buildTemplateService.buildTemplate(bizEvent, partialTemplate, receipt); + ReceiptPDFTemplate template = buildTemplateService.buildTemplate(bizEvent, isGeneratingDebtor, receipt); String dateFormatted = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd")); String blobName = String.format("%s-%s-%s-%s", TEMPLATE_PREFIX, dateFormatted, bizEvent.getId(), templateSuffix); PdfEngineResponse pdfEngineResponse = generatePDFReceipt(template, workingDirPath); 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 9e3b9294..71b6cf3d 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 @@ -46,8 +46,8 @@ class BuildTemplateServiceImplTest { public static final String AUTH_CODE = "authCode"; public static final String DATE_TIME_TIMESTAMP_MILLISECONDS = "2023-11-14T19:31:55.484065"; public static final String DATE_TIME_TIMESTAMP_ZONED = "2023-11-14T18:31:55Z"; - public static final boolean PARTIAL_TEMPLATE = true; - public static final boolean COMPLETE_TEMPLATE = false; + public static final boolean GENERATED_BY_DEBTOR = true; + public static final boolean GENERATED_BY_PAYER = false; public static final String PSP_NAME = "name"; public static final String PSP_LOGO = "logo"; public static final String PSP_COMPANY = "companyName"; @@ -68,7 +68,12 @@ class BuildTemplateServiceImplTest { 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"; - public static final String ID_PA = "idPa"; + private static final String ID_PA = "idPa"; + private static final String USER_NAME = "user_name"; + private static final String USER_SURNAME = "user_surname"; + private static final String USER_FORMATTED_FULL_NAME = "user_name user_surname"; + private static final String USER_TAX_CODE = "user tax code"; + public static final String PAGOPA_PA_CHANNEL_ID = "pagopa channel"; private BuildTemplateServiceImpl buildTemplateService; @BeforeEach @@ -81,7 +86,7 @@ void setUp() throws Exception { } @Test - void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception { + void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .idPaymentManager(BIZ_EVENT_ID) @@ -126,12 +131,17 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception .psp(TransactionPsp.builder() .businessName(PSP_NAME) .build()) + .origin(PAGOPA_PA_CHANNEL_ID) .build()) .build()) .eventStatus(BizEventStatusType.DONE) .build(); Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build(); - ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); + + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt))); + + ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get(); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -153,12 +163,10 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo()); assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder()); assertEquals(AUTH_CODE, transaction.getAuthCode()); - assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertEquals(GENERATED_BY_DEBTOR, 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()); + assertNull(receiptPdfTemplate.getUser()); it.gov.pagopa.receipt.pdf.generator.model.template.Cart cart = receiptPdfTemplate.getCart(); assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial()); @@ -173,7 +181,7 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception } @Test - void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Exception { + void mapTemplateAllFieldsSuccessCompleteTemplateAndPagoPaChannelOnTransactionOrigin() { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .idPaymentManager(BIZ_EVENT_ID) @@ -218,12 +226,17 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti .psp(TransactionPsp.builder() .businessName(PSP_NAME) .build()) + .origin(PAGOPA_PA_CHANNEL_ID) .build()) .build()) .eventStatus(BizEventStatusType.DONE) .build(); Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build(); - ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); + + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt))); + + ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get(); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -245,12 +258,10 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo()); assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder()); assertEquals(AUTH_CODE, transaction.getAuthCode()); - assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertEquals(GENERATED_BY_DEBTOR, 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()); + assertNull(receiptPdfTemplate.getUser()); it.gov.pagopa.receipt.pdf.generator.model.template.Cart cart = receiptPdfTemplate.getCart(); assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial()); @@ -265,12 +276,13 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti } @Test - void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exception { + void mapTemplateAllFieldsSuccessCompleteTemplateAndPagoPaChannelOnChannelId() { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) + .idPaymentManager(BIZ_EVENT_ID) .debtorPosition(DebtorPosition.builder() - .noticeNumber(NOTICE_NUMBER) - .modelType(MODEL_TYPE_NOTICE_CODE) + .iuv(IUV) + .modelType(MODEL_TYPE_IUV_CODE) .build()) .creditor(Creditor.builder() .companyName(COMPANY_NAME) @@ -296,8 +308,9 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce .transactionDetails(TransactionDetails.builder() .wallet(WalletItem.builder() .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build()) - .onboardingChannel(NOT_PAGO_PA_CHANNEL) + .onboardingChannel(PAGO_PA_CHANNEL_IO_PAY) .build()) + .info(InfoTransaction.builder().clientId(PAGOPA_PA_CHANNEL_ID).build()) .transaction(Transaction.builder() .idTransaction(ID_TRANSACTION) .grandTotal(GRAND_TOTAL_LONG) @@ -314,7 +327,11 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce .eventStatus(BizEventStatusType.DONE) .build(); Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build(); - ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, PARTIAL_TEMPLATE, receipt); + + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt))); + + ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get(); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -336,7 +353,82 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo()); assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder()); assertEquals(AUTH_CODE, transaction.getAuthCode()); - assertEquals(PARTIAL_TEMPLATE, transaction.isRequestedByDebtor()); + assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor()); + assertTrue(transaction.isProcessedByPagoPA()); + + assertNull(receiptPdfTemplate.getUser()); + + 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(COMPANY_NAME, cart.getItems().get(0).getPayee().getName()); + assertEquals(ID_PA, 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() { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .debtorPosition(DebtorPosition.builder() + .noticeNumber(NOTICE_NUMBER) + .modelType(MODEL_TYPE_NOTICE_CODE) + .build()) + .creditor(Creditor.builder() + .companyName(COMPANY_NAME) + .idPA(ID_PA) + .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()) + .eventStatus(BizEventStatusType.DONE) + .build(); + Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build(); + + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt))); + + ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get(); + + assertNotNull(receiptPdfTemplate); + assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); + + it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction(); + assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp()); + assertEquals(FORMATTED_AMOUNT, transaction.getAmount()); + assertEquals(PSP_LOGO, transaction.getPsp().getLogo()); + assertNull(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(PAYMENT_TOKEN, transaction.getRrn()); + assertNull(transaction.getPaymentMethod().getName()); + assertNull(transaction.getPaymentMethod().getLogo()); + assertNull(transaction.getPaymentMethod().getAccountHolder()); + assertNull(transaction.getAuthCode()); + assertTrue(transaction.isRequestedByDebtor()); assertFalse(transaction.isProcessedByPagoPA()); it.gov.pagopa.receipt.pdf.generator.model.template.User user = receiptPdfTemplate.getUser(); @@ -355,7 +447,7 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce } @Test - void mapTemplateWithoutTransactionDetailsSuccess() throws Exception { + void mapTemplateWithoutTransactionDetailsSuccess() { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .debtorPosition(DebtorPosition.builder() @@ -386,7 +478,11 @@ void mapTemplateWithoutTransactionDetailsSuccess() throws Exception { .eventStatus(BizEventStatusType.DONE) .build(); Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build(); - ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); + + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt))); + + ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get(); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -408,12 +504,10 @@ void mapTemplateWithoutTransactionDetailsSuccess() throws Exception { assertNull(transaction.getPaymentMethod().getLogo()); assertNull(transaction.getPaymentMethod().getAccountHolder()); assertNull(transaction.getAuthCode()); - assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor()); assertFalse(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()); + assertNull(receiptPdfTemplate.getUser()); it.gov.pagopa.receipt.pdf.generator.model.template.Cart cart = receiptPdfTemplate.getCart(); assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial()); @@ -428,7 +522,7 @@ void mapTemplateWithoutTransactionDetailsSuccess() throws Exception { } @Test - void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Exception { + void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .debtorPosition(DebtorPosition.builder() @@ -458,7 +552,11 @@ void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Excepti .eventStatus(BizEventStatusType.DONE) .build(); Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build(); - ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); + + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt))); + + ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get(); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -480,11 +578,9 @@ void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Excepti assertNull(transaction.getPaymentMethod().getLogo()); assertNull(transaction.getPaymentMethod().getAccountHolder()); assertNull(transaction.getAuthCode()); - assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor()); - 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()); + assertNull(receiptPdfTemplate.getUser()); it.gov.pagopa.receipt.pdf.generator.model.template.Cart cart = receiptPdfTemplate.getCart(); assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial()); @@ -499,7 +595,7 @@ void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Excepti } @Test - void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception { + void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .idPaymentManager(BIZ_EVENT_ID) @@ -544,12 +640,17 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception { .psp(TransactionPsp.builder() .businessName(PSP_NAME) .build()) + .origin(PAGOPA_PA_CHANNEL_ID) .build()) .build()) .eventStatus(BizEventStatusType.DONE) .build(); Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build(); - ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); + + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt))); + + ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get(); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -571,12 +672,10 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception { assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo()); assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder()); assertEquals(AUTH_CODE, transaction.getAuthCode()); - assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertEquals(GENERATED_BY_DEBTOR, 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()); + assertNull(receiptPdfTemplate.getUser()); it.gov.pagopa.receipt.pdf.generator.model.template.Cart cart = receiptPdfTemplate.getCart(); assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial()); @@ -591,7 +690,7 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception { } @Test - void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception { + void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .idPaymentManager(BIZ_EVENT_ID) @@ -636,12 +735,17 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception .psp(TransactionPsp.builder() .businessName(PSP_NAME) .build()) + .origin(PAGOPA_PA_CHANNEL_ID) .build()) .build()) .eventStatus(BizEventStatusType.DONE) .build(); Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build(); - ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); + + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt))); + + ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get(); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -663,12 +767,10 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo()); assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder()); assertEquals(AUTH_CODE, transaction.getAuthCode()); - assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertEquals(GENERATED_BY_DEBTOR, 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()); + assertNull(receiptPdfTemplate.getUser()); it.gov.pagopa.receipt.pdf.generator.model.template.Cart cart = receiptPdfTemplate.getCart(); assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial()); @@ -683,7 +785,7 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception } @Test - void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exception { + void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .idPaymentManager(BIZ_EVENT_ID) @@ -728,12 +830,17 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exceptio .psp(TransactionPsp.builder() .businessName(PSP_NAME) .build()) + .origin(PAGOPA_PA_CHANNEL_ID) .build()) .build()) .eventStatus(BizEventStatusType.DONE) .build(); Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build(); - ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); + + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt))); + + ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get(); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -755,12 +862,10 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exceptio assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo()); assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder()); assertEquals(AUTH_CODE, transaction.getAuthCode()); - assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor()); + assertEquals(GENERATED_BY_DEBTOR, 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()); + assertNull(receiptPdfTemplate.getUser()); it.gov.pagopa.receipt.pdf.generator.model.template.Cart cart = receiptPdfTemplate.getCart(); assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial()); @@ -775,7 +880,7 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exceptio } @Test - void mapTemplateLeastAmountOfInfoSuccess() { + void mapTemplateLeastAmountOfInfoSuccessPayer() { BizEvent event = BizEvent.builder() .id(BIZ_EVENT_ID) .paymentInfo(PaymentInfo.builder() @@ -802,6 +907,62 @@ void mapTemplateLeastAmountOfInfoSuccess() { .creditor(Creditor.builder() .idPA(ID_PA) .build()) + .build(); + assertDoesNotThrow(() -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); + } + + @Test + void mapTemplateLeastAmountOfInfoSuccessDebtor() { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .paymentInfo(PaymentInfo.builder() + .IUR(IUR) + .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) + .remittanceInformation(REMITTANCE_INFORMATION) + .amount(AMOUNT_WITHOUT_CENTS) + .build()) + .psp(Psp.builder() + .idPsp(ID_PSP) + .psp(PSP_NAME) + .build()) + .debtorPosition(DebtorPosition.builder() + .modelType(MODEL_TYPE_IUV_CODE) + .iuv(IUV) + .build()) + .debtor(Debtor.builder() + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .creditor(Creditor.builder() + .idPA(ID_PA) + .build()) + .build(); + assertDoesNotThrow(() -> buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build())); + } + + @Test + void mapTemplateSuccessRequestByDebtorTrueWithoutPayerAndUserFiscalCode() { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .paymentInfo(PaymentInfo.builder() + .IUR(IUR) + .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) + .remittanceInformation(REMITTANCE_INFORMATION) + .amount(AMOUNT_WITHOUT_CENTS) + .build()) + .psp(Psp.builder() + .idPsp(ID_PSP) + .psp(PSP_NAME) + .build()) + .debtorPosition(DebtorPosition.builder() + .modelType(MODEL_TYPE_IUV_CODE) + .iuv(IUV) + .build()) + .debtor(Debtor.builder() + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .creditor(Creditor.builder() + .idPA(ID_PA) + .build()) .transactionDetails(TransactionDetails.builder() .transaction(Transaction.builder() .grandTotal(GRAND_TOTAL_LONG).build() @@ -809,13 +970,273 @@ void mapTemplateLeastAmountOfInfoSuccess() { .build() ) .build(); - assertDoesNotThrow(() -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build()))); + + ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get(); + assertTrue(receiptPDFTemplate.getTransaction().isRequestedByDebtor()); + } + + @Test + void mapTemplateSuccessRequestByDebtorTrueWithPayerFiscalCodeDifferent() { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .paymentInfo(PaymentInfo.builder() + .IUR(IUR) + .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) + .remittanceInformation(REMITTANCE_INFORMATION) + .amount(AMOUNT_WITHOUT_CENTS) + .build()) + .psp(Psp.builder() + .idPsp(ID_PSP) + .psp(PSP_NAME) + .build()) + .debtorPosition(DebtorPosition.builder() + .modelType(MODEL_TYPE_IUV_CODE) + .iuv(IUV) + .build()) + .debtor(Debtor.builder() + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .payer(Payer.builder() + .entityUniqueIdentifierValue(PAYER_VALID_CF) + .build()) + .creditor(Creditor.builder() + .idPA(ID_PA) + .build()) + .transactionDetails(TransactionDetails.builder() + .transaction(Transaction.builder() + .grandTotal(GRAND_TOTAL_LONG).build() + ) + .build() + ) + .build(); + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build()))); + + ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get(); + assertTrue(receiptPDFTemplate.getTransaction().isRequestedByDebtor()); + } + + @Test + void mapTemplateSuccessRequestByDebtorTrueWithUserFiscalCodeDifferent() { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .paymentInfo(PaymentInfo.builder() + .IUR(IUR) + .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) + .remittanceInformation(REMITTANCE_INFORMATION) + .amount(AMOUNT_WITHOUT_CENTS) + .build()) + .psp(Psp.builder() + .idPsp(ID_PSP) + .psp(PSP_NAME) + .build()) + .debtorPosition(DebtorPosition.builder() + .modelType(MODEL_TYPE_IUV_CODE) + .iuv(IUV) + .build()) + .debtor(Debtor.builder() + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .creditor(Creditor.builder() + .idPA(ID_PA) + .build()) + .transactionDetails(TransactionDetails.builder() + .transaction(Transaction.builder() + .grandTotal(GRAND_TOTAL_LONG).build() + ) + .user(User.builder().fiscalCode(PAYER_VALID_CF).build()) + .build() + ) + .build(); + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build()))); + + ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get(); + assertTrue(receiptPDFTemplate.getTransaction().isRequestedByDebtor()); + } + + @Test + void mapTemplateSuccessRequestByDebtorFalseWithPayerAndUserFiscalCodeEqual() { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .paymentInfo(PaymentInfo.builder() + .IUR(IUR) + .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) + .remittanceInformation(REMITTANCE_INFORMATION) + .amount(AMOUNT_WITHOUT_CENTS) + .build()) + .psp(Psp.builder() + .idPsp(ID_PSP) + .psp(PSP_NAME) + .build()) + .debtorPosition(DebtorPosition.builder() + .modelType(MODEL_TYPE_IUV_CODE) + .iuv(IUV) + .build()) + .debtor(Debtor.builder() + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .payer(Payer.builder() + .fullName(PAYER_FULL_NAME) + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .creditor(Creditor.builder() + .idPA(ID_PA) + .build()) + .transactionDetails(TransactionDetails.builder() + .transaction(Transaction.builder() + .grandTotal(GRAND_TOTAL_LONG).build() + ) + .user(User.builder().fiscalCode(DEBTOR_VALID_CF).build()) + .build() + ) + .build(); + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build()))); + + ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get(); + assertFalse(receiptPDFTemplate.getTransaction().isRequestedByDebtor()); + } + + @Test + void mapTemplateSuccessRequestByDebtorFalseWhenGeneratedByPayer() { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .paymentInfo(PaymentInfo.builder() + .IUR(IUR) + .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) + .remittanceInformation(REMITTANCE_INFORMATION) + .amount(AMOUNT_WITHOUT_CENTS) + .build()) + .psp(Psp.builder() + .idPsp(ID_PSP) + .psp(PSP_NAME) + .build()) + .debtorPosition(DebtorPosition.builder() + .modelType(MODEL_TYPE_IUV_CODE) + .iuv(IUV) + .build()) + .debtor(Debtor.builder() + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .payer(Payer.builder() + .fullName(PAYER_FULL_NAME) + .entityUniqueIdentifierValue(PAYER_VALID_CF) + .build()) + .creditor(Creditor.builder() + .idPA(ID_PA) + .build()) + .transactionDetails(TransactionDetails.builder() + .transaction(Transaction.builder() + .grandTotal(GRAND_TOTAL_LONG).build() + ) + .build() + ) + .build(); + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()))); + + ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get(); + assertFalse(receiptPDFTemplate.getTransaction().isRequestedByDebtor()); + } + + @Test + void mapTemplateSuccessWithUserNameAndSurname() { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .paymentInfo(PaymentInfo.builder() + .IUR(IUR) + .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) + .remittanceInformation(REMITTANCE_INFORMATION) + .amount(AMOUNT_WITHOUT_CENTS) + .build()) + .psp(Psp.builder() + .idPsp(ID_PSP) + .psp(PSP_NAME) + .build()) + .debtorPosition(DebtorPosition.builder() + .modelType(MODEL_TYPE_IUV_CODE) + .iuv(IUV) + .build()) + .debtor(Debtor.builder() + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .payer(Payer.builder() + .entityUniqueIdentifierValue(PAYER_VALID_CF) + .build()) + .creditor(Creditor.builder() + .idPA(ID_PA) + .build()) + .transactionDetails(TransactionDetails.builder() + .transaction(Transaction.builder() + .grandTotal(GRAND_TOTAL_LONG).build() + ) + .user(User.builder() + .name(USER_NAME) + .surname(USER_SURNAME) + .build()) + .build() + ) + .build(); + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()))); + + ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get(); + assertEquals(USER_FORMATTED_FULL_NAME, receiptPDFTemplate.getUser().getData().getFullName()); + } + + @Test + void mapTemplateSuccessWithUserTaxCodeFromTransaction() { + BizEvent event = BizEvent.builder() + .id(BIZ_EVENT_ID) + .paymentInfo(PaymentInfo.builder() + .IUR(IUR) + .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) + .remittanceInformation(REMITTANCE_INFORMATION) + .amount(AMOUNT_WITHOUT_CENTS) + .build()) + .psp(Psp.builder() + .idPsp(ID_PSP) + .psp(PSP_NAME) + .build()) + .debtorPosition(DebtorPosition.builder() + .modelType(MODEL_TYPE_IUV_CODE) + .iuv(IUV) + .build()) + .debtor(Debtor.builder() + .entityUniqueIdentifierValue(DEBTOR_VALID_CF) + .build()) + .payer(Payer.builder() + .entityUniqueIdentifierValue(PAYER_VALID_CF) + .build()) + .creditor(Creditor.builder() + .idPA(ID_PA) + .build()) + .transactionDetails(TransactionDetails.builder() + .transaction(Transaction.builder() + .grandTotal(GRAND_TOTAL_LONG).build() + ) + .user(User.builder() + .name(USER_NAME) + .surname(USER_SURNAME) + .fiscalCode(USER_TAX_CODE) + .build()) + .build() + ) + .build(); + AtomicReference atomicReference = new AtomicReference<>(); + assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()))); + + ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get(); + assertEquals(USER_TAX_CODE, receiptPDFTemplate.getUser().getData().getTaxCode()); } @Test void mapTemplateNoServiceCustomerIdError() { BizEvent event = new BizEvent(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.SERVICE_CUSTOMER_ID), e.getMessage()); @@ -824,7 +1245,7 @@ void mapTemplateNoServiceCustomerIdError() { @Test void mapTemplateNoTransactionTimestampError() { 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, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_TIMESTAMP), e.getMessage()); @@ -839,7 +1260,7 @@ void mapTemplateNoTransactionAmountError() { .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_AMOUNT), e.getMessage()); @@ -855,7 +1276,7 @@ void mapTemplateNoPspError() { .amount(AMOUNT_WITHOUT_CENTS) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP), e.getMessage()); @@ -874,7 +1295,7 @@ void mapTemplateNoPspNameError() { .idPsp("noName") .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_NAME), e.getMessage()); @@ -894,7 +1315,7 @@ void mapTemplateNoPspCompanyNameError() { .psp(PSP_NAME) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_COMPANY_NAME), e.getMessage()); @@ -914,7 +1335,7 @@ void mapTemplateNoPspAddressError() { .psp(PSP_NAME) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_ADDRESS), e.getMessage()); @@ -934,7 +1355,7 @@ void mapTemplateNoPspCityError() { .psp(PSP_NAME) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_CITY), e.getMessage()); @@ -954,7 +1375,7 @@ void mapTemplateNoPspProvinceError() { .psp(PSP_NAME) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_PROVINCE), e.getMessage()); @@ -974,7 +1395,7 @@ void mapTemplateNoPspBuildingNumberError() { .psp(PSP_NAME) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_BUILDING_NUMBER), e.getMessage()); @@ -994,7 +1415,7 @@ void mapTemplateNoPspPostalCodeError() { .psp(PSP_NAME) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_POSTAL_CODE), e.getMessage()); @@ -1019,7 +1440,7 @@ void mapTemplateNoPspLogoError() { .build()) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_LOGO), e.getMessage()); @@ -1043,7 +1464,7 @@ void mapTemplateNoRrnError() { .build()) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_RRN), e.getMessage()); @@ -1063,7 +1484,7 @@ void mapTemplateNoUserDataFullNameError() { .psp(PSP_NAME) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.USER_DATA_FULL_NAME), e.getMessage()); @@ -1086,7 +1507,7 @@ void mapTemplateNoUserDataTaxCodeError() { .fullName(PAYER_FULL_NAME) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.USER_DATA_TAX_CODE), e.getMessage()); @@ -1110,7 +1531,7 @@ void mapTemplateNoCartItemRefNumberTypeError() { .entityUniqueIdentifierValue(PAYER_VALID_CF) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_TYPE), e.getMessage()); @@ -1137,7 +1558,7 @@ void mapTemplateNoCartItemRefNumberValueIUVError() { .modelType(MODEL_TYPE_IUV_CODE) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), e.getMessage()); @@ -1165,7 +1586,7 @@ void mapTemplateWrongModelTypeError() { .modelType(MODEL_TYPE_NOTICE_CODE) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), e.getMessage()); @@ -1193,7 +1614,7 @@ void mapTemplateNoCartItemDebtorTaxCodeValueError() { .iuv(IUV) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_DEBTOR_TAX_CODE), e.getMessage()); @@ -1224,7 +1645,7 @@ void mapTemplateNoCartItemPayeeTaxCodeValueError() { .entityUniqueIdentifierValue(DEBTOR_VALID_CF) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_PAYEE_TAX_CODE), e.getMessage()); @@ -1265,7 +1686,7 @@ void mapTemplateNoCartItemAmountValueError() { .build() ) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_AMOUNT), e.getMessage());