You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by si...@apache.org on 2006/08/24 22:15:25 UTC

svn commit: r434503 - in /incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order: order/OrderReturnServices.java shoppingcart/CheckOutEvents.java

Author: sichen
Date: Thu Aug 24 13:15:24 2006
New Revision: 434503

URL: http://svn.apache.org/viewvc?rev=434503&view=rev
Log:
Continuing work on refunding orders with multiple payment types: refunding to billing account requires creating a PaymentApplication

Modified:
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java?rev=434503&r1=434502&r2=434503&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Thu Aug 24 13:15:24 2006
@@ -1074,20 +1074,36 @@
         String paymentId = null;
         try {
             Map paymentCreationResult = dispatcher.runSync("createPayment", paymentCtx);
-            if (ModelService.RESPOND_ERROR.equals(paymentCreationResult.get(ModelService.RESPONSE_MESSAGE))) {
-                return ServiceUtil.returnError((String) paymentCreationResult.get(ModelService.ERROR_MESSAGE));
+            if (ServiceUtil.isError(paymentCreationResult)) {
+                return paymentCreationResult; 
             } else {
                 paymentId = (String) paymentCreationResult.get("paymentId");
             }
         } catch (GenericServiceException e) {
-            Debug.logError(e, "Problem creating Payment", module);
-            return ServiceUtil.returnError("Problem creating Payment");
+            return ServiceUtil.returnError("Problem creating Payment " + e.getMessage());
         }
 
         if (paymentId == null) {
             return ServiceUtil.returnError("Create payment failed");
         }
 
+        // if the original order was paid with a billing account, then go find the billing account from the order and associate this refund with that billing account
+        // thus returning value to the billing account 
+        if ("EXT_BILLACT".equals(paymentPref.getString("paymentMethodTypeId"))) {
+            GenericValue billingAccount = orh.getBillingAccount();
+            if (UtilValidate.isNotEmpty(billingAccount.getString("billingAccountId"))) {
+                try {
+                    Map paymentApplResult = dispatcher.runSync("createPaymentApplication", UtilMisc.toMap("paymentId", paymentId, "billingAccountId", billingAccount.getString("billingAccountId"),
+                                "amountApplied", refundAmount, "userLogin", userLogin));
+                    if (ServiceUtil.isError(paymentApplResult)) {
+                        return paymentApplResult; 
+                    }
+                } catch (GenericServiceException e) {
+                    return ServiceUtil.returnError("Problem creating PaymentApplication: " + e.getMessage());
+                }
+            }
+        }
+        
         Map result = ServiceUtil.returnSuccess();
         result.put("paymentId", paymentId);
         return result;

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java?rev=434503&r1=434502&r2=434503&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java Thu Aug 24 13:15:24 2006
@@ -957,7 +957,7 @@
         }
 
         // set the billing account amount to the minimum of billing account available balance or amount input if less than balance
-        if ((cart != null) && (billingAccountId != null) && !"_NA_".equals(billingAccountId)) {
+        if ((cart != null) && (billingAccountId != null) && !("".equals(billingAccountId)) && !"_NA_".equals(billingAccountId)) {
             double availableBalance = checkOutHelper.availableAccountBalance(billingAccountId);
 
             // set amount to be charged to entered amount unless it exceeds the available balance