svn commit: r806643 - in /ofbiz/trunk: applications/accounting/ applications/accounting/config/ applications/accounting/data/ applications/accounting/entitydef/ applications/accounting/servicedef/ applications/accounting/src/org/ofbiz/accounting/thirdp...

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

svn commit: r806643 - in /ofbiz/trunk: applications/accounting/ applications/accounting/config/ applications/accounting/data/ applications/accounting/entitydef/ applications/accounting/servicedef/ applications/accounting/src/org/ofbiz/accounting/thirdp...

ashish-18
Author: ashish
Date: Fri Aug 21 17:00:55 2009
New Revision: 806643

URL: http://svn.apache.org/viewvc?rev=806643&view=rev
Log:
First pass on Orbital Gateway: http://download.chasepaymentech.com/

Following things are covered in this implementation:

1) Services written for ccAuth, ccAuthCapture, ccAuthRelease, ccAuthRefund, ccCapture.
2) Instead of property files we have kept commonly used values in the entity - for this created new entity - PaymentGatewayOrbital.
3) The initialisation of "Configurator"(which is a class that is being used for the initialisation of configuration settings - like user credentials and many more things). For now configurator takes only file by name "linehandler.properties". So I have created new files by this name.
4) Also added demo data in ecommerce files so it can be used if someone want to use it for gateway purpose.
5) For now we have excluded the compilation of this gateway - I will provide an end user document for this soon so anybody would be able to configure it easily.

This is collaborative effort from me and following guys.

Scott Gray: Discussed so many things with me in the b/w this implementation. There were some security settings issue with jdk installation - Scott helped me in that area.
Anil  Patel & Tim Ruppert: Initial implementation plan discussed with Anil and there were so many things that I had discussed with Anil & Tim in b/w. Thanks Tim for encouraging us to put this gateway on OFBiz trunk so it could be used by larger audience.
Mridul & Sumit: I have asked these guys to see the results / outcome of implementation and asked them to provide their comments/ thoughts.

Thanks a lot guys for your help - it was simply awesome.

Suggestions and comments are most welcome - I will wait for them.
Thank you!

Added:
    ofbiz/trunk/applications/accounting/config/linehandler.properties   (with props)
    ofbiz/trunk/applications/accounting/servicedef/services_orbital.xml   (with props)
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/orbital/
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java   (with props)
Modified:
    ofbiz/trunk/applications/accounting/build.xml
    ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
    ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml
    ofbiz/trunk/applications/accounting/ofbiz-component.xml
    ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml

Modified: ofbiz/trunk/applications/accounting/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/build.xml?rev=806643&r1=806642&r2=806643&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/build.xml (original)
+++ ofbiz/trunk/applications/accounting/build.xml Fri Aug 21 17:00:55 2009
@@ -61,6 +61,7 @@
             <exclude name="org/ofbiz/accounting/thirdparty/verisign/**"/>
             <exclude name="org/ofbiz/accounting/thirdparty/cybersource/**"/>
             <exclude name="org/ofbiz/accounting/thirdparty/paypal/PayPalServices.java"/>
+            <exclude name="org/ofbiz/accounting/thirdparty/orbital/**"/>
         </javac15>
     </target>
 

Added: ofbiz/trunk/applications/accounting/config/linehandler.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/linehandler.properties?rev=806643&view=auto
==============================================================================
--- ofbiz/trunk/applications/accounting/config/linehandler.properties (added)
+++ ofbiz/trunk/applications/accounting/config/linehandler.properties Fri Aug 21 17:00:55 2009
@@ -0,0 +1,88 @@
+###############################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+###############################################################################
+
+##########################################################################
+# PaymentechSDK_6.3.0
+# Build Date: 06/26/2009
+# Build Time: 09:28:24
+##########################################################################
+
+##########################################################################
+# General Properties
+##########################################################################
+DTDVersion=PTI47
+
+##########################################################################
+# Transaction Processor Properties
+##########################################################################
+TransactionProcessor.poolSize=10
+TransactionProcessor.retries=2
+
+##########################################################################
+# Java Security Providers
+##########################################################################
+#security.provider.1=sun.security.provider.Sun
+#security.provider.2=com.sun.rsajca.Provider
+#security.provider.3=com.sun.net.ssl.internal.ssl.Provider
+
+##########################################################################
+# IBM Security Providers
+#For IBM JDK Websphere merchants
+#comment out or remove the above sun security provider list
+#uncomment the following IBM security provider  list
+#No need to have any sun related jar files in CLASSPATH for Orbital SDK
+##########################################################################
+#security.provider.1=com.ibm.crypto.provider.IBMJCE
+#security.provider.2=com.ibm.security.jgss.IBMJGSSProvider
+
+##########################################################################
+# Engine Properties
+##########################################################################
+
+# To specify a non-default location for your truststore (cacerts) file,
+# uncomment and edit these two lines
+#engine.ssl.trustore.filename=/opt/jdk1.6/jre/lib/security/cacerts
+#engine.ssl.trustore.passphrase=changeit
+
+
+##########################################################################
+# XML Templates Configuration
+##########################################################################
+
+# Templates
+XMLTemplates.Request.NewOrder=%ofbiz.home%/applications/accounting/templates/orbital/NewOrder.xml
+XMLTemplates.Request.EOD=%ofbiz.home%/applications/accounting/templates/orbital/EOD.xml
+XMLTemplates.Request.FlexCache=%ofbiz.home%/applications/accounting/templates/orbital/FlexCache.xml
+XMLTemplates.Request.MFC=%ofbiz.home%/applications/accounting/templates/orbital/MFC.xml
+XMLTemplates.Request.Profile=%ofbiz.home%/applications/accounting/templates/orbital/Profile.xml
+XMLTemplates.Request.Reverse=%ofbiz.home%/applications/accounting/templates/orbital/Reverse.xml
+XMLTemplates.Request.Inquiry=%ofbiz.home%/applications/accounting/templates/orbital/Inquiry.xml
+
+# Complex Type Mappings
+XMLTemplates.Request.ComplexRoot.PC3Core=%ofbiz.home%/applications/accounting/templates/orbital/templates/PC3Core.inc
+XMLTemplates.Request.ComplexRoot.PC3Core.RecursiveElement1=PC3LineItems
+XMLTemplates.Request.ComplexRoot.PC3Core.RecursiveElement1.CountElement=PC3LineItemCount
+XMLTemplates.Request.ComplexRoot.PC3Core.RecursiveElement1.EnforceGreaterThanZero=yes
+XMLTemplates.Request.ComplexRoot.PC3Core.RecursiveElement1.MaxCount=98
+
+XMLTemplates.Request.ComplexRoot.PC3LineItems=%ofbiz.home%/applications/accounting/templates/orbital/templates/PC3LineItems.inc
+XMLTemplates.Request.ComplexRoot.PC3LineItems.ChildIndexElement=PC3DtlIndex
+
+XMLTemplates.Request.ComplexRoot.SettleRejectBin=%ofbiz.home%/applications/accounting/templates/orbital/templates/SettleRejectBin.inc
+XMLTemplates.Request.ComplexRoot.PriorAuthID=%ofbiz.home%/applications/accounting/templates/orbital/templates/PriorAuthID.inc

