Author: lektran
Date: Wed Jul 22 11:35:45 2009
New Revision: 796676

URL: http://svn.apache.org/viewvc?rev=796676&view=rev
Log:
Another PayPal restriction whereby you cannot do a refund transaction for more 
than the capture transaction being referenced.

Fixed by having refundPayment return the amount actually refunded and using 
that amount in the processRefundReturn service.

Modified:
    ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml
    
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
    
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java
    
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java

Modified: 
ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml?rev=796676&r1=796675&r2=796676&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml 
(original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml 
Wed Jul 22 11:35:45 2009
@@ -355,7 +355,7 @@
             location="org.ofbiz.accounting.payment.PaymentGatewayServices" 
invoke="refundPayment" auth="true">
         <description>Refunds A Payment</description>
         <attribute name="orderPaymentPreference" 
type="org.ofbiz.entity.GenericValue" mode="IN" optional="false"/>
-        <attribute name="refundAmount" type="BigDecimal" mode="IN" 
optional="false"/>
+        <attribute name="refundAmount" type="BigDecimal" mode="INOUT" 
optional="false"/>
         <attribute name="paymentId" type="String" mode="OUT" optional="false"/>
     </service>
     
@@ -434,7 +434,7 @@
         <attribute name="payFromPartyId" type="String" mode="IN" 
optional="true"/>
         <attribute name="payToPartyId" type="String" mode="IN" 
optional="true"/>
         <attribute name="invoiceId" type="String" mode="IN" optional="true"/>
-        <attribute name="refundAmount" type="BigDecimal" mode="IN" 
optional="false"/>
+        <attribute name="refundAmount" type="BigDecimal" mode="INOUT" 
optional="false"/>
         <attribute name="currencyUomId" type="String" mode="IN" 
optional="true"/>
         <attribute name="refundResult" type="Boolean" mode="IN" 
optional="false"/>
         <attribute name="refundAltRefNum" type="String" mode="IN" 
optional="true"/>

Modified: 
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java?rev=796676&r1=796675&r2=796676&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
 (original)
+++ 
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
 Wed Jul 22 11:35:45 2009
@@ -2407,10 +2407,8 @@
 
                     // The refund amount could be different from what we tell 
the payment gateway due to issues
                     // such as having to void the entire original auth amount 
and re-authorize the new order total.
-                    // However, since some legacy services might be 
non-compliant, so as a safety measure we will
-                    // override the original refund amount if the refund 
response has a positive value
                     BigDecimal actualRefundAmount = (BigDecimal) 
refundResponse.get("refundAmount");
-                    if (actualRefundAmount != null && 
actualRefundAmount.compareTo(BigDecimal.ZERO) > 0) {
+                    if (actualRefundAmount != null && 
actualRefundAmount.compareTo(processAmount) != 0) {
                         refundResCtx.put("refundAmount", 
refundResponse.get("refundAmount"));
                     }
                     refundResRes = dispatcher.runSync(model.name, 
refundResCtx);
@@ -2524,6 +2522,7 @@
 
             Map<String, Object> result = ServiceUtil.returnSuccess();
             result.put("paymentId", paymentId);
+            result.put("refundAmount", context.get("refundAmount"));
             return result;
         } else {
             return ServiceUtil.returnFailure("The refund failed");

Modified: 
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java?rev=796676&r1=796675&r2=796676&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java
 (original)
+++ 
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/verisign/PayflowPro.java
 Wed Jul 22 11:35:45 2009
@@ -373,6 +373,9 @@
             data.put("TENDER", "P");
 
             data.put("MEMO", orderId);
+            // PayPal won't allow us to refund more than the capture amount
+            BigDecimal captureAmount = captureTrans.getBigDecimal("amount");
+            amount = amount.min(captureAmount);
         } else {
             // credit card tender
             data.put("TENDER", "C");

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java?rev=796676&r1=796675&r2=796676&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java
 (original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java
 Wed Jul 22 11:35:45 2009
@@ -1284,7 +1284,7 @@
                     BigDecimal orderPayPrefAvailableTotal = 
orderPayPrefReceivedTotal.subtract(orderPayPrefRefundedTotal);
 
                     // add the refundable amount and orderPaymentPreference to 
the paymentMethodTypeId map
-                    if (orderPayPrefAvailableTotal.compareTo(ZERO) == 1) {
+                    if (orderPayPrefAvailableTotal.compareTo(ZERO) > 0) {
                         Map orderPayPrefDetails = new HashMap();
                         orderPayPrefDetails.put("orderPaymentPreference", 
orderPayPref);
                         orderPayPrefDetails.put("availableTotal", 
orderPayPrefAvailableTotal);
@@ -1345,6 +1345,8 @@
 
                             // Refund up to the maxAmount for the paymentPref, 
or whatever is left to refund if that's less than the maxAmount
                             BigDecimal amountToRefund = 
orderPaymentPreferenceAvailable.min(amountLeftToRefund);
+                            // The amount actually refunded for the 
paymentPref, default to requested amount
+                            BigDecimal amountRefunded = amountToRefund;
 
                             String paymentId = null;
                             String returnItemStatusId = "RETURN_COMPLETED";  
// generally, the return item will be considered complete after this
@@ -1358,6 +1360,7 @@
                                         continue;
                                     }
                                     paymentId = (String) 
serviceResult.get("paymentId");
+                                    amountRefunded = (BigDecimal) 
serviceResult.get("refundAmount");
                                 } catch (GenericServiceException e) {
                                     Debug.logError(e, "Problem running the 
refundPayment service", module);
                                     return 
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemsWithTheRefundSeeLogs",
 locale));
@@ -1402,7 +1405,7 @@
                             // Fill out the data for the new ReturnItemResponse
                             Map response = FastMap.newInstance();
                             response.put("orderPaymentPreferenceId", 
orderPaymentPreference.getString("orderPaymentPreferenceId"));
-                            response.put("responseAmount", 
amountToRefund.setScale(decimals, rounding));
+                            response.put("responseAmount", 
amountRefunded.setScale(decimals, rounding));
                             response.put("responseDate", now);
                             response.put("userLogin", userLogin);
                             response.put("paymentId", paymentId);
@@ -1454,7 +1457,7 @@
                             }
 
                             // Update the amount necessary to refund
-                            amountLeftToRefund = 
amountLeftToRefund.subtract(amountToRefund);
+                            amountLeftToRefund = 
amountLeftToRefund.subtract(amountRefunded);
                         }
                     }
                 }


Reply via email to