IDEMPIERE-860 Review Payment Processors - include credit card validation

This commit is contained in:
Elaine Tan 2013-07-22 18:13:12 +08:00
parent 068897e912
commit a33c9c0817
4 changed files with 46 additions and 11 deletions

View File

@ -118,8 +118,6 @@ public abstract class PaymentProcessor
*/ */
public String validate() throws IllegalArgumentException { public String validate() throws IllegalArgumentException {
String msg = null; String msg = null;
if (p_mp.getC_BP_BankAccount_ID() != 0 || p_mp.getCustomerPaymentProfileID() != null)
return msg;
if (MPayment.TENDERTYPE_CreditCard.equals(p_mp.getTenderType())) { if (MPayment.TENDERTYPE_CreditCard.equals(p_mp.getTenderType())) {
msg = validateCreditCard(); msg = validateCreditCard();
} else if (MPayment.TENDERTYPE_Check.equals(p_mp.getTenderType())) { } else if (MPayment.TENDERTYPE_Check.equals(p_mp.getTenderType())) {
@ -143,7 +141,10 @@ public abstract class PaymentProcessor
} }
public String validateCreditCard() throws IllegalArgumentException { public String validateCreditCard() throws IllegalArgumentException {
String msg = MPaymentValidate.validateCreditCardNumber(p_mp.getCreditCardNumber(), p_mp.getCreditCardType()); String msg = null;
if (p_mp.getC_BP_BankAccount_ID() != 0 || (p_mp.getCustomerPaymentProfileID() != null && p_mp.getCustomerPaymentProfileID().length() > 0))
return msg;
msg = MPaymentValidate.validateCreditCardNumber(p_mp.getCreditCardNumber(), p_mp.getCreditCardType());
if (msg != null && msg.length() > 0) if (msg != null && msg.length() > 0)
throw new IllegalArgumentException(Msg.getMsg(Env.getCtx(), msg)); throw new IllegalArgumentException(Msg.getMsg(Env.getCtx(), msg));
msg = MPaymentValidate.validateCreditCardExp(p_mp.getCreditCardExpMM(), p_mp.getCreditCardExpYY()); msg = MPaymentValidate.validateCreditCardExp(p_mp.getCreditCardExpMM(), p_mp.getCreditCardExpYY());

View File

@ -274,7 +274,7 @@ public class VPaymentFormCreditCard extends PaymentFormCreditCard implements Act
ValueNamePair vp = (ValueNamePair)kTypeCombo.getSelectedItem(); ValueNamePair vp = (ValueNamePair)kTypeCombo.getSelectedItem();
String CCType = vp.getValue(); String CCType = vp.getValue();
boolean ok = processOnline(CCType, kNumberField.getText(), kExpField.getText()); boolean ok = processOnline(CCType, kNumberField.getText(), kApprovalField.getText(), kExpField.getText());
if (!ok) if (!ok)
ADialog.error(getWindowNo(), dialog, "PaymentError", processMsg); ADialog.error(getWindowNo(), dialog, "PaymentError", processMsg);
else else

View File

@ -76,8 +76,12 @@ public class WPaymentFormCreditCard extends PaymentFormCreditCard implements Eve
public void init() { public void init() {
Grid kLayout = GridFactory.newGridLayout(); Grid kLayout = GridFactory.newGridLayout();
window.getPanel().appendChild(kLayout); window.getPanel().appendChild(kLayout);
kNumberField.setMaxlength(16);
kNumberField.setCols(16); kNumberField.setCols(16);
kExpField.setMaxlength(4);
kExpField.setCols(4); kExpField.setCols(4);
kApprovalField.setMaxlength(4);
kApprovalField.setCols(4); kApprovalField.setCols(4);
kApprovalField.setType("password"); kApprovalField.setType("password");
kTypeLabel.setText(Msg.translate(Env.getCtx(), "CreditCardType")); kTypeLabel.setText(Msg.translate(Env.getCtx(), "CreditCardType"));
@ -291,7 +295,7 @@ public class WPaymentFormCreditCard extends PaymentFormCreditCard implements Eve
ValueNamePair vp = kTypeCombo.getSelectedItem().toValueNamePair(); ValueNamePair vp = kTypeCombo.getSelectedItem().toValueNamePair();
String CCType = vp.getValue(); String CCType = vp.getValue();
boolean ok = processOnline(CCType, kNumberField.getText(), kExpField.getText()); boolean ok = processOnline(CCType, kNumberField.getText(), kApprovalField.getText(), kExpField.getText());
if (!ok) if (!ok)
FDialog.error(getWindowNo(), window, "PaymentNotProcessed", processMsg); FDialog.error(getWindowNo(), window, "PaymentNotProcessed", processMsg);
else else

View File

@ -26,6 +26,7 @@ import org.compiere.model.MOrder;
import org.compiere.model.MPayment; import org.compiere.model.MPayment;
import org.compiere.model.MPaymentProcessor; import org.compiere.model.MPaymentProcessor;
import org.compiere.model.MPaymentTransaction; import org.compiere.model.MPaymentTransaction;
import org.compiere.model.MPaymentValidate;
import org.compiere.process.DocAction; import org.compiere.process.DocAction;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
@ -392,12 +393,12 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
return true; return true;
} }
public boolean processOnline(String CCType, String CCNumber, String CCExp) public boolean processOnline(String CCType, String CCNumber, String CCVV, String CCExp)
{ {
return processOnline(CCType, CCNumber, CCExp, 0); return processOnline(CCType, CCNumber, CCVV, CCExp, 0);
} }
public boolean processOnline(String CCType, String CCNumber, String CCExp, int C_PaymentProcessor_ID) public boolean processOnline(String CCType, String CCNumber, String CCVV, String CCExp, int C_PaymentProcessor_ID)
{ {
processMsg = null; processMsg = null;
boolean error = false; boolean error = false;
@ -430,7 +431,7 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
MPaymentTransaction mpt = new MPaymentTransaction(Env.getCtx(), 0, null); MPaymentTransaction mpt = new MPaymentTransaction(Env.getCtx(), 0, null);
mpt.setAD_Org_ID(m_AD_Org_ID); mpt.setAD_Org_ID(m_AD_Org_ID);
mpt.setCreditCard(MPayment.TRXTYPE_Sales, CCType, CCNumber, "", CCExp); mpt.setCreditCard(MPayment.TRXTYPE_Sales, CCType, CCNumber, CCVV != null ? CCVV : "", CCExp);
mpt.setAmount(m_C_Currency_ID, payAmount); mpt.setAmount(m_C_Currency_ID, payAmount);
mpt.setC_PaymentProcessor_ID(C_PaymentProcessor_ID); mpt.setC_PaymentProcessor_ID(C_PaymentProcessor_ID);
mpt.setPaymentProcessor(); mpt.setPaymentProcessor();
@ -461,10 +462,20 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
mpt.setC_Invoice_ID(C_Invoice_ID); mpt.setC_Invoice_ID(C_Invoice_ID);
mpt.setDateTrx(m_DateAcct); mpt.setDateTrx(m_DateAcct);
setCustomizeValues(mpt); setCustomizeValues(mpt);
// validate credit card
String msg = validateCreditCard(CCType, CCNumber, CCVV != null ? CCVV : "", CCExp, mpt.getC_BP_BankAccount_ID(), mpt.getCustomerPaymentProfileID());
if (msg != null && msg.trim().length() > 0)
{
processMsg = Msg.getMsg(Env.getCtx(), msg);
return false;
}
if (!mpt.save()) { if (!mpt.save()) {
processMsg = Msg.getMsg(Env.getCtx(), "PaymentNotCreated"); processMsg = Msg.getMsg(Env.getCtx(), "PaymentNotCreated");
return false; return false;
} else { } else {
mpt.setCreditCardVV(CCVV != null ? CCVV : "");
approved = mpt.processOnline(); approved = mpt.processOnline();
mpt.saveEx(); mpt.saveEx();
@ -507,4 +518,23 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
public boolean isApproved() { public boolean isApproved() {
return m_mPayment.isApproved(); return m_mPayment.isApproved();
} }
public String validateCreditCard(String CCType, String CCNumber, String CCVV, String CCExp, int C_BP_BankAccount_ID, String CustomerPaymentProfileID) throws IllegalArgumentException {
String msg = null;
if (C_BP_BankAccount_ID != 0 || (CustomerPaymentProfileID != null && CustomerPaymentProfileID.length() > 0))
return msg;
msg = MPaymentValidate.validateCreditCardNumber(CCNumber, CCType);
if (msg != null && msg.length() > 0)
return Msg.getMsg(Env.getCtx(), msg);
msg = MPaymentValidate.validateCreditCardExp(MPaymentValidate.getCreditCardExpMM(CCExp), MPaymentValidate.getCreditCardExpYY(CCExp));
if (msg != null && msg.length() > 0)
return Msg.getMsg(Env.getCtx(), msg);
if (CCVV != null && CCVV.length() > 0)
{
msg = MPaymentValidate.validateCreditCardVV(CCVV, CCType);
if (msg != null && msg.length() > 0)
return Msg.getMsg(Env.getCtx(), msg);
}
return msg;
}
} }