Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AD-394 Doubled shipment price on the express checkout on the cart #509

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading