From c89799bc2c243377e91e3067a9eb47ead869c54b Mon Sep 17 00:00:00 2001 From: PJaneta Date: Tue, 5 Nov 2024 12:31:29 +0100 Subject: [PATCH] AD-344 Develop Backend Logic for Place Order Endpoints to Handle Apple Pay Express Checkout in Accelerator Storefront and OCC Backend --- .../ApplePayExpressCheckoutController.java | 107 ++++++++++++++++ .../request/ApplePayExpressCartRequest.java | 27 ++++ .../request/ApplePayExpressPDPRequest.java | 13 ++ ...dyenApplePayExpressCheckoutController.java | 47 +++---- ...yenGooglePayExpressCheckoutController.java | 22 ++-- .../request/ApplePayExpressCartRequest.java | 29 +---- .../v6/request/ApplePayExpressPDPRequest.java | 42 +------ .../facades/AdyenExpressCheckoutFacade.java | 6 - .../DefaultAdyenExpressCheckoutFacade.java | 116 ++---------------- 9 files changed, 203 insertions(+), 206 deletions(-) create mode 100644 adyenocc/src/com/adyen/commerce/controllers/expresscheckout/ApplePayExpressCheckoutController.java create mode 100644 adyenocc/src/com/adyen/commerce/request/ApplePayExpressCartRequest.java create mode 100644 adyenocc/src/com/adyen/commerce/request/ApplePayExpressPDPRequest.java diff --git a/adyenocc/src/com/adyen/commerce/controllers/expresscheckout/ApplePayExpressCheckoutController.java b/adyenocc/src/com/adyen/commerce/controllers/expresscheckout/ApplePayExpressCheckoutController.java new file mode 100644 index 000000000..a0411df74 --- /dev/null +++ b/adyenocc/src/com/adyen/commerce/controllers/expresscheckout/ApplePayExpressCheckoutController.java @@ -0,0 +1,107 @@ + package com.adyen.commerce.controllers.expresscheckout; + + import com.adyen.commerce.constants.AdyenoccConstants; + import com.adyen.commerce.request.ApplePayExpressCartRequest; + import com.adyen.commerce.request.ApplePayExpressPDPRequest; + import com.adyen.commerce.resolver.PaymentRedirectReturnUrlResolver; + import com.adyen.commerce.response.OCCPlaceOrderResponse; + import com.adyen.model.checkout.ApplePayDetails; + import com.adyen.model.checkout.CheckoutPaymentMethod; + import com.adyen.model.checkout.PaymentRequest; + import com.adyen.v6.constants.Adyenv6coreConstants; + import com.adyen.v6.facades.AdyenExpressCheckoutFacade; + import de.hybris.platform.commercefacades.order.CartFacade; + import de.hybris.platform.commerceservices.request.mapping.annotation.ApiVersion; + import de.hybris.platform.commerceservices.strategies.CheckoutCustomerStrategy; + import de.hybris.platform.webservicescommons.swagger.ApiBaseSiteIdUserIdAndCartIdParam; + import io.swagger.v3.oas.annotations.Operation; + import io.swagger.v3.oas.annotations.tags.Tag; + import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.http.MediaType; + import org.springframework.http.ResponseEntity; + import org.springframework.security.access.annotation.Secured; + import org.springframework.web.bind.annotation.PostMapping; + import org.springframework.web.bind.annotation.RequestBody; + import org.springframework.web.bind.annotation.RequestMapping; + import org.springframework.web.bind.annotation.RestController; + + import javax.servlet.http.HttpServletRequest; + +@RestController +@RequestMapping(value = AdyenoccConstants.ADYEN_USER_CART_PREFIX + "/express-checkout/apple") +@ApiVersion("v2") +@Tag(name = "Adyen") +public class ApplePayExpressCheckoutController extends ExpressCheckoutControllerBase { + + @Autowired + private CartFacade cartFacade; + + @Autowired + private CheckoutCustomerStrategy checkoutCustomerStrategy; + + @Autowired + private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade; + + @Autowired + private PaymentRedirectReturnUrlResolver paymentRedirectReturnUrlResolver; + + + @Secured({"ROLE_CUSTOMERGROUP", "ROLE_CLIENT", "ROLE_CUSTOMERMANAGERGROUP", "ROLE_TRUSTED_CLIENT"}) + @PostMapping(value = "/PDP", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(operationId = "placeOrderApplePayExpressPDP", summary = "Handle applePayExpress place order request", description = + "Places order based on request data") + @ApiBaseSiteIdUserIdAndCartIdParam + public ResponseEntity applePayPDPExpressCheckout(final HttpServletRequest request, @RequestBody String applePayExpressPDPStringRequest) throws Exception { + ApplePayExpressPDPRequest applePayExpressPDPRequest = objectMapper.readValue(applePayExpressPDPStringRequest, ApplePayExpressPDPRequest.class); + + PaymentRequest paymentRequest = getPaymentRequest(applePayExpressPDPRequest); + + OCCPlaceOrderResponse placeOrderResponse = handlePayment(request, paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, applePayExpressPDPRequest.getAddressData(), applePayExpressPDPRequest.getProductCode(), true); + String response = objectMapper.writeValueAsString(placeOrderResponse); + return ResponseEntity.ok(response); + } + + @Secured({"ROLE_CUSTOMERGROUP", "ROLE_CLIENT", "ROLE_CUSTOMERMANAGERGROUP", "ROLE_TRUSTED_CLIENT"}) + @PostMapping(value = "/cart", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(operationId = "placeOrderApplePayExpressCart", summary = "Handle applePayExpress place order request", description = + "Places order based on request data") + @ApiBaseSiteIdUserIdAndCartIdParam + public ResponseEntity applePayCartExpressCheckout(final HttpServletRequest request, @RequestBody String applePayExpressCartStringRequest) throws Exception { + ApplePayExpressCartRequest applePayExpressCartRequest = objectMapper.readValue(applePayExpressCartStringRequest, ApplePayExpressCartRequest.class); + + PaymentRequest paymentRequest = getPaymentRequest(applePayExpressCartRequest); + + OCCPlaceOrderResponse placeOrderResponse = handlePayment(request, paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, applePayExpressCartRequest.getAddressData(), null, false); + String response = objectMapper.writeValueAsString(placeOrderResponse); + return ResponseEntity.ok(response); + } + + private static PaymentRequest getPaymentRequest(T request) { + PaymentRequest paymentRequest = new PaymentRequest(); + ApplePayDetails applePayDetails = request.getApplePayDetails(); + applePayDetails.setType(ApplePayDetails.TypeEnum.APPLEPAY); + paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(applePayDetails)); + return paymentRequest; + } + + @Override + public CartFacade getCartFacade() { + return cartFacade; + } + + @Override + public CheckoutCustomerStrategy getCheckoutCustomerStrategy() { + return checkoutCustomerStrategy; + } + + @Override + public String getPaymentRedirectReturnUrl() { + return paymentRedirectReturnUrlResolver.resolvePaymentRedirectReturnUrl(); + } + + @Override + public AdyenExpressCheckoutFacade getAdyenCheckoutApiFacade() { + return adyenExpressCheckoutFacade; + } +} + diff --git a/adyenocc/src/com/adyen/commerce/request/ApplePayExpressCartRequest.java b/adyenocc/src/com/adyen/commerce/request/ApplePayExpressCartRequest.java new file mode 100644 index 000000000..d182602df --- /dev/null +++ b/adyenocc/src/com/adyen/commerce/request/ApplePayExpressCartRequest.java @@ -0,0 +1,27 @@ +package com.adyen.commerce.request; + +import com.adyen.model.checkout.ApplePayDetails; +import de.hybris.platform.commercefacades.user.data.AddressData; + +import java.io.Serializable; + +public class ApplePayExpressCartRequest implements Serializable { + private AddressData addressData; + private ApplePayDetails applePayDetails; + + public AddressData getAddressData() { + return addressData; + } + + public void setAddressData(AddressData addressData) { + this.addressData = addressData; + } + + public ApplePayDetails getApplePayDetails() { + return applePayDetails; + } + + public void setApplePayDetails(ApplePayDetails applePayDetails) { + this.applePayDetails = applePayDetails; + } +} diff --git a/adyenocc/src/com/adyen/commerce/request/ApplePayExpressPDPRequest.java b/adyenocc/src/com/adyen/commerce/request/ApplePayExpressPDPRequest.java new file mode 100644 index 000000000..c37540fed --- /dev/null +++ b/adyenocc/src/com/adyen/commerce/request/ApplePayExpressPDPRequest.java @@ -0,0 +1,13 @@ +package com.adyen.commerce.request; + +public class ApplePayExpressPDPRequest extends ApplePayExpressCartRequest { + private String productCode; + + public String getProductCode() { + return productCode; + } + + public void setProductCode(String productCode) { + this.productCode = productCode; + } +} diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/checkout/AdyenApplePayExpressCheckoutController.java b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/checkout/AdyenApplePayExpressCheckoutController.java index 16748c4a2..ebd174aa7 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/checkout/AdyenApplePayExpressCheckoutController.java +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/checkout/AdyenApplePayExpressCheckoutController.java @@ -1,68 +1,73 @@ package com.adyen.v6.controllers.checkout; +import com.adyen.model.checkout.ApplePayDetails; +import com.adyen.model.checkout.CheckoutPaymentMethod; +import com.adyen.model.checkout.PaymentRequest; import com.adyen.model.checkout.PaymentResponse; +import com.adyen.v6.constants.Adyenv6coreConstants; import com.adyen.v6.facades.AdyenExpressCheckoutFacade; import com.adyen.v6.request.ApplePayExpressCartRequest; import com.adyen.v6.request.ApplePayExpressPDPRequest; -import de.hybris.platform.acceleratorstorefrontcommons.constants.WebConstants; import de.hybris.platform.acceleratorstorefrontcommons.security.GUIDCookieStrategy; -import de.hybris.platform.servicelayer.session.SessionService; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Controller +@RequestMapping("/express-checkout/apple/") public class AdyenApplePayExpressCheckoutController { private static final Logger LOG = Logger.getLogger(AdyenApplePayExpressCheckoutController.class); @Autowired private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade; - @Autowired - private SessionService sessionService; - @Autowired private GUIDCookieStrategy guidCookieStrategy; - @PostMapping("/expressCheckout/applePayPDP") + @PostMapping("PDP") public ResponseEntity applePayExpressPDP(final HttpServletRequest request, final HttpServletResponse response, @RequestBody ApplePayExpressPDPRequest applePayExpressPDPRequest) throws Exception { - PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.appleExpressPDPCheckout(applePayExpressPDPRequest.getAddressData(), applePayExpressPDPRequest.getProductCode(), - applePayExpressPDPRequest.getAdyenApplePayMerchantIdentifier(), applePayExpressPDPRequest.getAdyenApplePayMerchantName(), - applePayExpressPDPRequest.getApplePayToken(), request); + PaymentRequest paymentRequest = getPaymentRequest(applePayExpressPDPRequest); + + PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.expressCheckoutPDP(applePayExpressPDPRequest.getProductCode(), + paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, applePayExpressPDPRequest.getAddressData(), request); guidCookieStrategy.setCookie(request, response); - sessionService.setAttribute(WebConstants.ANONYMOUS_CHECKOUT, Boolean.TRUE); return new ResponseEntity<>(paymentsResponse, HttpStatus.OK); } - @PostMapping("/expressCheckout/cart") + @PostMapping("cart") public ResponseEntity cartExpressCheckout(final HttpServletRequest request, final HttpServletResponse response, @RequestBody ApplePayExpressCartRequest applePayExpressCartRequest) throws Exception { - PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.appleEexpressCartCheckout(applePayExpressCartRequest.getAddressData(), - applePayExpressCartRequest.getAdyenApplePayMerchantIdentifier(), applePayExpressCartRequest.getAdyenApplePayMerchantName(), - applePayExpressCartRequest.getApplePayToken(), request); + PaymentRequest paymentRequest = getPaymentRequest(applePayExpressCartRequest); + + PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.expressCheckoutCart(paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, + applePayExpressCartRequest.getAddressData(), request); guidCookieStrategy.setCookie(request, response); - sessionService.setAttribute(WebConstants.ANONYMOUS_CHECKOUT, Boolean.TRUE); return new ResponseEntity<>(paymentsResponse, HttpStatus.OK); } + private static PaymentRequest getPaymentRequest(T request) { + PaymentRequest paymentRequest = new PaymentRequest(); + ApplePayDetails applePayDetails = request.getApplePayDetails(); + applePayDetails.setType(ApplePayDetails.TypeEnum.APPLEPAY); + paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(applePayDetails)); + return paymentRequest; + } + + @ResponseStatus(value = HttpStatus.BAD_REQUEST) @ExceptionHandler(value = Exception.class) - public String adyenComponentExceptionHandler(Exception e) { + public void adyenComponentExceptionHandler(Exception e) { LOG.error("Exception during ApplePayExpress processing", e); - return "Exception during ApplePayExpress processing"; } } diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/checkout/AdyenGooglePayExpressCheckoutController.java b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/checkout/AdyenGooglePayExpressCheckoutController.java index ac0c66dda..96d990c1f 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/checkout/AdyenGooglePayExpressCheckoutController.java +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/checkout/AdyenGooglePayExpressCheckoutController.java @@ -1,15 +1,14 @@ package com.adyen.v6.controllers.checkout; import com.adyen.model.checkout.CheckoutPaymentMethod; +import com.adyen.model.checkout.GooglePayDetails; import com.adyen.model.checkout.PaymentRequest; import com.adyen.model.checkout.PaymentResponse; import com.adyen.v6.constants.Adyenv6coreConstants; import com.adyen.v6.facades.AdyenExpressCheckoutFacade; import com.adyen.v6.request.GooglePayExpressCartRequest; import com.adyen.v6.request.GooglePayExpressPDPRequest; -import de.hybris.platform.acceleratorstorefrontcommons.constants.WebConstants; import de.hybris.platform.acceleratorstorefrontcommons.security.GUIDCookieStrategy; -import de.hybris.platform.servicelayer.session.SessionService; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -28,23 +27,18 @@ public class AdyenGooglePayExpressCheckoutController { @Autowired private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade; - @Autowired - private SessionService sessionService; - @Autowired private GUIDCookieStrategy guidCookieStrategy; @PostMapping("PDP") public ResponseEntity googlePayExpressPDP(final HttpServletRequest request, final HttpServletResponse response, @RequestBody GooglePayExpressPDPRequest googlePayExpressPDPRequest) throws Exception { - PaymentRequest paymentRequest = new PaymentRequest(); - paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(googlePayExpressPDPRequest.getGooglePayDetails())); + PaymentRequest paymentRequest = getPaymentRequest(googlePayExpressPDPRequest); PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.expressCheckoutPDP(googlePayExpressPDPRequest.getProductCode(), paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_GOOGLE_PAY, googlePayExpressPDPRequest.getAddressData(), request); guidCookieStrategy.setCookie(request, response); - sessionService.setAttribute(WebConstants.ANONYMOUS_CHECKOUT, Boolean.TRUE); return new ResponseEntity<>(paymentsResponse, HttpStatus.OK); } @@ -52,18 +46,24 @@ public ResponseEntity googlePayExpressPDP(final HttpServletRequest request, fina @PostMapping("cart") public ResponseEntity googlePayCartExpressCheckout(final HttpServletRequest request, final HttpServletResponse response, @RequestBody GooglePayExpressCartRequest googlePayExpressCartRequest) throws Exception { - PaymentRequest paymentRequest = new PaymentRequest(); - paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(googlePayExpressCartRequest.getGooglePayDetails())); + PaymentRequest paymentRequest = getPaymentRequest(googlePayExpressCartRequest); PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.expressCheckoutCart(paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_GOOGLE_PAY, googlePayExpressCartRequest.getAddressData(), request); guidCookieStrategy.setCookie(request, response); - sessionService.setAttribute(WebConstants.ANONYMOUS_CHECKOUT, Boolean.TRUE); return new ResponseEntity<>(paymentsResponse, HttpStatus.OK); } + private static PaymentRequest getPaymentRequest(T request) { + PaymentRequest paymentRequest = new PaymentRequest(); + GooglePayDetails googlePayDetails = request.getGooglePayDetails(); + googlePayDetails.setType(GooglePayDetails.TypeEnum.GOOGLEPAY); + paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(googlePayDetails)); + return paymentRequest; + } + @ResponseStatus(value = HttpStatus.BAD_REQUEST) @ExceptionHandler(value = Exception.class) public void adyenComponentExceptionHandler(Exception e) { diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/ApplePayExpressCartRequest.java b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/ApplePayExpressCartRequest.java index 470b9a277..0844da8a4 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/ApplePayExpressCartRequest.java +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/ApplePayExpressCartRequest.java @@ -1,14 +1,13 @@ package com.adyen.v6.request; +import com.adyen.model.checkout.ApplePayDetails; import de.hybris.platform.commercefacades.user.data.AddressData; import java.io.Serializable; public class ApplePayExpressCartRequest implements Serializable { private AddressData addressData; - private String adyenApplePayMerchantName; - private String adyenApplePayMerchantIdentifier; - private String applePayToken; + private ApplePayDetails applePayDetails; public AddressData getAddressData() { return addressData; @@ -18,27 +17,11 @@ public void setAddressData(AddressData addressData) { this.addressData = addressData; } - public String getAdyenApplePayMerchantName() { - return adyenApplePayMerchantName; + public ApplePayDetails getApplePayDetails() { + return applePayDetails; } - public void setAdyenApplePayMerchantName(String adyenApplePayMerchantName) { - this.adyenApplePayMerchantName = adyenApplePayMerchantName; - } - - public String getAdyenApplePayMerchantIdentifier() { - return adyenApplePayMerchantIdentifier; - } - - public void setAdyenApplePayMerchantIdentifier(String adyenApplePayMerchantIdentifier) { - this.adyenApplePayMerchantIdentifier = adyenApplePayMerchantIdentifier; - } - - public String getApplePayToken() { - return applePayToken; - } - - public void setApplePayToken(String applePayToken) { - this.applePayToken = applePayToken; + public void setApplePayDetails(ApplePayDetails applePayDetails) { + this.applePayDetails = applePayDetails; } } diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/ApplePayExpressPDPRequest.java b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/ApplePayExpressPDPRequest.java index 9e5610055..c089ac3eb 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/ApplePayExpressPDPRequest.java +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/ApplePayExpressPDPRequest.java @@ -1,15 +1,7 @@ package com.adyen.v6.request; -import de.hybris.platform.commercefacades.user.data.AddressData; - -import java.io.Serializable; - -public class ApplePayExpressPDPRequest implements Serializable { +public class ApplePayExpressPDPRequest extends ApplePayExpressCartRequest { private String productCode; - private AddressData addressData; - private String adyenApplePayMerchantName; - private String adyenApplePayMerchantIdentifier; - private String applePayToken; public String getProductCode() { return productCode; @@ -18,36 +10,4 @@ public String getProductCode() { public void setProductCode(String productCode) { this.productCode = productCode; } - - public AddressData getAddressData() { - return addressData; - } - - public void setAddressData(AddressData addressData) { - this.addressData = addressData; - } - - public String getAdyenApplePayMerchantName() { - return adyenApplePayMerchantName; - } - - public void setAdyenApplePayMerchantName(String adyenApplePayMerchantName) { - this.adyenApplePayMerchantName = adyenApplePayMerchantName; - } - - public String getAdyenApplePayMerchantIdentifier() { - return adyenApplePayMerchantIdentifier; - } - - public void setAdyenApplePayMerchantIdentifier(String adyenApplePayMerchantIdentifier) { - this.adyenApplePayMerchantIdentifier = adyenApplePayMerchantIdentifier; - } - - public String getApplePayToken() { - return applePayToken; - } - - public void setApplePayToken(String applePayToken) { - this.applePayToken = applePayToken; - } } diff --git a/adyenv6core/src/com/adyen/v6/facades/AdyenExpressCheckoutFacade.java b/adyenv6core/src/com/adyen/v6/facades/AdyenExpressCheckoutFacade.java index a50e79f50..2cbd6a3d4 100644 --- a/adyenv6core/src/com/adyen/v6/facades/AdyenExpressCheckoutFacade.java +++ b/adyenv6core/src/com/adyen/v6/facades/AdyenExpressCheckoutFacade.java @@ -12,12 +12,6 @@ public interface AdyenExpressCheckoutFacade { - PaymentResponse appleExpressPDPCheckout(AddressData addressData, String productCode, String merchantId, String merchantName, - String applePayToken, HttpServletRequest request) throws Exception; - - PaymentResponse appleEexpressCartCheckout(AddressData addressData, String merchantId, String merchantName, - String applePayToken, HttpServletRequest request) throws Exception; - PaymentResponse expressCheckoutPDP(String productCode, PaymentRequest paymentRequest, String paymentMethod, AddressData addressData, HttpServletRequest request) throws Exception ; diff --git a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java index 334045dd0..3c47bbd3e 100644 --- a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java +++ b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java @@ -1,8 +1,8 @@ package com.adyen.v6.facades.impl; import com.adyen.commerce.facades.AdyenCheckoutApiFacade; -import com.adyen.model.checkout.*; -import com.adyen.v6.constants.Adyenv6coreConstants; +import com.adyen.model.checkout.PaymentRequest; +import com.adyen.model.checkout.PaymentResponse; import com.adyen.v6.facades.AdyenCheckoutFacade; import com.adyen.v6.facades.AdyenExpressCheckoutFacade; import de.hybris.platform.commercefacades.customer.CustomerFacade; @@ -55,6 +55,7 @@ public class DefaultAdyenExpressCheckoutFacade implements AdyenExpressCheckoutFa protected static final String USER_NAME = "ExpressCheckoutGuest"; private static final String DELIVERY_MODE_CODE = "adyen-express-checkout"; protected static final String ANONYMOUS_CHECKOUT_GUID = "anonymous_checkout_guid"; + protected static final String ANONYMOUS_CHECKOUT = "anonymous_checkout"; private CartFactory cartFactory; private CartService cartService; @@ -129,8 +130,10 @@ protected PaymentResponse expressPDPCheckout(PaymentRequest paymentRequest, Addr throw new IllegalArgumentException("Empty email address"); } CustomerModel user = (CustomerModel) userService.getCurrentUser(); + boolean isGuestUser = false; if (userService.isAnonymousUser(user)) { user = createGuestCustomer(addressData.getEmail()); + isGuestUser = true; } CartModel cart = createCartForExpressCheckout(user); @@ -160,9 +163,10 @@ protected PaymentResponse expressPDPCheckout(PaymentRequest paymentRequest, Addr PaymentResponse paymentsResponse = adyenCheckoutFacade.componentPayment(request, cartData, paymentRequest); - if (userService.isAnonymousUser(user)) { + if (isGuestUser) { sessionService.setAttribute(ANONYMOUS_CHECKOUT_GUID, org.apache.commons.lang.StringUtils.substringBefore(cart.getUser().getUid(), "|")); + sessionService.setAttribute(ANONYMOUS_CHECKOUT, Boolean.TRUE); } if (sessionCart != null) { @@ -224,71 +228,14 @@ protected OrderData expressPDPCheckoutOCC(PaymentRequest paymentRequest, Address } } - - //TODO: Remove after applepay - public PaymentResponse appleExpressPDPCheckout(AddressData addressData, String productCode, String merchantId, String merchantName, - String applePayToken, HttpServletRequest request) throws Exception { - validateParameterNotNull(addressData, "Empty address"); - if (StringUtils.isEmpty(addressData.getEmail())) { - throw new IllegalArgumentException("Empty email address"); - } - CustomerModel user = (CustomerModel) userService.getCurrentUser(); - if (userService.isAnonymousUser(user)) { - user = createGuestCustomer(addressData.getEmail()); - } - - CartModel cart = createCartForExpressCheckout(user); - - DeliveryModeModel deliveryMode = deliveryModeService.getDeliveryModeForCode(DELIVERY_MODE_CODE); - validateParameterNotNull(deliveryMode, "Delivery mode for Adyen express checkout not configured"); - - AddressModel addressModel = prepareAddressModel(addressData, user); - PaymentInfoModel paymentInfo = createPaymentInfoForCart(user, addressModel, cart, - Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, merchantId, merchantName); - - prepareCart(cart, deliveryMode, addressModel, paymentInfo); - - addProductToCart(productCode, cart); - - if (cartHasEntries(cart)) { - CommerceCartParameter commerceCartParameter = new CommerceCartParameter(); - commerceCartParameter.setCart(cart); - commerceCartService.calculateCart(commerceCartParameter); - - CartModel sessionCart = null; - if (cartService.hasSessionCart()) { - sessionCart = cartService.getSessionCart(); - } - cartService.setSessionCart(cart); - - CartData cartData = cartConverter.convert(cart); - - ApplePayDetails applePayDetails = new ApplePayDetails(); - applePayDetails.setApplePayToken(applePayToken); - CheckoutPaymentMethod checkoutPaymentMethod = new CheckoutPaymentMethod(applePayDetails); - PaymentRequest paymentRequest = new PaymentRequest(); - paymentRequest.setPaymentMethod(checkoutPaymentMethod); - PaymentResponse paymentsResponse = adyenCheckoutFacade.componentPayment(request, cartData, paymentRequest); - - sessionService.setAttribute(ANONYMOUS_CHECKOUT_GUID, - org.apache.commons.lang.StringUtils.substringBefore(cart.getUser().getUid(), "|")); - - if (sessionCart != null) { - cartService.setSessionCart(sessionCart); - } - - return paymentsResponse; - } else { - throw new InvalidCartException("Checkout attempt on empty cart"); - } - } - protected PaymentResponse expressCartCheckout(PaymentRequest paymentRequest, AddressData addressData, PaymentInfoModel paymentInfoModel, HttpServletRequest request) throws Exception { CustomerModel user = (CustomerModel) userService.getCurrentUser(); + boolean isGuestUser = false; if (userService.isAnonymousUser(user)) { user = createGuestCustomer(addressData.getEmail()); cartService.changeCurrentCartUser(user); + isGuestUser = true; } CartModel cart = cartService.getSessionCart(); @@ -308,9 +255,11 @@ protected PaymentResponse expressCartCheckout(PaymentRequest paymentRequest, Add if (cartHasEntries(cart)) { CartData cartData = cartConverter.convert(cart); - if (userService.isAnonymousUser(user)) { + if (isGuestUser) { sessionService.setAttribute(ANONYMOUS_CHECKOUT_GUID, org.apache.commons.lang.StringUtils.substringBefore(cart.getUser().getUid(), "|")); + sessionService.setAttribute(ANONYMOUS_CHECKOUT, Boolean.TRUE); + } return adyenCheckoutFacade.componentPayment(request, cartData, paymentRequest); @@ -350,47 +299,6 @@ protected OrderData expressCartCheckoutOCC(PaymentRequest paymentRequest, Addres } } - //TODO: Remove after applepay - public PaymentResponse appleEexpressCartCheckout(AddressData addressData, String merchantId, String merchantName, - String applePayToken, HttpServletRequest request) throws Exception { - CustomerModel user = (CustomerModel) userService.getCurrentUser(); - if (userService.isAnonymousUser(user)) { - user = createGuestCustomer(addressData.getEmail()); - cartService.changeCurrentCartUser(user); - } - - CartModel cart = cartService.getSessionCart(); - - DeliveryModeModel deliveryMode = deliveryModeService.getDeliveryModeForCode(DELIVERY_MODE_CODE); - validateParameterNotNull(deliveryMode, "Delivery mode for Adyen express checkout not configured"); - - AddressModel addressModel = prepareAddressModel(addressData, user); - - PaymentInfoModel paymentInfo = createPaymentInfoForCart(user, addressModel, cart, - Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, merchantId, merchantName); - - prepareCart(cart, deliveryMode, addressModel, paymentInfo); - - CommerceCartParameter commerceCartParameter = new CommerceCartParameter(); - commerceCartParameter.setCart(cart); - commerceCartService.recalculateCart(commerceCartParameter); - - if (cartHasEntries(cart)) { - CartData cartData = cartConverter.convert(cart); - - ApplePayDetails applePayDetails = new ApplePayDetails(); - applePayDetails.setApplePayToken(applePayToken); - - sessionService.setAttribute(ANONYMOUS_CHECKOUT_GUID, - org.apache.commons.lang.StringUtils.substringBefore(cart.getUser().getUid(), "|")); - PaymentRequest paymentRequest = new PaymentRequest(); - paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(applePayDetails)); - return adyenCheckoutFacade.componentPayment(request, cartData, paymentRequest); - } else { - throw new InvalidCartException("Checkout attempt on empty cart"); - } - } - public void removeDeliveryModeFromSessionCart() throws CalculationException { if (cartService.hasSessionCart()) { CartModel sessionCart = cartService.getSessionCart();