Skip to content

Commit

Permalink
AD-276 Implement "Thank You" Page for Order Status Feedback in Sparta…
Browse files Browse the repository at this point in the history
…cus Storefront
  • Loading branch information
pjaneta committed Jul 16, 2024
1 parent da370c8 commit d1bcd67
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class PlaceOrderController extends PlaceOrderControllerBase {
@ApiBaseSiteIdUserIdAndCartIdParam
public ResponseEntity<String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit d1bcd67

Please sign in to comment.