@Test public void shouldPopulateOrderLinesWithDeliveryCost() throws WorldpayConfigurationException { when(cartModelMock.getDeliveryCost()).thenReturn(5.99D); when(cartModelMock.getTotalTax()).thenReturn(12.32); 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, 12.32D, "GBP"))); when(cartEntryModelMock.getOrder().getCurrency().getDigits()).thenReturn(2); when(cartEntryModelMock.getEntryNumber()).thenReturn(0); when(cartEntryModelMock.getProduct().getName()).thenReturn("Helmet Women TSG Lotus Graphic Designs wms Butterfly LXL"); 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("1232"); final LineItem lineItem = result.getLineItems().get(0); assertThat(lineItem.getLineItemType()).isEqualTo(LineItem.LINE_ITEM_TYPE.PHYSICAL); assertThat(lineItem.getLineItemReference().getValue()).isEqualToIgnoringCase("0"); assertThat(lineItem.getName()).isEqualToIgnoringCase("Helmet Women TSG Lotus Graphic Designs wms Butterfly LXL"); 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 lineItemShipping = result.getLineItems().get(1); assertThat(lineItemShipping.getLineItemType()).isEqualTo(LineItem.LINE_ITEM_TYPE.SHIPPING_FEE); assertThat(lineItemShipping.getLineItemReference().getValue()).isEqualToIgnoringCase(SHIPPING_LINE_ITEM_REFERENCE); assertThat(lineItemShipping.getQuantity()).isEqualToIgnoringCase("1"); assertThat(lineItemShipping.getQuantityUnit()).isEqualToIgnoringCase(SHIPPING); assertThat(lineItemShipping.getUnitPrice()).isEqualToIgnoringCase(EXPECTED_599); assertThat(lineItemShipping.getTaxRate()).isEqualToIgnoringCase(EXPECTED_2000); assertThat(lineItemShipping.getTotalAmount()).isEqualToIgnoringCase(EXPECTED_599); assertThat(lineItemShipping.getTotalTaxAmount()).isEqualToIgnoringCase("99"); assertThat(lineItemShipping.getTotalDiscountAmount()).isEqualToIgnoringCase("0"); }
@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);  }