Skip to content

Commit

Permalink
AD-390: Payment result refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kpieloch committed Jan 3, 2025
1 parent 51efb84 commit c15988e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class Payment extends React.Component<Props, State> {
this.dropIn.handleAction(responseData.paymentsAction)
} else {
actions.resolve({
resultCode: 'Authorised'
resultCode: responseData.paymentsResponse.resultCode
});
this.setState({orderNumber: responseData.orderNumber})
this.setState({redirectToNextStep: true})
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
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
@@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adyen.commerce.controllerbase;

import com.adyen.commerce.dto.OrderPaymentResult;
import com.adyen.commerce.exception.AdyenControllerException;
import com.adyen.commerce.facades.AdyenCheckoutApiFacade;
import com.adyen.commerce.request.PlaceOrderRequest;
Expand Down Expand Up @@ -171,13 +172,14 @@ private OCCPlaceOrderResponse handlePayment(HttpServletRequest request, PlaceOrd

try {
cartData.setAdyenReturnUrl(getPaymentRedirectReturnUrl());
OrderData orderData = getAdyenCheckoutApiFacade().placeOrderWithPayment(request, cartData, placeOrderRequest.getPaymentRequest());

OrderPaymentResult orderPaymentResult = getAdyenCheckoutApiFacade().placeOrderWithPayment(request, cartData, placeOrderRequest.getPaymentRequest());
OrderData orderData = orderPaymentResult.getOrderData();
String orderCode = getCheckoutCustomerStrategy().isAnonymousCheckout() ? orderData.getGuid() : orderData.getCode();

OCCPlaceOrderResponse placeOrderResponse = new OCCPlaceOrderResponse();
placeOrderResponse.setOrderNumber(orderCode);
placeOrderResponse.setOrderData(orderData);
placeOrderResponse.setPaymentsResponse(orderPaymentResult.getPaymentResponse());
return placeOrderResponse;

} catch (ApiException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.adyen.commerce.response;

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

public class OCCPlaceOrderResponse extends PlaceOrderResponse {
Expand Down

0 comments on commit c15988e

Please sign in to comment.