From 8a11e2a6e63de55754e367bf693ab82b65f872a8 Mon Sep 17 00:00:00 2001 From: PJaneta Date: Tue, 14 Jan 2025 13:30:46 +0100 Subject: [PATCH] AD-394 Doubled shipment price on the express checkout on the cart --- .../controllers/PaymentMethodsController.java | 7 +++++- ...artExpressCheckoutComponentController.java | 5 ---- .../adyen/v6/facades/AdyenCheckoutFacade.java | 4 ++-- .../facades/AdyenExpressCheckoutFacade.java | 3 --- .../impl/DefaultAdyenCheckoutFacade.java | 16 +++++++++++-- .../DefaultAdyenExpressCheckoutFacade.java | 13 ---------- ...DefaultAdyenExpressCheckoutFacadeTest.java | 24 ------------------- 7 files changed, 22 insertions(+), 50 deletions(-) diff --git a/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java b/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java index fb3eff4f..0106e246 100644 --- a/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java +++ b/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java @@ -6,10 +6,12 @@ import com.adyen.commerce.constants.AdyenoccConstants; import com.adyen.service.exception.ApiException; import com.adyen.v6.facades.AdyenCheckoutFacade; +import com.adyen.v6.facades.AdyenExpressCheckoutFacade; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import de.hybris.platform.commerceservices.request.mapping.annotation.ApiVersion; +import de.hybris.platform.order.exceptions.CalculationException; import de.hybris.platform.webservicescommons.swagger.ApiBaseSiteIdAndUserIdParam; import de.hybris.platform.webservicescommons.swagger.ApiBaseSiteIdUserIdAndCartIdParam; import io.swagger.v3.oas.annotations.Operation; @@ -36,6 +38,9 @@ public class PaymentMethodsController @Autowired private AdyenCheckoutFacade adyenCheckoutFacade; + @Autowired + private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade; + @Secured({ "ROLE_CUSTOMERGROUP", "ROLE_TRUSTED_CLIENT", "ROLE_CUSTOMERMANAGERGROUP" }) @GetMapping(value = AdyenoccConstants.ADYEN_USER_CART_PREFIX + "/checkout-configuration") @Operation(operationId = "getCheckoutConfiguration", summary = "Get checkout configuration", description = @@ -61,7 +66,7 @@ public ResponseEntity getExpressPDPCheckoutConfiguration(@PathVariable S @Operation(operationId = "getExpressCartCheckoutConfiguration", summary = "Get express cart page checkout configuration", description = "Returns configuration for express payments on cart") @ApiBaseSiteIdUserIdAndCartIdParam - public ResponseEntity getExpressCartCheckoutConfiguration() throws ApiException, JsonProcessingException { + public ResponseEntity getExpressCartCheckoutConfiguration() throws ApiException, JsonProcessingException, CalculationException { String response = objectMapper.writeValueAsString(adyenCheckoutFacade.initializeExpressCheckoutCartPageDataOCC()); return ResponseEntity.ok().body(response); } diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/cms/AdyenAccCartExpressCheckoutComponentController.java b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/cms/AdyenAccCartExpressCheckoutComponentController.java index 4e184096..5c31c7ef 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/cms/AdyenAccCartExpressCheckoutComponentController.java +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/cms/AdyenAccCartExpressCheckoutComponentController.java @@ -2,7 +2,6 @@ import com.adyen.service.exception.ApiException; import com.adyen.v6.facades.AdyenCheckoutFacade; -import com.adyen.v6.facades.AdyenExpressCheckoutFacade; import com.adyen.v6.model.contents.components.AdyenAccExpressCheckoutCartPageComponentModel; import de.hybris.platform.addonsupport.controllers.cms.AbstractCMSAddOnComponentController; import de.hybris.platform.order.exceptions.CalculationException; @@ -20,13 +19,9 @@ public class AdyenAccCartExpressCheckoutComponentController extends AbstractCMSA @Autowired private AdyenCheckoutFacade adyenCheckoutFacade; - @Autowired - private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade; - @Override protected void fillModel(final HttpServletRequest request, final Model model, final AdyenAccExpressCheckoutCartPageComponentModel component) { try { - adyenExpressCheckoutFacade.removeDeliveryModeFromSessionCart(); adyenCheckoutFacade.initializeExpressCheckoutCartPageData(model); } catch (ApiException | CalculationException e) { throw new RuntimeException(e); diff --git a/adyenv6core/src/com/adyen/v6/facades/AdyenCheckoutFacade.java b/adyenv6core/src/com/adyen/v6/facades/AdyenCheckoutFacade.java index e5a7c389..a8cade57 100644 --- a/adyenv6core/src/com/adyen/v6/facades/AdyenCheckoutFacade.java +++ b/adyenv6core/src/com/adyen/v6/facades/AdyenCheckoutFacade.java @@ -142,11 +142,11 @@ public interface AdyenCheckoutFacade { void initializeSummaryData(Model model) throws ApiException; - void initializeExpressCheckoutCartPageData(Model model) throws ApiException; + void initializeExpressCheckoutCartPageData(Model model) throws ApiException, CalculationException; void initializeExpressCheckoutPDPData(Model model, String productCode) throws ApiException; - ExpressCheckoutConfigDTO initializeExpressCheckoutCartPageDataOCC() throws ApiException; + ExpressCheckoutConfigDTO initializeExpressCheckoutCartPageDataOCC() throws ApiException, CalculationException; ExpressCheckoutConfigDTO initializeExpressCheckoutPDPDataOCC(String productCode) throws ApiException; diff --git a/adyenv6core/src/com/adyen/v6/facades/AdyenExpressCheckoutFacade.java b/adyenv6core/src/com/adyen/v6/facades/AdyenExpressCheckoutFacade.java index 2cbd6a3d..8f5975d4 100644 --- a/adyenv6core/src/com/adyen/v6/facades/AdyenExpressCheckoutFacade.java +++ b/adyenv6core/src/com/adyen/v6/facades/AdyenExpressCheckoutFacade.java @@ -5,7 +5,6 @@ import de.hybris.platform.commercefacades.order.data.OrderData; import de.hybris.platform.commercefacades.user.data.AddressData; import de.hybris.platform.deliveryzone.model.ZoneDeliveryModeValueModel; -import de.hybris.platform.order.exceptions.CalculationException; import javax.servlet.http.HttpServletRequest; import java.util.Optional; @@ -26,6 +25,4 @@ OrderData expressCheckoutCartOCC(PaymentRequest paymentRequest, String paymentMe Optional getExpressDeliveryModePrice(); - void removeDeliveryModeFromSessionCart() throws CalculationException; - } diff --git a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenCheckoutFacade.java b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenCheckoutFacade.java index 51382beb..c15773dd 100644 --- a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenCheckoutFacade.java +++ b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenCheckoutFacade.java @@ -1040,7 +1040,7 @@ public void initializeSummaryData(Model model) throws ApiException { model.addAttribute(LOCALE, gson.toJson(setLocale(cartData.getAdyenAmazonPayConfiguration(), shopperLocale))); } - public void initializeExpressCheckoutCartPageData(Model model) throws ApiException { + public void initializeExpressCheckoutCartPageData(Model model) throws ApiException, CalculationException { ExpressCheckoutConfigDTO expressCheckoutConfigDTO = initializeExpressCheckoutCartPageDataOCC(); populateExpressCheckoutConfigModel(model, expressCheckoutConfigDTO); } @@ -1050,7 +1050,9 @@ public void initializeExpressCheckoutPDPData(Model model, String productCode) th populateExpressCheckoutConfigModel(model, expressCheckoutConfigDTO); } - public ExpressCheckoutConfigDTO initializeExpressCheckoutCartPageDataOCC() throws ApiException { + public ExpressCheckoutConfigDTO initializeExpressCheckoutCartPageDataOCC() throws ApiException, CalculationException { + removeDeliveryModeFromSessionCart(); + final CartData cartData = getCheckoutFacade().getCheckoutCart(); if (cartData != null && cartData.getTotalPriceWithTax() != null && cartData.getTotalPriceWithTax().getCurrencyIso() != null) { final String currencyIso = cartData.getTotalPriceWithTax().getCurrencyIso(); @@ -1141,6 +1143,16 @@ protected void populateExpressCheckoutConfigModel(final Model model, final Expre model.addAttribute(MODEL_CHECKOUT_SHOPPER_HOST, expressCheckoutConfigDTO.getCheckoutShopperHost()); } + protected void removeDeliveryModeFromSessionCart() throws CalculationException { + if (cartService.hasSessionCart()) { + CartModel sessionCart = cartService.getSessionCart(); + sessionCart.setDeliveryMode(null); + modelService.save(sessionCart); + + calculationService.recalculate(sessionCart); + } + } + protected BigDecimal getExpressDeliveryModeValue(final String currencyIso) { Optional expressDeliveryModePrice = adyenExpressCheckoutFacade.getExpressDeliveryModePrice(); diff --git a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java index 5f818831..c9c05fdd 100644 --- a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java +++ b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java @@ -30,7 +30,6 @@ import de.hybris.platform.order.CartService; import de.hybris.platform.order.DeliveryModeService; import de.hybris.platform.order.InvalidCartException; -import de.hybris.platform.order.exceptions.CalculationException; import de.hybris.platform.product.ProductService; import de.hybris.platform.servicelayer.dto.converter.Converter; import de.hybris.platform.servicelayer.i18n.CommonI18NService; @@ -301,18 +300,6 @@ protected OrderData expressCartCheckoutOCC(PaymentRequest paymentRequest, Addres } } - public void removeDeliveryModeFromSessionCart() throws CalculationException { - if (cartService.hasSessionCart()) { - CartModel sessionCart = cartService.getSessionCart(); - sessionCart.setDeliveryMode(null); - modelService.save(sessionCart); - - CommerceCartParameter commerceCartParameter = new CommerceCartParameter(); - commerceCartParameter.setCart(sessionCart); - commerceCartService.recalculateCart(commerceCartParameter); - } - } - protected void prepareCart(CartModel cart, DeliveryModeModel deliveryMode, AddressModel addressModel, PaymentInfoModel paymentInfo) { cart.setDeliveryMode(deliveryMode); cart.setDeliveryAddress(addressModel); diff --git a/adyenv6core/testsrc/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacadeTest.java b/adyenv6core/testsrc/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacadeTest.java index e5c51315..8a613948 100644 --- a/adyenv6core/testsrc/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacadeTest.java +++ b/adyenv6core/testsrc/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacadeTest.java @@ -30,7 +30,6 @@ import de.hybris.platform.order.CartFactory; import de.hybris.platform.order.CartService; import de.hybris.platform.order.DeliveryModeService; -import de.hybris.platform.order.exceptions.CalculationException; import de.hybris.platform.product.ProductService; import de.hybris.platform.servicelayer.dto.converter.Converter; import de.hybris.platform.servicelayer.i18n.CommonI18NService; @@ -339,29 +338,6 @@ public void expressCheckoutCartOCCNullPaymentMethod() throws Exception { defaultAdyenExpressCheckoutFacade.expressCheckoutCartOCC(paymentRequest, paymentMethod, addressData, request); } - @Test - public void removeDeliveryModeFromSessionCart() throws CalculationException { - //given - CartModel cartModel = new CartModel(); - DeliveryModeModel deliveryModeModel = new DeliveryModeModel(); - cartModel.setDeliveryMode(deliveryModeModel); - - when(cartService.getSessionCart()).thenReturn(cartModel); - when(cartService.hasSessionCart()).thenReturn(true); - - ArgumentCaptor cartCaptor = ArgumentCaptor.forClass(CartModel.class); - - //when - defaultAdyenExpressCheckoutFacade.removeDeliveryModeFromSessionCart(); - - //then - verify(modelService).save(cartCaptor.capture()); - CartModel capturedCart = cartCaptor.getValue(); - assertNull(capturedCart.getDeliveryMode()); - - verify(commerceCartService).recalculateCart((CommerceCartParameter) any()); - } - @Test public void prepareCart() { //given