diff --git a/base/src/org/compiere/model/MPayment.java b/base/src/org/compiere/model/MPayment.java index 2bbf9e1677..edd2a014d4 100644 --- a/base/src/org/compiere/model/MPayment.java +++ b/base/src/org/compiere/model/MPayment.java @@ -493,11 +493,18 @@ public final class MPayment extends X_C_Payment setErrorMessage("No Payment Processor"); else { - approved = pp.processCC (); - if (approved) - setErrorMessage(null); - else - setErrorMessage("From " + getCreditCardName() + ": " + getR_RespMsg()); + // Validate before trying to process + String msg = pp.validate(); + if (msg!=null && msg.trim().length()>0) { + setErrorMessage(Msg.getMsg(getCtx(), msg)); + } else { + // Process if validation succeeds + approved = pp.processCC (); + if (approved) + setErrorMessage(null); + else + setErrorMessage("From " + getCreditCardName() + ": " + getR_RespMsg()); + } } } catch (Exception e) diff --git a/base/src/org/compiere/model/PaymentProcessor.java b/base/src/org/compiere/model/PaymentProcessor.java index 3b50e294a9..17c1cc7610 100644 --- a/base/src/org/compiere/model/PaymentProcessor.java +++ b/base/src/org/compiere/model/PaymentProcessor.java @@ -31,6 +31,8 @@ import java.util.logging.Level; import javax.net.ssl.HttpsURLConnection; import org.compiere.util.CLogger; +import org.compiere.util.Env; +import org.compiere.util.Msg; /** * Payment Processor Abstract Class @@ -123,11 +125,58 @@ public abstract class PaymentProcessor public abstract boolean processCC () throws IllegalArgumentException; /** - * Payment is procesed successfully + * Payment is processed successfully * @return true if OK */ public abstract boolean isProcessedOK(); + /**************************************************************************/ + // Validation methods. Override if you have specific needs. + + /** + * Validate payment before process. + * @return "" or Error AD_Message. + * @throws IllegalArgumentException + */ + public String validate() throws IllegalArgumentException { + String msg = null; + if (MPayment.TENDERTYPE_CreditCard.equals(p_mp.getTenderType())) { + msg = validateCreditCard(); + } else if (MPayment.TENDERTYPE_Check.equals(p_mp.getTenderType())) { + msg = validateCheckNo(); + } else if (MPayment.TENDERTYPE_Account.equals(p_mp.getTenderType())) { + msg = validateAccountNo(); + } + return(msg); + } + + /** + * Standard account validation. + * @return + */ + 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) + throw new IllegalArgumentException(Msg.getMsg(Env.getCtx(), msg)); + msg = MPaymentValidate.validateCreditCardExp(p_mp.getCreditCardExpMM(), p_mp.getCreditCardExpYY()); + if (msg != null && msg.length() > 0) + throw new IllegalArgumentException(Msg.getMsg(Env.getCtx(), msg)); + if (p_mp.getCreditCardVV() != null && p_mp.getCreditCardVV().length() > 0) + { + msg = MPaymentValidate.validateCreditCardVV(p_mp.getCreditCardVV(), p_mp.getCreditCardType()); + if (msg != null && msg.length() > 0) + throw new IllegalArgumentException(Msg.getMsg(Env.getCtx(), msg)); + } + return(msg); + } /************************************************************************** * Set Timeout @@ -287,7 +336,6 @@ public abstract class PaymentProcessor // open secure connection URL url = new URL(urlString); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); - // URLConnection connection = url.openConnection(); connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); diff --git a/base/src/org/compiere/process/PaymentOnline.java b/base/src/org/compiere/process/PaymentOnline.java index a161bfb615..192e2fe216 100644 --- a/base/src/org/compiere/process/PaymentOnline.java +++ b/base/src/org/compiere/process/PaymentOnline.java @@ -20,8 +20,6 @@ package org.compiere.process; import java.util.logging.Level; import org.compiere.model.MPayment; -import org.compiere.model.MPaymentValidate; -import org.compiere.util.Msg; /** @@ -58,19 +56,6 @@ public class PaymentOnline extends SvrProcess log.info("Record_ID=" + getRecord_ID()); // get Payment MPayment pp = new MPayment (getCtx(), getRecord_ID(), get_TrxName()); - // Validate Number - String msg = MPaymentValidate.validateCreditCardNumber(pp.getCreditCardNumber(), pp.getCreditCardType()); - if (msg != null && msg.length() > 0) - throw new IllegalArgumentException(Msg.getMsg(getCtx(), msg)); - msg = MPaymentValidate.validateCreditCardExp(pp.getCreditCardExpMM(), pp.getCreditCardExpYY()); - if (msg != null && msg.length() > 0) - throw new IllegalArgumentException(Msg.getMsg(getCtx(), msg)); - if (pp.getCreditCardVV() != null && pp.getCreditCardVV().length() > 0) - { - msg = MPaymentValidate.validateCreditCardVV(pp.getCreditCardVV(), pp.getCreditCardType()); - if (msg != null && msg.length() > 0) - throw new IllegalArgumentException(Msg.getMsg(getCtx(), msg)); - } // Process it boolean ok = pp.processOnline(); diff --git a/client/src/org/compiere/grid/VPayment.java b/client/src/org/compiere/grid/VPayment.java index ce47a7b8ea..09c5d88cfe 100644 --- a/client/src/org/compiere/grid/VPayment.java +++ b/client/src/org/compiere/grid/VPayment.java @@ -1325,29 +1325,8 @@ public class VPayment extends CDialog vp = (ValueNamePair)kTypeCombo.getSelectedItem(); if (vp != null) CCType = vp.getValue(); - // - String error = MPaymentValidate.validateCreditCardNumber(kNumberField.getText(), CCType); - if (error.length() != 0) - { - kNumberField.setBackground(AdempierePLAF.getFieldBackground_Error()); - if (error.indexOf('?') == -1) - { - ADialog.error(m_WindowNo, this, error); - dataOK = false; - } - else // warning - { - if (!ADialog.ask(m_WindowNo, this, error)) - dataOK = false; - } - } - error = MPaymentValidate.validateCreditCardExp(kExpField.getText()); - if(error.length() != 0) - { - kExpField.setBackground(AdempierePLAF.getFieldBackground_Error()); - ADialog.error(m_WindowNo, this, error); - dataOK = false; - } + // Validation of the credit card number is moved to the payment processor. + // Different payment processors can have different validation rules. } // T (Transfer) BPartner_Bank