Skip to content

Commit

Permalink
Release 11.0.2 COMMIT
Browse files Browse the repository at this point in the history
  • Loading branch information
jluisalias-e2y committed Jul 6, 2023
1 parent 3bdeb71 commit e67a33f
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.google.gson.reflect.TypeToken;
import de.hybris.platform.acceleratorservices.enums.CheckoutPciOptionEnum;
import de.hybris.platform.acceleratorservices.urlresolver.SiteBaseUrlResolutionService;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import de.hybris.platform.acceleratorstorefrontcommons.annotations.PreValidateCheckoutStep;
Expand All @@ -56,7 +58,6 @@
import de.hybris.platform.order.exceptions.CalculationException;
import de.hybris.platform.servicelayer.config.ConfigurationService;
import de.hybris.platform.site.BaseSiteService;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -95,6 +96,7 @@

@Controller
@RequestMapping(value = SUMMARY_CHECKOUT_PREFIX)
@SuppressWarnings("java:S3776")
public class AdyenSummaryCheckoutStepController extends AbstractCheckoutStepController {
private static final Logger LOGGER = Logger.getLogger(AdyenSummaryCheckoutStepController.class);

Expand All @@ -106,6 +108,8 @@ public class AdyenSummaryCheckoutStepController extends AbstractCheckoutStepCont
private static final String PAYLOAD = "payload";
private static final String POS_TOTALTIMEOUT_KEY = "pos.totaltimeout";
private static final String CHECKOUT_ERROR_AUTHORIZATION_FAILED = "checkout.error.authorization.failed";
private static final String PAYMENT_NOT_SUPPORTED = "checkout.error.payment.not.supported";
private static final String CART_NOT_VALID = "checkout.error.cart.not.valid";
private static final String REDIRECTING_TO_CONFIRMATION = "Redirecting to confirmation!";
private static final String API_EXCEPTION_START_MESSAGE = "API exception ";
private static final String HANDLING_ADYEN_NON_AUTHORIZED_PAYMENT_EXCEPTION = "Handling AdyenNonAuthorizedPaymentException";
Expand All @@ -114,6 +118,7 @@ public class AdyenSummaryCheckoutStepController extends AbstractCheckoutStepCont
private static final String CHECKOUT_ERROR_AUTHORIZATION_PAYMENT_CANCELLED = "checkout.error.authorization.payment.cancelled";
private static final String CHECKOUT_ERROR_AUTHORIZATION_PAYMENT_ERROR = "checkout.error.authorization.payment.error";
private static final int POS_TOTAL_TIMEOUT_DEFAULT = 130;
private static final String NON_AUTHORIZED_ERROR = "Handling AdyenNonAuthorizedPaymentException. Checking PaymentResponse.";

@Resource(name = "siteBaseUrlResolutionService")
private SiteBaseUrlResolutionService siteBaseUrlResolutionService;
Expand Down Expand Up @@ -171,6 +176,70 @@ public String enterStep(final Model model, final RedirectAttributes redirectAttr
return AdyenControllerConstants.Views.Pages.MultiStepCheckout.CheckoutSummaryPage;
}

@PostMapping({"/placeOrderBizum"})
@RequireHardLogIn
@ResponseBody
public String placeOrderResponseBody(@ModelAttribute("placeOrderForm") final PlaceOrderForm placeOrderForm,
final Model model,
final HttpServletRequest request,
final RedirectAttributes redirectModel) throws CMSItemNotFoundException, CommerceCartModificationException {

final String error = validateOrderFormJson(placeOrderForm);
if (StringUtils.isNotEmpty(error)) {
return error;
}

//Validate the cart
if (validateCart(redirectModel)) {
// Invalid cart. Bounce back to the cart page.
final Optional<Object> flashError = redirectModel.getFlashAttributes().entrySet().stream().findFirst().map(Map.Entry::getValue);
if (flashError.isPresent()) {
return flashError.get().toString();
} else {
return CART_NOT_VALID;
}
}

final CartData cartData = getCheckoutFlowFacade().getCheckoutCart();

final String adyenPaymentMethod = cartData.getAdyenPaymentMethod();

try {
cartData.setAdyenReturnUrl(getReturnUrl(cartData.getAdyenPaymentMethod()));
OrderData orderData = adyenCheckoutFacade.authorisePayment(request, cartData);

return redirectToOrderConfirmationPage(orderData);
} catch (ApiException e) {
LOGGER.error(API_EXCEPTION_START_MESSAGE, e);
} catch (AdyenNonAuthorizedPaymentException e) {
LOGGER.debug(NON_AUTHORIZED_ERROR);
final PaymentsResponse paymentsResponse = e.getPaymentsResponse();
if (REDIRECTSHOPPER == paymentsResponse.getResultCode()) {
if (is3DSPaymentMethod(adyenPaymentMethod)) {
LOGGER.debug("PaymentResponse resultCode is REDIRECTSHOPPER, redirecting shopper to 3DS flow");
return PAYMENT_NOT_SUPPORTED;
}
LOGGER.debug("PaymentResponse resultCode is REDIRECTSHOPPER, redirecting shopper to local payment method page");
if (Objects.nonNull(paymentsResponse.getAction()) && "POST".equals(paymentsResponse.getAction().getMethod())) {
return makePostRedirect(paymentsResponse);
}
return makeGetRedirect(paymentsResponse);
}
if (REFUSED == paymentsResponse.getResultCode()) {
LOGGER.debug("PaymentResponse is REFUSED");
return getErrorMessageByRefusalReason(paymentsResponse.getRefusalReason());
}
if (CHALLENGESHOPPER == paymentsResponse.getResultCode() || IDENTIFYSHOPPER == paymentsResponse.getResultCode()) {
LOGGER.debug("PaymentResponse is " + paymentsResponse.getResultCode() + ", redirecting to 3DS2 flow");
return PAYMENT_NOT_SUPPORTED;
}
} catch (Exception e) {
LOGGER.error(ExceptionUtils.getStackTrace(e));
}

return CHECKOUT_ERROR_AUTHORIZATION_FAILED;
}

@RequestMapping({"/placeOrder"})
@RequireHardLogIn
public String placeOrder(@ModelAttribute("placeOrderForm") final PlaceOrderForm placeOrderForm,
Expand Down Expand Up @@ -260,7 +329,7 @@ public String placeOrder(@ModelAttribute("placeOrderForm") final PlaceOrderForm
} catch (ApiException e) {
LOGGER.error(API_EXCEPTION_START_MESSAGE, e);
} catch (AdyenNonAuthorizedPaymentException e) {
LOGGER.debug("Handling AdyenNonAuthorizedPaymentException. Checking PaymentResponse.");
LOGGER.debug(NON_AUTHORIZED_ERROR);
PaymentsResponse paymentsResponse = e.getPaymentsResponse();
if (REDIRECTSHOPPER == paymentsResponse.getResultCode()) {
if (is3DSPaymentMethod(adyenPaymentMethod)) {
Expand Down Expand Up @@ -291,6 +360,21 @@ public String placeOrder(@ModelAttribute("placeOrderForm") final PlaceOrderForm
return enterStep(model, redirectModel);
}

private String makePostRedirect(final PaymentsResponse paymentsResponse) {
final JSONObject json = new JSONObject();
json.put("url", paymentsResponse.getAction().getUrl());
json.put("data", paymentsResponse.getAction().getData());

return json.toString();
}

private String makeGetRedirect(final PaymentsResponse paymentsResponse) {
final JSONObject json = new JSONObject();
json.put("url", paymentsResponse.getAction().getUrl());

return json.toString();
}

@GetMapping(value = AUTHORISE_3D_SECURE_PAYMENT_URL)
@RequireHardLogIn
public String authorise3DS1Payment(final RedirectAttributes redirectModel,
Expand Down Expand Up @@ -332,7 +416,7 @@ public String authorise3DSPayment(final RedirectAttributes redirectModel,
LOGGER.debug("Redirecting to confirmation");
return redirectToOrderConfirmationPage(orderData);
} catch (AdyenNonAuthorizedPaymentException e) {
LOGGER.debug("Handling AdyenNonAuthorizedPaymentException. Checking PaymentResponse.");
LOGGER.debug(NON_AUTHORIZED_ERROR);
String errorMessage = CHECKOUT_ERROR_AUTHORIZATION_FAILED;
PaymentsDetailsResponse paymentsDetailsResponse = e.getPaymentsDetailsResponse();
if ((paymentsDetailsResponse != null) && (paymentsDetailsResponse.getResultCode() == PaymentsResponse.ResultCodeEnum.REFUSED)) {
Expand Down Expand Up @@ -473,7 +557,7 @@ private String getReturnUrl(String adyenPaymentMethod) {

protected String getErrorMessageByRefusalReason(String refusalReason) {
String errorMessage = CHECKOUT_ERROR_AUTHORIZATION_PAYMENT_REFUSED;
if(refusalReason != null) {
if (refusalReason != null) {
switch (refusalReason) {
case RefusalReason.TRANSACTION_NOT_PERMITTED:
errorMessage = "checkout.error.authorization.transaction.not.permitted";
Expand Down Expand Up @@ -548,6 +632,48 @@ protected boolean validateOrderForm(final PlaceOrderForm placeOrderForm, final M
return invalid;
}

protected String validateOrderFormJson(final PlaceOrderForm placeOrderForm) {
final String securityCode = placeOrderForm.getSecurityCode();

if (getCheckoutFlowFacade().hasNoDeliveryAddress()) {
return "checkout.deliveryAddress.notSelected";
}

if (getCheckoutFlowFacade().hasNoDeliveryMode()) {
return "checkout.deliveryMethod.notSelected";
}

if (getCheckoutFlowFacade().hasNoPaymentInfo()) {
return "checkout.paymentMethod.notSelected";

} else {
// Only require the Security Code to be entered on the summary page if the SubscriptionPciOption is set to Default.
if (CheckoutPciOptionEnum.DEFAULT.equals(getCheckoutFlowFacade().getSubscriptionPciOption()) && StringUtils.isBlank(securityCode)) {
return "checkout.paymentMethod.noSecurityCode";
}
}

if (!placeOrderForm.isTermsCheck()) {
return "checkout.error.terms.not.accepted";
}

final CartData cartData = getCheckoutFacade().getCheckoutCart();

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()));
return "checkout.error.tax.missing";

}

if (!cartData.isCalculated()) {
LOGGER.error(String.format("Cart %s has a calculated flag of FALSE, placement of order can't continue", cartData.getCode()));
return "checkout.error.cart.notcalculated";

}

return StringUtils.EMPTY;
}

@PostMapping(value = "/component-result")
@RequireHardLogIn
public String handleComponentResult(final HttpServletRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
fnCallbackArray['initiateMbway'] = callbackConfig
</c:when>
<c:when test="${selectedPaymentMethod eq 'bizum'}">
fnCallbackArray['initiateBizum'] = callbackConfig
</c:when>
<c:when test="${selectedPaymentMethod eq 'applepay'}">
fnCallbackArray['initiateApplePay'] = {
...callbackConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,64 @@ var AdyenCheckoutHybris = (function () {
});
},

initiateBizum: function (params) {
const {label} = params;
const self = this;

$(document).ready(function () {
$("#placeOrder-" + label).click(function () {
$(this).prop('disabled', true);

AdyenCheckoutHybris.showSpinner();

let termsCheck = document.getElementById('terms-conditions-check-' + label).checked

if (termsCheck === false) {
self.handleResult(ErrorMessages.TermsNotAccepted, true);
return;
}

const placeOrderForm = {
"securityCode": null,
"termsCheck": termsCheck,
};

$.ajax({
url: ACC.config.encodedContextPath + '/checkout/multi/adyen/summary/placeOrderBizum',
type: "POST",
data: placeOrderForm,
success: function (data) {
try {
let response = JSON.parse(data);

const form = document.createElement('form');
form.method = 'POST';
form.action = response.url;

for (const key in response.data) {
form.innerHTML+='<input type="hidden" name="' + key + '" value="' +response.data[key] + '" /> ';
}

document.body.appendChild(form);
form.submit();
} catch (e) {
console.log('Error place order: ' + e);
AdyenCheckoutHybris.hideSpinner();
$("#placeOrder-" + label).prop('disabled', false);
self.handleResult(data, true);
}
},
error: function (xmlHttpResponse, exception) {
console.log(exception);
AdyenCheckoutHybris.hideSpinner();
$("#placeOrder-" + label).prop('disabled', false);
self.handleResult(responseMessage, true);
}
});
});
});
},

/**
* @param form
* @param useSpinner
Expand Down
2 changes: 1 addition & 1 deletion adyenv6b2ccheckoutaddon/project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Mon, 24 Apr 2023 17:01:32 +0200
#Wed, 31 May 2023 17:06:25 +0200
# -----------------------------------------------------------------------
# [y] hybris Platform
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# put localizations of item types into this file
# Note that you can also add special locatizations which
# can be retrieved with the
Expand All @@ -16,14 +15,16 @@
#
# yourcustomlocalekey=value

address.line2BR = House number or name
address.line2BR.invalid = Please, enter a house number or name
address.postcodeBR.invalid = Please, the postcode has to contains 8 digits
address.phoneIN.invalid = Please introduce a correct phone number, the phone number is invalid
address.line2BR = House number or name
address.line2BR.invalid = Please, enter a house number or name
address.postcodeBR.invalid = Please, the postcode has to contains 8 digits
address.phoneIN.invalid = Please introduce a correct phone number, the phone number is invalid
address.postcodeBR.invalid.addressForm.postcode = Please, the postcode has to contain 8 digits
address.phoneIN.invalid.addressForm.phone = Please introduce a correct phone number, the phone number is invalid
customersupport_backoffice_addressForm.phone1=Phone Number
address.phoneIN.invalid.addressForm.phone = Please introduce a correct phone number, the phone number is invalid
customersupport_backoffice_addressForm.phone1 = Phone Number

checkout.error.authorization.failed = There was an internal technical error, please choose any other payment method to place your order. If the error persist, please contact us.
checkout.error.cart.notcalculated = There was an internal technical error, please choose any other payment method to place your order. If the error persist, please contact us.
checkout.error.tax.missing = There was an internal technical error, please choose any other payment method to place your order. If the error persist, please contact us.
checkout.error.authorization.failed = There was an internal technical error, please choose any other payment method to place your order. If the error persist, please contact us.
checkout.error.cart.notcalculated = There was an internal technical error, please choose any other payment method to place your order. If the error persist, please contact us.
checkout.error.tax.missing = There was an internal technical error, please choose any other payment method to place your order. If the error persist, please contact us.
checkout.error.payment.not.supported = This payment method is not supported, please choose any other payment method to place your order. If the error persist, please contact us.
checkout.error.cart.not.valid = An error occurred while validating your order. Please try again later. If the error persist, please contact us.
Binary file modified adyenv6backoffice/resources/backoffice/adyenv6backoffice_bof.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions adyenv6core/resources/adyenv6core-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@
<alias name="defaultPaytmPaymentMethodDetailsBuilderStrategy" alias="paytmPaymentMethodDetailsBuilderStrategy"/>
<bean id="defaultPaytmPaymentMethodDetailsBuilderStrategy" class="com.adyen.v6.paymentmethoddetails.builders.impl.PaytmPaymentMethodDetailsBuilderStrategy"/>

<alias name="defaultGenericAdyenPaymentMethodDetailsBuilderStrategy" alias="genericAdyenPaymentMethodDetailsBuilderStrategy"/>
<bean id="defaultGenericAdyenPaymentMethodDetailsBuilderStrategy" class="com.adyen.v6.paymentmethoddetails.builders.impl.GenericAdyenPaymentMethodDetailsBuilderStrategy"/>

<util:list id="adyenPaymentMethodDetailsBuilderStrategies">
<ref bean="clearpayPaymentMethodDetailsBuilderStrategy"/>
<ref bean="trustyPaymentMethodDetailsBuilderStrategy"/>
Expand Down Expand Up @@ -437,6 +440,7 @@
<alias name="defaultAdyenPaymentMethodDetailsStrategyExecutorImpl" alias="adyenPaymentMethodDetailsStrategyExecutorImpl"/>
<bean id="defaultAdyenPaymentMethodDetailsStrategyExecutorImpl" class="com.adyen.v6.paymentmethoddetails.executors.impl.AdyenPaymentMethodDetailsStrategyExecutorImpl">
<constructor-arg name="strategies" ref="adyenPaymentMethodDetailsBuilderStrategies"/>
<constructor-arg name="genericStrategy" ref="genericAdyenPaymentMethodDetailsBuilderStrategy"/>
</bean>

</beans>
Loading

0 comments on commit e67a33f

Please sign in to comment.