@Test public void calculateDeliveryTaxes() throws Exception { Double orderTaxes = 12D; BigDecimal itemTaxes = BigDecimal.TEN; BigDecimal deliveryAmount = BigDecimal.valueOf(20); String deliveryTaxes = "10.00"; AbstractOrderModel order = new OrderModel(); order.setTotalTax(orderTaxes); OrderItem orderItem = new OrderItem(); Money orderItemAmount = new Money(); orderItemAmount.setValue(deliveryAmount); orderItem.setAmount(orderItemAmount); wirecardPercentageTaxCalculatorStrategy.calculateDeliveryTaxes(order, orderItem, itemTaxes); assertEquals("Delivery tax rate does not match", deliveryTaxes, orderItem.getTaxRate().toString()); }
@Override public void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel, final OrderItem orderItem, BigDecimal totalItemTaxes) { BigDecimal taxAmount = BigDecimal.valueOf(abstractOrderModel.getTotalTax()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .subtract(totalItemTaxes) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); BigDecimal deliveryTaxes = (HUNDRED.multiply(taxAmount)).divide(orderItem.getAmount().getValue(), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(deliveryTaxes.setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); }
WirecardPercentageTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { @Override public void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel, final OrderItem orderItem, BigDecimal totalItemTaxes) { BigDecimal taxAmount = BigDecimal.valueOf(abstractOrderModel.getTotalTax()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .subtract(totalItemTaxes) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); BigDecimal deliveryTaxes = (HUNDRED.multiply(taxAmount)).divide(orderItem.getAmount().getValue(), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(deliveryTaxes.setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); } }
WirecardPercentageTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { @Override public void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel, final OrderItem orderItem, BigDecimal totalItemTaxes) { BigDecimal taxAmount = BigDecimal.valueOf(abstractOrderModel.getTotalTax()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .subtract(totalItemTaxes) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); BigDecimal deliveryTaxes = (HUNDRED.multiply(taxAmount)).divide(orderItem.getAmount().getValue(), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(deliveryTaxes.setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); }  }
WirecardPercentageTaxCalculatorStrategy implements WirecardTaxCalculatorStrategy { @Override public void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel, final OrderItem orderItem, BigDecimal totalItemTaxes) { BigDecimal taxAmount = BigDecimal.valueOf(abstractOrderModel.getTotalTax()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .subtract(totalItemTaxes) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); BigDecimal deliveryTaxes = (HUNDRED.multiply(taxAmount)).divide(orderItem.getAmount().getValue(), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(deliveryTaxes.setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); }  @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 void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel, final OrderItem orderItem, BigDecimal totalItemTaxes) { BigDecimal taxAmount = BigDecimal.valueOf(abstractOrderModel.getTotalTax()) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN) .subtract(totalItemTaxes) .setScale(DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); BigDecimal deliveryTaxes = (HUNDRED.multiply(taxAmount)).divide(orderItem.getAmount().getValue(), DECIMAL_DIGITS_INTERMEDIATE, RoundingMode.HALF_EVEN); orderItem.setTaxRate(deliveryTaxes.setScale(DECIMAL_DIGITS_MAX, RoundingMode.HALF_EVEN)); }  @Override BigDecimal calculateItemTaxes(final AbstractOrderEntryModel entry, final OrderItem orderItem, BigDecimal totalItemTaxes); @Override void calculateDeliveryTaxes(final AbstractOrderModel abstractOrderModel,
                                       final OrderItem orderItem,
                                       BigDecimal totalItemTaxes);  }