diff --git a/README.md b/README.md index c248eab37..eafb8d280 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,12 @@ https://docs.adyen.com/developers/payment-methods/boleto-bancario/boleto-payment ``` is3DS2allowed = false ``` +## POS Timeout configuration +POS timeout (time calculated since initiating a payment) is max time to keep terminal connection open. It is set to 130 seconds by default already. If you want to change it, please add following property in local.properties file, build your environment and restart the server. (Change 130 to your desired time, in seconds). +``` +pos.totaltimeout = 130 +``` + ## Documentation https://docs.adyen.com/developers/plugins/hybris diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/pages/AdyenSummaryCheckoutStepController.java b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/pages/AdyenSummaryCheckoutStepController.java index 73449dd1e..867132458 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/pages/AdyenSummaryCheckoutStepController.java +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/controllers/pages/AdyenSummaryCheckoutStepController.java @@ -20,6 +20,7 @@ */ package com.adyen.v6.controllers.pages; +import java.net.SocketTimeoutException; import java.net.UnknownHostException; import java.util.Arrays; import java.util.HashMap; @@ -43,6 +44,7 @@ import com.adyen.v6.constants.AdyenControllerConstants; import com.adyen.v6.exceptions.AdyenNonAuthorizedPaymentException; import com.adyen.v6.facades.AdyenCheckoutFacade; +import com.adyen.v6.util.TerminalAPIUtil; import de.hybris.platform.acceleratorservices.enums.CheckoutPciOptionEnum; import de.hybris.platform.acceleratorservices.urlresolver.SiteBaseUrlResolutionService; import de.hybris.platform.acceleratorstorefrontcommons.annotations.PreValidateCheckoutStep; @@ -61,7 +63,7 @@ import de.hybris.platform.commercefacades.product.ProductOption; import de.hybris.platform.commercefacades.product.data.ProductData; import de.hybris.platform.commerceservices.order.CommerceCartModificationException; -import de.hybris.platform.order.InvalidCartException; +import de.hybris.platform.servicelayer.config.ConfigurationService; import de.hybris.platform.site.BaseSiteService; import static com.adyen.constants.ApiConstants.Redirect.Data.MD; import static com.adyen.constants.ApiConstants.Redirect.Data.PAREQ; @@ -78,9 +80,10 @@ import static com.adyen.model.checkout.PaymentsResponse.ResultCodeEnum.REFUSED; import static com.adyen.v6.constants.Adyenv6coreConstants.PAYMENT_METHOD_BOLETO; import static com.adyen.v6.constants.Adyenv6coreConstants.PAYMENT_METHOD_CC; +import static com.adyen.v6.constants.Adyenv6coreConstants.PAYMENT_METHOD_MULTIBANCO; import static com.adyen.v6.constants.Adyenv6coreConstants.PAYMENT_METHOD_ONECLICK; +import static com.adyen.v6.constants.Adyenv6coreConstants.PAYMENT_METHOD_POS; import static com.adyen.v6.constants.Adyenv6coreConstants.RATEPAY; -import static com.adyen.v6.constants.Adyenv6coreConstants.PAYMENT_METHOD_MULTIBANCO; import static com.adyen.v6.facades.DefaultAdyenCheckoutFacade.MODEL_CHECKOUT_SHOPPER_HOST; import static com.adyen.v6.facades.DefaultAdyenCheckoutFacade.MODEL_ENVIRONMENT_MODE; @@ -95,6 +98,9 @@ public class AdyenSummaryCheckoutStepController extends AbstractCheckoutStepCont private static final String ADYEN_PAYLOAD = "payload"; private static final String REDIRECT_RESULT = "redirectResult"; + private static final int POS_TOTALTIMEOUT_DEFAULT = 130; + private static final String POS_TOTALTIMEOUT_KEY = "pos.totaltimeout"; + @Resource(name = "siteBaseUrlResolutionService") private SiteBaseUrlResolutionService siteBaseUrlResolutionService; @@ -107,6 +113,9 @@ public class AdyenSummaryCheckoutStepController extends AbstractCheckoutStepCont @Resource(name = "orderFacade") private OrderFacade orderFacade; + @Resource(name = "configurationService") + private ConfigurationService configurationService; + @RequestMapping(value = "/view", method = RequestMethod.GET) @RequireHardLogIn @Override @@ -144,8 +153,7 @@ public String enterStep(final Model model, final RedirectAttributes redirectAttr public String placeOrder(@ModelAttribute("placeOrderForm") final PlaceOrderForm placeOrderForm, final Model model, final HttpServletRequest request, - final RedirectAttributes redirectModel) throws CMSItemNotFoundException, // NOSONAR - InvalidCartException, CommerceCartModificationException { + final RedirectAttributes redirectModel) throws CMSItemNotFoundException, CommerceCartModificationException { if (validateOrderForm(placeOrderForm, model)) { return enterStep(model, redirectModel); } @@ -178,6 +186,43 @@ public String placeOrder(@ModelAttribute("placeOrderForm") final PlaceOrderForm } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } + } else if (PAYMENT_METHOD_POS.equals(adyenPaymentMethod)) { + try { + String originalServiceId = Long.toString(System.currentTimeMillis() % 10000000000L); + request.setAttribute("originalServiceId", originalServiceId); + Long paymentStartTime = System.currentTimeMillis(); + request.setAttribute("paymentStartTime", paymentStartTime); + OrderData orderData = adyenCheckoutFacade.initiatePosPayment(request, cartData); + LOGGER.debug("Redirecting to confirmation!"); + return redirectToOrderConfirmationPage(orderData); + } catch (SocketTimeoutException e) { + try { + LOGGER.debug("POS request timed out. Checking POS Payment status "); + int totalTimeout = POS_TOTALTIMEOUT_DEFAULT; + if(configurationService.getConfiguration().containsKey(POS_TOTALTIMEOUT_KEY)) { + totalTimeout = configurationService.getConfiguration().getInt(POS_TOTALTIMEOUT_KEY); + } + request.setAttribute("totalTimeout", totalTimeout); + OrderData orderData = adyenCheckoutFacade.checkPosPaymentStatus(request, cartData); + LOGGER.debug("Redirecting to confirmation!"); + return redirectToOrderConfirmationPage(orderData); + } catch (AdyenNonAuthorizedPaymentException nx) { + LOGGER.debug("AdyenNonAuthorizedPaymentException", nx); + errorMessage = TerminalAPIUtil.getErrorMessageForNonAuthorizedPosPayment(nx.getTerminalApiResponse()); + } catch (SocketTimeoutException to) { + LOGGER.debug("POS Status request timed out. Returning error message."); + errorMessage = "checkout.error.authorization.pos.configuration"; + } catch (Exception ex) { + LOGGER.error("Exception", ex); + } + } catch (ApiException e) { + LOGGER.error("API exception " + e.getError(), e); + } catch (AdyenNonAuthorizedPaymentException e) { + LOGGER.debug("AdyenNonAuthorizedPaymentException", e); + errorMessage = TerminalAPIUtil.getErrorMessageForNonAuthorizedPosPayment(e.getTerminalApiResponse()); + } catch (Exception e) { + LOGGER.error("Exception", e); + } } else { try { cartData.setAdyenReturnUrl(getReturnUrl()); @@ -493,6 +538,7 @@ protected boolean validateOrderForm(final PlaceOrderForm placeOrderForm, final M return invalid; } + @RequestMapping(value = "/back", method = RequestMethod.GET) @RequireHardLogIn @Override diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base.properties b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base.properties index 7495c9274..4f1e77de2 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base.properties +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/messages/base.properties @@ -6,6 +6,9 @@ checkout.error.authorization.payment.detail.not.found=The payment is REFUSED bec checkout.error.authorization.payment.refused=The payment is REFUSED. checkout.error.authorization.payment.cancelled=The payment is Cancelled. checkout.error.authorization.payment.error=An error occured. +checkout.error.authorization.pos.configuration=Error reaching POS terminal. Check the terminal connection/configuration and try again. +checkout.error.authorization.pos.busy=The terminal is busy. Wait for the current transaction to end and try again later. +checkout.error.authorization.pos.pin=The payment is REFUSED. Please check your Card details. text.account.storedCards.empty=There are no stored cards text.account.storedCard.delete=Remove diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/alternativeMethod.tag b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/alternativeMethod.tag index 3c7d4f91a..fbaac46ff 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/alternativeMethod.tag +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/alternativeMethod.tag @@ -25,6 +25,7 @@ <%@ attribute name="showSocialSecurityNumber" required="false" type="java.lang.Boolean" %> <%@ attribute name="showFirstName" required="false" type="java.lang.Boolean" %> <%@ attribute name="showLastName" required="false" type="java.lang.Boolean" %> +<%@ attribute name="showTerminalList" required="false" type="java.lang.Boolean" %> <%@ attribute name="countryCode" required="false" type="java.lang.String" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> @@ -52,6 +53,19 @@ + + + + + +