Propchange: ofbiz/trunk/applications/accounting/config/linehandler.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/applications/accounting/config/linehandler.properties
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/applications/accounting/config/linehandler.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?rev=806643&r1=806642&r2=806643&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original)
+++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Fri Aug 21 17:00:55 2009
@@ -708,7 +708,11 @@
     <PaymentGatewayConfigType paymentGatewayConfigTypeId="WORLDPAY" hasTable="N" description="RBS WorldPay Payment Gateway"/>
     <PaymentGatewayConfig paymentGatewayConfigId="WORLDPAY_CONFIG" paymentGatewayConfigTypeId="WORLDPAY" description="RBS WorldPay Config"/>
     <PaymentGatewayWorldPay paymentGatewayConfigId="WORLDPAY_CONFIG" redirectUrl="https://select-test.worldpay.com/wcc/purchase" instId="" authMode="A" fixContact="N" hideContact="N" hideCurrency="N" langId="" noLanguageMenu="N" withDelivery="N" testMode="100"/>
-    
+
+    <PaymentGatewayConfigType paymentGatewayConfigTypeId="ORBITAL" hasTable="N" description="Orbital Payment Gateway"/>
+    <PaymentGatewayConfig paymentGatewayConfigId="ORBITAL_CONFIG" paymentGatewayConfigTypeId="ORBITAL" description="Orbital Config"/>
+    <PaymentGatewayOrbital paymentGatewayConfigId="ORBITAL_CONFIG" username="ofbizuser" password="ofbizpwd" merchantId="785240009879" class="com.paymentech.orbital.sdk.engine.https.HttpsEngine" hostName="orbitalvar1.paymentech.net" port="443" hostNameFailover="orbitalvar2.paymentech.net" portFailover="443" connectionTimeoutSeconds="90" readTimeoutSeconds="90" authorizationURI="/authorize" sdkVersion="PaymentechSDK_6.3.0" sslSocketFactory="default" responseType="gateway"/>
+        
     <!--  Credit Card methods by type -->
     <CustomMethodType customMethodTypeId="CC_AUTH" parentTypeId="" hasTable="N" description="Credit Card authorize methods"/>
     <CustomMethodType customMethodTypeId="CC_CAPTURE" parentTypeId="" hasTable="N" description="Credit Card capture methods"/>
@@ -754,6 +758,8 @@
     <CustomMethod customMethodId="CC_AUTH_ALWAYSBADNUM" customMethodTypeId="CC_AUTH" customMethodName="alwaysBadCardNumberCCProcessor" description="CC Always decline for bad card number"/>
     <CustomMethod customMethodId="CC_AUTH_ALWAYSFAIL" customMethodTypeId="CC_AUTH" customMethodName="alwaysBadCardNumberCCProcessor" description="CC Always fail"/>
     <CustomMethod customMethodId="CC_AUTH_CAPTURE_ALWA" customMethodTypeId="CC_AUTH" customMethodName="alwaysApproveWithCaptureCCProcessor" description="CC Always authorize and capture"/>
+    <CustomMethod customMethodId="CC_AUTH_ORBITAL" customMethodTypeId="CC_AUTH" customMethodName="orbitalCCAuth" description="CC Orbital authorize"/>    
+    <CustomMethod customMethodId="CC_AUTH_CAPTR_ORBTL" customMethodTypeId="CC_AUTH" customMethodName="orbitalCCAuthCapture" description="CC Orbital authorize and capture"/>    
     
     <CustomMethod customMethodId="CC_CAPTURE_TEST" customMethodTypeId="CC_CAPTURE" customMethodName="testCCCapture" description="CC Test capture"/>
     <CustomMethod customMethodId="CC_CAPTURE_REAUTH" customMethodTypeId="CC_CAPTURE" customMethodName="testCCCaptureWithReAuth" description="CC Test reauth capture"/>
@@ -765,6 +771,7 @@
     <CustomMethod customMethodId="CC_CAPTURE_PCCHARGE" customMethodTypeId="CC_CAPTURE" customMethodName="pcChargeCCCapture" description="CC PCCharge capture"/>
     <CustomMethod customMethodId="CC_CAPTURE_RITA" customMethodTypeId="CC_CAPTURE" customMethodName="ritaCCCapture" description="CC RiTA capture"/>
     <CustomMethod customMethodId="CC_CAPTURE_RITA_REMO" customMethodTypeId="CC_CAPTURE" customMethodName="ritaCCCaptureRemote" description="CC RiTA remote capture"/>
+    <CustomMethod customMethodId="CC_CAPTURE_ORBITAL" customMethodTypeId="CC_CAPTURE" customMethodName="orbitalCCCapture" description="CC Orbital capture"/>    
     
     <CustomMethod customMethodId="CC_REFUND_TEST" customMethodTypeId="CC_REFUND" customMethodName="testCCRefund" description="CC Test refund"/>
     <CustomMethod customMethodId="CC_REFUND_TEST_FAIL" customMethodTypeId="CC_REFUND" customMethodName="testCCRefundFailure" description="CC Test refund failure"/>
@@ -775,6 +782,7 @@
     <CustomMethod customMethodId="CC_REFUND_PCCHARGE" customMethodTypeId="CC_REFUND" customMethodName="pcChargeCCRefund" description="CC PCCharge refund"/>
     <CustomMethod customMethodId="CC_REFUND_RITA" customMethodTypeId="CC_REFUND" customMethodName="ritaCCRefund" description="CC RiTA refund"/>
     <CustomMethod customMethodId="CC_REFUND_RITA_REMOT" customMethodTypeId="CC_REFUND" customMethodName="ritaCCRefundRemote" description="CC RiTA remote refund"/>
+    <CustomMethod customMethodId="CC_REFUND_ORBITAL" customMethodTypeId="CC_REFUND" customMethodName="orbitalCCRefund" description="CC Orbital refund"/>    
     
     <CustomMethod customMethodId="CC_RELEASE_TEST" customMethodTypeId="CC_RELEASE" customMethodName="testCCRelease" description="CC Test release"/>
     <CustomMethod customMethodId="CC_RELEASE_AIM" customMethodTypeId="CC_RELEASE" customMethodName="aimCCRelease" description="CC Authorize dot net release"/>
@@ -784,6 +792,7 @@
     <CustomMethod customMethodId="CC_RELEASE_PCCHARGE" customMethodTypeId="CC_RELEASE" customMethodName="pcChargeCCRelease" description="CC PCCharge release"/>
     <CustomMethod customMethodId="CC_RELEASE_RITA" customMethodTypeId="CC_RELEASE" customMethodName="ritaCCRelease" description="CC RiTA release"/>
     <CustomMethod customMethodId="CC_RELEASE_RITA_REMO" customMethodTypeId="CC_RELEASE" customMethodName="ritaCCReleaseRemote" description="CC RiTA remote release"/>
