Skip to content

Commit

Permalink
AD-334 Add Apple Pay Express Button with Frontend Logic and API Calls…
Browse files Browse the repository at this point in the history
… to CMS Components on PDP and Cart Pages - Spartacus

AD-336 Add Google Pay Express Button with Frontend Logic and API Calls to CMS Components on PDP and Cart Pages - Spartacus
Adyen Express configuration
  • Loading branch information
pjaneta committed Dec 30, 2024
1 parent c99ea73 commit c7af3a9
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@

import com.adyen.commerce.constants.AdyenoccConstants;
import com.adyen.service.exception.ApiException;
import com.adyen.v6.dto.CheckoutConfigDTO;
import com.adyen.v6.facades.AdyenCheckoutFacade;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import de.hybris.platform.commerceservices.request.mapping.annotation.ApiVersion;
import de.hybris.platform.webservicescommons.swagger.ApiBaseSiteIdAndUserIdParam;
import de.hybris.platform.webservicescommons.swagger.ApiBaseSiteIdUserIdAndCartIdParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = AdyenoccConstants.ADYEN_USER_CART_PREFIX)
@ApiVersion("v2")
@Tag(name = "Adyen")
public class PaymentMethodsController
Expand All @@ -38,12 +37,32 @@ public class PaymentMethodsController
private AdyenCheckoutFacade adyenCheckoutFacade;

@Secured({ "ROLE_CUSTOMERGROUP", "ROLE_TRUSTED_CLIENT", "ROLE_CUSTOMERMANAGERGROUP" })
@GetMapping(value = "/checkout-configuration")
@GetMapping(value = AdyenoccConstants.ADYEN_USER_CART_PREFIX + "/checkout-configuration")
@Operation(operationId = "getCheckoutConfiguration", summary = "Get checkout configuration", description =
"Returns configuration for Adyen dropin component")
@ApiBaseSiteIdUserIdAndCartIdParam
public ResponseEntity<String> getCheckoutConfiguration() throws ApiException, JsonProcessingException {
String response = objectMapper.writeValueAsString(adyenCheckoutFacade.getReactCheckoutConfig());
return ResponseEntity.ok().body(response);
}

@Secured({ "ROLE_CUSTOMERGROUP", "ROLE_TRUSTED_CLIENT", "ROLE_CUSTOMERMANAGERGROUP" })
@GetMapping(value = AdyenoccConstants.ADYEN_USER_PREFIX + "/checkout-configuration/express/PDP/{productCode}")
@Operation(operationId = "getExpressPDPCheckoutConfiguration", summary = "Get express product page checkout configuration", description =
"Returns configuration for express payments on PDP")
@ApiBaseSiteIdAndUserIdParam
public ResponseEntity<String> getExpressPDPCheckoutConfiguration(@PathVariable String productCode) throws ApiException, JsonProcessingException {
String response = objectMapper.writeValueAsString(adyenCheckoutFacade.initializeExpressCheckoutPDPDataOCC(productCode));
return ResponseEntity.ok().body(response);
}

