You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2010/11/10 22:21:25 UTC

svn commit: r1033717 - in /ofbiz/trunk/applications/accounting: config/ entitydef/ src/org/ofbiz/accounting/thirdparty/authorizedotnet/ widget/

Author: jaz
Date: Wed Nov 10 21:21:24 2010
New Revision: 1033717

URL: http://svn.apache.org/viewvc?rev=1033717&view=rev
Log:
added support for the card present api to the authorize.net integration; this uses the cardpresent.authorize.net url as well as the market_type and device_type properties. These were added to the entity for configuration. 

The request API was almost the same as the standard AIM; however the response is very different. Most of the changes here are around response processing and abstracting the position of the fields out of the main response class.

Added:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMRespPositions.java
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/CPRespPositions.java
Modified:
    ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml
    ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AuthorizeResponse.java
    ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml

Modified: ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml?rev=1033717&r1=1033716&r2=1033717&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml (original)
+++ ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml Wed Nov 10 21:21:24 2010
@@ -1157,6 +1157,15 @@
         <value xml:lang="hi_IN">अधिकृत Dot Net API संस्करणः</value>
         <value xml:lang="it">Versione API Authorize Dot Net</value>
     </property>
+    <property key="AccountingAuthorizeNetCpMarket">
+        <value xml:lang="en">Card Present Market Type</value>        
+    </property>
+    <property key="AccountingAuthorizeNetCpDevice">
+        <value xml:lang="en">Card Present Device Type</value>        
+    </property>
+    <property key="AccountingAuthorizeNetCpVersion">
+        <value xml:lang="en">Card Present API Version</value>        
+    </property>
     <property key="AccountingAuthorizeNetDelimiterChar">
         <value xml:lang="en">Delimited Char</value>
         <value xml:lang="hi_IN">सीमांकित वर्ण</value>

Modified: ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml?rev=1033717&r1=1033716&r2=1033717&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml Wed Nov 10 21:21:24 2010
@@ -3254,6 +3254,9 @@ under the License.
       <field name="apiVersion" type="short-varchar"><description>Target Authorize Dot Net API version</description></field>
       <field name="delimitedData" type="short-varchar"><description>Delimited data (TRUE|FALSE)</description></field>
       <field name="delimiterChar" type="short-varchar"><description>Delimited Character - the delimiter to use in the response</description></field>
+      <field name="cpVersion" type="short-varchar"><description>Card Present Version</description></field>
+      <field name="cpMarketType" type="short-varchar"><description>Card Present Market Type</description></field>
+      <field name="cpDeviceType" type="short-varchar"><description>Card Present Device Type</description></field>
       <field name="method" type="short-varchar"><description>Method - CC for credit card processing</description></field>
       <field name="emailCustomer" type="short-varchar"><description>Email Customer? - if should send an email to the customer for each transaction (TRUE|FALSE)</description></field>
       <field name="emailMerchant" type="short-varchar"><description>Email Merchant? - if should send email to the merchant for each transaction (TRUE|FALSE)</description></field>

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java?rev=1033717&r1=1033716&r2=1033717&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMPaymentServices.java Wed Nov 10 21:21:24 2010
@@ -304,21 +304,24 @@ public class AIMPaymentServices {
             Debug.logInfo("TEST Authorize.net request string " + request.toString(),module);
             Debug.logInfo("TEST Authorize.net properties string " + props.toString(),module);
         }
