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-178] Added onboardingChannel info to template #58

Merged
merged 3 commits into from
Oct 24, 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 @@ -19,4 +19,5 @@ public class Transaction {
private String authCode;
private PaymentMethod paymentMethod;
private boolean requestedByDebtor;
private boolean processedByPagoPA;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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.
Expand Down Expand Up @@ -77,6 +76,7 @@ public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTempla
.build())
.authCode(getAuthCode(bizEvent))
.requestedByDebtor(partialTemplate)
.processedByPagoPA(getProcessedByPagoPA(bizEvent))
.build())
.user(partialTemplate ?
null :
Expand Down Expand Up @@ -324,6 +324,18 @@ private String getOrThrow(LinkedHashMap<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
Loading