Skip to content

Commit

Permalink
Merge pull request #411 from Adyen/feature/AD-222b
Browse files Browse the repository at this point in the history
[AD-222] Fix for PayPal
  • Loading branch information
kpieloch authored May 10, 2024
2 parents 9805ce3 + 8fe2e28 commit c364aa9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import static com.adyen.model.checkout.PaymentResponse.ResultCodeEnum.CHALLENGESHOPPER;
import static com.adyen.model.checkout.PaymentResponse.ResultCodeEnum.IDENTIFYSHOPPER;
import static com.adyen.model.checkout.PaymentResponse.ResultCodeEnum.PENDING;
import static com.adyen.model.checkout.PaymentResponse.ResultCodeEnum.PRESENTTOSHOPPER;
import static com.adyen.model.checkout.PaymentResponse.ResultCodeEnum.REDIRECTSHOPPER;
import static com.adyen.model.checkout.PaymentResponse.ResultCodeEnum.REFUSED;
import static com.adyen.v6.constants.Adyenv6coreConstants.AFTERPAY_TOUCH;
import static com.adyen.v6.constants.Adyenv6coreConstants.PAYMENT_METHOD_BCMC;
import static com.adyen.v6.constants.Adyenv6coreConstants.PAYMENT_METHOD_CC;
import static com.adyen.v6.constants.Adyenv6coreConstants.PAYMENT_METHOD_SCHEME;
Expand Down Expand Up @@ -146,26 +146,15 @@ private ResponseEntity<PlaceOrderResponse> handlePayment(HttpServletRequest requ
} catch (AdyenNonAuthorizedPaymentException e) {
LOGGER.info("Handling AdyenNonAuthorizedPaymentException. Checking PaymentResponse.");
PaymentResponse paymentsResponse = e.getPaymentsResponse();
if (PENDING == paymentsResponse.getResultCode()) {
LOGGER.info("PaymentResponse is PENDING, pspReference: " + paymentsResponse.getPspReference());
PlaceOrderResponse placeOrderResponse = new PlaceOrderResponse();
placeOrderResponse.setPaymentsResponse(paymentsResponse);
placeOrderResponse.setExecuteAction(true);
placeOrderResponse.setPaymentsAction(paymentsResponse.getAction());
return ResponseEntity.status(HttpStatus.OK).body(placeOrderResponse);
}
if (REDIRECTSHOPPER == paymentsResponse.getResultCode()) {
return handleRedirect(adyenPaymentMethod, paymentsResponse);
}
if (REFUSED == paymentsResponse.getResultCode()) {
if (REDIRECTSHOPPER == paymentsResponse.getResultCode() || CHALLENGESHOPPER == paymentsResponse.getResultCode() ||
IDENTIFYSHOPPER == paymentsResponse.getResultCode() || PENDING == paymentsResponse.getResultCode() ||
PRESENTTOSHOPPER == paymentsResponse.getResultCode()) {
LOGGER.debug("PaymentResponse is " + paymentsResponse.getResultCode() + ", executing action for pspReference: " + paymentsResponse.getPspReference());
return executeAction(paymentsResponse);
} else if (REFUSED == paymentsResponse.getResultCode()) {
LOGGER.info("PaymentResponse is REFUSED, pspReference: " + paymentsResponse.getPspReference());
errorMessage = getErrorMessageByRefusalReason(paymentsResponse.getRefusalReason());
}
if (CHALLENGESHOPPER == paymentsResponse.getResultCode() || IDENTIFYSHOPPER == paymentsResponse.getResultCode()) {
LOGGER.debug("PaymentResponse is " + paymentsResponse.getResultCode() + ", redirecting to 3DS2 flow");
return redirectTo3DSValidation(paymentsResponse);
}
if (PaymentResponse.ResultCodeEnum.ERROR == paymentsResponse.getResultCode()) {
} else if (PaymentResponse.ResultCodeEnum.ERROR == paymentsResponse.getResultCode()) {
LOGGER.error("PaymentResponse is ERROR, reason: " + paymentsResponse.getRefusalReason() + " pspReference: " + paymentsResponse.getPspReference());
}
} catch (Exception e) {
Expand Down Expand Up @@ -194,25 +183,11 @@ private void preHandleAndValidateRequest(PlaceOrderRequest placeOrderRequest, St
placeOrderRequest.getBillingAddress(), placeOrderRequest.isUseAdyenDeliveryAddress());
}

private ResponseEntity<PlaceOrderResponse> handleRedirect(String adyenPaymentMethod, PaymentResponse paymentResponse) {
if (is3DSPaymentMethod(adyenPaymentMethod)) {
LOGGER.debug("PaymentResponse resultCode is REDIRECTSHOPPER, redirecting shopper to 3DS flow");
return redirectTo3DSValidation(paymentResponse);
}
if (AFTERPAY_TOUCH.equals(adyenPaymentMethod)) {
LOGGER.debug("PaymentResponse resultCode is REDIRECTSHOPPER, redirecting shopper to afterpaytouch page");
return ResponseEntity.status(HttpStatus.FOUND).build();

}
LOGGER.debug("PaymentResponse resultCode is REDIRECTSHOPPER, redirecting shopper to local payment method page");
return ResponseEntity.status(HttpStatus.FOUND).build();
}

private ResponseEntity<PlaceOrderResponse> redirectTo3DSValidation(PaymentResponse paymentsResponse) {
private ResponseEntity<PlaceOrderResponse> executeAction(PaymentResponse paymentsResponse) {
PlaceOrderResponse placeOrderResponse = new PlaceOrderResponse();
placeOrderResponse.setPaymentsResponse(paymentsResponse);
placeOrderResponse.setExecuteAction(true);
placeOrderResponse.setPaymentsAction(paymentsResponse.getAction());

return ResponseEntity.ok(placeOrderResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {translationsStore} from "../../store/translationsStore";
import AddressSection from "../common/AddressSection";
import {routes} from "../../router/routes";
import {Navigate} from "react-router-dom";
import {PaymentAction} from "@adyen/adyen-web/dist/types/types";
import {PaymentError} from "./PaymentError";
import {ScrollHere} from "../common/ScrollTo";
import DropinElement from "@adyen/adyen-web/dist/types/components/Dropin";
Expand Down Expand Up @@ -172,7 +171,7 @@ class Payment extends React.Component<Props, State> {
if (!!responseData) {
if (responseData.success) {
if (responseData.executeAction) {
await this.mount3DSComponent(responseData.paymentsAction)
this.dropIn.handleAction(responseData.paymentsAction)
} else {
this.setState({orderNumber: responseData.orderNumber})
this.setState({redirectToNextStep: true})
Expand All @@ -198,11 +197,6 @@ class Payment extends React.Component<Props, State> {
this.dropIn.mount(this.paymentRef.current)
}

private async mount3DSComponent(paymentAction: PaymentAction) {
let adyenCheckout = await AdyenCheckout(this.getAdyenCheckoutConfig());
adyenCheckout.createFromAction(paymentAction).mount(this.threeDSRef.current);
}

private renderScrollOnErrorCodes(): React.JSX.Element {
if (this.state.errorFieldCodes && this.state.errorFieldCodes.length > 0) {
return <ScrollHere/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ private String getReturnUrl(String paymentMethod) {
url = SUMMARY_CHECKOUT_PREFIX + "/authorise-3d-adyen-response";
} else {
url = SUMMARY_CHECKOUT_PREFIX + CHECKOUT_RESULT_URL;
;
}
BaseSiteModel currentBaseSite = baseSiteService.getCurrentBaseSite();
return siteBaseUrlResolutionService.getWebsiteUrlForSite(currentBaseSite, true, url);
Expand Down

0 comments on commit c364aa9

Please sign in to comment.