Skip to content

Commit

Permalink
Merge pull request #487 from Adyen/feature/AD-345
Browse files Browse the repository at this point in the history
Feature/ad 345
  • Loading branch information
kpieloch authored Dec 11, 2024
2 parents 9a9c963 + 83889e9 commit 0bed51e
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@adyen/adyen-web": "6.1.1",
"@adyen/adyen-web": "6.5.0",
"@babel/core": "^7.16.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
"@reduxjs/toolkit": "^2.0.1",
Expand All @@ -13,7 +13,7 @@
"@testing-library/user-event": "^13.5.0",
"@types/react": "^18.2.47",
"@types/react-dom": "^18.2.18",
"axios": "^1.6.2",
"axios": "1.7.4",
"babel-jest": "^27.4.2",
"babel-loader": "^8.2.3",
"babel-plugin-named-asset-import": "^0.3.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface ComponentProps {
interface StoreProps {
billingAddress: AddressModel,
shippingAddressFromCart: AddressData,
adyenConfig: AdyenConfigData
adyenConfig: AdyenConfigData,
}

interface DispatchProps {
Expand Down Expand Up @@ -133,7 +133,11 @@ class Payment extends React.Component<Props, State> {
type: 'card',
hasHolderName: true,
holderNameRequired: this.props.adyenConfig.cardHolderNameRequired,
enableStoreDetails: this.props.adyenConfig.showRememberTheseDetails
enableStoreDetails: this.props.adyenConfig.showRememberTheseDetails,
clickToPayConfiguration: {
merchantDisplayName: this.props.adyenConfig.merchantDisplayName,
shopperEmail: this.props.adyenConfig.shopperEmail
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const adyenConfigInitialState : AdyenConfigData = {
deviceFingerPrintUrl: "",
issuerLists: undefined,
sepaDirectDebit: undefined,
storedPaymentMethodList: []
storedPaymentMethodList: [],
merchantDisplayName: "",
shopperEmail: "",
}

export function adyenConfigReducer(adyenConfig: AdyenConfigData, action: RootAction): AdyenConfigData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface AdyenConfigData {
countryCode: string;
cardHolderNameRequired: boolean;
sepaDirectDebit: boolean;
merchantDisplayName: string,
shopperEmail: string,
}

interface SessionData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
paymentMethodConfigs['createCard'] = {
allowedCards,
showRememberDetails: ${showRememberTheseDetails},
cardHolderNameRequired: ${cardHolderNameRequired}
}
cardHolderNameRequired: ${cardHolderNameRequired},
merchantDisplayName: "${merchantDisplayName}",
shopperEmail: "${shopperEmail}",
};
const adyenCheckout = new AdyenCheckoutHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class AdyenCheckoutHelper {
onError: (error, component) => {
console.error(error.name, error.message, error.stack, component);
},
paymentMethodsConfiguration:{
card: {
enableStoreDetails: paymentMethodConfigs.enableStoreDetails,
},
}
};
console.log("Execution of initiateCheckout: ", this.i++);
this.checkout = await AdyenWeb.AdyenCheckout(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PaymentComponentFactory {
}

createCard(params) {
const {allowedCards, showRememberDetails, cardHolderNameRequired} = params;
const {allowedCards, showRememberDetails, cardHolderNameRequired,merchantDisplayName,shopperEmail} = params;

const copyCardBrand= (event) => {
context.selectedCardBrand = event.brand;
Expand All @@ -60,9 +60,14 @@ class PaymentComponentFactory {
type: 'card',
hasHolderName: true,
holderNameRequired: cardHolderNameRequired,
storePaymentMethod: showRememberDetails ? 'askForConsent': 'disabled',
enableStoreDetails: showRememberDetails,
brands: allowedCards,
onBrand: copyCardBrand
onBrand: copyCardBrand,
clickToPayConfiguration: {
merchantDisplayName: merchantDisplayName,
shopperEmail: shopperEmail
}
}).mount("#card-div");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ protected boolean canL23EdsBeSent(PaymentRequest paymentsRequest, CartModel sess
.map(method -> method.getActualInstance())
.filter(instance -> instance instanceof CardDetails)
.map(instance -> (CardDetails) instance)
.filter(cardDetails -> cardDetails.getBrand() != null)
.map(cardDetails -> getL2L3SupportedBrands().contains(cardDetails.getBrand()))
.orElse(false) &&
Optional.ofNullable(sessionCart.getDeliveryAddress())
Expand Down
18 changes: 18 additions & 0 deletions adyenv6core/src/com/adyen/v6/dto/CheckoutConfigDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class CheckoutConfigDTO {
private boolean sepaDirectDebit;
private BigDecimal amountDecimal;
private ExpressPaymentConfigDto expressPaymentConfig;
private String merchantDisplayName;
private String shopperEmail;

// Getters and setters for the new field
public ExpressPaymentConfigDto getExpressPaymentConfig() {
Expand Down Expand Up @@ -270,4 +272,20 @@ public BigDecimal getAmountDecimal() {
public void setAmountDecimal(BigDecimal amountDecimal) {
this.amountDecimal = amountDecimal;
}

public String getMerchantDisplayName() {
return merchantDisplayName;
}

public void setMerchantDisplayName(String merchantDisplayName) {
this.merchantDisplayName = merchantDisplayName;
}

public String getShopperEmail() {
return shopperEmail;
}

public void setShopperEmail(String shopperEmail) {
this.shopperEmail = shopperEmail;
}
}
10 changes: 10 additions & 0 deletions adyenv6core/src/com/adyen/v6/dto/CheckoutConfigDTOBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ public CheckoutConfigDTOBuilder setExpressPaymentConfig(ExpressPaymentConfigDto
checkoutConfigDTO.setExpressPaymentConfig(expressPaymentConfigDto);
return this;
}
public CheckoutConfigDTOBuilder setMerchantDisplayName(String merchantDisplayName) {
checkoutConfigDTO.setMerchantDisplayName(merchantDisplayName);
return this;
}

public CheckoutConfigDTOBuilder setShopperEmail(String shopperEmail) {
checkoutConfigDTO.setShopperEmail(shopperEmail);
return this;
}


public CheckoutConfigDTO build() {
return checkoutConfigDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ public void initializeCheckoutData(Model model) throws ApiException {
model.addAttribute(MODEL_CHECKOUT_SHOPPER_HOST, checkoutConfigDTO.getCheckoutShopperHost());
model.addAttribute(MODEL_ENVIRONMENT_MODE, checkoutConfigDTO.getEnvironmentMode());
model.addAttribute(SHOPPER_LOCALE, checkoutConfigDTO.getShopperLocale());
model.addAttribute("merchantDisplayName", checkoutConfigDTO.getMerchantDisplayName());
model.addAttribute("shopperEmail", checkoutConfigDTO.getShopperEmail());

// OpenInvoice Methods
model.addAttribute(MODEL_OPEN_INVOICE_METHODS, checkoutConfigDTO.getOpenInvoiceMethods());
Expand Down Expand Up @@ -771,7 +773,7 @@ public CheckoutConfigDTO getReactCheckoutConfig() throws ApiException {
.setAdyenClientKey(baseStore.getAdyenClientKey())
.setAdyenPaypalMerchantId(baseStore.getAdyenPaypalMerchantId())
.setDeviceFingerPrintUrl(adyenPaymentService.getDeviceFingerprintUrl())
.setSessionData(getAdyenSessionData())
.setSessionData(getAdyenSessionData(showRememberDetails()))
.setSelectedPaymentMethod(cartData.getAdyenPaymentMethod())
.setShowRememberTheseDetails(showRememberDetails())
.setCheckoutShopperHost(getCheckoutShopperHost())
Expand All @@ -785,7 +787,9 @@ public CheckoutConfigDTO getReactCheckoutConfig() throws ApiException {
.setImmediateCapture(isImmediateCapture())
.setCountryCode(cartData != null && cartData.getDeliveryAddress() != null && cartData.getDeliveryAddress().getCountry() != null ? cartData.getDeliveryAddress().getCountry().getIsocode() : "")
.setCardHolderNameRequired(getHolderNameRequired())
.setAmountDecimal(cartData.getTotalPriceWithTax().getValue());
.setAmountDecimal(cartData.getTotalPriceWithTax().getValue())
.setMerchantDisplayName(baseStore.getName())
.setShopperEmail(customerModel.getContactEmail());

ExpressPaymentConfigModel expressPaymentConfigModel = baseStore.getExpressPaymentConfig();
if (expressPaymentConfigModel != null) {
Expand Down Expand Up @@ -914,7 +918,7 @@ public CheckoutConfigDTO getCheckoutConfig() throws ApiException {
.setAdyenClientKey(baseStore.getAdyenClientKey())
.setAdyenPaypalMerchantId(baseStore.getAdyenPaypalMerchantId())
.setDeviceFingerPrintUrl(adyenCheckoutApiService.getDeviceFingerprintUrl())
.setSessionData(getAdyenSessionData())
.setSessionData(getAdyenSessionData(showRememberDetails()))
.setSelectedPaymentMethod(cartData.getAdyenPaymentMethod())
.setShowRememberTheseDetails(showRememberDetails())
.setCheckoutShopperHost(getCheckoutShopperHost())
Expand All @@ -929,7 +933,9 @@ public CheckoutConfigDTO getCheckoutConfig() throws ApiException {
.setCountryCode(cartData.getDeliveryAddress().getCountry().getIsocode())
.setCardHolderNameRequired(getHolderNameRequired())
.setSepaDirectDebit(sepaDirectDebit)
.setAmountDecimal(cartData.getTotalPriceWithTax().getValue());
.setAmountDecimal(cartData.getTotalPriceWithTax().getValue())
.setMerchantDisplayName(baseStore.getName())
.setShopperEmail(customerModel.getContactEmail());

ExpressPaymentConfigModel expressPaymentConfigModel = baseStore.getExpressPaymentConfig();
if (expressPaymentConfigModel != null) {
Expand Down Expand Up @@ -1022,10 +1028,10 @@ protected Map<String, String> getApplePayConfigFromPaymentMethods(List<PaymentMe
return new HashMap<>();
}

protected CreateCheckoutSessionResponse getAdyenSessionData() throws ApiException {
protected CreateCheckoutSessionResponse getAdyenSessionData(final boolean storePaymentMethod) throws ApiException {
try {
final CartData cartData = getCheckoutFacade().getCheckoutCart();
return getAdyenPaymentService().getPaymentSessionData(cartData);
return getAdyenPaymentService().getPaymentSessionData(cartData,storePaymentMethod);
} catch (JsonProcessingException e) {
LOGGER.error("Processing json failed. ", e);
return null;
Expand Down Expand Up @@ -1077,7 +1083,7 @@ public void initializeSummaryData(Model model) throws ApiException {
model.addAttribute(MODEL_AMAZONPAY_CONFIGURATION, gson.toJson(cartData.getAdyenAmazonPayConfiguration()));
model.addAttribute(MODEL_COUNTRY_CODE, countryCode);
model.addAttribute(MODEL_DELIVERY_ADDRESS, gson.toJson(cartData.getDeliveryAddress()));
model.addAttribute(SESSION_DATA, getAdyenSessionData());
model.addAttribute(SESSION_DATA, getAdyenSessionData(showRememberDetails()));
model.addAttribute(LOCALE, gson.toJson(setLocale(cartData.getAdyenAmazonPayConfiguration(), shopperLocale)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public interface AdyenCheckoutApiService {
*/
TerminalAPIResponse sendSyncPosStatusRequest(CartData cartData, String serviceId) throws Exception;

CreateCheckoutSessionResponse getPaymentSessionData(final CartData cartData) throws IOException, ApiException;
CreateCheckoutSessionResponse getPaymentSessionData(final CartData cartData, final boolean storePaymentMethod) throws IOException, ApiException;

CreateCheckoutSessionResponse getPaymentSessionData(final Amount amount) throws IOException, ApiException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static com.adyen.model.checkout.CreateCheckoutSessionRequest.StorePaymentMethodModeEnum.ASKFORCONSENT;

public class DefaultAdyenCheckoutApiService extends AbstractAdyenApiService implements AdyenCheckoutApiService {

private static final Logger LOG = Logger.getLogger(DefaultAdyenCheckoutApiService.class);
Expand Down Expand Up @@ -275,9 +277,8 @@ public PaymentDetailsResponse getPaymentDetailsFromPayload(PaymentDetailsRequest
return paymentsResponse;
}


@Override
public CreateCheckoutSessionResponse getPaymentSessionData(final CartData cartData) throws IOException, ApiException {
public CreateCheckoutSessionResponse getPaymentSessionData(final CartData cartData, final boolean storePaymentMethod) throws IOException, ApiException {
final PaymentsApi checkout = new PaymentsApi(client);
final PriceData totalPriceWithTax = cartData.getTotalPriceWithTax();

Expand All @@ -289,7 +290,13 @@ public CreateCheckoutSessionResponse getPaymentSessionData(final CartData cartDa
}
createCheckoutSessionRequest.returnUrl(Optional.ofNullable(cartData.getAdyenReturnUrl()).orElse("returnUrl"));
createCheckoutSessionRequest.reference(cartData.getCode());

createCheckoutSessionRequest.setStorePaymentMethod(storePaymentMethod);
createCheckoutSessionRequest.setStorePaymentMethodMode(ASKFORCONSENT);
createCheckoutSessionRequest.enableOneClick(true);
createCheckoutSessionRequest.shopperEmail(cartData.getUser().getUid());
createCheckoutSessionRequest.recurringProcessingModel(CreateCheckoutSessionRequest.RecurringProcessingModelEnum.CARDONFILE);
createCheckoutSessionRequest.shopperReference(cartData.getUser().getUid());

return checkout.sessions(createCheckoutSessionRequest);
}

Expand Down

0 comments on commit 0bed51e

Please sign in to comment.