use of org.broadleafcommerce.common.vendor.service.exception.PaymentException in project BroadleafCommerce by BroadleafCommerce.
the class CustomerPaymentGatewayAbstractController method createCustomerPayment.
// ***********************************************
// Customer Payment Result Processing
// ***********************************************
/**
* <p>This method is intended to initiate the creation of a saved payment token.</p>
*
* <p>This assumes that the implementing gateway's {@link org.broadleafcommerce.common.payment.service.PaymentGatewayWebResponseService}
* knows how to parse an incoming {@link javax.servlet.http.HttpServletRequest} into a
* {@link org.broadleafcommerce.common.payment.dto.PaymentResponseDTO} which will then be used by the
* customer profile engine to save a token to the user's account (e.g. wallet).</p>
*
* @param model - Spring MVC model
* @param request - the HTTPServletRequest (originating either from a Payment Gateway or from the implementing checkout engine)
* @param redirectAttributes - Spring MVC redirect attributes
* @return the resulting view
* @throws org.broadleafcommerce.common.vendor.service.exception.PaymentException
*/
public String createCustomerPayment(Model model, HttpServletRequest request, final RedirectAttributes redirectAttributes) throws PaymentException {
try {
PaymentResponseDTO responseDTO = getWebResponseService().translateWebResponse(request);
if (LOG.isTraceEnabled()) {
LOG.trace("HTTPRequest translated to Raw Response: " + responseDTO.getRawResponse());
}
Long customerPaymentId = applyCustomerTokenToProfile(responseDTO);
if (customerPaymentId != null) {
return getCustomerPaymentViewRedirect(String.valueOf(customerPaymentId));
}
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("HTTPRequest - " + webResponsePrintService.printRequest(request));
LOG.error("An exception was caught either from processing the response or saving the resulting " + "payment token to the customer's profile - delegating to the payment module to handle any other " + "exception processing. The error caught was: " + e);
}
handleProcessingException(e, redirectAttributes);
}
return getCustomerPaymentErrorRedirect();
}
use of org.broadleafcommerce.common.vendor.service.exception.PaymentException in project BroadleafCommerce by BroadleafCommerce.
the class PaymentGatewayAbstractController method process.
// ***********************************************
// Common Checkout Result Processing
// ***********************************************
/**
* This method is intended to initiate the final steps in checkout either
* via a request coming directly from a Payment Gateway (i.e. a Transparent Redirect) or from
* some sort of tokenization mechanism client-side.
*
* The assumption is that the implementing gateway's controller that extends this class
* will have implemented a {@link org.broadleafcommerce.common.payment.service.PaymentGatewayWebResponseService}
* with the ability to translate an {@link javax.servlet.http.HttpServletRequest} into a
* {@link org.broadleafcommerce.common.payment.dto.PaymentResponseDTO} which will then be used by the framework
* to create the appropriate order payments and transactions as well as invoke the checkout workflow
* if configured to do so.
*
* The general flow is as follows:
*
* try {
* translate http request to DTO
* apply payment to order (if unsuccessful, payment will be archived)
* if (not successful or not valid)
* redirect to error view
* if (complete checkout on callback == true)
* initiateCheckout(order id);
* else
* show review page;
* } catch (Exception e) {
* log error
* handle processing exception
* }
*
* @param model - Spring MVC model
* @param request - the HTTPServletRequest (originating either from a Payment Gateway or from the implementing checkout engine)
* @param redirectAttributes - Spring MVC redirect attributes
* @return the resulting view
* @throws PaymentException
*/
public String process(Model model, HttpServletRequest request, final RedirectAttributes redirectAttributes) throws PaymentException {
Long orderPaymentId = null;
try {
PaymentResponseDTO responseDTO = getWebResponseService().translateWebResponse(request);
if (LOG.isTraceEnabled()) {
LOG.trace("HTTPRequest translated to Raw Response: " + responseDTO.getRawResponse());
}
orderPaymentId = applyPaymentToOrder(responseDTO);
if (!responseDTO.isSuccessful()) {
if (LOG.isTraceEnabled()) {
LOG.trace("The Response DTO is marked as unsuccessful. Delegating to the " + "payment module to handle an unsuccessful transaction");
}
handleUnsuccessfulTransaction(model, redirectAttributes, responseDTO);
return getErrorViewRedirect();
}
if (!responseDTO.isValid()) {
throw new PaymentException("The validity of the response cannot be confirmed." + "Check the Tamper Proof Seal for more details.");
}
String orderId = responseDTO.getOrderId();
if (orderId == null) {
throw new RuntimeException("Order ID must be set on the Payment Response DTO");
}
if (responseDTO.isCompleteCheckoutOnCallback()) {
if (LOG.isTraceEnabled()) {
LOG.trace("The Response DTO for this Gateway is configured to complete checkout on callback. " + "Initiating Checkout with Order ID: " + orderId);
}
String orderNumber = initiateCheckout(Long.parseLong(orderId));
return getConfirmationViewRedirect(orderNumber);
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("The Gateway is configured to not complete checkout. " + "Redirecting to the Order Review Page for Order ID: " + orderId);
}
return getOrderReviewRedirect();
}
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("HTTPRequest - " + webResponsePrintService.printRequest(request));
LOG.error("An exception was caught either from processing the response and applying the payment to " + "the order, or an activity in the checkout workflow threw an exception. Attempting to " + "mark the payment as invalid and delegating to the payment module to handle any other " + "exception processing", e);
}
if (paymentGatewayCheckoutService != null && orderPaymentId != null) {
paymentGatewayCheckoutService.markPaymentAsInvalid(orderPaymentId);
}
handleProcessingException(e, redirectAttributes);
}
return getErrorViewRedirect();
}
use of org.broadleafcommerce.common.vendor.service.exception.PaymentException in project BroadleafCommerce by BroadleafCommerce.
the class DefaultCurrentOrderPaymentRequestService method addOrderAttributeToOrder.
@Override
public void addOrderAttributeToOrder(Long orderId, String orderAttributeKey, String orderAttributeValue) throws PaymentException {
Order currentCart = CartState.getCart();
Long currentCartId = currentCart.getId();
if (orderId != null && !currentCartId.equals(orderId)) {
logWarningIfCartMismatch(currentCartId, orderId);
currentCart = orderService.findOrderById(orderId);
}
OrderAttribute orderAttribute = new OrderAttributeImpl();
orderAttribute.setName(orderAttributeKey);
orderAttribute.setValue(orderAttributeValue);
orderAttribute.setOrder(currentCart);
currentCart.getOrderAttributes().put(orderAttributeKey, orderAttribute);
try {
orderService.save(currentCart, false);
} catch (PricingException e) {
throw new PaymentException(e);
}
}
use of org.broadleafcommerce.common.vendor.service.exception.PaymentException in project BroadleafCommerce by BroadleafCommerce.
the class AbstractExternalPaymentGatewayCall method process.
@Override
public R process(T paymentRequest) throws PaymentException {
R response;
try {
response = communicateWithVendor(paymentRequest);
} catch (Exception e) {
incrementFailure();
throw new PaymentException(e);
}
clearStatus();
return response;
}
use of org.broadleafcommerce.common.vendor.service.exception.PaymentException in project BroadleafCommerce by BroadleafCommerce.
the class TransparentRedirectCreditCardFormProcessor method getInjectedModelAndTagAttributes.
@Override
public BroadleafTemplateModelModifierDTO getInjectedModelAndTagAttributes(String rootTagName, Map<String, String> rootTagAttributes, BroadleafTemplateContext context) {
PaymentRequestDTO requestDTO = (PaymentRequestDTO) context.parseExpression(rootTagAttributes.get("paymentRequestDTO"));
Map<String, Map<String, String>> formParameters = new HashMap<>();
Map<String, String> configurationSettings = new HashMap<>();
// Create the configuration settings map to pass into the payment module
Map<String, String> keysToKeep = new HashMap<>();
for (String key : rootTagAttributes.keySet()) {
if (key.startsWith("config-")) {
final int trimLength = "config-".length();
String configParam = key.substring(trimLength);
configurationSettings.put(configParam, rootTagAttributes.get(key));
} else {
keysToKeep.put(key, rootTagAttributes.get(key));
}
}
keysToKeep.remove("paymentRequestDTO");
try {
extensionManager.getProxy().createTransparentRedirectForm(formParameters, requestDTO, configurationSettings);
} catch (PaymentException e) {
throw new RuntimeException("Unable to Create the Transparent Redirect Form", e);
}
StringBuilder formActionKey = new StringBuilder("formActionKey");
StringBuilder formHiddenParamsKey = new StringBuilder("formHiddenParamsKey");
extensionManager.getProxy().setFormActionKey(formActionKey);
extensionManager.getProxy().setFormHiddenParamsKey(formHiddenParamsKey);
// Change the action attribute on the form to the Payment Gateways Endpoint
String actionUrl = "";
Map<String, String> actionValue = formParameters.get(formActionKey.toString());
if (actionValue != null && actionValue.size() > 0) {
String key = (String) actionValue.keySet().toArray()[0];
actionUrl = actionValue.get(key);
}
keysToKeep.put("action", actionUrl);
BroadleafTemplateModel model = context.createModel();
// Append any hidden fields necessary for the Transparent Redirect
Map<String, String> hiddenFields = formParameters.get(formHiddenParamsKey.toString());
if (MapUtils.isNotEmpty(hiddenFields)) {
for (String key : hiddenFields.keySet()) {
Map<String, String> attributes = new HashMap<>();
attributes.put("type", "hidden");
attributes.put("name", key);
attributes.put("value", hiddenFields.get(key));
BroadleafTemplateElement input = context.createStandaloneElement("input", attributes, true);
model.addElement(input);
}
}
return new BroadleafTemplateModelModifierDTO(model, keysToKeep, "form");
}
Aggregations