@Test public void calculateItemTaxes() throws Exception { BigDecimal startingItemTaxes = BigDecimal.TEN; int entryTaxPercentage = 20; int entryTaxTotalAmount = 10; long entryQuantity = 5L; String entryUnitTaxAmount = "2.00"; String finalItemTaxes = "20.00"; TaxValue taxValue = new TaxValue("full-taxes", entryTaxPercentage, false, entryTaxTotalAmount, CURRENCY_EUR); AbstractOrderEntryModel entry = new AbstractOrderEntryModel(); entry.setTaxValues(Collections.singletonList(taxValue)); entry.setTaxValuesInternal(taxValue.toString()); entry.setQuantity(entryQuantity); OrderItem orderItem = new OrderItem(); BigDecimal accumulatedTaxes = wirecardAbsoluteTaxCalculatorStrategy.calculateItemTaxes(entry, orderItem, startingItemTaxes); assertNotNull("Tax amount should not be null", orderItem.getTaxAmount()); assertEquals("Currency does not match", CURRENCY_EUR, orderItem.getTaxAmount().getCurrency()); assertEquals("Unit tax amount does not match", entryUnitTaxAmount, orderItem.getTaxAmount().getValue().toString()); assertEquals("Total tax amount does not match", finalItemTaxes, accumulatedTaxes.toString()); }
public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { Money taxAmount = new Money(); TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal itemTax = BigDecimal.valueOf(tax.getAppliedValue()) .setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN) .divide(BigDecimal.valueOf(entry.getQuantity()), RoundingMode.HALF_EVEN); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(tax.getAppliedValue()).setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); taxAmount.setValue(itemTax); taxAmount.setCurrency(tax.getCurrencyIsoCode()); orderItem.setTaxAmount(taxAmount); return totalItemTaxes; }
WirecardAbsoluteTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { Money taxAmount = new Money(); TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal itemTax = BigDecimal.valueOf(tax.getAppliedValue()) .setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN) .divide(BigDecimal.valueOf(entry.getQuantity()), RoundingMode.HALF_EVEN); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(tax.getAppliedValue()).setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); taxAmount.setValue(itemTax); taxAmount.setCurrency(tax.getCurrencyIsoCode()); orderItem.setTaxAmount(taxAmount); return totalItemTaxes; } }
WirecardAbsoluteTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { Money taxAmount = new Money(); TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal itemTax = BigDecimal.valueOf(tax.getAppliedValue()) .setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN) .divide(BigDecimal.valueOf(entry.getQuantity()), RoundingMode.HALF_EVEN); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(tax.getAppliedValue()).setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); taxAmount.setValue(itemTax); taxAmount.setCurrency(tax.getCurrencyIsoCode()); orderItem.setTaxAmount(taxAmount); return totalItemTaxes; }  }
WirecardAbsoluteTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { Money taxAmount = new Money(); TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal itemTax = BigDecimal.valueOf(tax.getAppliedValue()) .setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN) .divide(BigDecimal.valueOf(entry.getQuantity()), RoundingMode.HALF_EVEN); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(tax.getAppliedValue()).setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); taxAmount.setValue(itemTax); taxAmount.setCurrency(tax.getCurrencyIsoCode()); orderItem.setTaxAmount(taxAmount); return totalItemTaxes; }  BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes); void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel,
                                       final OrderItem orderItem,
                                       BigDecimal totalItemTaxes); }
WirecardAbsoluteTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { Money taxAmount = new Money(); TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal itemTax = BigDecimal.valueOf(tax.getAppliedValue()) .setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN) .divide(BigDecimal.valueOf(entry.getQuantity()), RoundingMode.HALF_EVEN); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(tax.getAppliedValue()).setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); taxAmount.setValue(itemTax); taxAmount.setCurrency(tax.getCurrencyIsoCode()); orderItem.setTaxAmount(taxAmount); return totalItemTaxes; }  BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes); void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel,
                                       final OrderItem orderItem,
                                       BigDecimal totalItemTaxes);  }