+    <CustomMethod customMethodId="CC_RELEASE_ORBITAL" customMethodTypeId="CC_RELEASE" customMethodName="orbitalCCRelease" description="CC Orbital release"/>    
     
     <CustomMethod customMethodId="CC_CREDIT_AIM" customMethodTypeId="CC_CREDIT" customMethodName="aimCCCredit" description="CC Authorize dot net credit"/>
     <CustomMethod customMethodId="CC_CREDIT_CLEARCOMME" customMethodTypeId="CC_CREDIT" customMethodName="clearCommerceCCCredit" description="CC Clear Commerce credit"/>

Modified: ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml?rev=806643&r1=806642&r2=806643&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml Fri Aug 21 17:00:55 2009
@@ -3223,6 +3223,30 @@
         <key-map field-name="paymentGatewayConfigId"/>
       </relation>
     </entity>
+    <entity entity-name="PaymentGatewayOrbital"
+            package-name="org.ofbiz.accounting.payment"
+            title="Orbital Payment Gateway Config">
+      <field name="paymentGatewayConfigId" type="id-ne"></field>
+      <field name="username" type="short-varchar"><description>Orbital Username of account information</description></field>
+      <field name="password" type="value" encrypt="true"><description>Orbital Password of account information</description></field>
+      <field name="merchantId" type="value"><description>You merchant ID</description></field>
+      <field name="class" type="value"><description>Class for the Orbital Gateway - Default should be used - HttpsEngine</description></field>
+      <field name="hostName" type="value"><description>Address of the payment processor</description></field>
+      <field name="port" type="numeric"><description>Port of the payment processor</description></field>
+      <field name="hostNameFailover" type="value"><description>Failover Address of the payment processor</description></field>
+      <field name="portFailover" type="numeric"><description>Failover Port of the payment processor</description></field>
+      <field name="connectionTimeoutSeconds" type="numeric"><description>Timeout</description></field>
+      <field name="readTimeoutSeconds" type="numeric"><description>Read Timeout</description></field>
+      <field name="authorizationURI" type="value"><description>Authorization URI</description></field>
+      <field name="sdkVersion" type="short-varchar"><description>Target Orbital Gateway API version</description></field>
+      <field name="sslSocketFactory" type="short-varchar"><description>SSL Socket Factory (default|strict)</description></field>
+      <field name="responseType" type="short-varchar"><description>Response Type (gateway|host)</description></field>
+      <prim-key field="paymentGatewayConfigId"/>
+      <relation type="one" fk-name="PGORB_PGC" rel-entity-name="PaymentGatewayConfig">
+        <key-map field-name="paymentGatewayConfigId"/>
+      </relation>
+    </entity>
+    
     <entity entity-name="PaymentGatewayRespMsg"
             package-name="org.ofbiz.accounting.payment"
             title="Payment Gateway Response Message">

Modified: ofbiz/trunk/applications/accounting/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/ofbiz-component.xml?rev=806643&r1=806642&r2=806643&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/ofbiz-component.xml (original)
+++ ofbiz/trunk/applications/accounting/ofbiz-component.xml Fri Aug 21 17:00:55 2009
@@ -74,6 +74,7 @@
     <service-resource type="model" loader="main" location="servicedef/services_rita.xml"/>
     <service-resource type="model" loader="main" location="servicedef/services_valuelink.xml"/>
     <service-resource type="model" loader="main" location="servicedef/services_verisign.xml"/>
+    <service-resource type="model" loader="main" location="servicedef/services_orbital.xml"/>
 
     <service-resource type="group" loader="main" location="servicedef/groups.xml"/>
     <service-resource type="eca" loader="main" location="servicedef/secas.xml"/>

Added: ofbiz/trunk/applications/accounting/servicedef/services_orbital.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_orbital.xml?rev=806643&view=auto
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_orbital.xml (added)
+++ ofbiz/trunk/applications/accounting/servicedef/services_orbital.xml Fri Aug 21 17:00:55 2009
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/services.xsd">
+    <description>OrbitalGateway Services</description>
+    <vendor></vendor>
+    <version>1.0</version>
+
+    <!-- Chase Orbital Implementations -->
+    <service name="orbitalCCAuth" engine="java"
+            location="org.ofbiz.accounting.thirdparty.orbital.OrbitalPaymentServices" invoke="ccAuth">
+        <description>Orbital Payment Authorization</description>
+        <implements service="ccAuthInterface"/>
+    </service>
+    <service name="orbitalCCAuthCapture" engine="java"
+            location="org.ofbiz.accounting.thirdparty.orbital.OrbitalPaymentServices" invoke="ccAuthCapture">
+        <description>Orbital Payment Authorize and Capture service</description>
+        <implements service="ccAuthInterface"/>
+    </service>
+    <service name="orbitalCCCapture" engine="java"
+            location="org.ofbiz.accounting.thirdparty.orbital.OrbitalPaymentServices" invoke="ccCapture">
+        <description>Orbital Payment Capture Service</description>
+        <implements service="ccCaptureInterface"/>
+    </service>
+    <service name="orbitalCCRefund" engine="java"
+            location="org.ofbiz.accounting.thirdparty.orbital.OrbitalPaymentServices" invoke="ccRefund">
+        <description>Orbital Payment Refund Service</description>
+        <implements service="paymentRefundInterface"/>
+    </service>
+    <service name="orbitalCCRelease" engine="java"
+            location="org.ofbiz.accounting.thirdparty.orbital.OrbitalPaymentServices" invoke="ccRelease">
+        <description>Orbital Payment Release Service</description>
+        <implements service="paymentReleaseInterface"/>
+    </service>
+
+</services>

