Skip to content

Commit

Permalink
Merge pull request #209 from Adyen/develop
Browse files Browse the repository at this point in the history
Release Version bumped to 7.1.0
  • Loading branch information
rkewlani authored Sep 22, 2020
2 parents 931c229 + ebd8032 commit 3992c47
Show file tree
Hide file tree
Showing 32 changed files with 221 additions and 1,761 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @rkewlani @AlexandrosMor @martinsrenato @Aleffio @rikterbeek
* @rkewlani @martinsrenato @Aleffio @rikterbeek
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public interface AdyenControllerConstants
String ADDON_PREFIX = "addon:/adyenv6b2ccheckoutaddon/";
String SELECT_PAYMENT_METHOD_PREFIX = "/checkout/multi/adyen/select-payment-method";
String SUMMARY_CHECKOUT_PREFIX = "/checkout/multi/adyen/summary";
String PAYPAL_ECS_PREFIX = "/adyen/paypal-ecs";
String COMPONENT_PREFIX = "/adyen/component";

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import static com.adyen.constants.ApiConstants.ThreeDS2Property.FINGERPRINT_TOKEN;
import static com.adyen.constants.ApiConstants.ThreeDS2Property.THREEDS2_CHALLENGE_TOKEN;
import static com.adyen.constants.ApiConstants.ThreeDS2Property.THREEDS2_FINGERPRINT_TOKEN;
import static com.adyen.constants.BrandCodes.PAYPAL_ECS;
import static com.adyen.constants.HPPConstants.Response.SHOPPER_LOCALE;
import static com.adyen.model.checkout.PaymentsResponse.ResultCodeEnum.CHALLENGESHOPPER;
import static com.adyen.model.checkout.PaymentsResponse.ResultCodeEnum.IDENTIFYSHOPPER;
Expand Down Expand Up @@ -172,8 +171,7 @@ public String placeOrder(@ModelAttribute("placeOrderForm") final PlaceOrderForm
String errorMessage = "checkout.error.authorization.failed";

String adyenPaymentMethod = cartData.getAdyenPaymentMethod();

if (canUseAPI(adyenPaymentMethod)) {
if (adyenPaymentMethod.equals(RATEPAY)) {
try {
OrderData orderData = adyenCheckoutFacade.authorisePayment(request, cartData);
LOGGER.debug("Redirecting to confirmation!");
Expand Down Expand Up @@ -229,7 +227,7 @@ public String placeOrder(@ModelAttribute("placeOrderForm") final PlaceOrderForm
}
} else {
try {
cartData.setAdyenReturnUrl(getReturnUrl());
cartData.setAdyenReturnUrl(getReturnUrl(cartData.getAdyenPaymentMethod()));
OrderData orderData = adyenCheckoutFacade.authorisePayment(request, cartData);
//In case of Boleto, show link to pdf
if (PAYMENT_METHOD_BOLETO.equals(cartData.getAdyenPaymentMethod())) {
Expand All @@ -244,15 +242,11 @@ public String placeOrder(@ModelAttribute("placeOrderForm") final PlaceOrderForm
LOGGER.debug("Handling AdyenNonAuthorizedPaymentException. Checking PaymentResponse.");
PaymentsResponse paymentsResponse = e.getPaymentsResponse();
if (REDIRECTSHOPPER == paymentsResponse.getResultCode()) {
LOGGER.debug("PaymentResponse resultCode is REDIRECTSHOPPER, redirecting shopper to 3DS flow");
if (is3DSPaymentMethod(adyenPaymentMethod)) {
final String termUrl = getTermUrl();
model.addAttribute("paReq", paymentsResponse.getRedirect().getData().get(PAREQ));
model.addAttribute("md", paymentsResponse.getRedirect().getData().get(MD));
model.addAttribute("issuerUrl", paymentsResponse.getRedirect().getUrl());
model.addAttribute("termUrl", termUrl);
return AdyenControllerConstants.Views.Pages.MultiStepCheckout.Validate3DSecurePaymentPage;
LOGGER.debug("PaymentResponse resultCode is REDIRECTSHOPPER, redirecting shopper to 3DS flow");
return redirectTo3DSValidation(model, paymentsResponse);
}
LOGGER.debug("PaymentResponse resultCode is REDIRECTSHOPPER, redirecting shopper to local payment method page");
return REDIRECT_PREFIX + paymentsResponse.getRedirect().getUrl();
}
if (REFUSED == paymentsResponse.getResultCode()) {
Expand Down Expand Up @@ -286,13 +280,19 @@ public String authorise3DS2Payment(final Model model,
} catch (AdyenNonAuthorizedPaymentException e) {
LOGGER.debug("Handling AdyenNonAuthorizedPaymentException. Checking PaymentResponse.");
PaymentsResponse paymentsResponse = e.getPaymentsResponse();
if (paymentsResponse != null && (paymentsResponse.getResultCode() == CHALLENGESHOPPER || paymentsResponse.getResultCode() == IDENTIFYSHOPPER)) {
LOGGER.debug("PaymentResponse is "+paymentsResponse.getResultCode()+", redirecting to 3DS2 flow");
return redirectTo3DS2Validation(model, paymentsResponse);
}
if (paymentsResponse != null && paymentsResponse.getResultCode() == PaymentsResponse.ResultCodeEnum.REFUSED) {
errorMessage = getErrorMessageByRefusalReason(paymentsResponse.getRefusalReason());
LOGGER.debug("PaymentResponse is REFUSED: " + errorMessage);
if(paymentsResponse != null) {
if (paymentsResponse.getResultCode() == CHALLENGESHOPPER || paymentsResponse.getResultCode() == IDENTIFYSHOPPER) {
LOGGER.debug("PaymentResponse is " + paymentsResponse.getResultCode() + ", redirecting to 3DS2 flow");
return redirectTo3DS2Validation(model, paymentsResponse);
}
if (paymentsResponse.getResultCode() == REDIRECTSHOPPER) {
LOGGER.debug("PaymentResponse is " + paymentsResponse.getResultCode() + ", redirecting to 3DS flow");
return redirectTo3DSValidation(model, paymentsResponse);
}
if (paymentsResponse.getResultCode() == PaymentsResponse.ResultCodeEnum.REFUSED) {
errorMessage = getErrorMessageByRefusalReason(paymentsResponse.getRefusalReason());
LOGGER.debug("PaymentResponse is REFUSED: " + errorMessage);
}
}
return redirectToSelectPaymentMethodWithError(redirectModel, errorMessage);
} catch (CalculationException | InvalidCartException e) {
Expand All @@ -305,7 +305,7 @@ public String authorise3DS2Payment(final Model model,
return REDIRECT_PREFIX + "/cart";
}

@RequestMapping(value = AUTHORISE_3D_SECURE_PAYMENT_URL, method = RequestMethod.POST)
@RequestMapping(value = AUTHORISE_3D_SECURE_PAYMENT_URL, method = RequestMethod.GET)
@RequireHardLogIn
public String authorise3DSecurePayment(final RedirectAttributes redirectModel,
final HttpServletRequest request) {
Expand Down Expand Up @@ -417,20 +417,7 @@ private void addMultibancoMessage(RedirectAttributes redirectModel, final String
+ "</p>");
}

/**
* Methods supported via API
* Credit Cards/OneClick
* OpenInvoice
* Boleto
*/
private boolean canUseAPI(String paymentMethod) {
Set<String> apiPaymentMethods = new HashSet<>();

apiPaymentMethods.add(PAYPAL_ECS);
apiPaymentMethods.add(RATEPAY);

return apiPaymentMethods.contains(paymentMethod);
}

private boolean is3DSPaymentMethod(String adyenPaymentMethod) {
return adyenPaymentMethod.equals(PAYMENT_METHOD_CC) || adyenPaymentMethod.indexOf(PAYMENT_METHOD_ONECLICK) == 0;
Expand All @@ -443,6 +430,16 @@ private String redirectToSelectPaymentMethodWithError(final RedirectAttributes r
return REDIRECT_PREFIX + AdyenControllerConstants.SELECT_PAYMENT_METHOD_PREFIX;
}

private String redirectTo3DSValidation(Model model, PaymentsResponse paymentsResponse) {
if (paymentsResponse.getRedirect() != null && paymentsResponse.getRedirect().getData() != null) {
model.addAttribute("termUrl", paymentsResponse.getRedirect().getData().get("TermUrl"));
model.addAttribute("paReq", paymentsResponse.getRedirect().getData().get(PAREQ));
model.addAttribute("md", paymentsResponse.getRedirect().getData().get(MD));
model.addAttribute("issuerUrl", paymentsResponse.getRedirect().getUrl());
}
return AdyenControllerConstants.Views.Pages.MultiStepCheckout.Validate3DSecurePaymentPage;
}

private String redirectTo3DS2Validation(Model model, PaymentsResponse paymentsResponse) {
model.addAttribute(MODEL_CHECKOUT_SHOPPER_HOST, adyenCheckoutFacade.getCheckoutShopperHost());
model.addAttribute(MODEL_ENVIRONMENT_MODE, adyenCheckoutFacade.getEnvironmentMode());
Expand All @@ -456,18 +453,13 @@ private String redirectTo3DS2Validation(Model model, PaymentsResponse paymentsRe
return AdyenControllerConstants.Views.Pages.MultiStepCheckout.Validate3DS2PaymentPage;
}

private String getTermUrl() {
String authorise3DSecureUrl = AdyenControllerConstants.SUMMARY_CHECKOUT_PREFIX + AUTHORISE_3D_SECURE_PAYMENT_URL;
BaseSiteModel currentBaseSite = baseSiteService.getCurrentBaseSite();

return siteBaseUrlResolutionService.getWebsiteUrlForSite(currentBaseSite, true, authorise3DSecureUrl);
}

/**
* Construct the URL for HPP redirect
*/
private String getReturnUrl() {
String url = AdyenControllerConstants.SUMMARY_CHECKOUT_PREFIX + HPP_RESULT_URL;
private String getReturnUrl(String adyenPaymentMethod) {
String url;
if (is3DSPaymentMethod(adyenPaymentMethod)) {
url = AdyenControllerConstants.SUMMARY_CHECKOUT_PREFIX + AUTHORISE_3D_SECURE_PAYMENT_URL;
} else {
url = AdyenControllerConstants.SUMMARY_CHECKOUT_PREFIX + HPP_RESULT_URL;
}
BaseSiteModel currentBaseSite = baseSiteService.getCurrentBaseSite();

return siteBaseUrlResolutionService.getWebsiteUrlForSite(currentBaseSite, true, url);
Expand Down
Loading

0 comments on commit 3992c47

Please sign in to comment.