Skip to content

Commit

Permalink
Merge pull request #498 from Adyen/feature/AD-390
Browse files Browse the repository at this point in the history
Feature/ad 390
  • Loading branch information
kpieloch authored Jan 3, 2025
2 parents e75fccb + 31a2a79 commit 7600b11
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import {routes} from "../../router/routes";
import {Navigate} from "react-router-dom";
import {PaymentError} from "./PaymentError";
import {ScrollHere} from "../common/ScrollTo";
import {CoreConfiguration,CardConfiguration, UIElement} from "@adyen/adyen-web";
import {
CoreConfiguration,
CardConfiguration,
UIElement,
SubmitActions,
AdditionalDetailsActions
} from "@adyen/adyen-web";

interface State {
useDifferentBillingAddress: boolean
Expand Down Expand Up @@ -110,10 +116,6 @@ class Payment extends React.Component<Props, State> {
environment: this.castToEnvironment(this.props.adyenConfig.environmentMode),
clientKey: this.props.adyenConfig.adyenClientKey,
countryCode: this.props.adyenConfig.countryCode,
session: {
id: this.props.adyenConfig.sessionData.id,
sessionData: this.props.adyenConfig.sessionData.sessionData
},
analytics: {
enabled: false
},
Expand All @@ -124,8 +126,8 @@ class Payment extends React.Component<Props, State> {
onError: (error: AdyenCheckoutError, element?: UIElement) => {
this.handleError()
},
onSubmit: (state: any, element: UIElement) => this.handlePayment(state.data),
onAdditionalDetails: (state: any, element?: UIElement) => this.handleAdditionalDetails(state.data)
onSubmit: (state: any, element: UIElement, actions: SubmitActions) => this.handlePayment(state.data, actions),
onAdditionalDetails: (state: any, element: UIElement,actions: AdditionalDetailsActions) => this.handleAdditionalDetails(state.data, actions)
}
}

Expand Down Expand Up @@ -176,22 +178,22 @@ class Payment extends React.Component<Props, State> {
this.resetDropInComponent();
}

private async handlePayment(data: any) {
private async handlePayment(data: any, actions: SubmitActions) {
let adyenPaymentForm = PaymentService.preparePlaceOrderRequest(data,
this.state.useDifferentBillingAddress, this.isSaveInAddressBook(), this.props.billingAddress);

await this.executePaymentRequest(adyenPaymentForm)
await this.executePaymentRequest(adyenPaymentForm, actions)
}

private async handleAdditionalDetails(data: any) {
await this.executeAdditionalDetails(data)
private async handleAdditionalDetails(data: any,actions: AdditionalDetailsActions) {
await this.executeAdditionalDetails(data,actions)
}

private isSaveInAddressBook(): boolean {
return this.state.saveInAddressBook && this.state.useDifferentBillingAddress
}

private async handleResponse(response: Promise<void | PlaceOrderResponse>) {
private async handleResponse(response: Promise<void | PlaceOrderResponse>, actions: SubmitActions) {
this.setState({errorFieldCodes: []})

let responseData = await response;
Expand All @@ -200,6 +202,9 @@ class Payment extends React.Component<Props, State> {
if (responseData.executeAction) {
this.dropIn.handleAction(responseData.paymentsAction)
} else {
actions.resolve({
resultCode: responseData.paymentsResponse.resultCode
});
this.setState({orderNumber: responseData.orderNumber})
this.setState({redirectToNextStep: true})
}
Expand All @@ -211,12 +216,12 @@ class Payment extends React.Component<Props, State> {
}
}

private async executePaymentRequest(adyenPaymentForm: PlaceOrderRequest) {
await this.handleResponse(PaymentService.placeOrder(adyenPaymentForm));
private async executePaymentRequest(adyenPaymentForm: PlaceOrderRequest, actions: SubmitActions) {
await this.handleResponse(PaymentService.placeOrder(adyenPaymentForm), actions);
}

private async executeAdditionalDetails(details: any) {
await this.handleResponse(PaymentService.sendAdditionalDetails(details));
private async executeAdditionalDetails(details: any, actions: AdditionalDetailsActions) {
await this.handleResponse(PaymentService.sendAdditionalDetails(details), actions);
}

private resetDropInComponent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import {AxiosError, AxiosResponse} from "axios";
import {CSRFToken, urlContextPath} from "../util/baseUrlUtil";
import {AddressData, PlaceOrderRequest} from "../types/paymentForm";
import {AddressModel} from "../reducers/types";
import {PaymentAction} from "@adyen/adyen-web";
import {PaymentAction,PaymentResponseData} from "@adyen/adyen-web";
import {ErrorResponse} from "../types/errorResponse";
import {adyenAxios} from "../axios/AdyenAxios";

export interface PlaceOrderResponse {
success: boolean,
executeAction?: boolean,
paymentsAction?: PaymentAction,
paymentsResponse?: PaymentResponseData,
error?: string,
errorFieldCodes?: string[]
orderNumber?: string
Expand All @@ -30,7 +31,8 @@ export class PaymentService {
success: true,
executeAction: placeOrderData.executeAction,
paymentsAction: placeOrderData.paymentsAction,
orderNumber: placeOrderData.orderNumber
orderNumber: placeOrderData.orderNumber,
paymentsResponse: placeOrderData.paymentsResponse
}
})
.catch((errorResponse: AxiosError<ErrorResponse>): PlaceOrderResponse | void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
shopperLocale: '${shopperLocale}',
environment: '${environmentMode}',
clientKey: '${clientKey}',
session: {
id: '${sessionData.id}',
sessionData: '${sessionData.sessionData}'
},
countryCode: 'US'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<json:property name="locale" value="${shopperLocale}"/>
<json:property name="environment" value="${environmentMode}"/>
<json:property name="clientKey" value="${clientKey}"/>
<json:property name="sessionId" value="${sessionData.id}"/>
<json:property name="sessionData" value="${sessionData.sessionData}"/>
<json:property name="countryCode" value="${countryCode}"/>
<json:object name="risk" escapeXml="false">
<json:property name="enabled" value="${false}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@
<json:property name="shopperLocale" value="${shopperLocale}"/>
<json:property name="environment" value="${environmentMode}"/>
<json:property name="clientKey" value="${clientKey}"/>
<json:property name="sessionId" value="${sessionData.id}"/>
<json:property name="sessionData" value="${sessionData.sessionData}"/>
<json:object escapeXml="false" name="session">
<json:property name="id" value="${sessionData.id}"/>
<json:property name="sessionData" value="${sessionData.sessionData}"/>
</json:object>
<json:property name="countryCode" value="${countryCode}"/>
</json:object>
</c:set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@
const initConfig = {
shopperLocale: "${shopperLocale}",
environment: "${environmentMode}",
clientKey: "${clientKey}",
session: {
id: "${sessionData.id}",
sessionData: "${sessionData.sessionData}",
}
clientKey: "${clientKey}"
};
const paymentMethodConfigs = {};
Expand Down
22 changes: 22 additions & 0 deletions adyenv6core/src/com/adyen/commerce/dto/OrderPaymentResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.adyen.commerce.dto;

import com.adyen.model.checkout.PaymentResponse;
import de.hybris.platform.commercefacades.order.data.OrderData;

public class OrderPaymentResult {
private OrderData orderData;
private PaymentResponse paymentResponse;

public OrderPaymentResult(OrderData orderData, PaymentResponse paymentResponse) {
this.orderData = orderData;
this.paymentResponse = paymentResponse;
}

public OrderData getOrderData() {
return orderData;
}

public PaymentResponse getPaymentResponse() {
return paymentResponse;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adyen.commerce.facades;

import com.adyen.commerce.dto.OrderPaymentResult;
import com.adyen.model.checkout.PaymentDetailsRequest;
import com.adyen.model.checkout.PaymentRequest;
import com.adyen.v6.facades.AdyenCheckoutFacade;
Expand All @@ -13,7 +14,7 @@ public interface AdyenCheckoutApiFacade extends AdyenCheckoutFacade {

void preHandlePlaceOrder(PaymentRequest paymentRequest, String adyenPaymentMethod, AddressForm billingAddress, Boolean useAdyenDeliveryAddress);

OrderData placeOrderWithPayment(final HttpServletRequest request, final CartData cartData, PaymentRequest paymentRequest) throws Exception;
OrderPaymentResult placeOrderWithPayment(final HttpServletRequest request, final CartData cartData, PaymentRequest paymentRequest) throws Exception;

OrderData placeOrderWithAdditionalDetails(PaymentDetailsRequest detailsRequest) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adyen.commerce.facades.impl;

import com.adyen.commerce.dto.OrderPaymentResult;
import com.adyen.commerce.facades.AdyenCheckoutApiFacade;
import com.adyen.model.checkout.AfterpayDetails;
import com.adyen.model.checkout.ApplePayDetails;
Expand Down Expand Up @@ -96,7 +97,7 @@ protected static String getBrowserInfoJson(BrowserInfo browserInfo) {


@Override
public OrderData placeOrderWithPayment(final HttpServletRequest request, final CartData cartData, PaymentRequest paymentRequest) throws Exception {
public OrderPaymentResult placeOrderWithPayment(final HttpServletRequest request, final CartData cartData, PaymentRequest paymentRequest) throws Exception {

RequestInfo requestInfo = new RequestInfo(request);
requestInfo.setShopperLocale(getShopperLocale());
Expand All @@ -114,7 +115,9 @@ public OrderData placeOrderWithPayment(final HttpServletRequest request, final C
}
if (PaymentResponse.ResultCodeEnum.AUTHORISED == paymentResponse.getResultCode()) {
LOGGER.info("Creating authorized order");
return createAuthorizedOrder(paymentResponse);
OrderData authorizedOrder = createAuthorizedOrder(paymentResponse);
return new OrderPaymentResult(authorizedOrder, paymentResponse);

}

throw new AdyenNonAuthorizedPaymentException(paymentResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public void populateL2L3AdditionalData(final Map<String, String> additionalData,
if (cartData.getTotalTax() != null) {
additionalData.put(TOTAL_TAX_AMOUNT, String.valueOf(cartData.getTotalTax().getValue()));
}
if (StringUtils.isNotEmpty(cartData.getMerchantCustomerId())) {
additionalData.put(CUSTOMER_REFERENCE, cartData.getMerchantCustomerId());
if (StringUtils.isNotEmpty(cartData.getUser().getUid())) {
additionalData.put(CUSTOMER_REFERENCE, cartData.getUser().getUid());
}
// not required but available
if (cartData.getDeliveryCost() != null) {
Expand Down
9 changes: 0 additions & 9 deletions adyenv6core/src/com/adyen/v6/dto/CheckoutConfigDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class CheckoutConfigDTO {
private String adyenClientKey;
private String adyenPaypalMerchantId;
private String deviceFingerPrintUrl;
private CreateCheckoutSessionResponse sessionData;
private String selectedPaymentMethod;
private boolean showRememberTheseDetails;
private String checkoutShopperHost;
Expand Down Expand Up @@ -135,14 +134,6 @@ public void setDeviceFingerPrintUrl(String deviceFingerPrintUrl) {
this.deviceFingerPrintUrl = deviceFingerPrintUrl;
}

public CreateCheckoutSessionResponse getSessionData() {
return sessionData;
}

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

public String getSelectedPaymentMethod() {
return selectedPaymentMethod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ public CheckoutConfigDTOBuilder setDeviceFingerPrintUrl(String deviceFingerPrint
return this;
}

public CheckoutConfigDTOBuilder setSessionData(CreateCheckoutSessionResponse sessionData) {
checkoutConfigDTO.setSessionData(sessionData);
return this;
}

public CheckoutConfigDTOBuilder setSelectedPaymentMethod(String selectedPaymentMethod) {
checkoutConfigDTO.setSelectedPaymentMethod(selectedPaymentMethod);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public class DefaultAdyenCheckoutFacade implements AdyenCheckoutFacade {

public static final String DETAILS = "details";
private static final String LOCALE = "locale";
public static final String SESSION_DATA = "sessionData";
private static final String REGION = "region";
private static final String US_LOCALE = "en_US";
private static final String GB_LOCALE = "en_GB";
Expand Down Expand Up @@ -653,7 +652,6 @@ protected OrderData placeAuthorisedOrder(PaymentResponse.ResultCodeEnum resultCo
public void initializeCheckoutData(Model model) throws ApiException {
CheckoutConfigDTO checkoutConfigDTO = getCheckoutConfig();

model.addAttribute(SESSION_DATA, checkoutConfigDTO.getSessionData());

// current selected PaymentMethod
model.addAttribute(MODEL_SELECTED_PAYMENT_METHOD, checkoutConfigDTO.getSelectedPaymentMethod());
Expand Down Expand Up @@ -783,7 +781,6 @@ public CheckoutConfigDTO getReactCheckoutConfig() throws ApiException {
.setAdyenClientKey(baseStore.getAdyenClientKey())
.setAdyenPaypalMerchantId(baseStore.getAdyenPaypalMerchantId())
.setDeviceFingerPrintUrl(adyenPaymentService.getDeviceFingerprintUrl())
.setSessionData(getAdyenSessionData(showRememberDetails()))
.setSelectedPaymentMethod(cartData.getAdyenPaymentMethod())
.setShowRememberTheseDetails(showRememberDetails())
.setCheckoutShopperHost(getCheckoutShopperHost())
Expand Down Expand Up @@ -929,7 +926,6 @@ public CheckoutConfigDTO getCheckoutConfig() throws ApiException {
.setAdyenClientKey(baseStore.getAdyenClientKey())
.setAdyenPaypalMerchantId(baseStore.getAdyenPaypalMerchantId())
.setDeviceFingerPrintUrl(adyenCheckoutApiService.getDeviceFingerprintUrl())
.setSessionData(getAdyenSessionData(showRememberDetails()))
.setSelectedPaymentMethod(cartData.getAdyenPaymentMethod())
.setShowRememberTheseDetails(showRememberDetails())
.setCheckoutShopperHost(getCheckoutShopperHost())
Expand Down Expand Up @@ -1040,31 +1036,6 @@ protected Map<String, String> getApplePayConfigFromPaymentMethods(List<PaymentMe
return new HashMap<>();
}

protected CreateCheckoutSessionResponse getAdyenSessionData(final boolean storePaymentMethod) throws ApiException {
try {
final CartData cartData = getCheckoutFacade().getCheckoutCart();
return getAdyenPaymentService().getPaymentSessionData(cartData, storePaymentMethod);
} catch (JsonProcessingException e) {
LOGGER.error("Processing json failed. ", e);
return null;
} catch (IOException e) {
LOGGER.error("Exception during geting Adyen session data. ", e);
return null;
}
}

protected CreateCheckoutSessionResponse getAdyenSessionData(Amount amount) throws ApiException {
try {
return getAdyenPaymentService().getPaymentSessionData(amount);
} catch (JsonProcessingException e) {
LOGGER.error("Processing json failed. ", e);
return null;
} catch (IOException e) {
LOGGER.error("Exception during geting Adyen session data. ", e);
return null;
}
}

@Override
public void initializeSummaryData(Model model) throws ApiException {
final CartData cartData = getCheckoutFacade().getCheckoutCart();
Expand Down Expand Up @@ -1095,7 +1066,6 @@ 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(showRememberDetails()));
model.addAttribute(LOCALE, gson.toJson(setLocale(cartData.getAdyenAmazonPayConfiguration(), shopperLocale)));
}

Expand Down Expand Up @@ -1149,7 +1119,6 @@ protected void initializeApplePayExpressDataInternal(BigDecimal amountValue, Str
model.addAttribute(MODEL_ENVIRONMENT_MODE, getEnvironmentMode());
model.addAttribute(MODEL_CLIENT_KEY, baseStore.getAdyenClientKey());
model.addAttribute(MODEL_MERCHANT_ACCOUNT, adyenMerchantAccountStrategy.getWebMerchantAccount());
model.addAttribute(SESSION_DATA, getAdyenSessionData(amount));
model.addAttribute(MODEL_AMOUNT, amount);
model.addAttribute(MODEL_AMOUNT_DECIMAL, amountValue);
model.addAttribute(MODEL_DF_URL, getAdyenPaymentService().getDeviceFingerprintUrl());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adyen.v6.facades.impl;

import com.adyen.commerce.dto.OrderPaymentResult;
import com.adyen.commerce.facades.AdyenCheckoutApiFacade;
import com.adyen.model.checkout.PaymentRequest;
import com.adyen.model.checkout.PaymentResponse;
Expand Down Expand Up @@ -215,14 +216,14 @@ protected OrderData expressPDPCheckoutOCC(PaymentRequest paymentRequest, Address

CartData cartData = cartConverter.convert(cart);

OrderData orderData = adyenCheckoutApiFacade.placeOrderWithPayment(request, cartData, paymentRequest);
OrderPaymentResult orderPaymentResult = adyenCheckoutApiFacade.placeOrderWithPayment(request, cartData, paymentRequest);


if (sessionCart != null) {
cartService.setSessionCart(sessionCart);
}

return orderData;
return orderPaymentResult.getOrderData();
} else {
throw new InvalidCartException("Checkout attempt on empty cart");
}
Expand Down Expand Up @@ -293,7 +294,8 @@ protected OrderData expressCartCheckoutOCC(PaymentRequest paymentRequest, Addres
if (cartHasEntries(cart)) {
CartData cartData = cartConverter.convert(cart);

return adyenCheckoutApiFacade.placeOrderWithPayment(request, cartData, paymentRequest);
OrderPaymentResult orderPaymentResult = adyenCheckoutApiFacade.placeOrderWithPayment(request, cartData, paymentRequest);
return orderPaymentResult.getOrderData();
} else {
throw new InvalidCartException("Checkout attempt on empty cart");
}
Expand Down
Loading

0 comments on commit 7600b11

Please sign in to comment.