Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PRDP-215] chore: Add service customer id #79

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@JsonInclude(Include.NON_NULL)
public class ReceiptPDFTemplate {

private String serviceCustomerId;
private Transaction transaction;
private User user;
private Cart cart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@JsonInclude(Include.NON_NULL)
public class Transaction {

private String id;
private String timestamp;
private String amount;
private PSP psp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand All @@ -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());
Expand Down Expand Up @@ -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)
Expand All @@ -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());
Expand Down Expand Up @@ -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)
Expand All @@ -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());
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading