diff --git a/org.adempiere.base/plugin.xml b/org.adempiere.base/plugin.xml index 77a47b8167..b954f4a788 100644 --- a/org.adempiere.base/plugin.xml +++ b/org.adempiere.base/plugin.xml @@ -12,6 +12,7 @@ + + + + + + + + + Extension to provide payment gateway integration through payment gateway specific payment processor implementation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + numeric priority value, higher value is of higher priority + + + + + + + Class name for payment gateway processor that extend the org.compiere.model.PaymentProcessor abstract class. + + + + + + + + + + + + + + + 1.0.0 + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + The class attribute must extend the org.compiere.model.PaymentProcessor abstract class. + + + + + + + + + Default implementation in the org.adempiere.payment.processor bundle. + + + + + + + + + This file is part of Adempiere ERP Bazaar http://www.adempiere.org. + + Copyright (C) Jorg Viola. + Copyright (C) Contributors. + + This program is free software; you can redistribute it and/or modify it + under the terms version 2 of the GNU General Public License as published + by the Free Software Foundation. This program is distributed in the hope + that it will be useful, but WITHOUT ANY WARRANTY; without even the implied + warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + + + + diff --git a/org.adempiere.base/src/org/adempiere/base/Core.java b/org.adempiere.base/src/org/adempiere/base/Core.java index a277f03a9a..5a4f41d260 100644 --- a/org.adempiere.base/src/org/adempiere/base/Core.java +++ b/org.adempiere.base/src/org/adempiere/base/Core.java @@ -22,9 +22,14 @@ package org.adempiere.base; import java.net.URL; import java.util.List; +import java.util.logging.Level; +import org.compiere.model.MPayment; +import org.compiere.model.MPaymentProcessor; import org.compiere.model.ModelValidator; +import org.compiere.model.PaymentProcessor; import org.compiere.process.ProcessCall; +import org.compiere.util.CLogger; /** * This is a facade class for the Service Locator. @@ -35,6 +40,8 @@ import org.compiere.process.ProcessCall; */ public class Core { + private final static CLogger s_log = CLogger.getCLogger(Core.class); + /** * @return list of active resource finder */ @@ -89,4 +96,43 @@ public class Core { return Service.locate(ModelValidator.class, "org.adempiere.base.ModelValidator", query); } + /** + * Factory + * @param mpp payment processor model + * @param mp payment model + * @return initialized PaymentProcessor or null + */ + public static PaymentProcessor getPaymentProcessor(MPaymentProcessor mpp, MPayment mp) { + s_log.info("create for " + mpp); + String className = mpp.getPayProcessorClass(); + if (className == null || className.length() == 0) { + s_log.log(Level.SEVERE, "No PaymentProcessor class name in " + mpp); + return null; + } + // + PaymentProcessor myProcessor = null; + myProcessor = Service.locate(PaymentProcessor.class); + if (myProcessor == null) { + try { + Class ppClass = Class.forName(className); + if (ppClass != null) + myProcessor = (PaymentProcessor)ppClass.newInstance(); + } catch (Error e1) { // NoClassDefFound + s_log.log(Level.SEVERE, className + " - Error=" + e1.getMessage()); + return null; + } catch (Exception e2) { + s_log.log(Level.SEVERE, className, e2); + return null; + } + } + if (myProcessor == null) { + s_log.log(Level.SEVERE, "Not found in extension registry and classpath"); + return null; + } + + // Initialize + myProcessor.initialize(mpp, mp); + // + return myProcessor; + } } diff --git a/org.adempiere.base/src/org/compiere/model/PaymentProcessor.java b/org.adempiere.base/src/org/compiere/model/PaymentProcessor.java index 17c1cc7610..2f1a2dae54 100644 --- a/org.adempiere.base/src/org/compiere/model/PaymentProcessor.java +++ b/org.adempiere.base/src/org/compiere/model/PaymentProcessor.java @@ -30,6 +30,7 @@ import java.util.logging.Level; import javax.net.ssl.HttpsURLConnection; +import org.adempiere.base.Core; import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.util.Msg; @@ -58,9 +59,20 @@ public abstract class PaymentProcessor /** Encode Parameters */ private boolean m_encoded = false; /** Ampersand */ - public static final char AMP = '&'; + public static final char AMP = '&'; /** Equals */ - public static final char EQ = '='; + public static final char EQ = '='; + + /** + * + * @param mpp + * @param mp + */ + public void initialize(MPaymentProcessor mpp, MPayment mp) + { + p_mp = mp; + p_mpp = mpp; + } /** * Factory @@ -70,42 +82,7 @@ public abstract class PaymentProcessor */ public static PaymentProcessor create (MPaymentProcessor mpp, MPayment mp) { - s_log.info("create for " + mpp); - String className = mpp.getPayProcessorClass(); - if (className == null || className.length() == 0) - { - s_log.log(Level.SEVERE, "No PaymentProcessor class name in " + mpp); - return null; - } - // - PaymentProcessor myProcessor = null; - try - { - Class ppClass = Class.forName(className); - if (ppClass != null) - myProcessor = (PaymentProcessor)ppClass.newInstance(); - } - catch (Error e1) // NoClassDefFound - { - s_log.log(Level.SEVERE, className + " - Error=" + e1.getMessage()); - return null; - } - catch (Exception e2) - { - s_log.log(Level.SEVERE, className, e2); - return null; - } - if (myProcessor == null) - { - s_log.log(Level.SEVERE, "no class"); - return null; - } - - // Initialize - myProcessor.p_mpp = mpp; - myProcessor.p_mp = mp; - // - return myProcessor; + return Core.getPaymentProcessor(mpp, mp); } // create /*************************************************************************/ @@ -134,7 +111,7 @@ public abstract class PaymentProcessor // Validation methods. Override if you have specific needs. /** - * Validate payment before process. + * Validate payment before process. * @return "" or Error AD_Message. * @throws IllegalArgumentException */ @@ -149,7 +126,7 @@ public abstract class PaymentProcessor } return(msg); } - + /** * Standard account validation. * @return @@ -157,11 +134,11 @@ public abstract class PaymentProcessor public String validateAccountNo() { return MPaymentValidate.validateAccountNo(p_mp.getAccountNo()); } - + public String validateCheckNo() { return MPaymentValidate.validateCheckNo(p_mp.getCheckNo()); } - + public String validateCreditCard() throws IllegalArgumentException { String msg = MPaymentValidate.validateCreditCardNumber(p_mp.getCreditCardNumber(), p_mp.getCreditCardType()); if (msg != null && msg.length() > 0) @@ -177,7 +154,7 @@ public abstract class PaymentProcessor } return(msg); } - + /************************************************************************** * Set Timeout * @param newTimeout timeout @@ -195,7 +172,7 @@ public abstract class PaymentProcessor return m_timeout; } - + /************************************************************************** * Check for delimiter fields &= and add length of not encoded * @param name name @@ -235,7 +212,7 @@ public abstract class PaymentProcessor * @param name name * @param value value * @param maxLength maximum length - * @return name[5]=value or name=value + * @return name[5]=value or name=value */ protected String createPair(String name, String value, int maxLength) { @@ -243,10 +220,10 @@ public abstract class PaymentProcessor if (name == null || name.length() == 0 || value == null || value.length() == 0) return ""; - + if (value.length() > maxLength) value = value.substring(0, maxLength); - + StringBuffer retValue = new StringBuffer(name); if (m_encoded) try @@ -264,7 +241,7 @@ public abstract class PaymentProcessor retValue.append(value); return retValue.toString(); } // createPair - + /** * Set Encoded * @param doEncode true if encode @@ -281,7 +258,7 @@ public abstract class PaymentProcessor { return m_encoded; } // setEncode - + /** * Get Connect Post Properties * @param urlString POST url string @@ -321,7 +298,7 @@ public abstract class PaymentProcessor log.fine(ms + "ms - " + prop.toString()); return prop; } // connectPost - + /** * Connect via Post * @param urlString url destination (assuming https) @@ -360,5 +337,5 @@ public abstract class PaymentProcessor // return response; } // connectPost - + } // PaymentProcessor diff --git a/org.adempiere.payment.processor/.settings/org.eclipse.pde.core.prefs b/org.adempiere.payment.processor/.settings/org.eclipse.pde.core.prefs index 67f6ac9e18..1e7381c406 100644 --- a/org.adempiere.payment.processor/.settings/org.eclipse.pde.core.prefs +++ b/org.adempiere.payment.processor/.settings/org.eclipse.pde.core.prefs @@ -1,4 +1,4 @@ -#Sat Sep 25 06:49:38 MYT 2010 +#Mon Dec 20 14:26:28 MYT 2010 eclipse.preferences.version=1 -pluginProject.extensions=false +pluginProject.extensions=true resolve.requirebundle=false diff --git a/org.adempiere.payment.processor/META-INF/MANIFEST.MF b/org.adempiere.payment.processor/META-INF/MANIFEST.MF index 131e0047c9..97ed415d56 100644 --- a/org.adempiere.payment.processor/META-INF/MANIFEST.MF +++ b/org.adempiere.payment.processor/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Processor -Bundle-SymbolicName: org.adempiere.payment.processor +Bundle-SymbolicName: org.adempiere.payment.processor;singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Require-Bundle: org.adempiere.base;bundle-version="1.0.0" @@ -9,4 +9,4 @@ Bundle-ClassPath: jpayment.jar, payflow.jar, Verisign.jar, . -Eclipse-RegisterBuddy: org.adempiere.base + diff --git a/org.adempiere.payment.processor/build.properties b/org.adempiere.payment.processor/build.properties index bd5f976d98..cb6ef3cd7f 100644 --- a/org.adempiere.payment.processor/build.properties +++ b/org.adempiere.payment.processor/build.properties @@ -4,4 +4,5 @@ bin.includes = META-INF/,\ .,\ jpayment.jar,\ payflow.jar,\ - Verisign.jar + Verisign.jar,\ + plugin.xml diff --git a/org.adempiere.payment.processor/plugin.xml b/org.adempiere.payment.processor/plugin.xml new file mode 100644 index 0000000000..82ff8777a2 --- /dev/null +++ b/org.adempiere.payment.processor/plugin.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + +