From d9841a7d176719a64ea16d3af01f72bd3bbe9ea2 Mon Sep 17 00:00:00 2001 From: kpieloch <113994423+kpieloch@users.noreply.github.com> Date: Tue, 20 Feb 2024 11:51:09 +0100 Subject: [PATCH 1/3] [AD-195] Giftcard / Givex support on frontend + BLIK --- .../pages/AdyenComponentController.java | 239 +++++++++--------- .../webroot/WEB-INF/messages/base.properties | 2 + .../WEB-INF/messages/base_en.properties | 2 + .../tags/responsive/checkoutOrderSummary.tag | 14 + .../checkout/multi/checkoutSummaryPage.jsp | 169 +++++++------ .../responsive/common/js/adyen.checkout.js | 75 +++++- adyenv6b2ccheckoutaddon/project.properties | 2 +- 7 files changed, 302 insertions(+), 201 deletions(-) diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/pages/AdyenComponentController.java b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/pages/AdyenComponentController.java index 9831a68b7..34e8a2a5d 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/pages/AdyenComponentController.java +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/pages/AdyenComponentController.java @@ -53,7 +53,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.io.IOException; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -124,146 +123,150 @@ public String componentPayment(final HttpServletRequest request) throws AdyenCom } else if (PAYMENT_METHOD_PIX.equals(paymentMethod) || PAYMENT_METHOD_BCMC_MOBILE.equals(paymentMethod)) { paymentMethodDetails = new CardDetails(); paymentMethodDetails.setType(paymentMethod); - } else { - throw new InvalidCartException("checkout.error.paymentethod.formentry.invalid"); - } - - cartData.setAdyenReturnUrl(getReturnUrl(paymentMethod)); - - PaymentsResponse paymentsResponse = getAdyenCheckoutFacade().componentPayment(request, cartData, paymentMethodDetails); - return gson.toJson(paymentsResponse); - } catch(InvalidCartException e){ - LOGGER.error("InvalidCartException: " + e.getMessage()); - throw new AdyenComponentException(e.getMessage()); - } - catch(ApiException e){ - LOGGER.error("ApiException: " + e.toString()); - throw new AdyenComponentException("checkout.error.authorization.payment.refused"); - } catch(AdyenNonAuthorizedPaymentException e){ - LOGGER.warn("AdyenNonAuthorizedPaymentException occurred. Payment " + e.getPaymentResult().getPspReference() + "is refused."); - throw new AdyenComponentException("checkout.error.authorization.payment.refused"); - } catch(Exception e){ - LOGGER.error("Exception", e); - throw new AdyenComponentException("checkout.error.authorization.payment.error"); + } else if (BlikDetails.BLIK.equals(paymentMethod)) { + paymentMethodDetails = gson.fromJson(requestJson.get("paymentMethodDetails"), BlikDetails.class); + } else if (CardDetails.GIFTCARD.equals(paymentMethod)) { + paymentMethodDetails = gson.fromJson(requestJson.get("paymentMethodDetails"), CardDetails.class); + paymentMethodDetails.setType(paymentMethod); + } else { + throw new InvalidCartException("checkout.error.paymentethod.formentry.invalid"); } - } - @RequestMapping(value = "/submit-details", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public String submitDetails ( final HttpServletRequest request) throws AdyenComponentException { - try { - String requestJsonString = IOUtils.toString(request.getInputStream(), String.valueOf(StandardCharsets.UTF_8)); - JsonObject requestJson = new JsonParser().parse(requestJsonString).getAsJsonObject(); - - Gson gson = new GsonBuilder().disableHtmlEscaping().create(); - Type mapType = new TypeToken>() { - }.getType(); - Map details = gson.fromJson(requestJson.get("details"), mapType); - String paymentData = gson.fromJson(requestJson.get("paymentData"), String.class); - - PaymentsDetailsResponse paymentsResponse = getAdyenCheckoutFacade().componentDetails(request, details, paymentData); - return gson.toJson(paymentsResponse); - } catch (ApiException e) { - LOGGER.error("ApiException: " + e.toString()); - throw new AdyenComponentException("checkout.error.authorization.payment.refused"); - } catch (Exception e) { - LOGGER.error("Exception", e); - throw new AdyenComponentException("checkout.error.authorization.payment.error"); - } + cartData.setAdyenReturnUrl(getReturnUrl(paymentMethod)); + + PaymentsResponse paymentsResponse = getAdyenCheckoutFacade().componentPayment(request, cartData, paymentMethodDetails); + return gson.toJson(paymentsResponse); + } catch (InvalidCartException e) { + LOGGER.error("InvalidCartException: " + e.getMessage()); + throw new AdyenComponentException(e.getMessage()); + } catch (ApiException e) { + LOGGER.error("ApiException: " + e.toString()); + throw new AdyenComponentException("checkout.error.authorization.payment.refused"); + } catch (AdyenNonAuthorizedPaymentException e) { + LOGGER.warn("AdyenNonAuthorizedPaymentException occurred. Payment " + e.getPaymentResult().getPspReference() + "is refused."); + throw new AdyenComponentException("checkout.error.authorization.payment.refused"); + } catch (Exception e) { + LOGGER.error("Exception", e); + throw new AdyenComponentException("checkout.error.authorization.payment.error"); } + } - @ResponseStatus(value = HttpStatus.BAD_REQUEST) - @ExceptionHandler(value = AdyenComponentException.class) - public String adyenComponentExceptionHandler (AdyenComponentException e){ - return e.getMessage(); - } + @RequestMapping(value = "/submit-details", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody + public String submitDetails(final HttpServletRequest request) throws AdyenComponentException { + try { + String requestJsonString = IOUtils.toString(request.getInputStream(), String.valueOf(StandardCharsets.UTF_8)); + JsonObject requestJson = new JsonParser().parse(requestJsonString).getAsJsonObject(); - /** - * Validates the order form before to filter out invalid order states - * - * @return True if the order form is invalid and false if everything is valid. - * @param requestJson - */ - protected void validateOrderForm (JsonObject requestJson) throws InvalidCartException { Gson gson = new GsonBuilder().disableHtmlEscaping().create(); - Boolean termsCheck = gson.fromJson(requestJson.get("termsCheck"), Boolean.class); - JsonObject paymentMethodDetails = requestJson.get("paymentMethodDetails").getAsJsonObject(); - String paymentMethod = gson.fromJson(paymentMethodDetails.get("type"), String.class); - - // Some methods already have the terms validated on a previous step - if (!PAYMENT_METHODS_WITH_VALIDATED_TERMS.contains(paymentMethod) - && (termsCheck == null || !termsCheck)) { - throw new InvalidCartException("checkout.error.terms.not.accepted"); - } - - if (getCheckoutFlowFacade().hasNoDeliveryAddress()) { - throw new InvalidCartException("checkout.deliveryAddress.notSelected"); - } - - if (getCheckoutFlowFacade().hasNoDeliveryMode()) { - throw new InvalidCartException("checkout.deliveryMethod.notSelected"); - } - - if (getCheckoutFlowFacade().hasNoPaymentInfo()) { - throw new InvalidCartException("checkout.paymentMethod.notSelected"); - } - - final CartData cartData = getCheckoutFacade().getCheckoutCart(); + Type mapType = new TypeToken>() { + }.getType(); + Map details = gson.fromJson(requestJson.get("details"), mapType); + String paymentData = gson.fromJson(requestJson.get("paymentData"), String.class); + + PaymentsDetailsResponse paymentsResponse = getAdyenCheckoutFacade().componentDetails(request, details, paymentData); + return gson.toJson(paymentsResponse); + } catch (ApiException e) { + LOGGER.error("ApiException: " + e.toString()); + throw new AdyenComponentException("checkout.error.authorization.payment.refused"); + } catch (Exception e) { + LOGGER.error("Exception", e); + throw new AdyenComponentException("checkout.error.authorization.payment.error"); + } + } - if (!getCheckoutFacade().containsTaxValues()) { - LOGGER.error(String.format("Cart %s does not have any tax values, which means the tax cacluation was not properly done, placement of order can't continue", cartData.getCode())); - throw new InvalidCartException("checkout.error.tax.missing"); - } + @ResponseStatus(value = HttpStatus.BAD_REQUEST) + @ExceptionHandler(value = AdyenComponentException.class) + public String adyenComponentExceptionHandler(AdyenComponentException e) { + return e.getMessage(); + } - if (!cartData.isCalculated()) { - LOGGER.error(String.format("Cart %s has a calculated flag of FALSE, placement of order can't continue", cartData.getCode())); - throw new InvalidCartException("checkout.error.cart.notcalculated"); - } + /** + * Validates the order form before to filter out invalid order states + * + * @param requestJson + * @return True if the order form is invalid and false if everything is valid. + */ + protected void validateOrderForm(JsonObject requestJson) throws InvalidCartException { + Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + Boolean termsCheck = gson.fromJson(requestJson.get("termsCheck"), Boolean.class); + JsonObject paymentMethodDetails = requestJson.get("paymentMethodDetails").getAsJsonObject(); + String paymentMethod = gson.fromJson(paymentMethodDetails.get("type"), String.class); + + // Some methods already have the terms validated on a previous step + if (!PAYMENT_METHODS_WITH_VALIDATED_TERMS.contains(paymentMethod) + && (termsCheck == null || !termsCheck)) { + throw new InvalidCartException("checkout.error.terms.not.accepted"); } - private String getReturnUrl (String paymentMethod){ - String url; - if (GooglePayDetails.GOOGLEPAY.equals(paymentMethod)) { - //Google Pay will only use returnUrl if redirected to 3DS authentication - url = SUMMARY_CHECKOUT_PREFIX + "/authorise-3d-adyen-response"; - } else { - url = COMPONENT_PREFIX + "/submit-details"; - } - BaseSiteModel currentBaseSite = baseSiteService.getCurrentBaseSite(); - return siteBaseUrlResolutionService.getWebsiteUrlForSite(currentBaseSite, true, url); + if (getCheckoutFlowFacade().hasNoDeliveryAddress()) { + throw new InvalidCartException("checkout.deliveryAddress.notSelected"); } - public AdyenCheckoutFacade getAdyenCheckoutFacade () { - return adyenCheckoutFacade; + if (getCheckoutFlowFacade().hasNoDeliveryMode()) { + throw new InvalidCartException("checkout.deliveryMethod.notSelected"); } - public void setAdyenCheckoutFacade (AdyenCheckoutFacade adyenCheckoutFacade){ - this.adyenCheckoutFacade = adyenCheckoutFacade; + if (getCheckoutFlowFacade().hasNoPaymentInfo()) { + throw new InvalidCartException("checkout.paymentMethod.notSelected"); } - public CheckoutFlowFacade getCheckoutFlowFacade () { - return checkoutFlowFacade; - } + final CartData cartData = getCheckoutFacade().getCheckoutCart(); - public void setCheckoutFlowFacade (CheckoutFlowFacade checkoutFlowFacade){ - this.checkoutFlowFacade = checkoutFlowFacade; + if (!getCheckoutFacade().containsTaxValues()) { + LOGGER.error(String.format("Cart %s does not have any tax values, which means the tax cacluation was not properly done, placement of order can't continue", cartData.getCode())); + throw new InvalidCartException("checkout.error.tax.missing"); } - public AcceleratorCheckoutFacade getCheckoutFacade () { - return checkoutFacade; + if (!cartData.isCalculated()) { + LOGGER.error(String.format("Cart %s has a calculated flag of FALSE, placement of order can't continue", cartData.getCode())); + throw new InvalidCartException("checkout.error.cart.notcalculated"); } + } - public void setCheckoutFacade (AcceleratorCheckoutFacade checkoutFacade){ - this.checkoutFacade = checkoutFacade; + private String getReturnUrl(String paymentMethod) { + String url; + if (GooglePayDetails.GOOGLEPAY.equals(paymentMethod)) { + //Google Pay will only use returnUrl if redirected to 3DS authentication + url = SUMMARY_CHECKOUT_PREFIX + "/authorise-3d-adyen-response"; + } else { + url = COMPONENT_PREFIX + "/submit-details"; } + BaseSiteModel currentBaseSite = baseSiteService.getCurrentBaseSite(); + return siteBaseUrlResolutionService.getWebsiteUrlForSite(currentBaseSite, true, url); + } - private boolean isValidateSessionCart () { - CartData cart = getCheckoutFacade().getCheckoutCart(); - final AddressData deliveryAddress = cart.getDeliveryAddress(); - if (deliveryAddress == null || deliveryAddress.getCountry() == null || deliveryAddress.getCountry().getIsocode() == null) { - return false; - } - return true; + public AdyenCheckoutFacade getAdyenCheckoutFacade() { + return adyenCheckoutFacade; + } + public void setAdyenCheckoutFacade(AdyenCheckoutFacade adyenCheckoutFacade) { + this.adyenCheckoutFacade = adyenCheckoutFacade; + } + + public CheckoutFlowFacade getCheckoutFlowFacade() { + return checkoutFlowFacade; + } + + public void setCheckoutFlowFacade(CheckoutFlowFacade checkoutFlowFacade) { + this.checkoutFlowFacade = checkoutFlowFacade; + } + + public AcceleratorCheckoutFacade getCheckoutFacade() { + return checkoutFacade; + } + + public void setCheckoutFacade(AcceleratorCheckoutFacade checkoutFacade) { + this.checkoutFacade = checkoutFacade; + } + + private boolean isValidateSessionCart() { + CartData cart = getCheckoutFacade().getCheckoutCart(); + final AddressData deliveryAddress = cart.getDeliveryAddress(); + if (deliveryAddress == null || deliveryAddress.getCountry() == null || deliveryAddress.getCountry().getIsocode() == null) { + return false; } + return true; + } +} diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base.properties b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base.properties index 52eb7da17..4f0da870d 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base.properties +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base.properties @@ -36,5 +36,7 @@ payment.method.label.information=Bank Card checkout.summary.spinner.message=Please wait while your payment is processed. Do not click back or refresh the page. checkout.summary.component.mbway.payment=Provide your MB WAY account data to finalize your payment +checkout.summary.component.blik.payment=Provide your BLIK code to finalize your payment +checkout.summary.component.giftcard.payment=Provide your Giftcard data to finalize your payment checkout.summary.component.notavailable=This payment method is not available on your current browser or device checkout.summary.component.generateqr = Generate QR Code \ No newline at end of file diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base_en.properties b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base_en.properties index 80afd85a6..21b9a3550 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base_en.properties +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base_en.properties @@ -35,6 +35,8 @@ payment.method.telephonenumber=Phone Number checkout.summary.spinner.message=Please wait while your payment is processed. Do not click back or refresh the page. checkout.summary.component.mbway.payment=Provide your MB WAY account data to finalize your payment +checkout.summary.component.blik.payment=Provide your BLIK code to finalize your payment +checkout.summary.component.giftcard.payment=Provide your Giftcard data to finalize your payment checkout.summary.component.notavailable=This payment method is not available on your current browser or device checkout.summary.component.generateqr = Generate QR Code diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/checkoutOrderSummary.tag b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/checkoutOrderSummary.tag index 2f458fbb0..5cc68d49d 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/checkoutOrderSummary.tag +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/checkoutOrderSummary.tag @@ -51,6 +51,20 @@
+ +
+ +
+
+
+ + +
+ +
+
+
+ <%-- For components that do not have it's own button --%> diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/views/responsive/pages/checkout/multi/checkoutSummaryPage.jsp b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/views/responsive/pages/checkout/multi/checkoutSummaryPage.jsp index 8012c9334..a4818e919 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/views/responsive/pages/checkout/multi/checkoutSummaryPage.jsp +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/views/responsive/pages/checkout/multi/checkoutSummaryPage.jsp @@ -8,7 +8,6 @@ <%@ taglib prefix="ycommerce" uri="http://hybris.com/tld/ycommercetags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="order" tagdir="/WEB-INF/tags/responsive/order" %> -<%@ taglib prefix="adyen" tagdir="/WEB-INF/tags/addons/adyenv6b2ccheckoutaddon/responsive" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="json" uri="http://www.atg.com/taglibs/json" %> @@ -22,91 +21,99 @@ - -