svn commit: r787716 - /ofbiz/branches/release09.04/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java

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

svn commit: r787716 - /ofbiz/branches/release09.04/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java

ashish-18
Author: ashish
Date: Tue Jun 23 15:36:12 2009
New Revision: 787716

URL: http://svn.apache.org/viewvc?rev=787716&view=rev
Log:
Applied fix from trunk revision: 787715
Applied patch from jira issue OFBIZ-2653 (Payment authorization and capture is not possible for replacement orders)
Thanks Mridul for your contribution.

Modified:
    ofbiz/branches/release09.04/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java

Modified: ofbiz/branches/release09.04/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java?rev=787716&r1=787715&r2=787716&view=diff
==============================================================================
--- ofbiz/branches/release09.04/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java (original)
+++ ofbiz/branches/release09.04/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java Tue Jun 23 15:36:12 2009
@@ -495,8 +495,11 @@
             processAmount = paymentPreference.getBigDecimal("maxAmount");
         }
 
+        // Check if the order is a replacement order
+        boolean replacementOrderFlag = isReplacementOrder(orderHeader);
+        
         // don't authorized more then what is required
-        if (processAmount.compareTo(totalRemaining) > 0) {
+        if (!replacementOrderFlag && processAmount.compareTo(totalRemaining) > 0) {
             processAmount = totalRemaining;
         }
 
@@ -1201,7 +1204,10 @@
                 BigDecimal amountThisCapture;
 
                 // determine how much for *this* capture
-                if (authAmount.compareTo(amountToCapture) >= 0) {
+                if (isReplacementOrder(orderHeader)) {
+                    // if it is a replacement order then just capture the auth amount
+                    amountThisCapture = authAmount;
+                } else if (authAmount.compareTo(amountToCapture) >= 0) {
                     // if the auth amount is more then expected capture just capture what is expected
                     amountThisCapture = amountToCapture;
                 } else if (payments.hasNext()) {
@@ -1229,8 +1235,10 @@
                     // decrease amount of next payment preference to capture
                     amountToCapture = amountToCapture.subtract(amountCaptured);
 
-                    // add the invoiceId to the result for processing
-                    captureResult.put("invoiceId", invoiceId);
+                    // add the invoiceId to the result for processing, not for a replacement order
+                    if (!isReplacementOrder(orderHeader)) {
+                        captureResult.put("invoiceId", invoiceId);
+                    }
 
                     // process the capture's results
                     try {
@@ -3361,4 +3369,21 @@
         }
         return serviceName;
     }
+    
+    public static boolean isReplacementOrder(GenericValue orderHeader) {
+        boolean replacementOrderFlag = false;
+        
+        List<GenericValue> returnItemResponses = FastList.newInstance();
+        try {
+            returnItemResponses = orderHeader.getRelated("ReplacementReturnItemResponse");
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return replacementOrderFlag;
+        }
+        if (UtilValidate.isNotEmpty(returnItemResponses)) {
+            replacementOrderFlag = true;
+        }
+        
+        return replacementOrderFlag;
+    }
 }