use of org.apache.ofbiz.order.shoppingcart.ShoppingCart in project ofbiz-framework by apache.
the class ExpressCheckoutEvents method expressCheckoutRedirect.
public static String expressCheckoutRedirect(HttpServletRequest request, HttpServletResponse response) {
Delegator delegator = (Delegator) request.getAttribute("delegator");
ShoppingCart cart = ShoppingCartEvents.getCartObject(request);
String token = (String) cart.getAttribute("payPalCheckoutToken");
String paymentGatewayConfigId = null;
GenericValue payPalGatewayConfig = null;
String productStoreId = null;
if (UtilValidate.isEmpty(token)) {
Debug.logError("No ExpressCheckout token found in cart, you must do a successful setExpressCheckout before redirecting.", module);
return "error";
}
productStoreId = cart.getProductStoreId();
if (productStoreId != null) {
GenericValue payPalPaymentSetting = ProductStoreWorker.getProductStorePaymentSetting(delegator, productStoreId, "EXT_PAYPAL", null, true);
if (payPalPaymentSetting != null) {
paymentGatewayConfigId = payPalPaymentSetting.getString("paymentGatewayConfigId");
}
}
if (paymentGatewayConfigId != null) {
try {
payPalGatewayConfig = EntityQuery.use(delegator).from("PaymentGatewayPayPal").where("paymentGatewayConfigId", paymentGatewayConfigId).cache().queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
}
if (payPalGatewayConfig == null) {
request.setAttribute("_EVENT_MESSAGE_", "Couldn't retrieve a PaymentGatewayConfigPayPal record for Express Checkout, cannot continue.");
return "error";
}
StringBuilder redirectUrl = new StringBuilder(payPalGatewayConfig.getString("redirectUrl"));
redirectUrl.append("?cmd=_express-checkout&token=");
redirectUrl.append(token);
try {
response.sendRedirect(redirectUrl.toString());
} catch (IOException e) {
Debug.logError(e, module);
return "error";
}
return "success";
}
use of org.apache.ofbiz.order.shoppingcart.ShoppingCart in project ofbiz-framework by apache.
the class ExpressCheckoutEvents method getExpressCheckoutDetails.
public static String getExpressCheckoutDetails(HttpServletRequest request, HttpServletResponse response) {
Locale locale = UtilHttp.getLocale(request);
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
ShoppingCart cart = ShoppingCartEvents.getCartObject(request);
CheckoutType checkoutType = determineCheckoutType(request);
if (!checkoutType.equals(CheckoutType.NONE)) {
String serviceName = null;
if (checkoutType.equals(CheckoutType.PAYFLOW)) {
serviceName = "payflowGetExpressCheckout";
} else if (checkoutType.equals(CheckoutType.STANDARD)) {
serviceName = "payPalGetExpressCheckout";
}
Map<String, ? extends Object> inMap = UtilMisc.toMap("userLogin", cart.getUserLogin(), "cart", cart);
Map<String, Object> result = null;
try {
result = dispatcher.runSync(serviceName, inMap);
} catch (GenericServiceException e) {
request.setAttribute("_EVENT_MESSAGE_", UtilProperties.getMessage(resourceErr, "AccountingPayPalCommunicationError", locale));
return "error";
}
if (ServiceUtil.isError(result)) {
String errorMessage = ServiceUtil.getErrorMessage(result);
request.setAttribute("_ERROR_MESSAGE_", errorMessage);
Debug.logError(errorMessage, module);
return "error";
}
}
return "success";
}
Aggregations