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-314] fix: GrandTotal format #118

Merged
merged 1 commit into from
Jan 9, 2024
Merged
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 @@ -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
Loading