+        
+        // card present has a different layout from standard AIM; this determines how to parse the response
+        int apiType = props.get("cpMarketType") == null ? AuthorizeResponse.AIM_RESPONSE : AuthorizeResponse.CP_RESPONSE;
+        
         try {
             HttpClient httpClient = new HttpClient(url, request);
             String certificateAlias = props.getProperty("certificateAlias");
             httpClient.setClientCertificateAlias(certificateAlias);
             String httpResponse = httpClient.post();
             Debug.logInfo("transaction response: " + httpResponse,module);
-            AuthorizeResponse ar = new AuthorizeResponse(httpResponse);
-            String resp = ar.getResponseCode();
-            if (resp.equals(AuthorizeResponse.APPROVED)) {
+            AuthorizeResponse ar = new AuthorizeResponse(httpResponse, apiType);            
+            if (ar.isApproved()) {            
                 result.put("authResult", Boolean.TRUE);
             } else {
                 result.put("authResult", Boolean.FALSE);
-                Debug.logInfo("responseCode:   " + ar.getResponseField(AuthorizeResponse.RESPONSE_CODE),module);
-                Debug.logInfo("responseReason: " + ar.getResponseField(AuthorizeResponse.RESPONSE_REASON_CODE),module);
-                Debug.logInfo("reasonText:     " + ar.getResponseField(AuthorizeResponse.RESPONSE_REASON_TEXT),module);
+                Debug.logInfo("responseCode:   " + ar.getResponseCode(), module);
+                Debug.logInfo("responseReason: " + ar.getReasonCode(), module);
+                Debug.logInfo("reasonText:     " + ar.getReasonText(), module);
             }
             result.put("httpResponse", httpResponse);
             result.put("authorizeResponse", ar);
@@ -345,6 +348,9 @@ public class AIMPaymentServices {
         String ver = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "apiVersion", configStr, "payment.authorizedotnet.version");
         String delimited = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "delimitedData", configStr, "payment.authorizedotnet.delimited");
         String delimiter = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "delimiterChar", configStr, "payment.authorizedotnet.delimiter");
+        String cpVersion = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "cpVersion", configStr, "payment.authorizedotnet.cpVersion");
+        String cpMarketType = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "cpMarketType", configStr, "payment.authorizedotnet.cpMarketType");
+        String cpDeviceType = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "cpDeviceType", configStr, "payment.authorizedotnet.cpDeviceType");
         String method = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "method", configStr, "payment.authorizedotnet.method");
         String emailCustomer = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "emailCustomer", configStr, "payment.authorizedotnet.emailcustomer");
         String emailMerchant = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "emailMerchant", configStr, "payment.authorizedotnet.emailmerchant");
@@ -369,6 +375,10 @@ public class AIMPaymentServices {
                 ver = "3.0";
             }
         }
+        if (UtilValidate.isNotEmpty(cpMarketType) && UtilValidate.isEmpty(cpVersion)) {
+            cpVersion = "1.0";
+        }
+        
         Properties props = new Properties();
         props.put("url", url);
         props.put("certificateAlias", certificateAlias);
@@ -376,6 +386,9 @@ public class AIMPaymentServices {
         props.put("delimited", delimited);
         props.put("delimiter", delimiter);
         props.put("method", method);
+        props.put("cpVersion", cpVersion);
+        props.put("cpMarketType", cpMarketType);
+        props.put("cpDeviceType", cpDeviceType);
         props.put("emailCustomer", emailCustomer);
         props.put("emailMerchant", emailMerchant);
         props.put("testReq", testReq);
@@ -401,13 +414,48 @@ public class AIMPaymentServices {
         String trankey = props.getProperty("trankey");
         if (UtilValidate.isNotEmpty(trankey)) {
             AIMRequest.put("x_Tran_Key", props.getProperty("trankey"));
+        } else {
+            // only send password if no tran key
+            AIMRequest.put("x_Password",props.getProperty("password"));
+        }
+        
+        // api version (non Card Present)
+        String apiVersion = props.getProperty("ver");
+        if (UtilValidate.isNotEmpty(apiVersion)) {
+            AIMRequest.put("x_Version", props.getProperty("ver"));
+        }
+        
+        // CP version
+        String cpVersion = props.getProperty("cpver");
+        if (UtilValidate.isNotEmpty(cpVersion)) {
+            AIMRequest.put("x_cpversion", cpVersion);
+        }
+        
+        // CP market type
+        String cpMarketType = props.getProperty("cpMarketType");
+        if (UtilValidate.isNotEmpty(cpMarketType)) {
+            AIMRequest.put("x_market_type", cpMarketType);
+            
+            // CP test mode
+            if ("true".equalsIgnoreCase(props.getProperty("testReq"))) {
+                AIMRequest.put("x_test_request", props.getProperty("testReq"));                
+            }
         }
-        AIMRequest.put("x_Password",props.getProperty("password"));
-        AIMRequest.put("x_Version", props.getProperty("ver"));
+        
+        // CP device typ
+        String cpDeviceType = props.getProperty("cpDeviceType");
+        if (UtilValidate.isNotEmpty(cpDeviceType)) {
+            AIMRequest.put("x_device_type", cpDeviceType);
+        }                      
     }
 
     private static void buildGatewayResponeConfig(Map<String, Object> params, Properties props, Map<String, Object> AIMRequest) {
-        AIMRequest.put("x_Delim_Data", props.getProperty("delimited"));
+        if (AIMRequest.get("x_market_type") != null) {
+            // card present transaction
+            AIMRequest.put("x_response_format", "true".equalsIgnoreCase(props.getProperty("delimited")) ? "1" : "0");            
+        } else {
+            AIMRequest.put("x_Delim_Data", props.getProperty("delimited"));            
+        }
         AIMRequest.put("x_Delim_Char", props.getProperty("delimiter"));
     }
 
@@ -434,7 +482,7 @@ public class AIMPaymentServices {
                             AIMRequest.put("x_Zip", UtilFormatOut.checkNull(address.getString("postalCode")));
                             AIMRequest.put("x_Country", UtilFormatOut.checkNull(address.getString("countryGeoId")));
                         }
-                    }
+                    }                    
                 } else {
                     Debug.logWarning("Payment preference " + opp + " is not a credit card", module);
                 }
