From c15988ec74eafe9830bd3cb57ebfab97e72dec14 Mon Sep 17 00:00:00 2001 From: kpieloch <113994423+kpieloch@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:41:33 +0100 Subject: [PATCH] AD-390: Payment result refactoring --- .../src/components/payment/Payment.tsx | 2 +- .../src/service/paymentService.ts | 6 +++-- .../commerce/dto/OrderPaymentResult.java | 22 +++++++++++++++++++ .../facades/AdyenCheckoutApiFacade.java | 3 ++- .../impl/DefaultAdyenCheckoutApiFacade.java | 7 ++++-- .../DefaultAdyenExpressCheckoutFacade.java | 8 ++++--- .../PlaceOrderControllerBase.java | 6 +++-- .../response/OCCPlaceOrderResponse.java | 1 + 8 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 adyenv6core/src/com/adyen/commerce/dto/OrderPaymentResult.java diff --git a/adyencheckoutaddonspa/acceleratoraddon/web/webroot/_ui/responsive/common/js/adyen-checkout/src/components/payment/Payment.tsx b/adyencheckoutaddonspa/acceleratoraddon/web/webroot/_ui/responsive/common/js/adyen-checkout/src/components/payment/Payment.tsx index c8af21f4..3ac47517 100644 --- a/adyencheckoutaddonspa/acceleratoraddon/web/webroot/_ui/responsive/common/js/adyen-checkout/src/components/payment/Payment.tsx +++ b/adyencheckoutaddonspa/acceleratoraddon/web/webroot/_ui/responsive/common/js/adyen-checkout/src/components/payment/Payment.tsx @@ -203,7 +203,7 @@ class Payment extends React.Component { this.dropIn.handleAction(responseData.paymentsAction) } else { actions.resolve({ - resultCode: 'Authorised' + resultCode: responseData.paymentsResponse.resultCode }); this.setState({orderNumber: responseData.orderNumber}) this.setState({redirectToNextStep: true}) diff --git a/adyencheckoutaddonspa/acceleratoraddon/web/webroot/_ui/responsive/common/js/adyen-checkout/src/service/paymentService.ts b/adyencheckoutaddonspa/acceleratoraddon/web/webroot/_ui/responsive/common/js/adyen-checkout/src/service/paymentService.ts index 0ffec335..ce7f1f42 100644 --- a/adyencheckoutaddonspa/acceleratoraddon/web/webroot/_ui/responsive/common/js/adyen-checkout/src/service/paymentService.ts +++ b/adyencheckoutaddonspa/acceleratoraddon/web/webroot/_ui/responsive/common/js/adyen-checkout/src/service/paymentService.ts @@ -2,7 +2,7 @@ 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"; @@ -10,6 +10,7 @@ export interface PlaceOrderResponse { success: boolean, executeAction?: boolean, paymentsAction?: PaymentAction, + paymentsResponse?: PaymentResponseData, error?: string, errorFieldCodes?: string[] orderNumber?: string @@ -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): PlaceOrderResponse | void => { diff --git a/adyenv6core/src/com/adyen/commerce/dto/OrderPaymentResult.java b/adyenv6core/src/com/adyen/commerce/dto/OrderPaymentResult.java new file mode 100644 index 00000000..81f5a2f6 --- /dev/null +++ b/adyenv6core/src/com/adyen/commerce/dto/OrderPaymentResult.java @@ -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; + } +} diff --git a/adyenv6core/src/com/adyen/commerce/facades/AdyenCheckoutApiFacade.java b/adyenv6core/src/com/adyen/commerce/facades/AdyenCheckoutApiFacade.java index 70ad21bf..01839eac 100644 --- a/adyenv6core/src/com/adyen/commerce/facades/AdyenCheckoutApiFacade.java +++ b/adyenv6core/src/com/adyen/commerce/facades/AdyenCheckoutApiFacade.java @@ -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; @@ -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; } diff --git a/adyenv6core/src/com/adyen/commerce/facades/impl/DefaultAdyenCheckoutApiFacade.java b/adyenv6core/src/com/adyen/commerce/facades/impl/DefaultAdyenCheckoutApiFacade.java index 1303d6fa..3df1cfe1 100644 --- a/adyenv6core/src/com/adyen/commerce/facades/impl/DefaultAdyenCheckoutApiFacade.java +++ b/adyenv6core/src/com/adyen/commerce/facades/impl/DefaultAdyenCheckoutApiFacade.java @@ -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; @@ -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()); @@ -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); diff --git a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java index 3c47bbd3..5f818831 100644 --- a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java +++ b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenExpressCheckoutFacade.java @@ -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; @@ -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"); } @@ -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"); } diff --git a/adyenwebcommons/src/com/adyen/commerce/controllerbase/PlaceOrderControllerBase.java b/adyenwebcommons/src/com/adyen/commerce/controllerbase/PlaceOrderControllerBase.java index e7c7c6ee..bcede4ef 100644 --- a/adyenwebcommons/src/com/adyen/commerce/controllerbase/PlaceOrderControllerBase.java +++ b/adyenwebcommons/src/com/adyen/commerce/controllerbase/PlaceOrderControllerBase.java @@ -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; @@ -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) { diff --git a/adyenwebcommons/src/com/adyen/commerce/response/OCCPlaceOrderResponse.java b/adyenwebcommons/src/com/adyen/commerce/response/OCCPlaceOrderResponse.java index a0c97c12..e44ccf31 100644 --- a/adyenwebcommons/src/com/adyen/commerce/response/OCCPlaceOrderResponse.java +++ b/adyenwebcommons/src/com/adyen/commerce/response/OCCPlaceOrderResponse.java @@ -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 {