Search in sources :

Example 36 with ShoppingCart

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";
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) ShoppingCart(org.apache.ofbiz.order.shoppingcart.ShoppingCart) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) IOException(java.io.IOException)

Example 37 with ShoppingCart

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";
}
Also used : Locale(java.util.Locale) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) ShoppingCart(org.apache.ofbiz.order.shoppingcart.ShoppingCart) GenericServiceException(org.apache.ofbiz.service.GenericServiceException)

Aggregations

ShoppingCart (org.apache.ofbiz.order.shoppingcart.ShoppingCart)37 Delegator (org.apache.ofbiz.entity.Delegator)28 GenericValue (org.apache.ofbiz.entity.GenericValue)28 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)23 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)18 Locale (java.util.Locale)17 GeneralException (org.apache.ofbiz.base.util.GeneralException)14 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)13 BigDecimal (java.math.BigDecimal)9 CartItemModifyException (org.apache.ofbiz.order.shoppingcart.CartItemModifyException)9 HashMap (java.util.HashMap)8 CheckOutHelper (org.apache.ofbiz.order.shoppingcart.CheckOutHelper)8 ShoppingCartItem (org.apache.ofbiz.order.shoppingcart.ShoppingCartItem)7 Timestamp (java.sql.Timestamp)6 LinkedList (java.util.LinkedList)5 ItemNotFoundException (org.apache.ofbiz.order.shoppingcart.ItemNotFoundException)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 GenericTransactionException (org.apache.ofbiz.entity.transaction.GenericTransactionException)4 NVPEncoder (com.paypal.sdk.core.nvp.NVPEncoder)3 PayPalException (com.paypal.sdk.exceptions.PayPalException)3