Skip to content

Commit

Permalink
[PRDP-314] fix grand total format
Browse files Browse the repository at this point in the history
  • Loading branch information
giomella committed Jan 9, 2024
1 parent 50ce657 commit 958988a
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.slf4j.Logger;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -54,12 +55,8 @@ public static Receipt createReceipt(BizEvent bizEvent, BizEventToReceiptService

eventData.setTransactionCreationDate(
service.getTransactionCreationDate(bizEvent));
eventData.setAmount(
bizEvent.getTransactionDetails() != null && bizEvent
.getTransactionDetails().getTransaction() != null ?
String.valueOf(bizEvent.getTransactionDetails().getTransaction().getGrandTotal()) :
bizEvent.getPaymentInfo() != null ? bizEvent.getPaymentInfo().getAmount() : null
);
BigDecimal amount = getAmount(bizEvent);
eventData.setAmount(!amount.equals(BigDecimal.ZERO) ? amount.toString() : null);

CartItem item = new CartItem();
item.setPayeeName(bizEvent.getCreditor() != null ? bizEvent.getCreditor().getCompanyName() : null);
Expand Down Expand Up @@ -233,14 +230,20 @@ public static Receipt createCartReceipt(List<BizEvent> bizEventList, BizEventToR

private static BigDecimal getAmount(BizEvent bizEvent) {
if (bizEvent.getTransactionDetails() != null && bizEvent.getTransactionDetails().getTransaction() != null) {
return new BigDecimal(bizEvent.getTransactionDetails().getTransaction().getGrandTotal());
return formatAmount(bizEvent.getTransactionDetails().getTransaction().getGrandTotal());
}
if (bizEvent.getPaymentInfo() != null && bizEvent.getPaymentInfo().getAmount() != null) {
return new BigDecimal(bizEvent.getPaymentInfo().getAmount());
}
return BigDecimal.ZERO;
}

private static BigDecimal formatAmount(long grandTotal) {
BigDecimal amount = new BigDecimal(grandTotal);
BigDecimal divider = new BigDecimal(100);
return amount.divide(divider, 2, RoundingMode.UNNECESSARY);
}

private static String formatRemittanceInformation(String remittanceInformation) {
if (remittanceInformation != null) {
Pattern pattern = Pattern.compile(REMITTANCE_INFORMATION_REGEX);
Expand Down

0 comments on commit 958988a

Please sign in to comment.