@Test public void shouldPopulateOrderLinesFixedDiscountWithoutDelivery() throws WorldpayConfigurationException { when(cartModelMock.getTotalTax()).thenReturn(9.66); when(cartModelMock.getEntries()).thenReturn(singletonList(cartEntryModelMock)); when(cartModelMock.getCurrency().getDigits()).thenReturn(2); when(cartModelMock.getDeliveryMode().getName()).thenReturn(DELIVERY_MODE_NAME); when(cartModelMock.getTotalTaxValues()).thenReturn(singletonList(new TaxValue(UK_VAT_FULL, 20, false, 9.66D, "GBP"))); when(cartModelMock.getTotalDiscounts()).thenReturn(10D); when(cartModelMock.getGlobalDiscountValues()).thenReturn(singletonList(new DiscountValue("dv", 10D, true, 10D, "GBP"))); when(cartEntryModelMock.getOrder().getCurrency().getDigits()).thenReturn(2); when(cartEntryModelMock.getEntryNumber()).thenReturn(1); when(cartEntryModelMock.getProduct().getName()).thenReturn(PRODUCT_NAME); when(cartEntryModelMock.getQuantity()).thenReturn(1L); when(cartEntryModelMock.getProduct().getUnit().getName()).thenReturn(PIECES); when(cartEntryModelMock.getBasePrice()).thenReturn(67.96); when(cartEntryModelMock.getTotalPrice()).thenReturn(67.96); when(cartEntryModelMock.getTaxValues()).thenReturn(singletonList(new TaxValue(UK_VAT_FULL, 20, false, 11.33D, "GBP"))); when(commonI18NServiceMock.roundCurrency(anyDouble(), anyInt())).thenAnswer(invocationOnMock -> { final Double amount = (Double) invocationOnMock.getArguments()[0]; final Integer digits = (Integer) invocationOnMock.getArguments()[1]; return BigDecimal.valueOf(amount).movePointRight(digits).setScale(digits, RoundingMode.HALF_UP); }); final OrderLines result = testObj.createOrderLines(cartModelMock); assertThat(result.getTermsURL()).isEqualToIgnoringCase(TERMS_URL); assertThat(result.getLineItems()).hasSize(2); assertThat(result.getOrderTaxAmount()).isEqualToIgnoringCase("966"); final LineItem lineItem = result.getLineItems().get(0); assertThat(lineItem.getLineItemType()).isEqualTo(LineItem.LINE_ITEM_TYPE.PHYSICAL); assertThat(lineItem.getLineItemReference().getValue()).isEqualToIgnoringCase("1"); assertThat(lineItem.getName()).isEqualToIgnoringCase(PRODUCT_NAME); assertThat(lineItem.getQuantity()).isEqualToIgnoringCase("1"); assertThat(lineItem.getUnitPrice()).isEqualToIgnoringCase("6796"); assertThat(lineItem.getTaxRate()).isEqualToIgnoringCase(EXPECTED_2000); assertThat(lineItem.getTotalAmount()).isEqualToIgnoringCase("6796"); assertThat(lineItem.getTotalTaxAmount()).isEqualToIgnoringCase("1133"); assertThat(lineItem.getTotalDiscountAmount()).isEqualToIgnoringCase("0"); final LineItem lineItemDiscount = result.getLineItems().get(1); assertThat(lineItemDiscount.getLineItemType()).isEqualTo(LineItem.LINE_ITEM_TYPE.DISCOUNT); assertThat(lineItemDiscount.getLineItemReference().getValue()).isEqualToIgnoringCase(DISCOUNT_LINE_ITEM_REFERENCE); assertThat(lineItemDiscount.getName()).isEqualToIgnoringCase(ORDER_DISCOUNT); assertThat(lineItemDiscount.getQuantity()).isEqualToIgnoringCase("1"); assertThat(lineItemDiscount.getUnitPrice()).isEqualToIgnoringCase("0"); assertThat(lineItemDiscount.getTaxRate()).isEqualToIgnoringCase(EXPECTED_2000); assertThat(lineItemDiscount.getTotalAmount()).isEqualToIgnoringCase("-1000"); assertThat(lineItemDiscount.getTotalTaxAmount()).isEqualToIgnoringCase("-167"); assertThat(lineItemDiscount.getTotalDiscountAmount()).isEqualToIgnoringCase(EXPECTED_1000); }
@Override public OrderLines createOrderLines(CartModel cartModel) throws WorldpayConfigurationException { final Integer digits = cartModel.getCurrency().getDigits(); final String orderTaxAmount = convertDoubleToStringFormat(digits, cartModel.getTotalTax()); final String termsURL = worldpayUrlService.getFullTermsUrl(); final List<LineItem> lineItems = cartModel.getEntries().stream().map(this::createLineItem).collect(toList()); if (cartModel.getDeliveryCost() > 0) { addShippingFeeLineItem(cartModel, digits, lineItems); } if (cartModel.getGlobalDiscountValues().stream().anyMatch(DiscountValue::isAbsolute)) { lineItems.add(createDiscountLineItem(cartModel, digits)); } final OrderLines orderLines = new OrderLines(orderTaxAmount, termsURL, lineItems); if (orderLines.getLineItems().size() > 1) { verifySweepPennies(cartModel, orderLines); } return orderLines; }
DefaultWorldpayKlarnaStrategy implements WorldpayKlarnaStrategy { @Override public OrderLines createOrderLines(CartModel cartModel) throws WorldpayConfigurationException { final Integer digits = cartModel.getCurrency().getDigits(); final String orderTaxAmount = convertDoubleToStringFormat(digits, cartModel.getTotalTax()); final String termsURL = worldpayUrlService.getFullTermsUrl(); final List<LineItem> lineItems = cartModel.getEntries().stream().map(this::createLineItem).collect(toList()); if (cartModel.getDeliveryCost() > 0) { addShippingFeeLineItem(cartModel, digits, lineItems); } if (cartModel.getGlobalDiscountValues().stream().anyMatch(DiscountValue::isAbsolute)) { lineItems.add(createDiscountLineItem(cartModel, digits)); } final OrderLines orderLines = new OrderLines(orderTaxAmount, termsURL, lineItems); if (orderLines.getLineItems().size() > 1) { verifySweepPennies(cartModel, orderLines); } return orderLines; } }
DefaultWorldpayKlarnaStrategy implements WorldpayKlarnaStrategy { @Override public OrderLines createOrderLines(CartModel cartModel) throws WorldpayConfigurationException { final Integer digits = cartModel.getCurrency().getDigits(); final String orderTaxAmount = convertDoubleToStringFormat(digits, cartModel.getTotalTax()); final String termsURL = worldpayUrlService.getFullTermsUrl(); final List<LineItem> lineItems = cartModel.getEntries().stream().map(this::createLineItem).collect(toList()); if (cartModel.getDeliveryCost() > 0) { addShippingFeeLineItem(cartModel, digits, lineItems); } if (cartModel.getGlobalDiscountValues().stream().anyMatch(DiscountValue::isAbsolute)) { lineItems.add(createDiscountLineItem(cartModel, digits)); } final OrderLines orderLines = new OrderLines(orderTaxAmount, termsURL, lineItems); if (orderLines.getLineItems().size() > 1) { verifySweepPennies(cartModel, orderLines); } return orderLines; } DefaultWorldpayKlarnaStrategy(CommonI18NService commonI18NService, WorldpayUrlService worldpayUrlService); }
DefaultWorldpayKlarnaStrategy implements WorldpayKlarnaStrategy { @Override public OrderLines createOrderLines(CartModel cartModel) throws WorldpayConfigurationException { final Integer digits = cartModel.getCurrency().getDigits(); final String orderTaxAmount = convertDoubleToStringFormat(digits, cartModel.getTotalTax()); final String termsURL = worldpayUrlService.getFullTermsUrl(); final List<LineItem> lineItems = cartModel.getEntries().stream().map(this::createLineItem).collect(toList()); if (cartModel.getDeliveryCost() > 0) { addShippingFeeLineItem(cartModel, digits, lineItems); } if (cartModel.getGlobalDiscountValues().stream().anyMatch(DiscountValue::isAbsolute)) { lineItems.add(createDiscountLineItem(cartModel, digits)); } final OrderLines orderLines = new OrderLines(orderTaxAmount, termsURL, lineItems); if (orderLines.getLineItems().size() > 1) { verifySweepPennies(cartModel, orderLines); } return orderLines; } DefaultWorldpayKlarnaStrategy(CommonI18NService commonI18NService, WorldpayUrlService worldpayUrlService); @Override OrderLines createOrderLines(CartModel cartModel); }
DefaultWorldpayKlarnaStrategy implements WorldpayKlarnaStrategy { @Override public OrderLines createOrderLines(CartModel cartModel) throws WorldpayConfigurationException { final Integer digits = cartModel.getCurrency().getDigits(); final String orderTaxAmount = convertDoubleToStringFormat(digits, cartModel.getTotalTax()); final String termsURL = worldpayUrlService.getFullTermsUrl(); final List<LineItem> lineItems = cartModel.getEntries().stream().map(this::createLineItem).collect(toList()); if (cartModel.getDeliveryCost() > 0) { addShippingFeeLineItem(cartModel, digits, lineItems); } if (cartModel.getGlobalDiscountValues().stream().anyMatch(DiscountValue::isAbsolute)) { lineItems.add(createDiscountLineItem(cartModel, digits)); } final OrderLines orderLines = new OrderLines(orderTaxAmount, termsURL, lineItems); if (orderLines.getLineItems().size() > 1) { verifySweepPennies(cartModel, orderLines); } return orderLines; } DefaultWorldpayKlarnaStrategy(CommonI18NService commonI18NService, WorldpayUrlService worldpayUrlService); @Override OrderLines createOrderLines(CartModel cartModel);  }