Skip to content

Commit

Permalink
AD-294: Fix for AmountUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
kpieloch committed Sep 23, 2024
1 parent a9125f4 commit 88a4826
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion adyenv6core/src/com/adyen/v6/util/AmountUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,42 @@ public static Amount createAmount(BigDecimal value, String currency) {
Assert.isTrue(StringUtils.isNotBlank(currency), "Currency cannot be null or empty");
Amount amount = new Amount();
amount.setCurrency(currency);
amount.setValue(value.movePointRight(2).longValue());
int scale = getDecimalPlaces(currency);
amount.setValue(BigDecimal.TEN.pow(scale).multiply(value.setScale(scale, RoundingMode.HALF_UP)).longValue());
return amount;
}

public static int getDecimalPlaces(String currency) {
switch (currency) {
case "CVE":
case "DJF":
case "GNF":
case "IDR":
case "JPY":
case "KMF":
case "KRW":
case "PYG":
case "RWF":
case "UGX":
case "VND":
case "VUV":
case "XAF":
case "XOF":
case "XPF":
return 0;
case "BHD":
case "IQD":
case "JOD":
case "KWD":
case "LYD":
case "OMR":
case "TND":
return 3;
default:
return 2;
}
}

public static BigDecimal calculateAmountWithTaxes(final AbstractOrderModel abstractOrderModel) {
final Double totalPrice = abstractOrderModel.getTotalPrice();
final Double totalTax = Boolean.TRUE.equals(abstractOrderModel.getNet()) ? abstractOrderModel.getTotalTax() : Double.valueOf(0d);
Expand Down

0 comments on commit 88a4826

Please sign in to comment.