Propchange: ofbiz/trunk/applications/accounting/servicedef/services_orbital.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/applications/accounting/servicedef/services_orbital.xml
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/applications/accounting/servicedef/services_orbital.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java?rev=806643&view=auto
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java (added)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java Fri Aug 21 17:00:55 2009
@@ -0,0 +1,647 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.accounting.thirdparty.orbital;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+import javolution.util.FastMap;
+
+import org.ofbiz.accounting.payment.PaymentGatewayServices;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilFormatOut;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilNumber;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.service.ServiceUtil;
+
+import com.paymentech.orbital.sdk.configurator.Configurator;
+import com.paymentech.orbital.sdk.interfaces.RequestIF;
+import com.paymentech.orbital.sdk.interfaces.ResponseIF;
+import com.paymentech.orbital.sdk.interfaces.TransactionProcessorIF;
+import com.paymentech.orbital.sdk.request.FieldNotFoundException;
+import com.paymentech.orbital.sdk.request.Request;
+import com.paymentech.orbital.sdk.transactionProcessor.TransactionException;
+import com.paymentech.orbital.sdk.transactionProcessor.TransactionProcessor;
+import com.paymentech.orbital.sdk.util.exceptions.InitializationException;
+
+public class OrbitalPaymentServices {
+
+    public static String module = OrbitalPaymentServices.class.getName();
+    private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
+    private static int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
+
+    public static String APPROVED = "Approved";
+    public static String DECLINED = "Declined";
+    public static String ERROR    = "Error";
+    
+    public static final String BIN_VALUE = "000002";
+    public static TransactionProcessorIF tp = null;
+    public static ResponseIF response = null;
+    public static RequestIF request = null;
+    
+    public static Map<String, Object> ccAuth(DispatchContext ctx, Map<String, Object> context) {
+        GenericDelegator delegator = ctx.getDelegator();
+        Map<String, Object> results = ServiceUtil.returnSuccess();
+        Map<String, Object> props = buildOrbitalProperties(context, delegator);
+        props.put("transType", "AUTH_ONLY");
+        //Tell the request object which template to use (see RequestIF.java)
+        try {
+            request = new Request(RequestIF.NEW_ORDER_TRANSACTION);
+        } catch (InitializationException e) {
+            Debug.logError("Error in request initialization", module);            
+            e.printStackTrace();
+        }
+        buildAuthOrAuthCaptureTransaction(context, delegator, props, request, results);
+        Map<String, Object> validateResults = validateRequest(context, props, request);
+        String respMsg = (String) validateResults.get(ModelService.RESPONSE_MESSAGE);
+        if (ModelService.RESPOND_ERROR.equals(respMsg)) {
+            results.put(ModelService.ERROR_MESSAGE, "Validation Failed - invalid values");
+            return results;
+        }
+        initializeTransactionProcessor();
+        Map<String, Object> processCardResponseContext = processCard(request);
+        // For Debugging Purpose
+        printTransResult((ResponseIF) processCardResponseContext.get("processCardResponse"));
+        processAuthTransResult(processCardResponseContext, results);
+        return results;
+    }
+    
+    public static Map<String, Object> ccAuthCapture(DispatchContext ctx, Map<String, Object> context) {
+        GenericDelegator delegator = ctx.getDelegator();
+        Map<String, Object> results = ServiceUtil.returnSuccess();
+        Map<String, Object> props = buildOrbitalProperties(context, delegator);
+        props.put("transType", "AUTH_CAPTURE");
+        //Tell the request object which template to use (see RequestIF.java)
+        try {
+            request = new Request(RequestIF.NEW_ORDER_TRANSACTION);
+        } catch (InitializationException e) {
+            Debug.logError("Error in request initialization", module);            
+            e.printStackTrace();
+        }
+        buildAuthOrAuthCaptureTransaction(context, delegator, props, request, results);
+        Map<String, Object> validateResults = validateRequest(context, props, request);
+        String respMsg = (String) validateResults.get(ModelService.RESPONSE_MESSAGE);
+        if (ModelService.RESPOND_ERROR.equals(respMsg)) {
+            results.put(ModelService.ERROR_MESSAGE, "Validation Failed - invalid values");
+            return results;
+        }
+        initializeTransactionProcessor();
+        Map<String, Object> processCardResponseContext = processCard(request);
+        // For Debugging Purpose
+        printTransResult((ResponseIF) processCardResponseContext.get("processCardResponse"));
+        processAuthCaptureTransResult(processCardResponseContext, results);
+        return results;
+    }
+
+    public static Map<String, Object> ccCapture(DispatchContext ctx, Map<String, Object> context) {
+        GenericDelegator delegator = ctx.getDelegator();
+        Map<String, Object> results = ServiceUtil.returnSuccess();
+        Map<String, Object> props = buildOrbitalProperties(context, delegator);
+        
+        GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
+        GenericValue creditCard = null;
+        try {
+            creditCard = delegator.getRelatedOne("CreditCard",orderPaymentPreference);
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError("Unable to obtain cc information from payment preference");
+        }
+        GenericValue authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
+        if (authTransaction == null) {
+            return ServiceUtil.returnError("No authorization transaction found for the OrderPaymentPreference; cannot Capture");
+        }
+        context.put("creditCard", creditCard);
+        context.put("authTransaction", authTransaction);
+        context.put("orderId", orderPaymentPreference.getString("orderId"));
+        
+        props.put("transType", "PRIOR_AUTH_CAPTURE");
+        //Tell the request object which template to use (see RequestIF.java)
+        try {
+            request = new Request(RequestIF.MARK_FOR_CAPTURE_TRANSACTION);
+        } catch (InitializationException e) {
+            Debug.logError("Error in request initialization", module);            
+            e.printStackTrace();
+        }
+        buildCaptureTransaction(context, delegator, props, request, results);
+        Map<String, Object> validateResults = validateRequest(context, props, request);
+        String respMsg = (String) validateResults.get(ModelService.RESPONSE_MESSAGE);
+        if (ModelService.RESPOND_ERROR.equals(respMsg)) {
+            results.put(ModelService.ERROR_MESSAGE, "Validation Failed - invalid values");
+            return results;
+        }
+        initializeTransactionProcessor();
+        Map<String, Object> processCardResponseContext = processCard(request);
+        // For Debugging Purpose
+        printTransResult((ResponseIF) processCardResponseContext.get("processCardResponse"));
+        processCaptureTransResult(processCardResponseContext, results);
+        return results;
+    }
+
+    public static Map<String, Object> ccRefund(DispatchContext ctx, Map<String, Object> context) {
+        GenericDelegator delegator = ctx.getDelegator();
+        Map<String, Object> results = ServiceUtil.returnSuccess();
+        Map<String, Object> props = buildOrbitalProperties(context, delegator);
+        GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
+        GenericValue creditCard = null;
+        try {
+            creditCard = delegator.getRelatedOne("CreditCard",orderPaymentPreference);
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError("Unable to obtain cc information from payment preference");
+        }
+        GenericValue authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
+        if (authTransaction == null) {
+            return ServiceUtil.returnError("No authorization transaction found for the OrderPaymentPreference; cannot refund");
+        }
+        context.put("creditCard", creditCard);
+        context.put("authTransaction", authTransaction);
+        context.put("orderId", orderPaymentPreference.getString("orderId"));
+        
+        //Tell the request object which template to use (see RequestIF.java)
+        try {
+            request = new Request(RequestIF.NEW_ORDER_TRANSACTION);
+        } catch (InitializationException e) {
+            Debug.logError("Error in request initialization", module);            
+            e.printStackTrace();
+        }
+        buildRefundTransaction(context, props, request, results);
+        Map<String, Object> validateResults = validateRequest(context, props, request);
+        String respMsg = (String) validateResults.get(ModelService.RESPONSE_MESSAGE);
+        if (ModelService.RESPOND_ERROR.equals(respMsg)) {
+            results.put(ModelService.ERROR_MESSAGE, "Validation Failed - invalid values");
+            return results;
+        }
+        initializeTransactionProcessor();
+        Map<String, Object> processCardResponseContext = processCard(request);
+        // For Debugging Purpose
+        printTransResult((ResponseIF) processCardResponseContext.get("processCardResponse"));
+        processRefundTransResult(processCardResponseContext, results);
+        return results;
+    }
+    
+    public static Map<String, Object> ccRelease(DispatchContext ctx, Map<String, Object> context) {
+        GenericDelegator delegator = ctx.getDelegator();
+        Map<String, Object> results = ServiceUtil.returnSuccess();
+        Map<String, Object> props = buildOrbitalProperties(context, delegator);
+        
+        GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
+        GenericValue creditCard = null;
+        try {
+            creditCard = delegator.getRelatedOne("CreditCard",orderPaymentPreference);
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError("Unable to obtain cc information from payment preference");
+        }
+        GenericValue authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
+        if (authTransaction == null) {
+            return ServiceUtil.returnError("No authorization transaction found for the OrderPaymentPreference; cannot release");
+        }
+        context.put("authTransaction", authTransaction);
+        context.put("orderId", orderPaymentPreference.getString("orderId"));
+        
+        //Tell the request object which template to use (see RequestIF.java)
+        try {
+            request = new Request(RequestIF.REVERSE_TRANSACTION);
+        } catch (InitializationException e) {
+            Debug.logError("Error in request initialization", module);            
+            e.printStackTrace();
+        }
+        buildReleaseTransaction(context, delegator, props, request, results);
+        Map<String, Object> validateResults = validateRequest(context, props, request);
+        String respMsg = (String) validateResults.get(ModelService.RESPONSE_MESSAGE);
+        if (ModelService.RESPOND_ERROR.equals(respMsg)) {
+            results.put(ModelService.ERROR_MESSAGE, "Validation Failed - invalid values");
+            return results;
+        }
+        initializeTransactionProcessor();
+        Map<String, Object> processCardResponseContext = processCard(request);
+        // For Debugging Purpose
+        printTransResult((ResponseIF) processCardResponseContext.get("processCardResponse"));
+        processReleaseTransResult(processCardResponseContext, results);
+        return results;
+    }
+    
+    
+    private static Map<String, Object> buildOrbitalProperties(Map<String, Object> context, GenericDelegator delegator) {
+        //TODO: Will move this to property file and then will read it from there.
+        String configFile = "/applications/accounting/config/linehandler.properties";
+        String paymentGatewayConfigId = (String) context.get("paymentGatewayConfigId");
+        Map<String, Object> buildConfiguratorContext = FastMap.newInstance();
+        try {
+            buildConfiguratorContext.put("OrbitalConnectionUsername", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "username"));
+            buildConfiguratorContext.put("OrbitalConnectionPassword", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "password"));
+            buildConfiguratorContext.put("merchantId", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "merchantId"));
+            buildConfiguratorContext.put("engine.class", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "class"));
+            buildConfiguratorContext.put("engine.hostname", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "hostName"));
+            buildConfiguratorContext.put("engine.port", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "port"));
+            buildConfiguratorContext.put("engine.hostname.failover", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "hostNameFailover"));
+            buildConfiguratorContext.put("engine.port.failover", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "portFailover"));
+            buildConfiguratorContext.put("engine.connection_timeout_seconds", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "connectionTimeoutSeconds"));
+            buildConfiguratorContext.put("engine.read_timeout_seconds", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "readTimeoutSeconds"));
+            buildConfiguratorContext.put("engine.authorizationURI", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "authorizationURI"));
+            buildConfiguratorContext.put("engine.sdk_version", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "sdkVersion"));
+            buildConfiguratorContext.put("engine.ssl.socketfactory", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "sslSocketFactory"));
+            buildConfiguratorContext.put("Response.response_type", getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "responseType"));
+            String configFileLocation = System.getProperty("ofbiz.home") + configFile;
+            Configurator config = Configurator.getInstance(configFileLocation);
+            buildConfiguratorContext.putAll(config.getConfigurations());
+            config.setConfigurations(buildConfiguratorContext);
+        } catch (InitializationException e) {
+            Debug.logError("Orbital Configurator Initialization Error: " + e.getMessage(), module);
+            e.printStackTrace();
+        }
+        return buildConfiguratorContext;
+    }
+
+    private static String getPaymentGatewayConfigValue(GenericDelegator delegator, String paymentGatewayConfigId,
+            String paymentGatewayConfigParameterName) {
+        String returnValue = "";
+        if (UtilValidate.isNotEmpty(paymentGatewayConfigId)) {
+            try {
+                GenericValue paymentGatewayOrbital = delegator.findOne("PaymentGatewayOrbital", UtilMisc.toMap("paymentGatewayConfigId", paymentGatewayConfigId), false);
+                if (UtilValidate.isNotEmpty(paymentGatewayOrbital)) {
+                    Object paymentGatewayOrbitalField = paymentGatewayOrbital.get(paymentGatewayConfigParameterName);
+                    if (UtilValidate.isNotEmpty(paymentGatewayOrbitalField)) {
+                        return returnValue = paymentGatewayOrbitalField.toString().trim();
+                    }
+                }
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+            }
+        }
+        return returnValue;
+    }
+
+    private static void buildAuthOrAuthCaptureTransaction(Map<String, Object> params, GenericDelegator delegator, Map<String, Object> props, RequestIF request, Map<String, Object> results) {
+        GenericValue cc = (GenericValue) params.get("creditCard");
+        BigDecimal amount = (BigDecimal) params.get("processAmount");
+        String amountValue = amount.setScale(decimals, rounding).movePointRight(2).toPlainString();
+        String number = UtilFormatOut.checkNull(cc.getString("cardNumber"));
+        String expDate = UtilFormatOut.checkNull(cc.getString("expireDate"));
+        expDate = formatExpDateForOrbital(expDate);
+        String cardSecurityCode = (String) params.get("cardSecurityCode");
+        String orderId = UtilFormatOut.checkNull((String)params.get("orderId"));
+        String transType = props.get("transType").toString();
+        String messageType = null;
+        if ("AUTH_ONLY".equals(transType)) {
+            messageType = "A";
+        } else if ("AUTH_CAPTURE".equals(transType)) {
+            messageType = "AC";
+        }
+        try {
+            request.setFieldValue("IndustryType", "EC");
+            request.setFieldValue("MessageType", UtilFormatOut.checkNull(messageType));
+            request.setFieldValue("MerchantID", UtilFormatOut.checkNull(props.get("merchantId").toString()));
+            request.setFieldValue("BIN", BIN_VALUE);
+            request.setFieldValue("OrderID", UtilFormatOut.checkNull(orderId));
+            request.setFieldValue("AccountNum", UtilFormatOut.checkNull(number));
+            
+            request.setFieldValue("Amount", UtilFormatOut.checkNull(amountValue));
+            request.setFieldValue("Exp", UtilFormatOut.checkNull(expDate));
+            // AVS Information
+            GenericValue creditCard = null;
+            if (params.get("orderPaymentPreference") != null) {
+                GenericValue opp = (GenericValue) params.get("orderPaymentPreference");
+                if ("CREDIT_CARD".equals(opp.getString("paymentMethodTypeId"))) {
+                    // sometimes the ccAuthCapture interface is used, in which case the creditCard is passed directly
+                     creditCard = (GenericValue) params.get("creditCard");
+                    if (creditCard == null || ! (opp.get("paymentMethodId").equals(creditCard.get("paymentMethodId")))) {
+                        creditCard = opp.getRelatedOne("CreditCard");
+                    }
+                }
+                
+                request.setFieldValue("AVSname", "Demo Customer");
+                if (UtilValidate.isNotEmpty(creditCard.getString("contactMechId"))) {
+                    GenericValue address = creditCard.getRelatedOne("PostalAddress");
+                    if (address != null) {
+                        request.setFieldValue("AVSaddress1", UtilFormatOut.checkNull(address.getString("address1")));
+                        request.setFieldValue("AVScity", UtilFormatOut.checkNull(address.getString("city")));
+                        request.setFieldValue("AVSstate", UtilFormatOut.checkNull(address.getString("stateProvinceGeoId")));
+                        request.setFieldValue("AVSzip", UtilFormatOut.checkNull(address.getString("postalCode")));
+                    }
+                }
+            } else {
+                // this would be the case for an authorization
+                GenericValue cp = (GenericValue)params.get("billToParty");
+                GenericValue ba = (GenericValue)params.get("billingAddress");
+                request.setFieldValue("AVSname", UtilFormatOut.checkNull(cp.getString("firstName")) + UtilFormatOut.checkNull(cp.getString("lastName")));
+                request.setFieldValue("AVSaddress1", UtilFormatOut.checkNull(ba.getString("address1")));
+                request.setFieldValue("AVScity", UtilFormatOut.checkNull(ba.getString("city")));
+                request.setFieldValue("AVSstate", UtilFormatOut.checkNull(ba.getString("stateProvinceGeoId")));
+                request.setFieldValue("AVSzip", UtilFormatOut.checkNull(ba.getString("postalCode")));
+                request.setFieldValue("AVSCountryCode", UtilFormatOut.checkNull(ba.getString("countryGeoId")));
+            }
+            // Additional Information
+            request.setFieldValue("Comments", "This is building of request object");
+            String shippingRef = getShippingRefForOrder(orderId, delegator);
+            request.setFieldValue("ShippingRef", shippingRef);
+            request.setFieldValue("CardSecVal", UtilFormatOut.checkNull(cardSecurityCode));
+
+            //Display the request
+            if ("AUTH_ONLY".equals(transType)) {
+                Debug.log("\nAuth Request:\n ======== " + request.getXML());
+            } else if ("AUTH_CAPTURE".equals(transType)) {
+                Debug.log("\nAuth Capture Request:\n ======== " + request.getXML());
+            }
+            results.put("processAmount", amount);
+        } catch (InitializationException ie) {
+            Debug.logInfo("Unable to initialize request object", module);
+        } catch (FieldNotFoundException fnfe) {
+            Debug.logError("Unable to find XML field in template", module);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static void buildCaptureTransaction(Map<String, Object> params, GenericDelegator delegator, Map<String, Object> props, RequestIF request, Map<String, Object> results) {
+        GenericValue authTransaction = (GenericValue) params.get("authTransaction");
+        GenericValue creditCard = (GenericValue) params.get("creditCard");
+        BigDecimal amount = (BigDecimal) params.get("captureAmount");
+        String amountValue = amount.setScale(decimals, rounding).movePointRight(2).toPlainString();
+        String orderId = UtilFormatOut.checkNull((String)params.get("orderId"));
+        try {
+            //If there were no errors preparing the template, we can now specify the data
+            //Basic Auth Fields
+            request.setFieldValue("MerchantID", UtilFormatOut.checkNull(props.get("merchantId").toString()));
+            request.setFieldValue("BIN", BIN_VALUE);
+            request.setFieldValue("TxRefNum", UtilFormatOut.checkNull(authTransaction.get("referenceNum").toString()));
+            request.setFieldValue("OrderID", UtilFormatOut.checkNull(orderId));
+            request.setFieldValue("Amount", UtilFormatOut.checkNull(amountValue));
+          
+            request.setFieldValue("PCDestName", UtilFormatOut.checkNull(creditCard.getString("firstNameOnCard") + creditCard.getString("lastNameOnCard")));
+            if (UtilValidate.isNotEmpty(creditCard.getString("contactMechId"))) {
+                GenericValue address = creditCard.getRelatedOne("PostalAddress");
+                if (address != null) {
+                    request.setFieldValue("PCOrderNum", UtilFormatOut.checkNull(orderId));
+                    request.setFieldValue("PCDestAddress1", UtilFormatOut.checkNull(address.getString("address1")));
+                    request.setFieldValue("PCDestAddress2", UtilFormatOut.checkNull(address.getString("address2")));
+                    request.setFieldValue("PCDestCity", UtilFormatOut.checkNull(address.getString("city")));
+                    request.setFieldValue("PCDestState", UtilFormatOut.checkNull(address.getString("stateProvinceGeoId")));
+                    request.setFieldValue("PCDestZip", UtilFormatOut.checkNull(address.getString("postalCode")));
+                }
+            }    
+            //Display the request
+            Debug.log("\nCapture Request:\n ======== " + request.getXML());
+            results.put("captureAmount", amount);
+        } catch (InitializationException ie) {
+            Debug.logInfo("Unable to initialize request object", module);
+        } catch (FieldNotFoundException fnfe) {
+            Debug.logError("Unable to find XML field in template" + fnfe.getMessage(), module);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static void buildRefundTransaction(Map<String, Object> params, Map<String, Object> props, RequestIF request, Map<String, Object> results) {
+        GenericValue cc = (GenericValue) params.get("creditCard");
+        BigDecimal amount = (BigDecimal) params.get("refundAmount");
+        String amountValue = amount.setScale(decimals, rounding).movePointRight(2).toPlainString();
+        String number = UtilFormatOut.checkNull(cc.getString("cardNumber"));
+        String expDate = UtilFormatOut.checkNull(cc.getString("expireDate"));
+        expDate = formatExpDateForOrbital(expDate);
+        String orderId = UtilFormatOut.checkNull((String)params.get("orderId"));
+        try {
+            //If there were no errors preparing the template, we can now specify the data
+            //Basic Auth Fields
+            request.setFieldValue("IndustryType", "EC");
+            request.setFieldValue("MessageType", "R");
+            request.setFieldValue("MerchantID", UtilFormatOut.checkNull(props.get("merchantId").toString()));
+            request.setFieldValue("BIN", BIN_VALUE);
+            request.setFieldValue("OrderID", UtilFormatOut.checkNull(orderId));
+            request.setFieldValue("AccountNum", UtilFormatOut.checkNull(number));
+            request.setFieldValue("Amount", UtilFormatOut.checkNull(amountValue));
+            request.setFieldValue("Exp", UtilFormatOut.checkNull(expDate));
+            request.setFieldValue("Comments", "This is a credit card refund");
+            
+            Debug.log("\nRefund Request:\n ======== " + request.getXML());
+            results.put("refundAmount", amount);
+        } catch (InitializationException ie) {
+            Debug.logInfo("Unable to initialize request object", module);
+        } catch (FieldNotFoundException fnfe) {
+            Debug.logError("Unable to find XML field in template", module);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    private static void buildReleaseTransaction(Map<String, Object> params, GenericDelegator delegator, Map<String, Object> props, RequestIF request, Map<String, Object> results) {
+        BigDecimal amount = (BigDecimal) params.get("releaseAmount");
+        GenericValue authTransaction = (GenericValue) params.get("authTransaction");
+        String orderId = UtilFormatOut.checkNull((String)params.get("orderId"));
+        try {
+            //If there were no errors preparing the template, we can now specify the data
+            //Basic Auth Fields
+            request.setFieldValue("MerchantID", UtilFormatOut.checkNull(props.get("merchantId").toString()));
+            request.setFieldValue("BIN", BIN_VALUE);
+            request.setFieldValue("TxRefNum", UtilFormatOut.checkNull(authTransaction.get("referenceNum").toString()));
+            request.setFieldValue("OrderID", UtilFormatOut.checkNull(orderId));
+          
+            //Display the request
+            Debug.log("\nRelease Request:\n ======== " + request.getXML());
+            results.put("releaseAmount", amount);
+        } catch (InitializationException ie) {
+            Debug.logInfo("Unable to initialize request object", module);
+        } catch (FieldNotFoundException fnfe) {
+            Debug.logError("Unable to find XML field in template" + fnfe.getMessage(), module);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    
+    private static void initializeTransactionProcessor() {
+        //Create a Transaction Processor
+        //The Transaction Processor acquires and releases resources and executes transactions.
+        //It configures a pool of protocol engines, then uses the pool to execute transactions.
+        try {
+            tp = new TransactionProcessor();
+        } catch (InitializationException iex) {
+            Debug.logError("TransactionProcessor failed to initialize" + iex.getMessage(), module);
+            iex.printStackTrace();
+        }
+    }
+    
+    private static Map<String, Object> processCard(RequestIF request) {
+        Map<String, Object> processCardResult = FastMap.newInstance();
+        try {
+            response = tp.process(request);
+            if (response.isApproved()) {
+                processCardResult.put("authResult", Boolean.TRUE);
+            } else {
+                processCardResult.put("authResult", Boolean.FALSE);
+            }
+            processCardResult.put("processCardResponse", response);
+        } catch (TransactionException tex) {
+            Debug.logError("TransactionProcessor failed to initialize" + tex.getMessage(), module);
+            tex.printStackTrace();
+        }
+        processCardResult.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
+        return processCardResult;
+    }
+    
+    private static void processAuthTransResult(Map<String, Object> processCardResponseContext, Map<String, Object> results) {
+        ResponseIF response = (ResponseIF) processCardResponseContext.get("processCardResponse");
+        Boolean authResult = (Boolean) processCardResponseContext.get("authResult");
+        results.put("authResult", new Boolean(authResult.booleanValue()));
+        results.put("authFlag", response.getResponseCode());
+        results.put("authMessage", response.getMessage());
+        if (authResult.booleanValue()) { //passed
+            results.put("authCode", response.getAuthCode());
+            results.put("authRefNum", response.getTxRefNum());
+            results.put("cvCode", UtilFormatOut.checkNull(response.getCVV2RespCode()));
+            results.put("avsCode", response.getAVSResponseCode());
+            results.put("processAmount", new BigDecimal(results.get("processAmount").toString()));
+        } else {
+            results.put("authCode", response.getAuthCode());
+            results.put("processAmount", new BigDecimal("0.00"));
+            results.put("authRefNum", OrbitalPaymentServices.ERROR);
+        }
+        Debug.logInfo("processAuthTransResult: " + results.toString(),module);
+    }
+
+    private static void processAuthCaptureTransResult(Map<String, Object> processCardResponseContext, Map<String, Object> results) {
+        ResponseIF response = (ResponseIF) processCardResponseContext.get("processCardResponse");
+        Boolean authResult = (Boolean) processCardResponseContext.get("authResult");
+        results.put("authResult", new Boolean(authResult.booleanValue()));
+        results.put("authFlag", response.getResponseCode());
+        results.put("authMessage", response.getMessage());
+        results.put("captureResult", new Boolean(authResult.booleanValue()));
+        results.put("captureFlag", response.getResponseCode());
+        results.put("captureMessage", response.getMessage());
+        results.put("captureRefNum", response.getTxRefNum());
+        if (authResult.booleanValue()) { //passed
+            results.put("authCode", response.getAuthCode());
+            results.put("authRefNum", response.getTxRefNum());
+            results.put("cvCode", UtilFormatOut.checkNull(response.getCVV2RespCode()));
+            results.put("avsCode", response.getAVSResponseCode());
+            results.put("processAmount", new BigDecimal(results.get("processAmount").toString()));
+        } else {
+            results.put("authCode", response.getAuthCode());
+            results.put("processAmount", new BigDecimal("0.00"));
+            results.put("authRefNum", OrbitalPaymentServices.ERROR);
+        }
+        Debug.logInfo("processAuthCaptureTransResult: " + results.toString(),module);
+    }
+    
+    private static void processCaptureTransResult(Map<String, Object> processCardResponseContext, Map<String, Object> results) {
+        ResponseIF response = (ResponseIF) processCardResponseContext.get("processCardResponse");
+        Boolean captureResult = (Boolean) processCardResponseContext.get("authResult");
+        results.put("captureResult", new Boolean(captureResult.booleanValue()));
+        results.put("captureFlag", response.getResponseCode());
+        results.put("captureMessage", response.getMessage());
+        results.put("captureRefNum", response.getTxRefNum());
+        if (captureResult.booleanValue()) { //passed
+            results.put("captureCode", response.getAuthCode());
+            results.put("captureAmount", new BigDecimal(results.get("captureAmount").toString()));
+        } else {
+            results.put("captureAmount", new BigDecimal("0.00"));
+        }
+        Debug.logInfo("processCaptureTransResult: " + results.toString(),module);
+    }
+
+    private static void processRefundTransResult(Map<String, Object> processCardResponseContext, Map<String, Object> results) {
+        ResponseIF response = (ResponseIF) processCardResponseContext.get("processCardResponse");
+        Boolean refundResult = (Boolean) processCardResponseContext.get("authResult");
+        results.put("refundResult", new Boolean(refundResult.booleanValue()));
+        results.put("refundFlag", response.getResponseCode());
+        results.put("refundMessage", response.getMessage());
+        results.put("refundRefNum", response.getTxRefNum());
+        if (refundResult.booleanValue()) { //passed
+            results.put("refundCode", response.getAuthCode());
+            results.put("refundAmount", new BigDecimal(results.get("refundAmount").toString()));
+        } else {
+            results.put("refundAmount", new BigDecimal("0.00"));
+        }
+        Debug.logInfo("processRefundTransResult: " + results.toString(),module);
+    }
+    
+    private static void processReleaseTransResult(Map<String, Object> processCardResponseContext, Map<String, Object> results) {
+        ResponseIF response = (ResponseIF) processCardResponseContext.get("processCardResponse");
+        Boolean releaseResult = (Boolean) processCardResponseContext.get("authResult");
+        results.put("releaseResult", new Boolean(releaseResult.booleanValue()));
+        results.put("releaseFlag", response.getResponseCode());
+        results.put("releaseMessage", response.getMessage());
+        results.put("releaseRefNum", response.getTxRefNum());
+        if (releaseResult.booleanValue()) { //passed
+            results.put("releaseCode", response.getAuthCode());
+            results.put("releaseAmount", new BigDecimal(results.get("releaseAmount").toString()));
+        } else {
+            results.put("releaseAmount", new BigDecimal("0.00"));
+        }
+        Debug.logInfo("processReleaseTransResult: " + results.toString(),module);
+    }
+    
+    private static void printTransResult(ResponseIF response) {
+        Map<String, Object> generatedResponse = FastMap.newInstance();
+        generatedResponse.put("isGood",  response.isGood());
+        generatedResponse.put("isError", response.isError());
+        generatedResponse.put("isQuickResponse",  response.isQuickResponse());
+        generatedResponse.put("isApproved", response.isApproved());
+        generatedResponse.put("isDeclined",  response.isDeclined());
+        generatedResponse.put("AuthCode",  response.getAuthCode());
+        generatedResponse.put("TxRefNum",  response.getTxRefNum());
+        generatedResponse.put("ResponseCode",  response.getResponseCode());
+        generatedResponse.put("Status",  response.getStatus());
+        generatedResponse.put("Message",  response.getMessage());
+        generatedResponse.put("AVSCode",  response.getAVSResponseCode());
+        generatedResponse.put("CVV2ResponseCode", response.getCVV2RespCode());
+        
+        Debug.logInfo("printTransResult === " + generatedResponse.toString(),module);
+    }
+    
+    private static String formatExpDateForOrbital(String expDate) {
+        String formatedDate = expDate.substring(0, 2) + expDate.substring(5);
+        return formatedDate;
+    }
+    
+    private static String getShippingRefForOrder(String orderId, GenericDelegator delegator) {
+        String shippingRef = "";
+        try {
+            GenericValue orderHeader = delegator.findOne("OrderHeader", false, UtilMisc.toMap("orderId", orderId));
+            GenericValue trackingCodeOrder = EntityUtil.getFirst(orderHeader.getRelated("TrackingCodeOrder"));
+            GenericValue trackingCode = null;
+            if (UtilValidate.isNotEmpty(trackingCodeOrder)) {
+                trackingCode = trackingCodeOrder.getRelatedOne("TrackingCode");
+            }    
+            if (UtilValidate.isNotEmpty(trackingCode) && UtilValidate.isNotEmpty(trackingCode.getString("description"))) {
+                // get tracking code description and provide it into shipping reference.
+                shippingRef = trackingCode.getString("trackingCodeId") + "====" + trackingCode.getString("description");
+            } else {
+                shippingRef = "No Tracking Info processed in order";
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError("Shipping Ref not found returning empty string", module);
+            e.printStackTrace();
+        }
+        return shippingRef;
+    }
+    
+    private static Map<String, Object> validateRequest(Map<String, Object> params, Map props, RequestIF request) {
+        Map<String, Object> result = FastMap.newInstance();
+        result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
+        return result;
+    }
+}
\ No newline at end of file

Propchange: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml?rev=806643&r1=806642&r2=806643&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml (original)
+++ ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml Fri Aug 21 17:00:55 2009
@@ -84,6 +84,12 @@
     <ProductStorePaymentSetting productStoreId="9000" paymentMethodTypeId="EXT_PAYPAL" paymentServiceTypeEnumId="PRDS_PAY_REFUND" paymentService="" paymentCustomMethodId="PAYPAL_REFUND" paymentGatewayConfigId="PAYPAL_CONFIG"/>
     <ProductStorePaymentSetting productStoreId="9000" paymentMethodTypeId="EXT_PAYPAL" paymentServiceTypeEnumId="PRDS_PAY_RELEASE" paymentService="" paymentCustomMethodId="PAYPAL_CAPTURE" paymentGatewayConfigId="PAYPAL_CONFIG"/>
     -->
+    <!-- Example Orbital Gateway Settings -->
+    <ProductStorePaymentSetting productStoreId="9000" paymentMethodTypeId="CREDIT_CARD" paymentServiceTypeEnumId="PRDS_PAY_REAUTH" paymentService="orbitalCCAuth" paymentCustomMethodId="CC_AUTH_ORBITAL" paymentGatewayConfigId="ORBITAL_CONFIG"/>
+    <ProductStorePaymentSetting productStoreId="9000" paymentMethodTypeId="CREDIT_CARD" paymentServiceTypeEnumId="PRDS_PAY_AUTH" paymentService="orbitalCCAuthCapture" paymentCustomMethodId="CC_AUTH_CAPTR_ORBTL" paymentGatewayConfigId="ORBITAL_CONFIG"/>
+    <ProductStorePaymentSetting productStoreId="9000" paymentMethodTypeId="CREDIT_CARD" paymentServiceTypeEnumId="PRDS_PAY_CAPTURE" paymentService="orbitalCCCapture" paymentCustomMethodId="CC_CAPTURE_ORBITAL" paymentGatewayConfigId="ORBITAL_CONFIG"/>
+    <ProductStorePaymentSetting productStoreId="9000" paymentMethodTypeId="CREDIT_CARD" paymentServiceTypeEnumId="PRDS_PAY_REFUND" paymentService="orbitalCCRefund" paymentCustomMethodId="CC_REFUND_ORBITAL" paymentGatewayConfigId="ORBITAL_CONFIG"/>
+    <ProductStorePaymentSetting productStoreId="9000" paymentMethodTypeId="CREDIT_CARD" paymentServiceTypeEnumId="PRDS_PAY_RELEASE" paymentService="orbitalCCRelease" paymentCustomMethodId="CC_RELEASE_ORBITAL" paymentGatewayConfigId="ORBITAL_CONFIG"/>
 
     <ProductStorePaymentSetting productStoreId="9000" paymentMethodTypeId="EXT_WORLDPAY" paymentServiceTypeEnumId="PRDS_PAY_EXTERNAL" paymentService="" paymentCustomMethodId="" paymentGatewayConfigId="WORLDPAY_CONFIG"/>
     <ProductStorePaymentSetting productStoreId="9000" paymentMethodTypeId="EXT_OFFLINE" paymentServiceTypeEnumId="PRDS_PAY_EXTERNAL" paymentService="" paymentCustomMethodId=""/>