From d1bcd672b93594f89cfd06257ef607140dc018c7 Mon Sep 17 00:00:00 2001
From: PJaneta
Date: Tue, 16 Jul 2024 10:31:20 +0200
Subject: [PATCH] AD-276 Implement "Thank You" Page for Order Status Feedback
in Spartacus Storefront
---
.../controllers/PlaceOrderController.java | 3 ++-
.../PlaceOrderControllerBase.java | 17 +++++++++++++----
.../response/OCCPlaceOrderResponse.java | 15 +++++++++++++++
3 files changed, 30 insertions(+), 5 deletions(-)
create mode 100644 adyenwebcommons/src/com/adyen/commerce/response/OCCPlaceOrderResponse.java
diff --git a/adyenocc/src/com/adyen/commerce/controllers/PlaceOrderController.java b/adyenocc/src/com/adyen/commerce/controllers/PlaceOrderController.java
index d8debf39..0cd21413 100644
--- a/adyenocc/src/com/adyen/commerce/controllers/PlaceOrderController.java
+++ b/adyenocc/src/com/adyen/commerce/controllers/PlaceOrderController.java
@@ -4,6 +4,7 @@
import com.adyen.commerce.controllerbase.PlaceOrderControllerBase;
import com.adyen.commerce.facades.AdyenCheckoutApiFacade;
import com.adyen.commerce.request.PlaceOrderRequest;
+import com.adyen.commerce.response.OCCPlaceOrderResponse;
import com.adyen.commerce.response.PlaceOrderResponse;
import com.adyen.model.checkout.PaymentDetailsRequest;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -55,7 +56,7 @@ public class PlaceOrderController extends PlaceOrderControllerBase {
@ApiBaseSiteIdUserIdAndCartIdParam
public ResponseEntity onPlaceOrder(@RequestBody String placeOrderStringRequest, HttpServletRequest request) throws Exception {
PlaceOrderRequest placeOrderRequest = objectMapper.readValue(placeOrderStringRequest, PlaceOrderRequest.class);
- PlaceOrderResponse placeOrderResponse = super.placeOrder(placeOrderRequest, request);
+ OCCPlaceOrderResponse placeOrderResponse = super.placeOrderOCC(placeOrderRequest, request);
String response = objectMapper.writeValueAsString(placeOrderResponse);
return ResponseEntity.ok(response);
}
diff --git a/adyenwebcommons/src/com/adyen/commerce/controllerbase/PlaceOrderControllerBase.java b/adyenwebcommons/src/com/adyen/commerce/controllerbase/PlaceOrderControllerBase.java
index 8b3350c3..95d251b3 100644
--- a/adyenwebcommons/src/com/adyen/commerce/controllerbase/PlaceOrderControllerBase.java
+++ b/adyenwebcommons/src/com/adyen/commerce/controllerbase/PlaceOrderControllerBase.java
@@ -3,6 +3,7 @@
import com.adyen.commerce.exception.AdyenControllerException;
import com.adyen.commerce.facades.AdyenCheckoutApiFacade;
import com.adyen.commerce.request.PlaceOrderRequest;
+import com.adyen.commerce.response.OCCPlaceOrderResponse;
import com.adyen.commerce.response.PlaceOrderResponse;
import com.adyen.commerce.validators.PaymentRequestValidator;
import com.adyen.model.checkout.PaymentDetailsRequest;
@@ -45,6 +46,13 @@ public PlaceOrderControllerBase() {
public PlaceOrderResponse placeOrder(PlaceOrderRequest placeOrderRequest, HttpServletRequest request) {
+ OCCPlaceOrderResponse occPlaceOrderResponse = placeOrderOCC(placeOrderRequest, request);
+ occPlaceOrderResponse.setOrderData(null);
+ return occPlaceOrderResponse;
+ }
+
+ public OCCPlaceOrderResponse placeOrderOCC(PlaceOrderRequest placeOrderRequest, HttpServletRequest request) {
+
String adyenPaymentMethodType = extractPaymentMethodType(placeOrderRequest);
preHandleAndValidateRequest(placeOrderRequest, adyenPaymentMethodType);
@@ -145,7 +153,7 @@ private boolean isCartValid() {
return true;
}
- private PlaceOrderResponse handlePayment(HttpServletRequest request, PlaceOrderRequest placeOrderRequest) {
+ private OCCPlaceOrderResponse handlePayment(HttpServletRequest request, PlaceOrderRequest placeOrderRequest) {
final CartData cartData = getCartFacade().getSessionCart();
String errorMessage = CHECKOUT_ERROR_AUTHORIZATION_FAILED;
@@ -154,8 +162,9 @@ private PlaceOrderResponse handlePayment(HttpServletRequest request, PlaceOrder
cartData.setAdyenReturnUrl(getPaymentRedirectReturnUrl());
OrderData orderData = getAdyenCheckoutApiFacade().placeOrderWithPayment(request, cartData, placeOrderRequest.getPaymentRequest());
- PlaceOrderResponse placeOrderResponse = new PlaceOrderResponse();
+ OCCPlaceOrderResponse placeOrderResponse = new OCCPlaceOrderResponse();
placeOrderResponse.setOrderNumber(orderData.getCode());
+ placeOrderResponse.setOrderData(orderData);
return placeOrderResponse;
} catch (ApiException e) {
@@ -181,8 +190,8 @@ private PlaceOrderResponse handlePayment(HttpServletRequest request, PlaceOrder
throw new AdyenControllerException(errorMessage);
}
- private PlaceOrderResponse executeAction(PaymentResponse paymentsResponse) {
- PlaceOrderResponse placeOrderResponse = new PlaceOrderResponse();
+ private OCCPlaceOrderResponse executeAction(PaymentResponse paymentsResponse) {
+ OCCPlaceOrderResponse placeOrderResponse = new OCCPlaceOrderResponse();
placeOrderResponse.setPaymentsResponse(paymentsResponse);
placeOrderResponse.setExecuteAction(true);
placeOrderResponse.setPaymentsAction(paymentsResponse.getAction());
diff --git a/adyenwebcommons/src/com/adyen/commerce/response/OCCPlaceOrderResponse.java b/adyenwebcommons/src/com/adyen/commerce/response/OCCPlaceOrderResponse.java
new file mode 100644
index 00000000..a0c97c12
--- /dev/null
+++ b/adyenwebcommons/src/com/adyen/commerce/response/OCCPlaceOrderResponse.java
@@ -0,0 +1,15 @@
+package com.adyen.commerce.response;
+
+import de.hybris.platform.commercefacades.order.data.OrderData;
+
+public class OCCPlaceOrderResponse extends PlaceOrderResponse {
+ private OrderData orderData;
+
+ public OrderData getOrderData() {
+ return orderData;
+ }
+
+ public void setOrderData(OrderData orderData) {
+ this.orderData = orderData;
+ }
+}