Skip to content

Commit

Permalink
Merge branch 'develop' into feature/AD-219-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz756 authored Apr 3, 2024
2 parents 1475283 + b98b70d commit 360d1c4
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private AdyencheckoutaddonapiWebConstants()
public static final String ADYEN_CHECKOUT_API_PREFIX = "/api/checkout";
public static final String ADYEN_CHECKOUT_PAGE_PREFIX = "/checkout/multi";
public static final String ADYEN_CHECKOUT_ORDER_CONFIRMATION = "/adyen/order-confirmation";
public static final String ADYEN_CHECKOUT_SELECT_PAYMENT = "/adyen/payment-method";
public static final String AUTHORISE_3D_SECURE_PAYMENT_URL = "/authorise-3d-adyen-response";

public static final String CART_PREFIX = "/cart";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.adyen.model.checkout.PaymentDetailsResponse;
import com.adyen.v6.exceptions.AdyenNonAuthorizedPaymentException;
import com.adyen.v6.facades.AdyenCheckoutFacade;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import de.hybris.platform.acceleratorstorefrontcommons.annotations.RequireHardLogIn;
import de.hybris.platform.commercefacades.order.data.OrderData;
import de.hybris.platform.order.InvalidCartException;
Expand All @@ -21,15 +19,12 @@

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Map;
import java.util.Base64;

import static com.adyen.commerce.constants.AdyencheckoutaddonapiWebConstants.*;
import static com.adyen.commerce.util.ErrorMessageUtil.getErrorMessageByRefusalReason;
import static com.adyen.model.checkout.PaymentDetailsResponse.*;
import static com.adyen.model.checkout.PaymentDetailsResponse.ResultCodeEnum;
import static com.adyen.model.checkout.PaymentDetailsResponse.ResultCodeEnum.REFUSED;
import static com.adyen.v6.facades.impl.DefaultAdyenCheckoutFacade.DETAILS;
import static de.hybris.platform.acceleratorstorefrontcommons.controllers.AbstractController.REDIRECT_PREFIX;

@Controller
Expand All @@ -42,6 +37,7 @@ public class Adyen3DSResponseController {
private static final String CHECKOUT_ERROR_AUTHORIZATION_FAILED = "checkout.error.authorization.failed";
private static final String REDIRECTING_TO_CART_PAGE = "Redirecting to cart page...";
private static final String ORDER_CONFIRMATION_URL = ADYEN_CHECKOUT_PAGE_PREFIX + ADYEN_CHECKOUT_ORDER_CONFIRMATION;
private static final String SELECT_PAYMENT_METHOD_URL = ADYEN_CHECKOUT_PAGE_PREFIX + ADYEN_CHECKOUT_SELECT_PAYMENT;


@Resource(name = "adyenCheckoutFacade")
Expand Down Expand Up @@ -96,7 +92,7 @@ public String authorise3DSPayment(final PaymentDetailsRequest details) {
+ response.getRefusalReason());
}
}
//implement in 3ds error handling return redirectToSelectPaymentMethodWithError(errorMessage);
return getErrorRedirectUrl(errorMessage);
} catch (CalculationException | InvalidCartException e) {
LOGGER.warn(e.getMessage(), e);
} catch (Exception e) {
Expand All @@ -106,4 +102,8 @@ public String authorise3DSPayment(final PaymentDetailsRequest details) {
LOGGER.warn(REDIRECTING_TO_CART_PAGE);
return REDIRECT_PREFIX + CART_PREFIX;
}

private String getErrorRedirectUrl(String errorMessage) {
return REDIRECT_PREFIX + SELECT_PAYMENT_METHOD_URL + "/error/" + Base64.getUrlEncoder().encodeToString(errorMessage.getBytes());
}
}
4 changes: 0 additions & 4 deletions adyencheckoutaddonapi/extensioninfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@


<meta key="classpathgen" value="false"/>


<meta key="deprecated" value="true"/>


