Skip to content

Commit

Permalink
Merge pull request #427 from Adyen/feature/AD-278-
Browse files Browse the repository at this point in the history
AD-278 Implement Support for Redirect Payment Methods and 3D Secure i…
  • Loading branch information
pjaneta authored Aug 1, 2024
2 parents 2d54255 + df02d74 commit 7e8a9c4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import de.hybris.platform.acceleratorfacades.flow.CheckoutFlowFacade;
import de.hybris.platform.acceleratorservices.urlresolver.SiteBaseUrlResolutionService;
import de.hybris.platform.acceleratorstorefrontcommons.annotations.RequireHardLogIn;
import de.hybris.platform.basecommerce.model.site.BaseSiteModel;
import de.hybris.platform.commercefacades.order.CartFacade;
import de.hybris.platform.order.InvalidCartException;
import de.hybris.platform.order.exceptions.CalculationException;
Expand All @@ -24,6 +25,9 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.adyen.commerce.constants.AdyenwebcommonsConstants.ADYEN_CHECKOUT_API_PREFIX;
import static com.adyen.commerce.constants.AdyenwebcommonsConstants.AUTHORISE_3D_SECURE_PAYMENT_URL;


@RequestMapping("/api/checkout")
@Controller
Expand Down Expand Up @@ -70,6 +74,16 @@ public ResponseEntity<Void> onCancel() throws InvalidCartException, CalculationE
return ResponseEntity.ok().build();
}


@Override
public String getPaymentRedirectReturnUrl() {
String url = ADYEN_CHECKOUT_API_PREFIX + AUTHORISE_3D_SECURE_PAYMENT_URL;

BaseSiteModel currentBaseSite = getBaseSiteService().getCurrentBaseSite();

return getSiteBaseUrlResolutionService().getWebsiteUrlForSite(currentBaseSite, true, url);
}

@Override
public AdyenCheckoutApiFacade getAdyenCheckoutApiFacade() {
return adyenCheckoutApiFacade;
Expand Down
5 changes: 4 additions & 1 deletion adyenocc/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ adyenocc.application-context=adyenocc-spring.xml
adyenocc.documentation.static.generate=true
ext.adyenocc.extension.webmodule.webroot=/occ/v2

adyen.spartacus.baseurl=https://electronics.local:9002/spartacus
adyen.spartacus.baseurl=http://localhost:4200/

webroot.commercewebservices.http=http://localhost:9001/occ
webroot.commercewebservices.https=https://localhost:9002/occ
4 changes: 4 additions & 0 deletions adyenocc/resources/adyenocc-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@

<context:annotation-config/>

<bean id="webServicesBaseUrlResolver" class="com.adyen.commerce.utils.WebServicesBaseUrlResolver">
<property name="configurationService" ref="configurationService"/>
</bean>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.adyen.commerce.request.PlaceOrderRequest;
import com.adyen.commerce.response.OCCPlaceOrderResponse;
import com.adyen.commerce.response.PlaceOrderResponse;
import com.adyen.commerce.utils.WebServicesBaseUrlResolver;
import com.adyen.model.checkout.PaymentDetailsRequest;
import com.adyen.v6.facades.AdyenCheckoutFacade;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -55,6 +56,9 @@ public class PlaceOrderController extends PlaceOrderControllerBase {
@Autowired
private AdyenCheckoutFacade adyenCheckoutFacade;

@Autowired
private WebServicesBaseUrlResolver webServicesBaseUrlResolver;

@Secured({"ROLE_CUSTOMERGROUP", "ROLE_CLIENT", "ROLE_CUSTOMERMANAGERGROUP", "ROLE_TRUSTED_CLIENT"})
@PostMapping(value = "/place-order", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(operationId = "placeOrder", summary = "Handle place order request", description =
Expand Down Expand Up @@ -89,6 +93,14 @@ public ResponseEntity<Void> onCancel() throws InvalidCartException, CalculationE
return ResponseEntity.ok().build();
}

@Override
public String getPaymentRedirectReturnUrl() {
String occBaseUrl = webServicesBaseUrlResolver.getOCCBaseUrl(true);
String baseSiteUid = baseSiteService.getCurrentBaseSite().getUid();

return occBaseUrl + "/v2/" + baseSiteUid + "/adyen/redirect";
}

@Override
public AdyenCheckoutApiFacade getAdyenCheckoutApiFacade() {
return adyenCheckoutApiFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import java.util.Base64;

import static com.adyen.commerce.constants.AdyenwebcommonsConstants.REDIRECT_PREFIX;

@Controller
Expand All @@ -28,6 +30,7 @@
@Tag(name = "Adyen")
public class RedirectController extends RedirectControllerBase {
private static final String REDIRECT_URL = "/redirect";
private static final String ADYEN_REDIRECT_URL = "/adyen/redirect/";

@Resource(name = "adyenCheckoutFacade")
private AdyenCheckoutFacade adyenCheckoutFacade;
Expand Down Expand Up @@ -57,24 +60,29 @@ public String authorizeRedirectPaymentPost(@Parameter(description = "Payment det

@Override
public String getErrorRedirectUrl(String errorMessage) {
//TODO: will be implemented
return "error url";
String encodedMessage = Base64.getUrlEncoder().encodeToString(errorMessage.getBytes());
return getSpartacusUrlPrefix() + ADYEN_REDIRECT_URL + "error/" + encodedMessage;
}

@Override
public String getOrderConfirmationUrl(String orderCode) {
//TODO: will be implemented
return "order confirmation";
return getSpartacusUrlPrefix() + ADYEN_REDIRECT_URL + orderCode;

}

@Override
public String getCartUrl() {
return getSpartacusUrlPrefix() + "/cart";
}

private String getSpartacusUrlPrefix() {
String currency = commerceCommonI18NService.getCurrentCurrency().getIsocode();
String language = commerceCommonI18NService.getCurrentLanguage().getIsocode();
String baseSiteUid = baseSiteService.getCurrentBaseSite().getUid();

String baseUrl = configurationService.getConfiguration().getString("adyen.spartacus.baseurl");
return REDIRECT_PREFIX + baseUrl + "/" + baseSiteUid + "/" + language + "/" + currency + "/cart";

return REDIRECT_PREFIX + baseUrl + baseSiteUid + "/" + language + "/" + currency;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.adyen.commerce.utils;

import de.hybris.platform.servicelayer.config.ConfigurationService;

public class WebServicesBaseUrlResolver {
private ConfigurationService configurationService;


public String getOCCBaseUrl(final boolean isSecure) {
String baseUrlKey = "webroot.commercewebservices." + (isSecure ? "https" : "http");
return configurationService.getConfiguration().getString(baseUrlKey, "");
}

public void setConfigurationService(ConfigurationService configurationService) {
this.configurationService = configurationService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,7 @@ private OCCPlaceOrderResponse executeAction(PaymentResponse paymentsResponse) {
return placeOrderResponse;
}

private String getPaymentRedirectReturnUrl() {
String url = ADYEN_CHECKOUT_API_PREFIX + AUTHORISE_3D_SECURE_PAYMENT_URL;

BaseSiteModel currentBaseSite = getBaseSiteService().getCurrentBaseSite();

return getSiteBaseUrlResolutionService().getWebsiteUrlForSite(currentBaseSite, true, url);
}
public abstract String getPaymentRedirectReturnUrl();

public abstract AdyenCheckoutApiFacade getAdyenCheckoutApiFacade();

Expand Down

0 comments on commit 7e8a9c4

Please sign in to comment.