Skip to content

Commit

Permalink
AD-394 Doubled shipment price on the express checkout on the cart
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaneta committed Jan 14, 2025
1 parent a84dcdc commit 8a11e2a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 =
Expand All @@ -61,7 +66,7 @@ public ResponseEntity<String> getExpressPDPCheckoutConfiguration(@PathVariable S
@Operation(operationId = "getExpressCartCheckoutConfiguration", summary = "Get express cart page checkout configuration", description =
"Returns configuration for express payments on cart")
@ApiBaseSiteIdUserIdAndCartIdParam
public ResponseEntity<String> getExpressCartCheckoutConfiguration() throws ApiException, JsonProcessingException {
public ResponseEntity<String> getExpressCartCheckoutConfiguration() throws ApiException, JsonProcessingException, CalculationException {
String response = objectMapper.writeValueAsString(adyenCheckoutFacade.initializeExpressCheckoutCartPageDataOCC());
return ResponseEntity.ok().body(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions adyenv6core/src/com/adyen/v6/facades/AdyenCheckoutFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +25,4 @@ OrderData expressCheckoutCartOCC(PaymentRequest paymentRequest, String paymentMe

Optional<ZoneDeliveryModeValueModel> getExpressDeliveryModePrice();

void removeDeliveryModeFromSessionCart() throws CalculationException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();
Expand Down Expand Up @@ -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<ZoneDeliveryModeValueModel> expressDeliveryModePrice = adyenExpressCheckoutFacade.getExpressDeliveryModePrice();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CartModel> 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
Expand Down

0 comments on commit 8a11e2a

Please sign in to comment.