Skip to content

Commit

Permalink
AD-50 add user login
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaneta committed Nov 17, 2023
1 parent fda88e4 commit 252290e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.adyen.v6.facades.AdyenExpressCheckoutFacade;
import com.adyen.v6.request.ApplePayExpressCartRequest;
import com.adyen.v6.request.ApplePayExpressPDPRequest;
import de.hybris.platform.acceleratorstorefrontcommons.security.GUIDCookieStrategy;
import de.hybris.platform.acceleratorstorefrontcommons.security.AutoLoginStrategy;
import de.hybris.platform.servicelayer.user.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -15,28 +16,30 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class AdyenApplePayExpressCheckoutController {
private static final Logger LOG = Logger.getLogger(AdyenApplePayExpressCheckoutController.class);

@Resource(name = "guidCookieStrategy")
private GUIDCookieStrategy guidCookieStrategy;

@Autowired
private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade;

@Autowired
private UserService userService;

@Autowired
private AutoLoginStrategy autoLoginStrategy;

@PostMapping("/expressCheckout/applePayPDP")
public ResponseEntity applePayExpressPDP(final HttpServletRequest request, final HttpServletResponse response, @RequestBody ApplePayExpressPDPRequest applePayExpressPDPRequest) throws Exception {

PaymentsResponse paymentsResponse = adyenExpressCheckoutFacade.expressPDPCheckout(applePayExpressPDPRequest.getAddressData(), applePayExpressPDPRequest.getProductCode(),
applePayExpressPDPRequest.getAdyenApplePayMerchantIdentifier(), applePayExpressPDPRequest.getAdyenApplePayMerchantName(),
applePayExpressPDPRequest.getApplePayToken(), request);

guidCookieStrategy.setCookie(request, response);
autoLoginStrategy.login(userService.getCurrentUser().getUid(), null, request, response);

return new ResponseEntity<>(paymentsResponse, HttpStatus.OK);
}
Expand All @@ -48,7 +51,7 @@ public ResponseEntity cartExpressCheckout(final HttpServletRequest request, fina
applePayExpressCartRequest.getAdyenApplePayMerchantIdentifier(), applePayExpressCartRequest.getAdyenApplePayMerchantName(),
applePayExpressCartRequest.getApplePayToken(), request);

guidCookieStrategy.setCookie(request, response);
autoLoginStrategy.login(userService.getCurrentUser().getUid(), null, request, response);

return new ResponseEntity<>(paymentsResponse, HttpStatus.OK);
}
Expand Down
1 change: 0 additions & 1 deletion adyenv6core/resources/adyenv6core-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,5 @@
<property name="adyenCheckoutFacade" ref="adyenCheckoutFacade"/>
<property name="cartConverter" ref="cartConverter"/>
<property name="userService" ref="userService"/>
<property name="sessionService" ref="sessionService"/>
</bean>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import de.hybris.platform.servicelayer.dto.converter.Converter;
import de.hybris.platform.servicelayer.i18n.CommonI18NService;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.servicelayer.session.SessionService;
import de.hybris.platform.servicelayer.user.UserService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -60,7 +59,6 @@ public class DefaultAdyenExpressCheckoutFacade implements AdyenExpressCheckoutFa
private ZoneDeliveryModeService zoneDeliveryModeService;
private AdyenCheckoutFacade adyenCheckoutFacade;
private UserService userService;
private SessionService sessionService;
private Converter<AddressData, AddressModel> addressReverseConverter;
private Converter<CartModel, CartData> cartConverter;

Expand All @@ -74,7 +72,6 @@ public PaymentsResponse expressPDPCheckout(AddressData addressData, String produ

CustomerModel user = createGuestCustomer(addressData.getEmail());
userService.setCurrentUser(user);
sessionService.setAttribute("anonymous_checkout", Boolean.TRUE);

CartModel cart = createCartForExpressCheckout(user);

Expand Down Expand Up @@ -133,7 +130,6 @@ public PaymentsResponse expressCartCheckout(AddressData addressData, String merc
CustomerModel user = createGuestCustomer(addressData.getEmail());
userService.setCurrentUser(user);
cartService.changeCurrentCartUser(user);
sessionService.setAttribute("anonymous_checkout", Boolean.TRUE);

CartModel cart = cartService.getSessionCart();
AddressModel addressModel = addressReverseConverter.convert(addressData);
Expand Down Expand Up @@ -293,8 +289,4 @@ public void setCartConverter(Converter<CartModel, CartData> cartConverter) {
public void setUserService(UserService userService) {
this.userService = userService;
}

public void setSessionService(SessionService sessionService) {
this.sessionService = sessionService;
}
}

0 comments on commit 252290e

Please sign in to comment.