svn commit: r547346 - in /ofbiz/trunk/applications/accounting: servicedef/services_paymentmethod.xml src/org/ofbiz/accounting/finaccount/FinAccountServices.java src/org/ofbiz/accounting/payment/PaymentMethodServices.java

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

svn commit: r547346 - in /ofbiz/trunk/applications/accounting: servicedef/services_paymentmethod.xml src/org/ofbiz/accounting/finaccount/FinAccountServices.java src/org/ofbiz/accounting/payment/PaymentMethodServices.java

jaz-3
Author: jaz
Date: Thu Jun 14 11:18:37 2007
New Revision: 547346

URL: http://svn.apache.org/viewvc?view=rev&rev=547346
Log:
fixed refund fin account service to check if the account is refundable; added method to clear the credit card data and expire the payment method (useful when needed for custom applications)

Modified:
    ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java

Modified: ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml?view=diff&rev=547346&r1=547345&r2=547346
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml Thu Jun 14 11:18:37 2007
@@ -77,6 +77,11 @@
         <attribute name="paymentMethodId" type="String" mode="OUT" optional="false"/> <!-- This is the id of the new cc -->
         <attribute name="oldPaymentMethodId" type="String" mode="OUT" optional="false"/> <!-- This is the id of the old cc -->
     </service>
+    <service name="clearCreditCardDataAndExpire" engine="java"
+            location="org.ofbiz.accounting.payment.PaymentMethodServices" invoke="clearCreditCardData" auth="true">
+        <description>Clears the credit card number out of the value object and expires the payment method</description>
+        <attribute name="paymentMethodId" type="String" mode="IN" optional="false"/>
+    </service>
     <service name="buildCcExpireDate" engine="java"
                 location="org.ofbiz.accounting.payment.PaymentMethodServices" invoke="makeExpireDate">
         <description>Makes a Expire Date</description>

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java?view=diff&rev=547346&r1=547345&r2=547346
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/finaccount/FinAccountServices.java Thu Jun 14 11:18:37 2007
@@ -323,6 +323,11 @@
         }
 
         if (finAccount != null) {
+            // check to make sure the account is refundable
+            if (!"Y".equals(finAccount.getString("isRefundable"))) {
+                return ServiceUtil.returnError("Account is not refunable");    
+            }
+
             // get the actual and available balance
             BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance");
             BigDecimal actualBalance = finAccount.getBigDecimal("actualBalance");

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java?view=diff&rev=547346&r1=547345&r2=547346
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java Thu Jun 14 11:18:37 2007
@@ -34,9 +34,7 @@
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.security.Security;
-import org.ofbiz.service.DispatchContext;
-import org.ofbiz.service.ModelService;
-import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.service.*;
 
 /**
  * Services for Payment maintenance
@@ -403,6 +401,47 @@
 
         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
         return result;
+    }
+
+    public static Map clearCreditCardData(DispatchContext dctx, Map context) {
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        String paymentMethodId = (String) context.get("paymentMethodId");
+
+        // get the cc object
+        GenericDelegator delegator = dctx.getDelegator();
+        GenericValue creditCard;
+        try {
+            creditCard = delegator.findByPrimaryKey("CreditCard", UtilMisc.toMap("paymentMethodId", paymentMethodId));
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+
+        // clear the info and store it
+        creditCard.set("cardNumber", "0000000000000000"); // set so it doesn't blow up in UIs
+        creditCard.set("expireDate", "01/1970"); // same here
+        try {
+            delegator.store(creditCard);
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+
+        // expire the payment method
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        Map expireCtx = UtilMisc.toMap("userLogin", userLogin, "paymentMethodId", paymentMethodId);
+        Map expireResp;
+        try {
+            expireResp = dispatcher.runSync("deletePaymentMethod", expireCtx);
+        } catch (GenericServiceException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        if (ServiceUtil.isError(expireResp)) {
+            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(expireResp));
+        }
+
+        return ServiceUtil.returnSuccess();
     }
 
     public static Map createGiftCard(DispatchContext ctx, Map context) {