FR 2884597 - More flexible Credit Card validation in PaymentProcessor
https://sourceforge.net/tracker/index.php?func=detail&aid=2884597&group_id=176962&atid=879335 Changes in brief: MPayment: change in the processOnline method: * Call the payment processor's validate method before calling pp.processCC In this way we can validate the card details before trying to process. PaymentProcessor: * Create a standard validation (using existing CC-validation) method that's overridable by subclasses. PaymentOnline: * Remove CC-validation from here since it prevents the use of custom CC-validation in the custom PaymentProcessor. VPayment: * Don't validate the credit card details here since the payment processor is not yet known here. The validation is made later by the payment processor. If validation should be done at this point it should depend on the payment processor. Reasons for change: Not all credit cards and payment gateways have the same validation standard. Especially test payment gateways can have very different validation standards. With this change, the same validation remains, but it can be changed by extending the PaymentProcessor class.
This commit is contained in:
parent
760ac455f1
commit
af81a9f30e
|
@ -493,6 +493,12 @@ public final class MPayment extends X_C_Payment
|
|||
setErrorMessage("No Payment Processor");
|
||||
else
|
||||
{
|
||||
// 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);
|
||||
|
@ -500,6 +506,7 @@ public final class MPayment extends X_C_Payment
|
|||
setErrorMessage("From " + getCreditCardName() + ": " + getR_RespMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "processOnline", e);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue