svn commit: r598608 - in /ofbiz/trunk/applications/accounting: config/AccountingUiLabels.properties config/payment.properties servicedef/secas.xml servicedef/services_paymentmethod.xml 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: r598608 - in /ofbiz/trunk/applications/accounting: config/AccountingUiLabels.properties config/payment.properties servicedef/secas.xml servicedef/services_paymentmethod.xml src/org/ofbiz/accounting/payment/PaymentGatewayServices.java

apatel-2
Author: apatel
Date: Tue Nov 27 03:52:45 2007
New Revision: 598608

URL: http://svn.apache.org/viewvc?rev=598608&view=rev
Log:
 New verifyCreditCard service which will be called as an ECA on createCreditCard and updateCreditCard services

Modified:
    ofbiz/trunk/applications/accounting/config/AccountingUiLabels.properties
    ofbiz/trunk/applications/accounting/config/payment.properties
    ofbiz/trunk/applications/accounting/servicedef/secas.xml
    ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java

Modified: ofbiz/trunk/applications/accounting/config/AccountingUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/AccountingUiLabels.properties?rev=598608&r1=598607&r2=598608&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/config/AccountingUiLabels.properties (original)
+++ ofbiz/trunk/applications/accounting/config/AccountingUiLabels.properties Tue Nov 27 03:52:45 2007
@@ -140,6 +140,9 @@
 AccountingCreatePaymentPermissionError=Security Error : To Create a Payment you must either be the to or from party or have the PAY_INFO_CREATE or PAY_INFO_ADMIN permissions.
 AccountingCreatePermissionError=Security Error: to run createGlAccount you must have the ACCOUNTING_CREATE or ACCOUNTING_ADMIN permission<br>
 AccountingCreditCard=Credit Card
+AccountingCreditCardBillingAddNotFoundError=Billing Address associated with Credit Card not found.
+AccountingCreditCardEmailAddNotFoundError=Bill To Email Address not found.
+AccountingCreditCardManualAuthFailedError=Not creating credit card.  Credit card not verified, authentication failed.
 AccountingCustomer=Customer
 AccountingCustNr=Cust.Nr
 AccountingDataExchange=DataExchange

Modified: ofbiz/trunk/applications/accounting/config/payment.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/payment.properties?rev=598608&r1=598607&r2=598608&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/config/payment.properties (original)
+++ ofbiz/trunk/applications/accounting/config/payment.properties Tue Nov 27 03:52:45 2007
@@ -33,6 +33,8 @@
 payment.general.reauth.mc.days=30
 payment.general.reauth.visa.days=7
 payment.general.reauth.other.days=7
+payment.general.cc_create.auth=0
+payment.general.cc_update.auth=0
 
 ############################################
 # General Gift Certificate Configuration

Modified: ofbiz/trunk/applications/accounting/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/secas.xml?rev=598608&r1=598607&r2=598608&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/secas.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/secas.xml Tue Nov 27 03:52:45 2007
@@ -67,6 +67,15 @@
         <condition field-name="expYear" operator="is-not-empty"/>
         <action service="buildCcExpireDate" mode="sync"/>
     </eca>
+    <eca service="createCreditCard" event="commit">
+        <set field-name="mode" value="CREATE"/>
+        <action service="verifyCreditCard" mode="sync" run-as-user="system"/>
+    </eca>
+    <eca service="updateCreditCard" event="commit">
+        <condition-field field-name="oldPaymentMethodId" operator="not-equals" to-field-name="paymentMethodId"/>
+        <set field-name="mode" value="UPDATE"/>
+        <action service="verifyCreditCard" mode="sync" run-as-user="system"/>
+    </eca>
 
     <eca service="createCreditCardAndAddress" event="in-validate">
         <condition field-name="expMonth" operator="is-not-empty"/>

Modified: ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml?rev=598608&r1=598607&r2=598608&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml Tue Nov 27 03:52:45 2007
@@ -45,6 +45,7 @@
         <!-- these two will be assembled into a expireDate by buildCcExpireDate on an ECA if needed -->
         <attribute name="expMonth" type="String" mode="IN" optional="true"/>
         <attribute name="expYear" type="String" mode="IN" optional="true"/>
+        <attribute name="productStoreId" type="String" mode="IN" optional="true"/>
         <override name="firstNameOnCard" optional="false"/>
         <override name="lastNameOnCard" optional="false"/>
         <override name="cardType" optional="false"/>
@@ -76,6 +77,7 @@
         <attribute name="expYear" type="String" mode="IN" optional="true"/>
         <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 -->
+        <attribute name="productStoreId" type="String" mode="IN" optional="true"/>
     </service>
     <service name="clearCreditCardDataAndExpire" engine="java"
             location="org.ofbiz.accounting.payment.PaymentMethodServices" invoke="clearCreditCardData" auth="true">
@@ -196,8 +198,10 @@
         <attribute name="cardSecurityCode" type="String" mode="IN" optional="true"/>
         <attribute name="expMonth" type="String" mode="IN" optional="false"/>
         <attribute name="expYear" type="String" mode="IN" optional="false"/>
+        <!-- Not used in the service any more
         <attribute name="firstName" type="String" mode="IN" optional="false"/>
         <attribute name="lastName" type="String" mode="IN" optional="false"/>
+        -->
         <attribute name="infoString" type="String" mode="IN" optional="false"/>
         <attribute name="address1" type="String" mode="IN" optional="false"/>
         <attribute name="address2" type="String" mode="IN" optional="true"/>
@@ -656,5 +660,14 @@
             location="org.ofbiz.accounting.payment.PaymentGatewayServices" invoke="testRelease">
         <description>EFT Account Test Release</description>
         <implements service="paymentReleaseInterface"/>
+    </service>
+    
+    <!-- Verify Credit Card Service-->
+    <service name="verifyCreditCard" engine="java"
+            location="org.ofbiz.accounting.payment.PaymentGatewayServices" invoke="verifyCreditCard" auth="true">
+        <attribute name="paymentMethodId" type="String" mode="IN" optional="false"/>
+        <attribute name="oldPaymentMethodId" type="String" mode="IN" optional="true"/>
+        <attribute name="productStoreId" type="String" mode="IN" optional="true"/>
+        <attribute name="mode" type="String" mode="IN" optional="false"/>
     </service>
 </services>

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=598608&r1=598607&r2=598608&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 Tue Nov 27 03:52:45 2007
@@ -24,6 +24,9 @@
 import java.math.BigDecimal;
 import java.sql.Timestamp;
 
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
 import org.ofbiz.accounting.invoice.InvoiceWorker;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
@@ -2762,6 +2765,125 @@
         Map returnResults = ServiceUtil.returnSuccess("Transaction result [" + msg + "/" + code +"] Ref#: " + refNum);
         returnResults.put("referenceNum", refNum);
         return returnResults;
+    }
+    
+    // Verify Credit Card (Manually) Service
+    
+    public static Map verifyCreditCard(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericDelegator delegator = dctx.getDelegator();
+        String productStoreId = (String) context.get("productStoreId");
+        String mode = (String) context.get("mode");
+        String paymentMethodId = (String) context.get("paymentMethodId");
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        
+        GenericValue productStore = null;
+        productStore = ProductStoreWorker.getProductStore(productStoreId, delegator);
+        
+        String productStorePaymentProperties = "payment.properties";
+        if (productStore != null) {
+            productStorePaymentProperties = ProductStoreWorker.getProductStorePaymentProperties(delegator, productStoreId, "CREDIT_CARD", "PRDS_PAY_CREDIT", false);
+        }
+        
+        String amount = null;
+        if (mode.equalsIgnoreCase("CREATE")) {
+            amount = UtilProperties.getPropertyValue(productStorePaymentProperties, "payment.general.cc_create.auth");
+        } else if (mode.equalsIgnoreCase("UPDATE")) {
+            amount = UtilProperties.getPropertyValue(productStorePaymentProperties, "payment.general.cc_update.auth");
+        }
+                
+        if (amount != null && amount.length() > 0) {
+            double authAmount = Double.parseDouble(amount);
+            if (authAmount > 0.0) {
+                Map ccAuthContext = FastMap.newInstance();
+                ccAuthContext.put("paymentMethodTypeId", "CREDIT_CARD");
+                ccAuthContext.put("productStoreId", productStoreId);
+                ccAuthContext.put("transactionType", "PRDS_PAY_CREDIT");
+                    
+                GenericValue paymentMethod = null;
+                GenericValue creditCard = null;
+                GenericValue postalAddress = null;
+                try {
+                    paymentMethod = delegator.findByPrimaryKey("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId));
+                    creditCard = paymentMethod.getRelatedOne("CreditCard");
+                    postalAddress = creditCard.getRelatedOne("PostalAddress");
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());
+                }
+                if (postalAddress == null) {
+                    String errMsg = UtilProperties.getPropertyValue("AccountingUiLabels", "AccountingCreditCardBillingAddNotFoundError");
+                    return ServiceUtil.returnError(errMsg);
+                }
+                        
+                ccAuthContext.put("firstNameOnCard", creditCard.getString("firstNameOnCard"));
+                ccAuthContext.put("lastNameOnCard", creditCard.getString("lastNameOnCard"));
+                ccAuthContext.put("cardType", creditCard.getString("cardType"));
+                ccAuthContext.put("cardNumber", creditCard.getString("cardNumber"));
+                String expireDate = creditCard.getString("expireDate");
+                String expMonth = expireDate.substring(0, expireDate.indexOf('/'));
+                String expYear = expireDate.substring(expireDate.indexOf('/') + 1);
+                ccAuthContext.put("expMonth", expMonth);
+                ccAuthContext.put("expYear", expYear);
+                ccAuthContext.put("amount", authAmount);
+                ccAuthContext.put("address1", postalAddress.getString("address1"));
+                ccAuthContext.put("address2", postalAddress.getString("address2"));
+                ccAuthContext.put("city", postalAddress.getString("city"));
+                ccAuthContext.put("stateProvinceGeoId", postalAddress.getString("stateProvinceGeoId"));
+                ccAuthContext.put("countryGeoId", postalAddress.getString("countryGeoId"));
+                ccAuthContext.put("postalCode", postalAddress.getString("postalCode"));
+                        
+                List partyContactMechPurposeList = FastList.newInstance();
+                try {
+                    partyContactMechPurposeList = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose", UtilMisc.toMap("partyId", paymentMethod.getString("partyId"), "contactMechPurposeTypeId", "BILLING_EMAIL"), UtilMisc.toList("-fromDate")));
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());
+                }
+                if (UtilValidate.isEmpty(partyContactMechPurposeList)) {
+                    String errMsg = UtilProperties.getPropertyValue("AccountingUiLabels", "AccountingCreditCardEmailAddNotFoundError");
+                    return ServiceUtil.returnError(errMsg);
+                }
+
+                GenericValue partyContactMechPurpose = EntityUtil.getFirst(partyContactMechPurposeList);
+                List partyContactMechList = FastList.newInstance();
+                try {
+                    partyContactMechList = EntityUtil.filterByDate(partyContactMechPurpose.getRelated("PartyContactMech", UtilMisc.toList("-fromDate")));
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());
+                }
+                if (UtilValidate.isEmpty(partyContactMechList)) {
+                    String errMsg = UtilProperties.getPropertyValue("AccountingUiLabels", "AccountingCreditCardEmailAddNotFoundError");
+                    return ServiceUtil.returnError(errMsg);
+                }
+                        
+                GenericValue partyContactMech = EntityUtil.getFirst(partyContactMechList);
+                GenericValue contactMech = null;
+                try {
+                    contactMech = partyContactMech.getRelatedOne("ContactMech");
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());                            
+                }
+                ccAuthContext.put("infoString", contactMech.getString("infoString"));
+                ccAuthContext.put("userLogin", userLogin);
+                        
+                Map results = FastMap.newInstance();
+                try {
+                    results = dispatcher.runSync("manualForcedCcTransaction", ccAuthContext);
+                } catch (GenericServiceException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());
+                }
+                        
+                if (ServiceUtil.isError(results)) {
+                    String errMsg = UtilProperties.getPropertyValue("AccountingUiLabels", "AccountingCreditCardManualAuthFailedError");
+                    return ServiceUtil.returnError(errMsg);
+                }
+            }
+        }
+        return ServiceUtil.returnSuccess();
     }
 
     // ****************************************************