@Secured({ "ROLE_CUSTOMERGROUP", "ROLE_TRUSTED_CLIENT", "ROLE_CUSTOMERMANAGERGROUP" })
@GetMapping(value = AdyenoccConstants.ADYEN_USER_CART_PREFIX + "/checkout-configuration/express/cart")
@Operation(operationId = "getExpressCartCheckoutConfiguration", summary = "Get express cart page checkout configuration", description =
"Returns configuration for express payments on cart")
@ApiBaseSiteIdUserIdAndCartIdParam
public ResponseEntity<String> getExpressCartCheckoutConfiguration() throws ApiException, JsonProcessingException {
String response = objectMapper.writeValueAsString(adyenCheckoutFacade.initializeExpressCheckoutCartPageDataOCC());
return ResponseEntity.ok().body(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AdyenAccCartExpressCheckoutComponentController extends AbstractCMSA
protected void fillModel(final HttpServletRequest request, final Model model, final AdyenAccExpressCheckoutCartPageComponentModel component) {
try {
adyenExpressCheckoutFacade.removeDeliveryModeFromSessionCart();
adyenCheckoutFacade.initializeApplePayExpressCartPageData(model);
adyenCheckoutFacade.initializeExpressCheckoutCartPageData(model);
} catch (ApiException | CalculationException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import de.hybris.platform.acceleratorservices.data.RequestContextData;
import de.hybris.platform.addonsupport.controllers.cms.AbstractCMSAddOnComponentController;
import de.hybris.platform.commercefacades.product.ProductFacade;
import de.hybris.platform.commercefacades.product.ProductOption;
import de.hybris.platform.commercefacades.product.data.ProductData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

@Controller(AdyenAccExpressCheckoutProductPageComponentModel._TYPECODE + "Controller")
@RequestMapping(value = "/view/" + AdyenAccExpressCheckoutProductPageComponentModel._TYPECODE + "Controller")
Expand All @@ -30,10 +27,8 @@ public class AdyenAccProductExpressCheckoutComponentController extends AbstractC
protected void fillModel(final HttpServletRequest request, final Model model, final AdyenAccExpressCheckoutProductPageComponentModel component) {
try {
RequestContextData requestContextData = getRequestContextData(request);
requestContextData.getProduct();
final ProductData productData = productFacade.getProductForCodeAndOptions(requestContextData.getProduct().getCode(), Arrays.asList(ProductOption.BASIC, ProductOption.PRICE));

adyenCheckoutFacade.initializeApplePayExpressPDPData(model, productData);
adyenCheckoutFacade.initializeExpressCheckoutPDPData(model, requestContextData.getProduct().getCode());
} catch (ApiException e) {
throw new RuntimeException(e);
}
Expand Down
1 change: 1 addition & 0 deletions adyenv6core/resources/adyenv6core-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
<property name="configurationService" ref="configurationService"/>
<property name="adyenMerchantAccountStrategy" ref="adyenMerchantStrategy"/>
<property name="adyenOrderFacade" ref="adyenOrderFacade"/>
<property name="productFacade" ref="productFacade"/>
</bean>

<alias name="defaultAdyenCheckoutApiFacade" alias="adyenCheckoutApiFacade" />
Expand Down
127 changes: 127 additions & 0 deletions adyenv6core/src/com/adyen/v6/dto/ExpressCheckoutConfigDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.adyen.v6.dto;

import com.adyen.model.checkout.Amount;
import com.adyen.model.checkout.CreateCheckoutSessionResponse;

import java.math.BigDecimal;

public class ExpressCheckoutConfigDTO {
private String applePayMerchantId;
private String applePayMerchantName;
private String payPalIntent;
private String shopperLocale;
private String environmentMode;
private String clientKey;
private String merchantAccount;
//TODO: Remove in 13.3
private CreateCheckoutSessionResponse sessionData;
private Amount amount;
private BigDecimal amountDecimal;
private String dfUrl;
private String checkoutShopperHost;
private ExpressPaymentConfigDto expressPaymentConfig;

public String getApplePayMerchantId() {
return applePayMerchantId;
}

public void setApplePayMerchantId(String applePayMerchantId) {
this.applePayMerchantId = applePayMerchantId;
}

public String getApplePayMerchantName() {
return applePayMerchantName;
}

public void setApplePayMerchantName(String applePayMerchantName) {
this.applePayMerchantName = applePayMerchantName;
}

public String getPayPalIntent() {
return payPalIntent;
}

public void setPayPalIntent(String payPalIntent) {
this.payPalIntent = payPalIntent;
}

public String getShopperLocale() {
return shopperLocale;
}

public void setShopperLocale(String shopperLocale) {
this.shopperLocale = shopperLocale;
}

public String getEnvironmentMode() {
return environmentMode;
}

public void setEnvironmentMode(String environmentMode) {
this.environmentMode = environmentMode;
}

public String getClientKey() {
return clientKey;
}

public void setClientKey(String clientKey) {
this.clientKey = clientKey;
}

public String getMerchantAccount() {
return merchantAccount;
}

public void setMerchantAccount(String merchantAccount) {
this.merchantAccount = merchantAccount;
}

public CreateCheckoutSessionResponse getSessionData() {
return sessionData;
}

public void setSessionData(CreateCheckoutSessionResponse sessionData) {
this.sessionData = sessionData;
}

public Amount getAmount() {
return amount;
}

public void setAmount(Amount amount) {
this.amount = amount;
}

public BigDecimal getAmountDecimal() {
return amountDecimal;
}

public void setAmountDecimal(BigDecimal amountDecimal) {
this.amountDecimal = amountDecimal;
}

public String getDfUrl() {
return dfUrl;
}

public void setDfUrl(String dfUrl) {
this.dfUrl = dfUrl;
}

public String getCheckoutShopperHost() {
return checkoutShopperHost;
}

public void setCheckoutShopperHost(String checkoutShopperHost) {
this.checkoutShopperHost = checkoutShopperHost;
}

public ExpressPaymentConfigDto getExpressPaymentConfig() {
return expressPaymentConfig;
}

public void setExpressPaymentConfig(ExpressPaymentConfigDto expressPaymentConfig) {
this.expressPaymentConfig = expressPaymentConfig;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.adyen.v6.dto;

import com.adyen.model.checkout.Amount;
import com.adyen.model.checkout.CreateCheckoutSessionResponse;

import java.math.BigDecimal;

public class ExpressCheckoutConfigDTOBuilder {
private final ExpressCheckoutConfigDTO expressCheckoutConfigDTO;

public ExpressCheckoutConfigDTOBuilder() {
this.expressCheckoutConfigDTO = new ExpressCheckoutConfigDTO();
}

public ExpressCheckoutConfigDTOBuilder setApplePayMerchantId(String applePayMerchantId) {
expressCheckoutConfigDTO.setApplePayMerchantId(applePayMerchantId);
return this;
}

public ExpressCheckoutConfigDTOBuilder setApplePayMerchantName(String applePayMerchantName) {
expressCheckoutConfigDTO.setApplePayMerchantName(applePayMerchantName);
return this;
}

public ExpressCheckoutConfigDTOBuilder setPayPalIntent(String payPalIntent) {
expressCheckoutConfigDTO.setPayPalIntent(payPalIntent);
return this;
}

public ExpressCheckoutConfigDTOBuilder setShopperLocale(String shopperLocale) {
expressCheckoutConfigDTO.setShopperLocale(shopperLocale);
return this;
}

public ExpressCheckoutConfigDTOBuilder setEnvironmentMode(String environmentMode) {
expressCheckoutConfigDTO.setEnvironmentMode(environmentMode);
return this;
}

public ExpressCheckoutConfigDTOBuilder setClientKey(String clientKey) {
expressCheckoutConfigDTO.setClientKey(clientKey);
return this;
}

public ExpressCheckoutConfigDTOBuilder setMerchantAccount(String merchantAccount) {
expressCheckoutConfigDTO.setMerchantAccount(merchantAccount);
return this;
}

public ExpressCheckoutConfigDTOBuilder setSessionData(CreateCheckoutSessionResponse sessionData) {
expressCheckoutConfigDTO.setSessionData(sessionData);
return this;
}

public ExpressCheckoutConfigDTOBuilder setAmount(Amount amount) {
expressCheckoutConfigDTO.setAmount(amount);
return this;
}

public ExpressCheckoutConfigDTOBuilder setAmountDecimal(BigDecimal amountDecimal) {
expressCheckoutConfigDTO.setAmountDecimal(amountDecimal);
return this;
}

public ExpressCheckoutConfigDTOBuilder setDfUrl(String dfUrl) {
expressCheckoutConfigDTO.setDfUrl(dfUrl);
return this;
}

public ExpressCheckoutConfigDTOBuilder setCheckoutShopperHost(String checkoutShopperHost) {
expressCheckoutConfigDTO.setCheckoutShopperHost(checkoutShopperHost);
return this;
}

public ExpressCheckoutConfigDTOBuilder setExpressPaymentConfigDto(ExpressPaymentConfigDto expressPaymentConfigDto) {
expressCheckoutConfigDTO.setExpressPaymentConfig(expressPaymentConfigDto);
return this;
}

public ExpressCheckoutConfigDTO build() {
return expressCheckoutConfigDTO;
}
}
19 changes: 8 additions & 11 deletions adyenv6core/src/com/adyen/v6/facades/AdyenCheckoutFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,20 @@
*/
package com.adyen.v6.facades;

import com.adyen.model.checkout.CheckoutPaymentMethod;
import com.adyen.model.checkout.PaymentCompletionDetails;
import com.adyen.model.checkout.PaymentDetailsRequest;
import com.adyen.model.checkout.PaymentDetailsResponse;
import com.adyen.model.checkout.PaymentRequest;
import com.adyen.model.checkout.PaymentResponse;
import com.adyen.model.checkout.*;
import com.adyen.service.exception.ApiException;
import com.adyen.v6.controllers.dtos.PaymentResultDTO;
import com.adyen.v6.dto.CheckoutConfigDTO;
import com.adyen.v6.dto.ExpressCheckoutConfigDTO;
import com.adyen.v6.forms.AdyenPaymentForm;
import de.hybris.platform.commercefacades.order.data.CartData;
import de.hybris.platform.commercefacades.order.data.OrderData;
import de.hybris.platform.commercefacades.product.data.ProductData;
import de.hybris.platform.commercefacades.user.data.AddressData;
import de.hybris.platform.commercewebservicescommons.dto.order.PaymentDetailsWsDTO;
import de.hybris.platform.core.model.order.CartModel;
import de.hybris.platform.core.model.order.payment.PaymentInfoModel;
import de.hybris.platform.order.InvalidCartException;
import de.hybris.platform.order.exceptions.CalculationException;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -149,9 +142,13 @@ public interface AdyenCheckoutFacade {

void initializeSummaryData(Model model) throws ApiException;

void initializeApplePayExpressCartPageData(Model model) throws ApiException;
void initializeExpressCheckoutCartPageData(Model model) throws ApiException;

void initializeApplePayExpressPDPData(Model model, ProductData productData) throws ApiException;
void initializeExpressCheckoutPDPData(Model model, String productCode) throws ApiException;

ExpressCheckoutConfigDTO initializeExpressCheckoutCartPageDataOCC() throws ApiException;

ExpressCheckoutConfigDTO initializeExpressCheckoutPDPDataOCC(String productCode) throws ApiException;

/**
* Returns whether Boleto should be shown as an available payment method on the checkout page
Expand Down
Loading

0 comments on commit c7af3a9

Please sign in to comment.