-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #477 from Adyen/feature/AD-344
AD-344 Develop Backend Logic for Place Order Endpoints to Handle Appl…
- Loading branch information
Showing
9 changed files
with
203 additions
and
206 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
...src/com/adyen/commerce/controllers/expresscheckout/ApplePayExpressCheckoutController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.adyen.commerce.controllers.expresscheckout; | ||
|
||
import com.adyen.commerce.constants.AdyenoccConstants; | ||
import com.adyen.commerce.request.ApplePayExpressCartRequest; | ||
import com.adyen.commerce.request.ApplePayExpressPDPRequest; | ||
import com.adyen.commerce.resolver.PaymentRedirectReturnUrlResolver; | ||
import com.adyen.commerce.response.OCCPlaceOrderResponse; | ||
import com.adyen.model.checkout.ApplePayDetails; | ||
import com.adyen.model.checkout.CheckoutPaymentMethod; | ||
import com.adyen.model.checkout.PaymentRequest; | ||
import com.adyen.v6.constants.Adyenv6coreConstants; | ||
import com.adyen.v6.facades.AdyenExpressCheckoutFacade; | ||
import de.hybris.platform.commercefacades.order.CartFacade; | ||
import de.hybris.platform.commerceservices.request.mapping.annotation.ApiVersion; | ||
import de.hybris.platform.commerceservices.strategies.CheckoutCustomerStrategy; | ||
import de.hybris.platform.webservicescommons.swagger.ApiBaseSiteIdUserIdAndCartIdParam; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.annotation.Secured; | ||
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; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
@RestController | ||
@RequestMapping(value = AdyenoccConstants.ADYEN_USER_CART_PREFIX + "/express-checkout/apple") | ||
@ApiVersion("v2") | ||
@Tag(name = "Adyen") | ||
public class ApplePayExpressCheckoutController extends ExpressCheckoutControllerBase { | ||
|
||
@Autowired | ||
private CartFacade cartFacade; | ||
|
||
@Autowired | ||
private CheckoutCustomerStrategy checkoutCustomerStrategy; | ||
|
||
@Autowired | ||
private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade; | ||
|
||
@Autowired | ||
private PaymentRedirectReturnUrlResolver paymentRedirectReturnUrlResolver; | ||
|
||
|
||
@Secured({"ROLE_CUSTOMERGROUP", "ROLE_CLIENT", "ROLE_CUSTOMERMANAGERGROUP", "ROLE_TRUSTED_CLIENT"}) | ||
@PostMapping(value = "/PDP", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Operation(operationId = "placeOrderApplePayExpressPDP", summary = "Handle applePayExpress place order request", description = | ||
"Places order based on request data") | ||
@ApiBaseSiteIdUserIdAndCartIdParam | ||
public ResponseEntity<String> applePayPDPExpressCheckout(final HttpServletRequest request, @RequestBody String applePayExpressPDPStringRequest) throws Exception { | ||
ApplePayExpressPDPRequest applePayExpressPDPRequest = objectMapper.readValue(applePayExpressPDPStringRequest, ApplePayExpressPDPRequest.class); | ||
|
||
PaymentRequest paymentRequest = getPaymentRequest(applePayExpressPDPRequest); | ||
|
||
OCCPlaceOrderResponse placeOrderResponse = handlePayment(request, paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, applePayExpressPDPRequest.getAddressData(), applePayExpressPDPRequest.getProductCode(), true); | ||
String response = objectMapper.writeValueAsString(placeOrderResponse); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@Secured({"ROLE_CUSTOMERGROUP", "ROLE_CLIENT", "ROLE_CUSTOMERMANAGERGROUP", "ROLE_TRUSTED_CLIENT"}) | ||
@PostMapping(value = "/cart", produces = MediaType.APPLICATION_JSON_VALUE) | ||
@Operation(operationId = "placeOrderApplePayExpressCart", summary = "Handle applePayExpress place order request", description = | ||
"Places order based on request data") | ||
@ApiBaseSiteIdUserIdAndCartIdParam | ||
public ResponseEntity<String> applePayCartExpressCheckout(final HttpServletRequest request, @RequestBody String applePayExpressCartStringRequest) throws Exception { | ||
ApplePayExpressCartRequest applePayExpressCartRequest = objectMapper.readValue(applePayExpressCartStringRequest, ApplePayExpressCartRequest.class); | ||
|
||
PaymentRequest paymentRequest = getPaymentRequest(applePayExpressCartRequest); | ||
|
||
OCCPlaceOrderResponse placeOrderResponse = handlePayment(request, paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, applePayExpressCartRequest.getAddressData(), null, false); | ||
String response = objectMapper.writeValueAsString(placeOrderResponse); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
private static <T extends ApplePayExpressCartRequest> PaymentRequest getPaymentRequest(T request) { | ||
PaymentRequest paymentRequest = new PaymentRequest(); | ||
ApplePayDetails applePayDetails = request.getApplePayDetails(); | ||
applePayDetails.setType(ApplePayDetails.TypeEnum.APPLEPAY); | ||
paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(applePayDetails)); | ||
return paymentRequest; | ||
} | ||
|
||
@Override | ||
public CartFacade getCartFacade() { | ||
return cartFacade; | ||
} | ||
|
||
@Override | ||
public CheckoutCustomerStrategy getCheckoutCustomerStrategy() { | ||
return checkoutCustomerStrategy; | ||
} | ||
|
||
@Override | ||
public String getPaymentRedirectReturnUrl() { | ||
return paymentRedirectReturnUrlResolver.resolvePaymentRedirectReturnUrl(); | ||
} | ||
|
||
@Override | ||
public AdyenExpressCheckoutFacade getAdyenCheckoutApiFacade() { | ||
return adyenExpressCheckoutFacade; | ||
} | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
adyenocc/src/com/adyen/commerce/request/ApplePayExpressCartRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.adyen.commerce.request; | ||
|
||
import com.adyen.model.checkout.ApplePayDetails; | ||
import de.hybris.platform.commercefacades.user.data.AddressData; | ||
|
||
import java.io.Serializable; | ||
|
||
public class ApplePayExpressCartRequest implements Serializable { | ||
private AddressData addressData; | ||
private ApplePayDetails applePayDetails; | ||
|
||
public AddressData getAddressData() { | ||
return addressData; | ||
} | ||
|
||
public void setAddressData(AddressData addressData) { | ||
this.addressData = addressData; | ||
} | ||
|
||
public ApplePayDetails getApplePayDetails() { | ||
return applePayDetails; | ||
} | ||
|
||
public void setApplePayDetails(ApplePayDetails applePayDetails) { | ||
this.applePayDetails = applePayDetails; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
adyenocc/src/com/adyen/commerce/request/ApplePayExpressPDPRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.adyen.commerce.request; | ||
|
||
public class ApplePayExpressPDPRequest extends ApplePayExpressCartRequest { | ||
private String productCode; | ||
|
||
public String getProductCode() { | ||
return productCode; | ||
} | ||
|
||
public void setProductCode(String productCode) { | ||
this.productCode = productCode; | ||
} | ||
} |
47 changes: 26 additions & 21 deletions
47
...don/web/src/com/adyen/v6/controllers/checkout/AdyenApplePayExpressCheckoutController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,73 @@ | ||
package com.adyen.v6.controllers.checkout; | ||
|
||
import com.adyen.model.checkout.ApplePayDetails; | ||
import com.adyen.model.checkout.CheckoutPaymentMethod; | ||
import com.adyen.model.checkout.PaymentRequest; | ||
import com.adyen.model.checkout.PaymentResponse; | ||
import com.adyen.v6.constants.Adyenv6coreConstants; | ||
import com.adyen.v6.facades.AdyenExpressCheckoutFacade; | ||
import com.adyen.v6.request.ApplePayExpressCartRequest; | ||
import com.adyen.v6.request.ApplePayExpressPDPRequest; | ||
import de.hybris.platform.acceleratorstorefrontcommons.constants.WebConstants; | ||
import de.hybris.platform.acceleratorstorefrontcommons.security.GUIDCookieStrategy; | ||
import de.hybris.platform.servicelayer.session.SessionService; | ||
import org.apache.log4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Controller | ||
@RequestMapping("/express-checkout/apple/") | ||
public class AdyenApplePayExpressCheckoutController { | ||
private static final Logger LOG = Logger.getLogger(AdyenApplePayExpressCheckoutController.class); | ||
|
||
@Autowired | ||
private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade; | ||
|
||
@Autowired | ||
private SessionService sessionService; | ||
|
||
@Autowired | ||
private GUIDCookieStrategy guidCookieStrategy; | ||
|
||
@PostMapping("/expressCheckout/applePayPDP") | ||
@PostMapping("PDP") | ||
public ResponseEntity applePayExpressPDP(final HttpServletRequest request, final HttpServletResponse response, @RequestBody ApplePayExpressPDPRequest applePayExpressPDPRequest) throws Exception { | ||
|
||
PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.appleExpressPDPCheckout(applePayExpressPDPRequest.getAddressData(), applePayExpressPDPRequest.getProductCode(), | ||
applePayExpressPDPRequest.getAdyenApplePayMerchantIdentifier(), applePayExpressPDPRequest.getAdyenApplePayMerchantName(), | ||
applePayExpressPDPRequest.getApplePayToken(), request); | ||
PaymentRequest paymentRequest = getPaymentRequest(applePayExpressPDPRequest); | ||
|
||
PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.expressCheckoutPDP(applePayExpressPDPRequest.getProductCode(), | ||
paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, applePayExpressPDPRequest.getAddressData(), request); | ||
|
||
guidCookieStrategy.setCookie(request, response); | ||
sessionService.setAttribute(WebConstants.ANONYMOUS_CHECKOUT, Boolean.TRUE); | ||
|
||
return new ResponseEntity<>(paymentsResponse, HttpStatus.OK); | ||
} | ||
|
||
@PostMapping("/expressCheckout/cart") | ||
@PostMapping("cart") | ||
public ResponseEntity cartExpressCheckout(final HttpServletRequest request, final HttpServletResponse response, @RequestBody ApplePayExpressCartRequest applePayExpressCartRequest) throws Exception { | ||
|
||
PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.appleEexpressCartCheckout(applePayExpressCartRequest.getAddressData(), | ||
applePayExpressCartRequest.getAdyenApplePayMerchantIdentifier(), applePayExpressCartRequest.getAdyenApplePayMerchantName(), | ||
applePayExpressCartRequest.getApplePayToken(), request); | ||
PaymentRequest paymentRequest = getPaymentRequest(applePayExpressCartRequest); | ||
|
||
PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.expressCheckoutCart(paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_APPLEPAY, | ||
applePayExpressCartRequest.getAddressData(), request); | ||
|
||
guidCookieStrategy.setCookie(request, response); | ||
sessionService.setAttribute(WebConstants.ANONYMOUS_CHECKOUT, Boolean.TRUE); | ||
|
||
return new ResponseEntity<>(paymentsResponse, HttpStatus.OK); | ||
} | ||
|
||
private static <T extends ApplePayExpressCartRequest> PaymentRequest getPaymentRequest(T request) { | ||
PaymentRequest paymentRequest = new PaymentRequest(); | ||
ApplePayDetails applePayDetails = request.getApplePayDetails(); | ||
applePayDetails.setType(ApplePayDetails.TypeEnum.APPLEPAY); | ||
paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(applePayDetails)); | ||
return paymentRequest; | ||
} | ||
|
||
|
||
@ResponseStatus(value = HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(value = Exception.class) | ||
public String adyenComponentExceptionHandler(Exception e) { | ||
public void adyenComponentExceptionHandler(Exception e) { | ||
LOG.error("Exception during ApplePayExpress processing", e); | ||
return "Exception during ApplePayExpress processing"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.