-
Notifications
You must be signed in to change notification settings - Fork 30
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 #484 from Adyen/feature/AD-342
AD-342 Develop Backend Logic for Place Order Endpoints to Handle PayP…
- Loading branch information
Showing
8 changed files
with
267 additions
and
9 deletions.
There are no files selected for viewing
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
105 changes: 105 additions & 0 deletions
105
...c/src/com/adyen/commerce/controllers/expresscheckout/PayPalExpressCheckoutController.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,105 @@ | ||
package com.adyen.commerce.controllers.expresscheckout; | ||
|
||
import com.adyen.commerce.constants.AdyenoccConstants; | ||
import com.adyen.commerce.request.PayPalExpressCartRequest; | ||
import com.adyen.commerce.request.PayPalExpressPDPRequest; | ||
import com.adyen.commerce.resolver.PaymentRedirectReturnUrlResolver; | ||
import com.adyen.commerce.response.OCCPlaceOrderResponse; | ||
import com.adyen.model.checkout.CheckoutPaymentMethod; | ||
import com.adyen.model.checkout.PayPalDetails; | ||
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/paypal") | ||
@ApiVersion("v2") | ||
@Tag(name = "Adyen") | ||
public class PayPalExpressCheckoutController 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 = "placeOrderPayPalExpressPDP", summary = "Handle PayPalExpress place order request", description = | ||
"Places order based on request data") | ||
@ApiBaseSiteIdUserIdAndCartIdParam | ||
public ResponseEntity<String> PayPalCartExpressCheckoutPDP(final HttpServletRequest request, @RequestBody String PayPalExpressPDPRequestString) throws Exception { | ||
PayPalExpressPDPRequest payPalExpressPDPRequest = objectMapper.readValue(PayPalExpressPDPRequestString, PayPalExpressPDPRequest.class); | ||
|
||
PaymentRequest paymentRequest = getPaymentRequest(payPalExpressPDPRequest); | ||
|
||
OCCPlaceOrderResponse placeOrderResponse = handlePayment(request, paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_PAYPAL, payPalExpressPDPRequest.getAddressData(), payPalExpressPDPRequest.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 = "placeOrderPayPalExpressCart", summary = "Handle PayPalExpress place order request", description = | ||
"Places order based on request data") | ||
@ApiBaseSiteIdUserIdAndCartIdParam | ||
public ResponseEntity<String> PayPalCartExpressCheckoutCart(final HttpServletRequest request, @RequestBody String PayPalExpressCartRequestString) throws Exception { | ||
PayPalExpressCartRequest payPalExpressCartRequest = objectMapper.readValue(PayPalExpressCartRequestString, PayPalExpressCartRequest.class); | ||
PaymentRequest paymentRequest = getPaymentRequest(payPalExpressCartRequest); | ||
|
||
OCCPlaceOrderResponse placeOrderResponse = handlePayment(request, paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_PAYPAL, payPalExpressCartRequest.getAddressData(), null, false); | ||
String response = objectMapper.writeValueAsString(placeOrderResponse); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
private static <T extends PayPalExpressCartRequest> PaymentRequest getPaymentRequest(T request) { | ||
PaymentRequest paymentRequest = new PaymentRequest(); | ||
PayPalDetails payPalDetails = request.getPayPalDetails(); | ||
payPalDetails.setType(PayPalDetails.TypeEnum.PAYPAL); | ||
paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(payPalDetails)); | ||
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/PayPalExpressCartRequest.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.PayPalDetails; | ||
import de.hybris.platform.commercefacades.user.data.AddressData; | ||
|
||
import java.io.Serializable; | ||
|
||
public class PayPalExpressCartRequest implements Serializable { | ||
private PayPalDetails payPalDetails; | ||
private AddressData addressData; | ||
|
||
public PayPalDetails getPayPalDetails() { | ||
return payPalDetails; | ||
} | ||
|
||
public void setPayPalDetails(PayPalDetails payPalDetails) { | ||
this.payPalDetails = payPalDetails; | ||
} | ||
|
||
public AddressData getAddressData() { | ||
return addressData; | ||
} | ||
|
||
public void setAddressData(AddressData addressData) { | ||
this.addressData = addressData; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
adyenocc/src/com/adyen/commerce/request/PayPalExpressPDPRequest.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 PayPalExpressPDPRequest extends PayPalExpressCartRequest { | ||
private String productCode; | ||
|
||
public String getProductCode() { | ||
return productCode; | ||
} | ||
|
||
public void setProductCode(String productCode) { | ||
this.productCode = productCode; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...addon/web/src/com/adyen/v6/controllers/checkout/AdyenPayPalExpressCheckoutController.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,72 @@ | ||
package com.adyen.v6.controllers.checkout; | ||
|
||
import com.adyen.model.checkout.CheckoutPaymentMethod; | ||
import com.adyen.model.checkout.PayPalDetails; | ||
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.PayPalExpressCartRequest; | ||
import com.adyen.v6.request.PayPalExpressPDPRequest; | ||
import de.hybris.platform.acceleratorstorefrontcommons.security.GUIDCookieStrategy; | ||
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.*; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Controller | ||
@RequestMapping("/express-checkout/paypal/") | ||
public class AdyenPayPalExpressCheckoutController { | ||
private static final Logger LOG = Logger.getLogger(AdyenApplePayExpressCheckoutController.class); | ||
|
||
@Autowired | ||
private AdyenExpressCheckoutFacade adyenExpressCheckoutFacade; | ||
|
||
@Autowired | ||
private GUIDCookieStrategy guidCookieStrategy; | ||
|
||
@PostMapping("PDP") | ||
public ResponseEntity payPalExpressPDP(final HttpServletRequest request, final HttpServletResponse response, @RequestBody PayPalExpressPDPRequest paypalExpressPDPRequest) throws Exception { | ||
|
||
PaymentRequest paymentRequest = getPaymentRequest(paypalExpressPDPRequest); | ||
|
||
PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.expressCheckoutPDP(paypalExpressPDPRequest.getProductCode(), | ||
paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_PAYPAL, paypalExpressPDPRequest.getAddressData(), request); | ||
|
||
guidCookieStrategy.setCookie(request, response); | ||
|
||
return new ResponseEntity<>(paymentsResponse, HttpStatus.OK); | ||
} | ||
|
||
@PostMapping("cart") | ||
public ResponseEntity paypalCartExpressCheckout(final HttpServletRequest request, final HttpServletResponse response, @RequestBody PayPalExpressCartRequest paypalExpressCartRequest) throws Exception { | ||
|
||
PaymentRequest paymentRequest = getPaymentRequest(paypalExpressCartRequest); | ||
|
||
PaymentResponse paymentsResponse = adyenExpressCheckoutFacade.expressCheckoutCart(paymentRequest, Adyenv6coreConstants.PAYMENT_METHOD_PAYPAL, | ||
paypalExpressCartRequest.getAddressData(), request); | ||
|
||
guidCookieStrategy.setCookie(request, response); | ||
|
||
return new ResponseEntity<>(paymentsResponse, HttpStatus.OK); | ||
} | ||
|
||
private static <T extends PayPalExpressCartRequest> PaymentRequest getPaymentRequest(T request) { | ||
PaymentRequest paymentRequest = new PaymentRequest(); | ||
PayPalDetails paypalDetails = request.getPayPalDetails(); | ||
paypalDetails.setType(PayPalDetails.TypeEnum.PAYPAL); | ||
paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(paypalDetails)); | ||
return paymentRequest; | ||
} | ||
|
||
@ResponseStatus(value = HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(value = Exception.class) | ||
public void adyenComponentExceptionHandler(Exception e) { | ||
LOG.error("Exception during PaypalExpress processing", e); | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
...eckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/GooglePayExpressPDPRequest.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
27 changes: 27 additions & 0 deletions
27
...checkoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/PayPalExpressCartRequest.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.v6.request; | ||
|
||
import com.adyen.model.checkout.PayPalDetails; | ||
import de.hybris.platform.commercefacades.user.data.AddressData; | ||
|
||
import java.io.Serializable; | ||
|
||
public class PayPalExpressCartRequest implements Serializable { | ||
private PayPalDetails payPalDetails; | ||
private AddressData addressData; | ||
|
||
public PayPalDetails getPayPalDetails() { | ||
return payPalDetails; | ||
} | ||
|
||
public void setPayPalDetails(PayPalDetails payPalDetails) { | ||
this.payPalDetails = payPalDetails; | ||
} | ||
|
||
public AddressData getAddressData() { | ||
return addressData; | ||
} | ||
|
||
public void setAddressData(AddressData addressData) { | ||
this.addressData = addressData; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ccheckoutaddon/acceleratoraddon/web/src/com/adyen/v6/request/PayPalExpressPDPRequest.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.v6.request; | ||
|
||
public class PayPalExpressPDPRequest extends PayPalExpressCartRequest { | ||
private String productCode; | ||
|
||
public String getProductCode() { | ||
return productCode; | ||
} | ||
|
||
public void setProductCode(String productCode) { | ||
this.productCode = productCode; | ||
} | ||
} |