svn commit: r949465 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/thirdparty/paypal/ExpressCheckoutEvents.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r949465 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/thirdparty/paypal/ExpressCheckoutEvents.java

ashish-18
Author: ashish
Date: Sun May 30 03:25:35 2010
New Revision: 949465

URL: http://svn.apache.org/viewvc?rev=949465&view=rev
Log:
The paypal checkout should always redirect to sandbox while you are in production environment. Contribution from Divesh & Pranay - Thanks Guys.

Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/thirdparty/paypal/ExpressCheckoutEvents.java

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/thirdparty/paypal/ExpressCheckoutEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/thirdparty/paypal/ExpressCheckoutEvents.java?rev=949465&r1=949464&r2=949465&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/thirdparty/paypal/ExpressCheckoutEvents.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/thirdparty/paypal/ExpressCheckoutEvents.java Sun May 30 03:25:35 2010
@@ -81,13 +81,37 @@ public class ExpressCheckoutEvents {
     }
 
     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";
         }
-        StringBuilder redirectUrl = new StringBuilder("https://www.sandbox.paypal.com/cgi-bin/webscr");
+        if (cart != null) {
+            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 = delegator.findOne("PaymentGatewayPayPal", true, "paymentGatewayConfigId", paymentGatewayConfigId);
+            } 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 {