</extension>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.annotation.Resource;
Expand All @@ -30,9 +29,7 @@
public class AdyenPageCheckoutStepController extends AbstractCheckoutStepController {
private static final String DELIVERY_ADDRESS = "delivery-address";
private static final String SHOW_SAVE_TO_ADDRESS_BOOK_ATTR = "showSaveToAddressBook";

@Resource(name = "addressDataUtil")
private AddressDataUtil addressDataUtil;
public static final String SPA_CHECKOUT_PAGE = "addon:/adyencheckoutaddonspa/pages/adyenSPACheckout";


@GetMapping(value = "/adyen/*")
Expand All @@ -45,7 +42,19 @@ public String enterStep(final Model model, final RedirectAttributes redirectAttr

populateCommonModelAttributes(model, cartData, new AddressForm());

return "addon:/adyencheckoutaddonspa/pages/adyenSPACheckout";
return SPA_CHECKOUT_PAGE;
}

@GetMapping(value = "/adyen/payment-method/error/*")
@RequireHardLogIn
@PreValidateQuoteCheckoutStep
@PreValidateCheckoutStep(checkoutStep = DELIVERY_ADDRESS)
public String enterPaymentStepWithError(final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException {
final CartData cartData = getCheckoutFacade().getCheckoutCart();

populateCommonModelAttributes(model, cartData, new AddressForm());

return SPA_CHECKOUT_PAGE;
}

@GetMapping(value = {ADYEN_CHECKOUT_ORDER_CONFIRMATION, ADYEN_CHECKOUT_ORDER_CONFIRMATION + "/**"})
Expand All @@ -55,17 +64,17 @@ public String enterOrderConfirmationStep(final Model model) throws CMSItemNotFou
storeCmsPageInModel(model, multiCheckoutSummaryPage);
setUpMetaDataForContentPage(model, multiCheckoutSummaryPage);

return "addon:/adyencheckoutaddonspa/pages/adyenSPACheckout";
return SPA_CHECKOUT_PAGE;
}

protected void populateCommonModelAttributes(final Model model, final CartData cartData, final AddressForm addressForm)
throws CMSItemNotFoundException {
model.addAttribute("cartData", cartData);
model.addAttribute("addressForm", addressForm);
model.addAttribute("deliveryAddresses", getDeliveryAddresses(cartData.getDeliveryAddress()));
model.addAttribute("noAddress", Boolean.valueOf(getCheckoutFlowFacade().hasNoDeliveryAddress()));
model.addAttribute("addressFormEnabled", Boolean.valueOf(getCheckoutFacade().isNewAddressEnabledForCart()));
model.addAttribute("removeAddressEnabled", Boolean.valueOf(getCheckoutFacade().isRemoveAddressEnabledForCart()));
model.addAttribute("noAddress", getCheckoutFlowFacade().hasNoDeliveryAddress());
model.addAttribute("addressFormEnabled", getCheckoutFacade().isNewAddressEnabledForCart());
model.addAttribute("removeAddressEnabled", getCheckoutFacade().isRemoveAddressEnabledForCart());
model.addAttribute(SHOW_SAVE_TO_ADDRESS_BOOK_ATTR, Boolean.TRUE);
model.addAttribute(WebConstants.BREADCRUMBS_KEY, getResourceBreadcrumbBuilder().getBreadcrumbs(getBreadcrumbKey()));
model.addAttribute("metaRobots", "noindex,nofollow");
Expand All @@ -79,6 +88,7 @@ protected void populateCommonModelAttributes(final Model model, final CartData c
setUpMetaDataForContentPage(model, multiCheckoutSummaryPage);
setCheckoutStepLinksForModel(model, getCheckoutStep());
}

protected String getBreadcrumbKey() {
return "checkout.multi." + getCheckoutStep().getProgressBarId() + ".breadcrumb";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ interface State {
errorCode: string
}

interface ComponentProps {
errorCode?: string
}

interface StoreProps {
billingAddress: AddressModel,
shippingAddressFromCart: AddressData,
Expand All @@ -57,7 +61,7 @@ interface DispatchProps {
setSelectedAddress: (address: AddressModel) => void
}

type Props = StoreProps & DispatchProps
type Props = StoreProps & DispatchProps & ComponentProps

class Payment extends React.Component<Props, State> {

Expand All @@ -71,8 +75,8 @@ class Payment extends React.Component<Props, State> {
useDifferentBillingAddress: false,
redirectToNextStep: false,
redirectTo3DS: false,
errorCode: "",
saveInAddressBook: false,
errorCode: this.props.errorCode ? this.props.errorCode : ""
}
this.paymentRef = React.createRef();
this.threeDSRef = React.createRef();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import React from "react";
import React, {useEffect} from "react";
import {ShippingMethodHeader} from "../headers/ShippingMethodHeader";
import {ShippingAddressHeader} from "../headers/ShippingAddressHeader";
import Payment from "../payment/Payment";
import RedirectOnIncompleteData from "../common/RedirectOnIncompleteData";
import {CheckoutSteps} from "../../types/checkoutStepsEnum";
import {CartDataService} from "../../service/cartDataService";

export class PaymentStep extends React.Component<{}, null> {
export function PaymentStep() {
const {errorCode} = useParams();

componentDidMount() {

useEffect(() => {
CartDataService.fetchCartData();
}
})

render() {
return (
<>
<RedirectOnIncompleteData currentCheckoutStep={CheckoutSteps.PAYMENT_METHOD}>
<ShippingAddressHeader editEnabled={true}/>
<ShippingMethodHeader editEnabled={true}/>
<Payment/>
</RedirectOnIncompleteData>
</>
)
function getErrorCode(): string {
return errorCode ? atob(errorCode) : undefined;
}

return (
<RedirectOnIncompleteData currentCheckoutStep={CheckoutSteps.PAYMENT_METHOD}>
<ShippingAddressHeader editEnabled={true}/>
<ShippingMethodHeader editEnabled={true}/>
<Payment errorCode={getErrorCode()}/>
</RedirectOnIncompleteData>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export const router = createBrowserRouter([
element: <TranslationWrapper><NotificationWrapper
checkoutStep={CheckoutSteps.THANK_YOU_PAGE}><ThankYouPageUrlWrapper/></NotificationWrapper></TranslationWrapper>,
},
{
path: routes.paymentMethod + "/error/:errorCode",
element: <TranslationWrapper><CheckoutStepWrapper><PaymentStep/></CheckoutStepWrapper></TranslationWrapper>,
},
{
//in case url doesn't match - redirect to shipping address
path: "*",
Expand Down
4 changes: 0 additions & 4 deletions adyencheckoutaddonspa/extensioninfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@


<meta key="classpathgen" value="false"/>


<meta key="deprecated" value="true"/>


</extension>

Expand Down

0 comments on commit 360d1c4

Please sign in to comment.