@@ -489,6 +537,9 @@ public class AIMPaymentServices {
         if (UtilValidate.isNotEmpty(cardSecurityCode)) {
             AIMRequest.put("x_card_code", cardSecurityCode);
         }
+        if (AIMRequest.get("x_market_type") != null) {
+            AIMRequest.put("x_card_type", getCardType(UtilFormatOut.checkNull(cc.getString("cardType"))));
+        }
     }
 
     private static void buildCaptureTransaction(Map<String, Object> params, Properties props, Map<String, Object> AIMRequest) {
@@ -506,6 +557,9 @@ public class AIMPaymentServices {
         AIMRequest.put("x_Exp_Date", expDate);
         AIMRequest.put("x_Trans_ID", at.get("referenceNum"));
         AIMRequest.put("x_Auth_Code", at.get("gatewayCode"));
+        if (AIMRequest.get("x_market_type") != null) {
+            AIMRequest.put("x_card_type", getCardType(UtilFormatOut.checkNull(cc.getString("cardType"))));
+        }
     }
 
     private static void buildRefundTransaction(Map<String, Object> params, Properties props, Map<String, Object> AIMRequest) {
@@ -523,6 +577,9 @@ public class AIMPaymentServices {
         AIMRequest.put("x_Exp_Date", expDate);
         AIMRequest.put("x_Trans_ID", at.get("referenceNum"));
         AIMRequest.put("x_Auth_Code", at.get("gatewayCode"));
+        if (AIMRequest.get("x_market_type") != null) {
+            AIMRequest.put("x_card_type", getCardType(UtilFormatOut.checkNull(cc.getString("cardType"))));
+        }
         Debug.logInfo("buildCaptureTransaction. " + at.toString(), module);
     }
 
@@ -550,11 +607,11 @@ public class AIMPaymentServices {
         results.put("authFlag", ar.getReasonCode());
         results.put("authMessage", ar.getReasonText());
         if (authResult.booleanValue()) { //passed
-            results.put("authCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
-            results.put("authRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
-            results.put("cvCode", ar.getResponseField(AuthorizeResponse.CID_RESPONSE_CODE));
-            results.put("avsCode", ar.getResponseField(AuthorizeResponse.AVS_RESULT_CODE));
-            results.put("processAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+            results.put("authCode", ar.getAuthorizationCode());
+            results.put("authRefNum", ar.getTransactionId());
+            results.put("cvCode", ar.getCvResult());
+            results.put("avsCode", ar.getAvsResult());
+            results.put("processAmount", ar.getAmount());
         } else {
             results.put("authCode", ar.getResponseCode());
             results.put("processAmount", BigDecimal.ZERO);
@@ -569,10 +626,10 @@ public class AIMPaymentServices {
         results.put("captureResult", new Boolean(captureResult.booleanValue()));
         results.put("captureFlag", ar.getReasonCode());
         results.put("captureMessage", ar.getReasonText());
-        results.put("captureRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
+        results.put("captureRefNum", ar.getTransactionId());
         if (captureResult.booleanValue()) { //passed
-            results.put("captureCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
-            results.put("captureAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+            results.put("captureCode", ar.getAuthorizationCode());
+            results.put("captureAmount", ar.getAmount());
         } else {
             results.put("captureAmount", BigDecimal.ZERO);
         }
@@ -586,10 +643,10 @@ public class AIMPaymentServices {
         results.put("refundResult", new Boolean(captureResult.booleanValue()));
         results.put("refundFlag", ar.getReasonCode());
         results.put("refundMessage", ar.getReasonText());
-        results.put("refundRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
+        results.put("refundRefNum", ar.getTransactionId());
         if (captureResult.booleanValue()) { //passed
-            results.put("refundCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
-            results.put("refundAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+            results.put("refundCode", ar.getAuthorizationCode());
+            results.put("refundAmount", ar.getAmount());
         } else {
             results.put("refundAmount", BigDecimal.ZERO);
         }
@@ -604,10 +661,10 @@ public class AIMPaymentServices {
         results.put("releaseResult", new Boolean(captureResult.booleanValue()));
         results.put("releaseFlag", ar.getReasonCode());
         results.put("releaseMessage", ar.getReasonText());
-        results.put("releaseRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
+        results.put("releaseRefNum", ar.getTransactionId());
         if (captureResult.booleanValue()) { //passed
-            results.put("releaseCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
-            results.put("releaseAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+            results.put("releaseCode", ar.getAuthorizationCode());
+            results.put("releaseAmount", ar.getAmount());
         } else {
             results.put("releaseAmount", BigDecimal.ZERO);
         }
@@ -624,13 +681,13 @@ public class AIMPaymentServices {
         results.put("captureResult", new Boolean(authResult.booleanValue()));
         results.put("captureFlag", ar.getReasonCode());
         results.put("captureMessage", ar.getReasonText());
-        results.put("captureRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
+        results.put("captureRefNum", ar.getTransactionId());
         if (authResult.booleanValue()) { //passed
-            results.put("authCode", ar.getResponseField(AuthorizeResponse.AUTHORIZATION_CODE));
-            results.put("authRefNum", ar.getResponseField(AuthorizeResponse.TRANSACTION_ID));
-            results.put("cvCode", ar.getResponseField(AuthorizeResponse.CID_RESPONSE_CODE));
-            results.put("avsCode", ar.getResponseField(AuthorizeResponse.AVS_RESULT_CODE));
-            results.put("processAmount", new BigDecimal(ar.getResponseField(AuthorizeResponse.AMOUNT)));
+            results.put("authCode", ar.getAuthorizationCode());
+            results.put("authRefNum", ar.getTransactionId());
+            results.put("cvCode", ar.getCvResult());
+            results.put("avsCode", ar.getAvsResult());
+            results.put("processAmount", ar.getAmount());
         } else {
             results.put("authCode", ar.getResponseCode());
             results.put("processAmount", BigDecimal.ZERO);
@@ -662,4 +719,14 @@ public class AIMPaymentServices {
         }
         return returnValue;
     }
+    
+    private static String getCardType(String cardType) {
+        if ((cardType.equalsIgnoreCase("VISA"))) return "V";
+        if ((cardType.equalsIgnoreCase("MASTERCARD"))) return "M";
+        if (((cardType.equalsIgnoreCase("AMERICANEXPRESS")) || (cardType.equalsIgnoreCase("AMEX")))) return "A";
+        if ((cardType.equalsIgnoreCase("DISCOVER"))) return "D";
+        if ((cardType.equalsIgnoreCase("JCB"))) return "J";
+        if (((cardType.equalsIgnoreCase("DINERSCLUB")))) return "C";        
+        return "";
+    }
 }

Added: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMRespPositions.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMRespPositions.java?rev=1033717&view=auto
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMRespPositions.java (added)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AIMRespPositions.java Wed Nov 10 21:21:24 2010
@@ -0,0 +1,34 @@
+package org.ofbiz.accounting.thirdparty.authorizedotnet;
+
+import java.util.Map;
+
+import javolution.util.FastMap;
+
+public class AIMRespPositions extends AuthorizeResponse.RespPositions {
+
+    private static Map<String, Integer> positions = FastMap.newInstance();
+    static {
+        positions.put(AuthorizeResponse.RESPONSE_CODE, 1);
+        positions.put(AuthorizeResponse.REASON_CODE, 3);
+        positions.put(AuthorizeResponse.REASON_TEXT, 4);
+        positions.put(AuthorizeResponse.AUTHORIZATION_CODE, 5);
+        positions.put(AuthorizeResponse.AVS_RESULT_CODE, 6);
+        positions.put(AuthorizeResponse.CVV_RESULT_CODE, 39);
+        positions.put(AuthorizeResponse.TRANSACTION_ID, 7);
+        positions.put(AuthorizeResponse.AMOUNT, 10);               
+    }
+    
+    @Override
+    public int getPosition(String name) {
+        if (positions.containsKey(name)) {
+            return positions.get(name);
+        } else {
+            return -1;
+        }              
+    }
+    
+    @Override
+    public String getApprovalString() {
+        return "APPROVED";
+    }
+}

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AuthorizeResponse.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AuthorizeResponse.java?rev=1033717&r1=1033716&r2=1033717&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AuthorizeResponse.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/AuthorizeResponse.java Wed Nov 10 21:21:24 2010
@@ -19,140 +19,114 @@
 
 package org.ofbiz.accounting.thirdparty.authorizedotnet;
 
+import java.math.BigDecimal;
 import java.util.*;
 
 import org.ofbiz.base.util.UtilValidate;
 
 public class AuthorizeResponse {
 
-    private String rawResp = null;
     private List<String> response = new ArrayList<String>();
-    private String respCode = "";
-    private String reasonCode = "";
-    private String reasonText = "";
-    private String version = "3.0";
-    private int maxPos = 39; //maximum number of field positions in response. there are more, but currently none are used.
-
-    //constant names for response fields
-    public static int RESPONSE_CODE           = 1;
-    public static int RESPONSE_SUBCODE        = 2;
-    public static int RESPONSE_REASON_CODE    = 3;
-    public static int RESPONSE_REASON_TEXT    = 4;
-    public static int APPROVAL_CODE           = 5;
-    public static int AUTHORIZATION_CODE      = 5;
-    public static int AVS_RESULT_CODE         = 6;
-    public static int TRANSACTION_ID          = 7;
-
-    // 8 - 37 echoed from request
-    public static int INVOICE_NUMBER          = 8;
-    public static int DESCRIPTION             = 9;
-    public static int AMOUNT                  = 10;
-    public static int METHOD                  = 11;
-    public static int TRANSACTION_TYPE        = 12;
-    public static int CUSTOMER_ID             = 13;
-    public static int CARDHOLDER_FIRST_NAME   = 14;
-    public static int CARDHOLDER_LAST_NAME    = 15;
-    public static int COMPANY                 = 16;
-    public static int BILLING_ADDRESS         = 17;
-    public static int CITY                    = 18;
-    public static int STATE                   = 19;
-    public static int ZIP                     = 20;
-    public static int COUNTRY                 = 21;
-    public static int PHONE                   = 22;
-    public static int FAX                     = 23;
-    public static int EMAIL                   = 24;
-    public static int SHIP_TO_FIRST_NAME      = 25;
-    public static int SHIP_TO_LAST_NAME       = 26;
-    public static int SHIP_TO_COMPANY         = 27;
-    public static int SHIP_TO_ADDRESS         = 28;
-    public static int SHIP_TO_CITY            = 29;
-    public static int SHIP_TO_STATE           = 30;
-    public static int SHIP_TO_ZIP             = 31;
-    public static int SHIP_TO_COUNTRY         = 32;
-    public static int TAX_AMOUNT              = 33;
-    public static int DUTY_AMOUNT             = 34;
-    public static int FREIGHT_AMOUNT          = 35;
-    public static int TAX_EXEMPT_FLAG         = 36;
-    public static int PO_NUMBER               = 37;
-    public static int MD5_HASH                = 38;
-    public static int CID_RESPONSE_CODE       = 39;
-    //public static int CAVV_RESPONSE_CODE    = 40;
-
-    //some other constants
-    public static String APPROVED = "Approved";
-    public static String DECLINED = "Declined";
-    public static String ERROR    = "Error";
-
-
-    public AuthorizeResponse(String resp) {
-        this(resp, "|");
+    private RespPositions pos;
+    private String rawResp;
+     
+    // response types
+    public static final int AIM_RESPONSE = 1;
+    public static final int CP_RESPONSE = 2;
+    
+    // status constants
+    public static final String APPROVED = "Approved";
+    public static final String DECLINED = "Declined";
+    public static final String ERROR    = "Error";
+    
+    // positions of the result
+    public static final String RESPONSE_CODE = "RESPONSE_CODE";
+    public static final String REASON_CODE = "REASON_CODE";
+    public static final String REASON_TEXT = "REASON_TEXT";
+    public static final String AUTHORIZATION_CODE = "AUTHORIZATION_CODE";
+    public static final String AVS_RESULT_CODE = "AVS_RESULT_CODE";
+    public static final String CVV_RESULT_CODE = "CVV_RESULT_CODE";
+    public static final String TRANSACTION_ID = "TRANSACTION_ID";
+    public static final String AMOUNT = "AMOUNT";    
+    
+    // singletons
+    private static final AIMRespPositions aimPos = new AIMRespPositions();
+    private static final CPRespPositions cpPos = new CPRespPositions();
+    
+    public AuthorizeResponse(String resp, int responseType) {
+        this(resp, "|", responseType);
     }
 
-    public AuthorizeResponse(String resp, String delim) {
+    public AuthorizeResponse(String resp, String delim, int responseType) {
         this.rawResp = resp;
         this.response = splitResp(resp, delim);
-        setApproval();
-    }
-
-    private void setApproval() {
-        String rc = response.get(RESPONSE_CODE);
-
-        if (rc.equals("1")) {
-            this.respCode = APPROVED;
-        }
-
-        if (rc.equals("2")) {
-            this.respCode = DECLINED;
+        if (responseType == CP_RESPONSE) {
+            pos = cpPos;
+        } else {
+            pos = aimPos;
         }
-
-        if (rc.equals("3")) {
-            this.respCode = ERROR;
-        }
-
-        this.reasonCode = response.get(RESPONSE_REASON_CODE);
-        this.reasonText = response.get(RESPONSE_REASON_TEXT);
-
     }
-
-    public void setVersion(String version)
-    {
-        if (UtilValidate.isNotEmpty(version))
-        {
-            if (version.equals("3.0") || version.equals("3.1"))
-                this.version = version;
-        }
-
+        
+    public boolean isApproved() {
+        return pos.getApprovalString().equals(getResponseCode());
     }
-
+    
+    public String getTransactionId() {
+        return getResponseField(TRANSACTION_ID);
+    }
+    
+    public String getAuthorizationCode() {
+        return getResponseField(AUTHORIZATION_CODE);
+    }
+    
     public String getResponseCode() {
-        return this.respCode;
+        return getResponseField(RESPONSE_CODE);
     }
 
     public String getReasonCode() {
-        return this.reasonCode;
+        return getResponseField(REASON_CODE);
     }
 
     public String getReasonText() {
-        return this.reasonText;
+        return getResponseField(REASON_TEXT);
     }
-
-    public String getResponseField(int posNum) {
-
-        if (this.version.equals("3.0"))
-        {
-            if (posNum == CID_RESPONSE_CODE)
-                return "M";
+    
+    public String getAvsResult() {
+        return getResponseField(AVS_RESULT_CODE);
+    }
+    
+    public String getCvResult() {
+        return getResponseField(CVV_RESULT_CODE);
+    }
+    
+    public BigDecimal getAmount() {
+        BigDecimal amount = BigDecimal.ZERO;
+        String amtStr = getResponseField(AMOUNT);
+        if (UtilValidate.isNotEmpty(amtStr) && !UtilValidate.isAlphabetic(amtStr)) {
+            amount = new BigDecimal(amtStr);
         }
-        if (posNum < 1 || posNum > maxPos) {
-            return "unknown_field";
-        }
-        return response.get(posNum);
+        return amount;
     }
-
+            
     public String getRawResponse() {
         return this.rawResp;
     }
 
+    private String getResponseField(String field) {
+        int position = pos.getPosition(field);
+        if (position == -1) 
+            return null;
+        return getResponseField(position);
+    }
+    
+    private String getResponseField(int position) {
+        if (response.size() < position) {
+            return null;
+        } else {
+            return response.get(position);
+        }
+    }
+    
     private List<String> splitResp(String r, String delim) {
         int s1=0, s2=-1;
         List<String> out = new ArrayList<String>(40);
@@ -179,5 +153,9 @@ public class AuthorizeResponse {
     public String toString() {
         return response.toString();
     }
-
+    
+    public static abstract class RespPositions {        
+        public abstract int getPosition(String name);
+        public abstract String getApprovalString();
+    }
 }

Added: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/CPRespPositions.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/CPRespPositions.java?rev=1033717&view=auto
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/CPRespPositions.java (added)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/authorizedotnet/CPRespPositions.java Wed Nov 10 21:21:24 2010
@@ -0,0 +1,34 @@
+package org.ofbiz.accounting.thirdparty.authorizedotnet;
+
+import java.util.Map;
+
+import javolution.util.FastMap;
+
+public class CPRespPositions extends AuthorizeResponse.RespPositions {
+    
+    private static Map<String, Integer> positions = FastMap.newInstance();
+    static {
+        positions.put(AuthorizeResponse.RESPONSE_CODE, 2);
+        positions.put(AuthorizeResponse.REASON_CODE, 3);
+        positions.put(AuthorizeResponse.REASON_TEXT, 4);
+        positions.put(AuthorizeResponse.AUTHORIZATION_CODE, 5);
+        positions.put(AuthorizeResponse.AVS_RESULT_CODE, 6);
+        positions.put(AuthorizeResponse.CVV_RESULT_CODE, 7);
+        positions.put(AuthorizeResponse.TRANSACTION_ID, 8);
+        positions.put(AuthorizeResponse.AMOUNT, 25);                
+    }
+    
+    @Override
+    public int getPosition(String name) {
+        if (positions.containsKey(name)) {
+            return positions.get(name);
+        } else {
+            return -1;
+        }
+    }
+    
+    @Override
+    public String getApprovalString() {
+        return "1";
+    }
+}

Modified: ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml?rev=1033717&r1=1033716&r2=1033717&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml (original)
+++ ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml Wed Nov 10 21:21:24 2010
@@ -158,13 +158,22 @@ under the License.
                 <option key="TRUE" description="${uiLabelMap.CommonTrue}"/>
                 <option key="FALSE" description="${uiLabelMap.CommonFalse}"/>
             </drop-down>
-        </field>
+        </field>        
         <field name="relayResponse" title="${uiLabelMap.AccountingAuthorizeNetRelayResponse}">
             <drop-down>
                 <option key="TRUE" description="${uiLabelMap.CommonTrue}"/>
                 <option key="FALSE" description="${uiLabelMap.CommonFalse}"/>
             </drop-down>
         </field>
+        <field name="cpVersion" title="${uiLabelMap.AccountingAuthorizeNetCpVersion}">
+            <text size="10" maxlength="10"/>
+        </field>
+        <field name="cpMarketType" title="${uiLabelMap.AccountingAuthorizeNetCpMarket}">
+            <text size="10" maxlength="10"/>
+        </field>
+        <field name="cpDeviceType" title="${uiLabelMap.AccountingAuthorizeNetCpDevice}">
+            <text size="10" maxlength="10"/>
+        </field>
         <field name="tranKey" title="${uiLabelMap.AccountingAuthorizeNetTransKey}">
             <text size="60" maxlength="60"/>
         </field>