From 63d1b6ea9b5ab652a51eacf1eda8b11a3668af7c Mon Sep 17 00:00:00 2001
From: PJaneta
Date: Tue, 18 Jun 2024 14:38:35 +0200
Subject: [PATCH 1/2] AD-276 Implement "Thank You" Page for Order Status
Feedback in Spartacus Storefront
---
.../controllers/PaymentMethodsController.java | 4 +-
.../controllers/PaymentStatusController.java | 45 +++++++++++++++++++
.../controllers/PlaceOrderController.java | 4 +-
.../adyen/v6/facades/AdyenOrderFacade.java | 1 +
.../facades/impl/DefaultAdyenOrderFacade.java | 33 +++++++++++++-
5 files changed, 81 insertions(+), 6 deletions(-)
create mode 100644 adyenocc/src/com/adyen/commerce/controllers/PaymentStatusController.java
diff --git a/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java b/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java
index 0632594c..09fdc975 100644
--- a/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java
+++ b/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java
@@ -14,11 +14,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
-import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
@RequestMapping(value = AdyenoccConstants.ADYEN_USER_CART_PREFIX)
@ApiVersion("v2")
@Tag(name = "Adyen")
diff --git a/adyenocc/src/com/adyen/commerce/controllers/PaymentStatusController.java b/adyenocc/src/com/adyen/commerce/controllers/PaymentStatusController.java
new file mode 100644
index 00000000..63878ec8
--- /dev/null
+++ b/adyenocc/src/com/adyen/commerce/controllers/PaymentStatusController.java
@@ -0,0 +1,45 @@
+package com.adyen.commerce.controllers;
+
+import com.adyen.commerce.constants.AdyenoccConstants;
+import com.adyen.v6.facades.AdyenOrderFacade;
+import de.hybris.platform.commerceservices.request.mapping.annotation.ApiVersion;
+import de.hybris.platform.commercewebservices.core.strategies.OrderCodeIdentificationStrategy;
+import de.hybris.platform.webservicescommons.swagger.ApiBaseSiteIdAndUserIdParam;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.annotation.Secured;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping(value = AdyenoccConstants.ADYEN_USER_PREFIX)
+@ApiVersion("v2")
+@Tag(name = "Adyen")
+public class PaymentStatusController {
+
+ @Autowired
+ private OrderCodeIdentificationStrategy orderCodeIdentificationStrategy;
+
+ @Autowired
+ private AdyenOrderFacade adyenOrderFacade;
+
+
+ @Secured({"ROLE_CUSTOMERGROUP", "ROLE_CLIENT", "ROLE_TRUSTED_CLIENT", "ROLE_CUSTOMERMANAGERGROUP"})
+ @GetMapping(value = "/payment-status/{orderCode}")
+ @Operation(operationId = "getPaymentStatus", summary = "Get order payment status.", description = "Returns payment status of order with given code.")
+ @ApiBaseSiteIdAndUserIdParam
+ public ResponseEntity getPaymentStatus(
+ @Parameter(description = "Order GUID (Globally Unique Identifier) or order CODE", required = true) @PathVariable final String orderCode) {
+ try {
+ String paymentStatus = adyenOrderFacade.getPaymentStatusOCC(orderCode);
+ return ResponseEntity.ok(paymentStatus);
+ } catch (Exception e) {
+ return ResponseEntity.badRequest().build();
+ }
+ }
+}
diff --git a/adyenocc/src/com/adyen/commerce/controllers/PlaceOrderController.java b/adyenocc/src/com/adyen/commerce/controllers/PlaceOrderController.java
index 12d7c6f2..1f2c25cc 100644
--- a/adyenocc/src/com/adyen/commerce/controllers/PlaceOrderController.java
+++ b/adyenocc/src/com/adyen/commerce/controllers/PlaceOrderController.java
@@ -14,12 +14,12 @@
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
-import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
-@Controller
+@RestController
@RequestMapping(value = AdyenoccConstants.ADYEN_USER_CART_PREFIX)
@ApiVersion("v2")
@Tag(name = "Adyen")
diff --git a/adyenv6core/src/com/adyen/v6/facades/AdyenOrderFacade.java b/adyenv6core/src/com/adyen/v6/facades/AdyenOrderFacade.java
index 306a90c2..8b8303f1 100644
--- a/adyenv6core/src/com/adyen/v6/facades/AdyenOrderFacade.java
+++ b/adyenv6core/src/com/adyen/v6/facades/AdyenOrderFacade.java
@@ -2,4 +2,5 @@
public interface AdyenOrderFacade {
String getPaymentStatus(final String orderCode, final String sessionGuid);
+ String getPaymentStatusOCC(final String code);
}
\ No newline at end of file
diff --git a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenOrderFacade.java b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenOrderFacade.java
index 8de9b22f..ce1284c6 100644
--- a/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenOrderFacade.java
+++ b/adyenv6core/src/com/adyen/v6/facades/impl/DefaultAdyenOrderFacade.java
@@ -32,7 +32,19 @@ public class DefaultAdyenOrderFacade implements AdyenOrderFacade {
@Override
public String getPaymentStatus(final String orderCode, final String sessionGuid) {
- OrderModel orderModel = getOrderDetailsForCodeInternal(orderCode, sessionGuid);
+ OrderModel orderModel = getOrderModelForCode(orderCode, sessionGuid);
+
+ return getPaymentStatusForOrder(orderModel);
+ }
+
+ @Override
+ public String getPaymentStatusOCC(final String code) {
+ final OrderModel orderModel = getOrderModelForCodeOCC(code);
+
+ return getPaymentStatusForOrder(orderModel);
+ }
+
+ private String getPaymentStatusForOrder(final OrderModel orderModel) {
List paymentTransactions = orderModel.getPaymentTransactions();
if (paymentTransactions.isEmpty()) {
return getMessageFromStatus(TransactionStatus.REVIEW.name());
@@ -40,7 +52,24 @@ public String getPaymentStatus(final String orderCode, final String sessionGuid)
return getStatus(paymentTransactions);
}
- private OrderModel getOrderDetailsForCodeInternal(final String code, final String sessionGuid) {
+ private OrderModel getOrderModelForCodeOCC(String code) {
+ BaseStoreModel currentBaseStore = baseStoreService.getCurrentBaseStore();
+ final OrderModel orderModel;
+
+ if (checkoutCustomerStrategy.isAnonymousCheckout()) {
+ orderModel = customerAccountService.getGuestOrderForGUID(code,
+ currentBaseStore);
+ } else {
+ orderModel = customerAccountService.getOrderForCode((CustomerModel) userService.getCurrentUser(), code, currentBaseStore);
+ }
+
+ if (orderModel == null) {
+ throw new UnknownIdentifierException(String.format(ORDER_NOT_FOUND_FOR_USER_AND_BASE_STORE, code));
+ }
+ return orderModel;
+ }
+
+ private OrderModel getOrderModelForCode(final String code, final String sessionGuid) {
final BaseStoreModel baseStoreModel = baseStoreService.getCurrentBaseStore();
OrderModel orderModel = null;
From d1bcd672b93594f89cfd06257ef607140dc018c7 Mon Sep 17 00:00:00 2001
From: PJaneta
Date: Tue, 16 Jul 2024 10:31:20 +0200
Subject: [PATCH 2/2] 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;
+ }
+}