@Test public void calculateItemTaxes() throws Exception { BigDecimal startingItemTaxes = BigDecimal.TEN; Double entryTotalPrice = 240D; int entryTaxPercentage = 20; int entryTaxTotalAmount = 40; long entryQuantity = 5L; String orderItemTaxRate = "20.0000"; String finalItemTaxes = "50.0000"; 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); entry.setTotalPrice(entryTotalPrice); OrderItem orderItem = new OrderItem(); BigDecimal accumulatedTaxes = wirecardPercentageTaxCalculatorStrategy.calculateItemTaxes(entry, orderItem, startingItemTaxes); assertEquals("Order item tax rate does not match", orderItemTaxRate, orderItem.getTaxRate().toString()); assertEquals("Total tax amount does not match", finalItemTaxes, accumulatedTaxes.toString()); }
@Override public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal taxRate = BigDecimal.valueOf(tax.getValue()).setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(taxRate); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(entry.getTotalPrice()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .multiply(taxRate) .divide(HUNDRED.add(taxRate), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN)); return totalItemTaxes; }
WirecardPercentageTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { @Override public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal taxRate = BigDecimal.valueOf(tax.getValue()).setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(taxRate); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(entry.getTotalPrice()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .multiply(taxRate) .divide(HUNDRED.add(taxRate), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN)); return totalItemTaxes; } }
WirecardPercentageTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { @Override public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal taxRate = BigDecimal.valueOf(tax.getValue()).setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(taxRate); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(entry.getTotalPrice()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .multiply(taxRate) .divide(HUNDRED.add(taxRate), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN)); return totalItemTaxes; }  }
WirecardPercentageTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { @Override public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal taxRate = BigDecimal.valueOf(tax.getValue()).setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(taxRate); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(entry.getTotalPrice()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .multiply(taxRate) .divide(HUNDRED.add(taxRate), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN)); return totalItemTaxes; }  @Override BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes); @Override void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel,
                                       final OrderItem orderItem,
                                       BigDecimal totalItemTaxes); }
WirecardPercentageTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { @Override public BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes) { TaxValue tax = TaxValue.parseTaxValue(entry.getTaxValuesInternal()); BigDecimal taxRate = BigDecimal.valueOf(tax.getValue()).setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(taxRate); totalItemTaxes = totalItemTaxes.add(BigDecimal.valueOf(entry.getTotalPrice()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .multiply(taxRate) .divide(HUNDRED.add(taxRate), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN)); return totalItemTaxes; }  @Override BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes); @Override void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel,
                                       final OrderItem orderItem,
                                       BigDecimal totalItemTaxes);  }