IDEMPIERE-5459 Refactoring of Payment Form (#1541)

This commit is contained in:
hengsin 2022-11-01 01:39:55 +08:00 committed by GitHub
parent 17b31a14b3
commit f9b070bcaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 1131 additions and 274 deletions

View File

@ -46,5 +46,13 @@
priority="0">
</processor>
</extension>
<extension
id="org.compiere.model.PP_Dummy"
name="Dummy Payment Processor"
point="org.compiere.model.PaymentProcessor">
<processor
class="org.compiere.model.PP_Dummy">
</processor>
</extension>
</plugin>

View File

@ -0,0 +1,75 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - hengsin *
**********************************************************************/
package org.compiere.model;
/**
* dummy cc payment processor, for testing only
* @author hengsin
*
*/
public class PP_Dummy extends PaymentProcessor {
@Override
public boolean processCC() throws IllegalArgumentException {
//Clear CVV value and encrypt the CC# even if the transaction has not been approved
if (p_mp.getTrxType().equals(MPayment.TRXTYPE_Authorization)) {
//need to store following data as TrxType is now Authorization only
p_mp.setCreditCardVV(p_mp.getCreditCardVV());
p_mp.setCreditCardNumber(p_mp.getCreditCardNumber());
} else {
p_mp.setCreditCardVV(null);
p_mp.setCreditCardNumber(encrpytCreditCard(p_mp
.getCreditCardNumber()));
}
return true;
}
@Override
public boolean isProcessedOK() {
return true;
}
//Encrypt credit card - leave 4 last numbers
private String encrpytCreditCard(String value) {
if (value == null)
return "";
else
if (value.length() <= 4)
return value;
Integer valueLength = value.length();
StringBuffer encryptedCC = new StringBuffer();
for (int i = 0; i < (valueLength - 4); i++) {
encryptedCC.append("0");
}
encryptedCC.append(value.substring(valueLength - 4, valueLength));
return encryptedCC.toString();
}
}

View File

@ -16,7 +16,6 @@ package org.adempiere.webui.apps.form;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Enumeration;
import org.adempiere.webui.component.Column;
import org.adempiere.webui.component.Columns;
@ -34,19 +33,16 @@ import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.window.Dialog;
import org.compiere.grid.PaymentFormCash;
import org.compiere.model.GridTab;
import org.compiere.model.MConversionRate;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
/**
*
* @author Elaine
*
*/
public class WPaymentFormCash extends PaymentFormCash implements EventListener<Event> {
public class WPaymentFormCash extends PaymentFormCash {
private WPaymentFormWindow window;
@ -54,8 +50,6 @@ public class WPaymentFormCash extends PaymentFormCash implements EventListener<E
private Listbox bBankAccountCombo = ListboxFactory.newDropdownListbox();
private Label bCashBookLabel = new Label();
private Listbox bCashBookCombo = ListboxFactory.newDropdownListbox();
private Label bCurrencyLabel = new Label();
private Listbox bCurrencyCombo = ListboxFactory.newDropdownListbox();
private Label bDateLabel = new Label();
private WDateEditor bDateField;
private Label bAmountLabel = new Label();
@ -74,7 +68,6 @@ public class WPaymentFormCash extends PaymentFormCash implements EventListener<E
Grid bPanelLayout = GridFactory.newGridLayout();
window.getPanel().appendChild(bPanelLayout);
bCashBookLabel.setText(Msg.translate(Env.getCtx(), "C_CashBook_ID"));
bCurrencyLabel.setText(Msg.translate(Env.getCtx(), "C_Currency_ID"));
bAmountLabel.setText(Msg.getMsg(Env.getCtx(), "Amount"));
//bAmountField.setText("");
bDateLabel.setText(Msg.translate(Env.getCtx(), "DateAcct"));
@ -104,10 +97,6 @@ public class WPaymentFormCash extends PaymentFormCash implements EventListener<E
row.appendChild(bCashBookCombo);
}
row = rows.newRow();
row.appendChild(bCurrencyLabel.rightAlign());
row.appendChild(bCurrencyCombo);
row = rows.newRow();
row.appendChild(bDateLabel.rightAlign());
row.appendChild(bDateField.getComponent());
@ -133,23 +122,6 @@ public class WPaymentFormCash extends PaymentFormCash implements EventListener<E
// Accounting Date
bDateField.setValue(m_DateAcct);
// Is the currency an EMU currency?
Integer C_Currency_ID = Integer.valueOf(m_C_Currency_ID);
if (s_Currencies.containsKey(C_Currency_ID)) {
Enumeration<Integer> en = s_Currencies.keys();
while (en.hasMoreElements()) {
Object key = en.nextElement();
bCurrencyCombo.addItem(s_Currencies.get(key));
}
bCurrencyCombo.addActionListener(this);
bCurrencyCombo.setSelectedKeyNamePair(s_Currencies.get(C_Currency_ID));
}
else // No EMU Currency
{
bCurrencyLabel.setVisible(false); // Cash
bCurrencyCombo.setVisible(false);
}
ArrayList<KeyNamePair> list = getBankAccountList();
for (KeyNamePair pp : list)
bBankAccountCombo.addItem(pp);
@ -168,16 +140,6 @@ public class WPaymentFormCash extends PaymentFormCash implements EventListener<E
bCashBookCombo.setSelectedKeyNamePair(selectedCashBook);
}
public void onEvent(Event e)
{
if (e.getTarget() == bCurrencyCombo)
{
KeyNamePair pp = bCurrencyCombo.getSelectedItem().toKeyNamePair();
BigDecimal amt = MConversionRate.convert(Env.getCtx(), m_Amount, m_C_Currency_ID, pp.getKey(), m_AD_Client_ID, m_AD_Org_ID);
bAmountField.setValue(amt);
}
}
@Override
public boolean checkMandatory() {
int C_BankAccount_ID = 0;

View File

@ -15,7 +15,6 @@ package org.adempiere.webui.apps.form;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.logging.Level;
import org.adempiere.webui.LayoutUtils;
@ -36,8 +35,6 @@ import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.window.Dialog;
import org.compiere.grid.PaymentFormCheck;
import org.compiere.model.GridTab;
import org.compiere.model.MBankAccountProcessor;
import org.compiere.model.MConversionRate;
import org.compiere.model.MPaymentValidate;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
@ -60,9 +57,6 @@ public class WPaymentFormCheck extends PaymentFormCheck implements EventListener
private Label sBankAccountLabel = new Label();
private Listbox sBankAccountCombo = ListboxFactory.newDropdownListbox();
private Label sCurrencyLabel = new Label();
private Listbox sCurrencyCombo = ListboxFactory.newDropdownListbox();
private Space sCurrencySpace = new Space();
private Label sAmountLabel = new Label();
private WNumberEditor sAmountField = new WNumberEditor();
private Label sRoutingLabel = new Label();
@ -74,13 +68,18 @@ public class WPaymentFormCheck extends PaymentFormCheck implements EventListener
private Button sOnline = new Button();
private Label sStatus = new Label();
/**
*
* @param windowNo
* @param mTab
*/
public WPaymentFormCheck(int windowNo, GridTab mTab) {
super(windowNo, mTab);
window = new WPaymentFormWindow(this, windowNo);
init();
}
public void init() {
protected void init() {
Grid sPanelLayout = GridFactory.newGridLayout();
window.getPanel().appendChild(sPanelLayout);
sBankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID"));
@ -89,7 +88,6 @@ public class WPaymentFormCheck extends PaymentFormCheck implements EventListener
sNumberLabel.setText(Msg.translate(Env.getCtx(), "AccountNo"));
sCheckLabel.setText(Msg.translate(Env.getCtx(), "CheckNo"));
sCheckField.setCols(8);
sCurrencyLabel.setText(Msg.translate(Env.getCtx(), "C_Currency_ID"));
ZKUpdateUtil.setWidth(sNumberField, "100pt");
ZKUpdateUtil.setWidth(sRoutingField, "70pt");
sOnline.setLabel(Msg.getMsg(Env.getCtx(), "Online"));
@ -115,10 +113,6 @@ public class WPaymentFormCheck extends PaymentFormCheck implements EventListener
row.appendChild(sBankAccountLabel.rightAlign());
row.appendChild(sBankAccountCombo);
row = rows.newRow();
row.appendChild(sCurrencyLabel.rightAlign());
row.appendChild(sCurrencyCombo);
row = rows.newRow();
row.appendChild(sAmountLabel.rightAlign());
row.appendChild(sAmountField.getComponent());
@ -159,26 +153,6 @@ public class WPaymentFormCheck extends PaymentFormCheck implements EventListener
sAmountField.setValue(m_mPayment.getPayAmt());
}
// Is the currency an EMU currency?
Integer C_Currency_ID = Integer.valueOf(m_C_Currency_ID);
if (s_Currencies.containsKey(C_Currency_ID))
{
Enumeration<Integer> en = s_Currencies.keys();
while (en.hasMoreElements())
{
Object key = en.nextElement();
sCurrencyCombo.addItem(s_Currencies.get(key));
}
sCurrencyCombo.addActionListener(this);
sCurrencyCombo.setSelectedKeyNamePair(s_Currencies.get(C_Currency_ID));
}
else // No EMU Currency
{
sCurrencyLabel.setVisible(false); // Check
sCurrencyCombo.setVisible(false);
sCurrencySpace.setVisible(false);
}
ArrayList<KeyNamePair> list = getBankAccountList();
for (KeyNamePair pp : list)
sBankAccountCombo.addItem(pp);
@ -187,29 +161,13 @@ public class WPaymentFormCheck extends PaymentFormCheck implements EventListener
if (selectedBankAccount != null)
sBankAccountCombo.setSelectedKeyNamePair(selectedBankAccount);
boolean exist = isBankAccountProcessorExist(m_C_Currency_ID, (BigDecimal) sAmountField.getValue());
sOnline.setVisible(exist);
if (exist)
updateOnlineButton();
}
public void onEvent(Event e)
{
if (e.getTarget() == sCurrencyCombo || e.getTarget() == sAmountField)
if (e.getTarget() == sAmountField)
{
int C_Currency_ID = 0;
KeyNamePair pp = sCurrencyCombo.getSelectedItem().toKeyNamePair();
if (pp != null)
C_Currency_ID = pp.getKey();
if (e.getTarget() == sCurrencyCombo)
{
BigDecimal amt = MConversionRate.convert(Env.getCtx(),
m_Amount, m_C_Currency_ID, C_Currency_ID, m_AD_Client_ID, m_AD_Org_ID);
sAmountField.setValue(amt);
}
updateOnlineButton();
}
else if (e.getTarget() == sOnline)
@ -221,24 +179,8 @@ public class WPaymentFormCheck extends PaymentFormCheck implements EventListener
private void updateOnlineButton()
{
int C_Currency_ID = 0;
KeyNamePair pp = sCurrencyCombo.getSelectedItem().toKeyNamePair();
if (pp != null)
C_Currency_ID = pp.getKey();
BigDecimal PayAmt = (BigDecimal) sAmountField.getValue();
if (C_Currency_ID > 0 && PayAmt != null)
{
MBankAccountProcessor bankAccountProcessor = getBankAccountProcessor(C_Currency_ID, PayAmt);
sOnline.setEnabled(bankAccountProcessor != null);
setBankAccountProcessor(bankAccountProcessor);
}
else
{
sOnline.setEnabled(false);
setBankAccountProcessor(null);
}
boolean exist = isBankAccountProcessorExist(m_C_Currency_ID, (BigDecimal) sAmountField.getValue());
sOnline.setVisible(exist);
}
@Override

View File

@ -68,13 +68,18 @@ public class WPaymentFormCreditCard extends PaymentFormCreditCard implements Eve
private Button kOnline = ButtonFactory.createNamedButton("Online");
private Label kStatus = new Label();
/**
*
* @param windowNo
* @param mTab
*/
public WPaymentFormCreditCard(int windowNo, GridTab mTab) {
super(windowNo, mTab);
window = new WPaymentFormWindow(this, windowNo);
init();
}
public void init() {
protected void init() {
Grid kLayout = GridFactory.newGridLayout();
window.getPanel().appendChild(kLayout);
kNumberField.setMaxlength(16);
@ -226,6 +231,7 @@ public class WPaymentFormCreditCard extends PaymentFormCreditCard implements Eve
}
}
@Override
public void onEvent(Event e)
{
if (e.getTarget() == kOnline) {
@ -296,7 +302,7 @@ public class WPaymentFormCreditCard extends PaymentFormCreditCard implements Eve
ValueNamePair vp = kTypeCombo.getSelectedItem().toValueNamePair();
String CCType = vp.getValue();
boolean ok = processOnline(CCType, kNumberField.getText(), kApprovalField.getText(), kExpField.getText());
boolean ok = processOnline(CCType, kNumberField.getText(), kApprovalField.getValue(), kExpField.getText());
if (!ok)
Dialog.error(getWindowNo(), "PaymentNotProcessed", processMsg);
else

View File

@ -33,6 +33,7 @@ import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.window.Dialog;
import org.compiere.grid.PaymentFormDirect;
import org.compiere.model.GridTab;
import org.compiere.model.MBankAccount;
import org.compiere.model.MBankAccountProcessor;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
@ -61,16 +62,22 @@ public abstract class WPaymentFormDirect extends PaymentFormDirect implements Ev
private Label tRoutingText = new Label();
private Label tNumberText = new Label();
/**
*
* @param windowNo
* @param mTab
* @param isDebit
*/
public WPaymentFormDirect(int windowNo, GridTab mTab, boolean isDebit) {
super(windowNo, mTab, isDebit);
window = new WPaymentFormWindow(this, windowNo);
init();
}
public void init() {
protected void init() {
Grid tPanelLayout = GridFactory.newGridLayout();
window.getPanel().appendChild(tPanelLayout);
tAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BP_BankAccount_ID"));
tAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID"));
tRoutingField.setCols(8);
tNumberField.setCols(10);
tRoutingText.setText(Msg.translate(Env.getCtx(), "RoutingNo"));
@ -114,6 +121,8 @@ public abstract class WPaymentFormDirect extends PaymentFormDirect implements Ev
@Override
public void loadData() {
super.loadData();
if (m_C_Payment_ID != 0)
{
tRoutingField.setText(m_mPayment.getRoutingNo());
@ -121,7 +130,7 @@ public abstract class WPaymentFormDirect extends PaymentFormDirect implements Ev
tStatus.setText(m_mPayment.getR_PnRef());
}
ArrayList<KeyNamePair> list = getBPBankAccountList();
ArrayList<KeyNamePair> list = getBankAccountList();
for (KeyNamePair pp : list)
tAccountCombo.addItem(pp);
@ -132,6 +141,7 @@ public abstract class WPaymentFormDirect extends PaymentFormDirect implements Ev
setBankAccountProcessor(bankAccountProcessor);
}
@Override
public void onEvent(Event e)
{
if (e.getTarget() == tOnline)
@ -148,10 +158,10 @@ public abstract class WPaymentFormDirect extends PaymentFormDirect implements Ev
*/
boolean dataOK = true;
ListItem selected = tAccountCombo.getSelectedItem();
KeyNamePair bpba = selected != null ? selected.toKeyNamePair() : null;
if (bpba == null)
KeyNamePair ba = selected != null ? selected.toKeyNamePair() : null;
if (ba == null)
{
Dialog.error(getWindowNo(), "PaymentBPBankNotFound");
Dialog.error(getWindowNo(), "FillMandatory", Msg.translate(Env.getCtx(), MBankAccount.COLUMNNAME_C_BankAccount_ID));
dataOK = false;
}
//
@ -161,10 +171,13 @@ public abstract class WPaymentFormDirect extends PaymentFormDirect implements Ev
@Override
public boolean saveChangesInTrx(final String trxName) {
boolean ok = save(0, tRoutingField.getText(), tNumberField.getText(), trxName);
ListItem selected = tAccountCombo.getSelectedItem();
KeyNamePair ba = selected != null ? selected.toKeyNamePair() : null;
int C_BankAccount_ID = ba != null ? ba.getKey() : 0;
boolean ok = save(C_BankAccount_ID, tRoutingField.getText(), tNumberField.getText(), trxName);
if (!ok)
Dialog.error(getWindowNo(), "PaymentError", processMsg);
else if (processMsg != null)
else
Dialog.info(getWindowNo(), "PaymentCreated", m_mPayment.getDocumentNo());
return ok;

View File

@ -23,6 +23,11 @@ import org.compiere.model.GridTab;
*/
public class WPaymentFormDirectDebit extends WPaymentFormDirect {
/**
*
* @param windowNo
* @param mTab
*/
public WPaymentFormDirectDebit(int windowNo, GridTab mTab) {
super(windowNo, mTab, true);
}

View File

@ -23,6 +23,11 @@ import org.compiere.model.GridTab;
*/
public class WPaymentFormDirectDeposit extends WPaymentFormDirect {
/**
*
* @param windowNo
* @param mTab
*/
public WPaymentFormDirectDeposit(int windowNo, GridTab mTab) {
super(windowNo, mTab, false);
}

View File

@ -58,4 +58,8 @@ public class WPaymentFormMixedPOS extends PaymentFormMixedPOS {
public Object getWindow() {
return window;
}
@Override
protected void afterSave(boolean success) {
}
}

View File

@ -44,13 +44,18 @@ public class WPaymentFormOnCredit extends PaymentFormOnCredit {
private Label pTermLabel = new Label();
private Listbox pTermCombo = ListboxFactory.newDropdownListbox();
/**
*
* @param windowNo
* @param mTab
*/
public WPaymentFormOnCredit(int windowNo, GridTab mTab) {
super(windowNo, mTab);
window = new WPaymentFormWindow(this, windowNo);
init();
}
public void init() {
protected void init() {
Grid pPanelLayout = GridFactory.newGridLayout();
window.getPanel().appendChild(pPanelLayout);
pTermLabel.setText(Msg.translate(Env.getCtx(), "C_PaymentTerm_ID"));

View File

@ -44,7 +44,7 @@ public class WPaymentFormWindow extends Window implements EventListener<Event>,
private static final long serialVersionUID = 2710316463655831868L;
private PaymentForm paymentForm;
// private int windowNo;
private int windowNo;
private Panel mainPanel = new Panel();
private Panel centerPanel = new Panel();
@ -60,7 +60,7 @@ public class WPaymentFormWindow extends Window implements EventListener<Event>,
super();
this.paymentForm = paymentForm;
// this.windowNo = windowNo;
this.windowNo = windowNo;
try {
zkInit();
@ -79,6 +79,10 @@ public class WPaymentFormWindow extends Window implements EventListener<Event>,
this.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED);
}
protected int getWindowNo() {
return this.windowNo;
}
private void zkInit() throws Exception {
this.appendChild(mainPanel);
mainPanel.appendChild(mainLayout);

View File

@ -510,7 +510,7 @@ public final class Dialog {
}
String dialogTitle = getDialogTitle(title, windowNo);
String message = constructMessage(adMessage, null);
String message = constructMessage(adMessage, additionalMessage);
message = formatDialogMessage(message);
Messagebox.showDialog(message, dialogTitle, Messagebox.OK, Messagebox.INFORMATION);

View File

@ -16,39 +16,92 @@ package org.compiere.grid;
import org.compiere.model.MBankAccountProcessor;
import org.compiere.model.PO;
/**
*
* Interface for payment form for different payment mode (cash, credit card, etc)
*
*/
public interface IPaymentForm {
/**
* dynamic initialization
* @return false if there are errors, true otherwise
* @throws Exception
*/
public boolean dynInit() throws Exception;
/**
* Load payment and related transaction records. Usually call from dynInit()
*/
public void loadData();
/**
* mandatory field validations
* @return true if all mandatory field have been populated
*/
public boolean checkMandatory();
/**
*
* @return true if only show payment rule and doesn't save changes to DB
*/
public boolean isOnlyRule();
/**************************************************************************
* Save Changes
* @return true, if Window can exit
*/
public boolean saveChanges();
/**
* Save changes to DB
* @param trxName
* @return true if save successfully
*/
public boolean saveChangesInTrx(final String trxName);
/**
* Need Save record (payment with waiting order)
* @return true if payment with waiting order
* Need to save the calling window (order, invoice)
* @return true if changes have been to the calling window
*/
public boolean needSave();
/**
* online payment processing (for e.g credit card)
*/
public void processOnline();
/**
*
* @return true if payment transaction have been approved by payment gateway
*/
public boolean isApproved();
/**
* show form
*/
public void showWindow();
/**
* close form
*/
public void closeWindow();
/**
*
* @return instance of UI form
*/
public Object getWindow();
/**
* Make additional changes to PO before write to DB
* @param po
*/
public void setCustomizeValues(PO po);
/**
* Set online payment processor configuration
* @param bankAccountProcessor
*/
public void setBankAccountProcessor(MBankAccountProcessor bankAccountProcessor);
}

View File

@ -22,6 +22,13 @@ import org.compiere.model.GridTab;
*/
public interface IPaymentFormFactory {
/**
* Create payment form instance by paymentRule
* @param windowNo
* @param mTab
* @param paymentRule
* @return {@link IPaymentForm} instance
*/
public IPaymentForm create(int windowNo, GridTab mTab, String paymentRule);
}

View File

@ -18,7 +18,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Hashtable;
import java.util.Properties;
import java.util.logging.Level;
@ -30,7 +29,6 @@ import org.compiere.model.PO;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.Trx;
import org.compiere.util.TrxRunnable;
@ -51,32 +49,31 @@ public abstract class PaymentForm implements IPaymentForm {
private GridTab m_mTab;
// Data from Order/Invoice
public String m_DocStatus = null;
protected String m_DocStatus = null;
/** Start Payment Rule */
public String m_PaymentRule = "";
protected String m_PaymentRule = "";
/** Start Acct Date */
public Timestamp m_DateAcct = null;
/** Start Payment */
// public int m_C_Payment_ID = 0;
// public MPayment m_mPayment = null;
// public MPayment m_mPaymentOriginal = null;
protected Timestamp m_DateAcct = null;
/** Invoice Currency */
public int m_C_Currency_ID = 0;
public int m_AD_Client_ID = 0;
public boolean m_Cash_As_Payment = true;
public int m_AD_Org_ID = 0;
public int m_C_BPartner_ID = 0;
public BigDecimal m_Amount = Env.ZERO; // Payment Amount
protected int m_C_Currency_ID = 0;
protected int m_AD_Client_ID = 0;
protected boolean m_Cash_As_Payment = true;
protected int m_AD_Org_ID = 0;
protected int m_C_BPartner_ID = 0;
protected BigDecimal m_Amount = Env.ZERO; // Payment Amount
public boolean m_needSave = false;
protected boolean m_needSave = false;
/** Only allow changing Rule */
public boolean m_onlyRule = false;
protected boolean m_onlyRule = false;
/** Is SOTrx */
public boolean m_isSOTrx = true;
public Hashtable<Integer,KeyNamePair> s_Currencies = null;
protected boolean m_isSOTrx = true;
/**
*
* @param WindowNo
* @param mTab
*/
public PaymentForm(int WindowNo, GridTab mTab) {
m_WindowNo = WindowNo;
m_isSOTrx = "Y".equals(Env.getContext(Env.getCtx(), WindowNo, "IsSOTrx"));
@ -127,9 +124,6 @@ public abstract class PaymentForm implements IPaymentForm {
m_C_Currency_ID = ((Integer)m_mTab.getValue("C_Currency_ID")).intValue();
m_DateAcct = (Timestamp)m_mTab.getValue("DateAcct");
if (s_Currencies == null)
loadCurrencies();
/**
* Payment Combo
*/
@ -146,10 +140,9 @@ public abstract class PaymentForm implements IPaymentForm {
// BF [ 1920179 ] perform the save in a trx's context.
final boolean[] success = new boolean[] { false };
final TrxRunnable r = new TrxRunnable() {
public void run(String trxName) {
// only Payment Rule
if (m_onlyRule)
if (isOnlyRule())
success[0] = true;
else
success[0] = saveChangesInTrx(trxName);
@ -164,42 +157,18 @@ public abstract class PaymentForm implements IPaymentForm {
success[0] = false;
throw new AdempiereException("PaymentError", e);
}
afterSave(success[0]);
return success[0];
} // saveChanges
}
/**
* Fill s_Currencies with EMU currencies
* after save and trx committed/rollback
* @param success
*/
protected void loadCurrencies()
{
s_Currencies = new Hashtable<Integer,KeyNamePair>(12); // Currenly only 10+1
String SQL = "SELECT C_Currency_ID, ISO_Code FROM C_Currency "
+ "WHERE (IsEMUMember='Y' AND EMUEntryDate<getDate()) OR IsEuro='Y' "
+ "ORDER BY 2";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(SQL, null);
rs = pstmt.executeQuery();
while (rs.next())
{
int id = rs.getInt(1);
String name = rs.getString(2);
s_Currencies.put(Integer.valueOf(id), new KeyNamePair(id, name));
}
}
catch (SQLException e)
{
log.log(Level.SEVERE, SQL, e);
}
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
} // loadCurrencies
protected abstract void afterSave(boolean success);
@Override
public boolean needSave()
@ -248,6 +217,17 @@ public abstract class PaymentForm implements IPaymentForm {
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "ActionNotSupported"));
}
/**
*
* @param ctx
* @param tender
* @param CCType
* @param AD_Client_ID
* @param C_Currency_ID
* @param PayAmt
* @param trxName
* @return true if online payment processor have been configured for bank account
*/
protected boolean isBankAccountProcessorExist(Properties ctx, String tender, String CCType, int AD_Client_ID, int C_Currency_ID, BigDecimal PayAmt, String trxName)
{
MBankAccountProcessor[] m_mBankAccountProcessors = MBankAccountProcessor.find(ctx, tender, CCType, AD_Client_ID, C_Currency_ID, PayAmt, trxName);
@ -259,6 +239,17 @@ public abstract class PaymentForm implements IPaymentForm {
return true;
}
/**
* Get online payment processor configuration
* @param ctx
* @param tender tender type
* @param CCType credit card type
* @param AD_Client_ID
* @param C_Currency_ID
* @param PayAmt
* @param trxName
* @return {@link MBankAccountProcessor}
*/
protected MBankAccountProcessor getBankAccountProcessor(Properties ctx, String tender, String CCType, int AD_Client_ID, int C_Currency_ID, BigDecimal PayAmt, String trxName)
{
MBankAccountProcessor[] m_mBankAccountProcessors = MBankAccountProcessor.find(ctx, tender, CCType, AD_Client_ID, C_Currency_ID, PayAmt, trxName);
@ -283,11 +274,16 @@ public abstract class PaymentForm implements IPaymentForm {
return m_mBankAccountProcessor;
}
/**
*
* @return {@link GridTab}
*/
public GridTab getGridTab()
{
return m_mTab;
}
@Override
public boolean isOnlyRule()
{
return m_onlyRule;
@ -299,6 +295,10 @@ public abstract class PaymentForm implements IPaymentForm {
return true;
}
/**
*
* @return window no
*/
public int getWindowNo()
{
return m_WindowNo;

View File

@ -46,17 +46,22 @@ public abstract class PaymentFormCash extends PaymentForm {
private static final String PAYMENTRULE = MInvoice.PAYMENTRULE_Cash;
/** Start Payment */
public int m_C_Payment_ID = 0;
public MPayment m_mPayment = null;
public MPayment m_mPaymentOriginal = null;
protected int m_C_Payment_ID = 0;
protected MPayment m_mPayment = null;
protected MPayment m_mPaymentOriginal = null;
/** Start Bank Account */
public int m_C_BankAccount_ID = 0;
protected int m_C_BankAccount_ID = 0;
/** Start CashBook Line */
public int m_C_CashLine_ID = 0;
public MCashLine m_cashLine = null;
protected int m_C_CashLine_ID = 0;
protected MCashLine m_cashLine = null;
/** Start CashBook */
public int m_C_CashBook_ID = 0;
protected int m_C_CashBook_ID = 0;
/**
*
* @param windowNo
* @param mTab
*/
public PaymentFormCash(int windowNo, GridTab mTab) {
super(windowNo, mTab);
}
@ -100,7 +105,12 @@ public abstract class PaymentFormCash extends PaymentForm {
}
}
public KeyNamePair selectedBankAccount;
protected KeyNamePair selectedBankAccount;
/**
*
* @return list of active bank account
*/
public ArrayList<KeyNamePair> getBankAccountList() {
selectedBankAccount = null;
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
@ -146,7 +156,12 @@ public abstract class PaymentFormCash extends PaymentForm {
return list;
}
public KeyNamePair selectedCashBook;
protected KeyNamePair selectedCashBook;
/**
*
* @return list of active cash book
*/
public ArrayList<KeyNamePair> getCashBookList() {
selectedCashBook = null;
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
@ -207,8 +222,20 @@ public abstract class PaymentFormCash extends PaymentForm {
return ok;
}
public String processMsg;
public boolean save(int newC_BankAccount_ID, int newC_CashBook_ID, Timestamp newDateAcct, BigDecimal newAmount, String trxName)
protected String processMsg;
private int newC_CashLine_ID;
/**
*
* @param C_BankAccount_ID
* @param C_CashBook_ID
* @param dateAcct
* @param amount
* @param trxName
* @return true if save successfully
*/
public boolean save(int C_BankAccount_ID, int C_CashBook_ID, Timestamp dateAcct, BigDecimal amount, String trxName)
{
// set trxname for class objects
if (m_cashLine != null)
@ -219,7 +246,7 @@ public abstract class PaymentFormCash extends PaymentForm {
m_mPaymentOriginal.set_TrxName(trxName);
processMsg = null;
int newC_CashLine_ID = m_C_CashLine_ID;
newC_CashLine_ID = m_C_CashLine_ID;
/***********************
* Changed PaymentRule
@ -259,7 +286,7 @@ public abstract class PaymentFormCash extends PaymentForm {
if (invoice == null && C_Order_ID != 0)
order = new MOrder (Env.getCtx(), C_Order_ID, null);
BigDecimal payAmount = newAmount;
BigDecimal payAmount = amount;
// Info
if (log.isLoggable(Level.CONFIG)) log.config("C_Order_ID=" + C_Order_ID + ", C_Invoice_ID=" + C_Invoice_ID);
@ -273,7 +300,7 @@ public abstract class PaymentFormCash extends PaymentForm {
if (C_Invoice_ID == 0 && order == null)
{
log.config("No Invoice!");
if (log.isLoggable(Level.CONFIG)) log.config("No Invoice!");
processMsg = Msg.getMsg(Env.getCtx(), "CashNotCreated");
throw new AdempiereException(processMsg);
}
@ -283,16 +310,16 @@ public abstract class PaymentFormCash extends PaymentForm {
if (m_cashLine != null
&& payAmount.compareTo(m_cashLine.getAmount()) != 0)
{
log.config("Changed CashBook Amount");
m_cashLine.setAmount(newAmount);
if (log.isLoggable(Level.CONFIG)) log.config("Changed CashBook Amount");
m_cashLine.setAmount(amount);
m_cashLine.saveEx();
}
// Different Date/CashBook
if (m_cashLine != null
&& (newC_CashBook_ID != m_C_CashBook_ID
|| !TimeUtil.isSameDay(m_cashLine.getStatementDate(), newDateAcct)))
&& (C_CashBook_ID != m_C_CashBook_ID
|| !TimeUtil.isSameDay(m_cashLine.getStatementDate(), dateAcct)))
{
if (log.isLoggable(Level.CONFIG)) log.config("Changed CashBook/Date: " + m_C_CashBook_ID + "->" + newC_CashBook_ID);
if (log.isLoggable(Level.CONFIG)) log.config("Changed CashBook/Date: " + m_C_CashBook_ID + "->" + C_CashBook_ID);
MCashLine reverse = m_cashLine.createReversal();
reverse.saveEx();
m_cashLine = null;
@ -301,17 +328,17 @@ public abstract class PaymentFormCash extends PaymentForm {
// Create new
if (m_cashLine == null)
{
log.config("New CashBook");
if (log.isLoggable(Level.CONFIG)) log.config("New CashBook");
int C_Currency_ID = 0;
if (invoice != null)
C_Currency_ID = invoice.getC_Currency_ID();
if (C_Currency_ID == 0 && order != null)
C_Currency_ID = order.getC_Currency_ID();
MCash cash = null;
if (newC_CashBook_ID != 0)
cash = MCash.get (Env.getCtx(), newC_CashBook_ID, newDateAcct, null);
if (C_CashBook_ID != 0)
cash = MCash.get (Env.getCtx(), C_CashBook_ID, dateAcct, null);
else // Default
cash = MCash.get (Env.getCtx(), m_AD_Org_ID, newDateAcct, C_Currency_ID, null);
cash = MCash.get (Env.getCtx(), m_AD_Org_ID, dateAcct, C_Currency_ID, null);
if (cash == null || cash.get_ID() == 0)
{
processMsg = CLogger.retrieveErrorString("CashNotCreated");
@ -320,8 +347,6 @@ public abstract class PaymentFormCash extends PaymentForm {
else
{
MCashLine cl = new MCashLine (cash);
// cl.setAmount(new BigDecimal(bAmountField.getText()));
//ADialog.info(m_WindowNo, this, "m_cashLine - New Cashbook", "Amount: "+cl.getAmount());
if (invoice != null)
cl.setInvoice(invoice); // overrides amount
if (order != null)
@ -329,9 +354,9 @@ public abstract class PaymentFormCash extends PaymentForm {
cl.setOrder(order, null); // overrides amount
m_needSave = true;
}
cl.setAmount(newAmount);
cl.setAmount(amount);
cl.saveEx();
log.config("CashCreated");
if (log.isLoggable(Level.CONFIG)) log.config("CashCreated");
if (invoice == null && C_Invoice_ID != 0)
{
invoice = new MInvoice (Env.getCtx(), C_Invoice_ID, null);
@ -348,7 +373,7 @@ public abstract class PaymentFormCash extends PaymentForm {
order.setC_CashLine_ID(cl.getC_CashLine_ID());
order.saveEx(trxName);
}
log.config("Update Order & Invoice with CashLine");
if (log.isLoggable(Level.CONFIG)) log.config("Update Order & Invoice with CashLine");
}
}
} // have invoice
@ -364,16 +389,15 @@ public abstract class PaymentFormCash extends PaymentForm {
m_mPayment.setAmount(m_C_Currency_ID, payAmount);
// Get changes to cash amount
m_mPayment.setTenderType(MPayment.TENDERTYPE_Cash);
m_mPayment.setBankCash(newC_BankAccount_ID, m_isSOTrx, MPayment.TENDERTYPE_Cash);
m_mPayment.setBankCash(C_BankAccount_ID, m_isSOTrx, MPayment.TENDERTYPE_Cash);
m_mPayment.setC_BPartner_ID(m_C_BPartner_ID);
m_mPayment.setC_Invoice_ID(C_Invoice_ID);
if (order != null)
{
m_mPayment.setC_Order_ID(C_Order_ID);
m_needSave = true;
}
m_mPayment.setDateTrx(newDateAcct);
m_mPayment.setDateAcct(newDateAcct);
m_mPayment.setDateTrx(dateAcct);
m_mPayment.setDateAcct(dateAcct);
m_mPayment.saveEx();
// Save/Post
@ -393,11 +417,25 @@ public abstract class PaymentFormCash extends PaymentForm {
if (log.isLoggable(Level.FINE)) log.fine("NotDraft " + m_mPayment);
}
return true;
}
@Override
public void afterSave(boolean success)
{
if (!success)
return;
/**********************
* Save Values to mTab
*/
log.config("Saving changes");
//
//refresh
getGridTab().dataRefresh(false);
Object paymentIdValue = getGridTab().getValue("C_Payment_ID");
if (paymentIdValue != null && paymentIdValue instanceof Number)
m_C_Payment_ID = ((Number)paymentIdValue).intValue();
else
m_C_Payment_ID = 0;
// Set Payment
if (m_mPayment.getC_Payment_ID() != m_C_Payment_ID)
{
@ -405,7 +443,13 @@ public abstract class PaymentFormCash extends PaymentForm {
getGridTab().setValue("C_Payment_ID", null);
else
getGridTab().setValue("C_Payment_ID", Integer.valueOf(m_mPayment.getC_Payment_ID()));
m_needSave = true;
}
Object cashLineIdValue = getGridTab().getValue("C_CashLine_ID");
if (cashLineIdValue != null && cashLineIdValue instanceof Number)
m_C_CashLine_ID = ((Number)cashLineIdValue).intValue();
else
m_C_CashLine_ID = 0;
// Set Cash
if (newC_CashLine_ID != m_C_CashLine_ID)
{
@ -413,7 +457,7 @@ public abstract class PaymentFormCash extends PaymentForm {
getGridTab().setValue("C_CashLine_ID", null);
else
getGridTab().setValue("C_CashLine_ID", Integer.valueOf(newC_CashLine_ID));
}
return true;
m_needSave = true;
}
}
}

View File

@ -42,12 +42,17 @@ public abstract class PaymentFormCheck extends PaymentForm {
private static final String PAYMENTRULE = MInvoice.PAYMENTRULE_Check;
/** Start Payment */
public int m_C_Payment_ID = 0;
public MPayment m_mPayment = null;
public MPayment m_mPaymentOriginal = null;
protected int m_C_Payment_ID = 0;
protected MPayment m_mPayment = null;
protected MPayment m_mPaymentOriginal = null;
/** Start Bank Account */
public int m_C_BankAccount_ID = 0;
protected int m_C_BankAccount_ID = 0;
/**
*
* @param windowNo
* @param mTab
*/
public PaymentFormCheck(int windowNo, GridTab mTab) {
super(windowNo, mTab);
}
@ -76,7 +81,12 @@ public abstract class PaymentFormCheck extends PaymentForm {
m_C_BankAccount_ID = m_mPayment.getC_BankAccount_ID();
}
public KeyNamePair selectedBankAccount;
protected KeyNamePair selectedBankAccount;
/**
* set default selected bank account and return list of active bank account records
* @return list of active bank account
*/
public ArrayList<KeyNamePair> getBankAccountList() {
selectedBankAccount = null;
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
@ -132,8 +142,19 @@ public abstract class PaymentFormCheck extends PaymentForm {
return ok;
}
public String processMsg = null;
public boolean save(int newC_BankAccount_ID, String routing, String number, String check, BigDecimal amount, String trxName)
protected String processMsg = null;
/**
*
* @param C_BankAccount_ID
* @param routing routing number
* @param number account number
* @param check check number
* @param amount
* @param trxName
* @return true if save successfully
*/
public boolean save(int C_BankAccount_ID, String routing, String number, String check, BigDecimal amount, String trxName)
{
// set trxname for class objects
if (m_mPayment != null)
@ -222,14 +243,13 @@ public abstract class PaymentFormCheck extends PaymentForm {
if (log.isLoggable(Level.FINE)) log.fine("Payment - " + PAYMENTRULE);
// Set Amount
m_mPayment.setAmount(m_C_Currency_ID, payAmount);
m_mPayment.setBankCheck(newC_BankAccount_ID, m_isSOTrx, routing,
m_mPayment.setBankCheck(C_BankAccount_ID, m_isSOTrx, routing,
number, check);
m_mPayment.setC_BPartner_ID(m_C_BPartner_ID);
m_mPayment.setC_Invoice_ID(C_Invoice_ID);
if (order != null)
{
m_mPayment.setC_Order_ID(C_Order_ID);
m_needSave = true;
}
m_mPayment.setDateTrx(m_DateAcct);
m_mPayment.setDateAcct(m_DateAcct);
@ -252,10 +272,25 @@ public abstract class PaymentFormCheck extends PaymentForm {
else
if (log.isLoggable(Level.FINE)) log.fine("NotDraft " + m_mPayment);
return true;
}
@Override
protected void afterSave(boolean success)
{
if (!success)
return;
/**********************
* Save Values to mTab
*/
log.config("Saving changes");
//refresh
getGridTab().dataRefresh(false);
Object paymentIdValue = getGridTab().getValue("C_Payment_ID");
if (paymentIdValue != null && paymentIdValue instanceof Number)
m_C_Payment_ID = ((Number)paymentIdValue).intValue();
else
m_C_Payment_ID = 0;
// Set Payment
if (m_mPayment.getC_Payment_ID() != m_C_Payment_ID)
{
@ -263,15 +298,27 @@ public abstract class PaymentFormCheck extends PaymentForm {
getGridTab().setValue("C_Payment_ID", null);
else
getGridTab().setValue("C_Payment_ID", Integer.valueOf(m_mPayment.getC_Payment_ID()));
m_needSave = true;
}
return true;
}
/**
*
* @param C_Currency_ID
* @param PayAmt
* @return if online payment processor have been configured for tender type check
*/
public boolean isBankAccountProcessorExist(int C_Currency_ID, BigDecimal PayAmt)
{
return isBankAccountProcessorExist(Env.getCtx(), MPayment.TENDERTYPE_Check, "", Env.getAD_Client_ID(Env.getCtx()), C_Currency_ID, PayAmt, null);
}
/**
* Get online payment processor configuration for tender type check
* @param C_Currency_ID
* @param PayAmt
* @return {@link MBankAccountProcessor}
*/
public MBankAccountProcessor getBankAccountProcessor(int C_Currency_ID, BigDecimal PayAmt)
{
return getBankAccountProcessor(Env.getCtx(), MPayment.TENDERTYPE_Check, "", Env.getAD_Client_ID(Env.getCtx()), C_Currency_ID, PayAmt, null);

View File

@ -41,13 +41,18 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
private static final String PAYMENTRULE = MInvoice.PAYMENTRULE_CreditCard;
/** Start Payment */
public int m_C_Payment_ID = 0;
public MPayment m_mPayment = null;
public MPayment m_mPaymentOriginal = null;
public MPaymentTransaction m_mPaymentTransaction = null;
protected int m_C_Payment_ID = 0;
protected MPayment m_mPayment = null;
protected MPayment m_mPaymentOriginal = null;
protected MPaymentTransaction m_mPaymentTransaction = null;
/** Start CreditCard */
public String m_CCType = "";
protected String m_CCType = "";
/**
*
* @param windowNo
* @param mTab
*/
public PaymentFormCreditCard(int windowNo, GridTab mTab) {
super(windowNo, mTab);
}
@ -187,7 +192,12 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
m_CCType = m_mPaymentTransaction.getCreditCardType();
}
public ValueNamePair selectedCreditCard;
protected ValueNamePair selectedCreditCard;
/**
*
* @return list of accepted credit card types
*/
public ValueNamePair[] getCreditCardList()
{
selectedCreditCard = null;
@ -212,8 +222,18 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
return ok;
}
public String processMsg = null;
public boolean save(String newCCType, String newCCNumber, String newCCExp, BigDecimal newAmount, String trxName)
protected String processMsg = null;
/**
*
* @param CCType credit card type
* @param CCNumber credit card number
* @param CCExp credit card expire date
* @param amount ignore
* @param trxName
* @return true if save successfully
*/
public boolean save(String CCType, String CCNumber, String CCExp, BigDecimal amount, String trxName)
{
// set trxname for class objects
if (m_mPayment != null)
@ -307,7 +327,7 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
if (log.isLoggable(Level.FINE)) log.fine("Payment - " + PAYMENTRULE);
// Set Amount
m_mPayment.setAmount(m_C_Currency_ID, payAmount);
m_mPayment.setCreditCard(MPayment.TRXTYPE_Sales, newCCType, newCCNumber, "", newCCExp);
m_mPayment.setCreditCard(MPayment.TRXTYPE_Sales, CCType, CCNumber, "", CCExp);
m_mPayment.setPaymentProcessor();
if (isPOSOrder || isInvoice)
@ -315,7 +335,6 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
else if (isCreditMemo)
{
m_mPayment.setTrxType(MPayment.TRXTYPE_CreditPayment);
// m_mPayment.setOrig_TrxID(kPGOrderIDField.getValue());
}
else if (C_Invoice_ID != 0)
{
@ -342,7 +361,6 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
if (order != null)
{
m_mPayment.setC_Order_ID(C_Order_ID);
m_needSave = true;
}
m_mPayment.setDateTrx(m_DateAcct);
m_mPayment.setDateAcct(m_DateAcct);
@ -377,10 +395,25 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
m_mPayment.saveEx();
}
return true;
}
@Override
protected void afterSave(boolean success)
{
if (!success)
return;
/**********************
* Save Values to mTab
*/
log.config("Saving changes");
//refresh
getGridTab().dataRefresh(false);
Object paymentIdValue = getGridTab().getValue("C_Payment_ID");
if (paymentIdValue != null && paymentIdValue instanceof Number)
m_C_Payment_ID = ((Number)paymentIdValue).intValue();
else
m_C_Payment_ID = 0;
// Set Payment
if (m_mPayment.getC_Payment_ID() != m_C_Payment_ID)
{
@ -388,16 +421,32 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
getGridTab().setValue("C_Payment_ID", null);
else
getGridTab().setValue("C_Payment_ID", Integer.valueOf(m_mPayment.getC_Payment_ID()));
m_needSave = true;
}
}
return true;
}
/**
*
* @param CCType credit card type
* @param CCNumber credit card number
* @param CCVV credit card ccv
* @param CCExp credit card expire date
* @return true if process successfully
*/
public boolean processOnline(String CCType, String CCNumber, String CCVV, String CCExp)
{
return processOnline(CCType, CCNumber, CCVV, CCExp, 0);
}
/**
*
* @param CCType credit card type
* @param CCNumber credit card number
* @param CCVV credit card ccv
* @param CCExp credit card expire date
* @param C_PaymentProcessor_ID optional payment processor id. use the first configure if this is 0
* @return true if process successfully
*/
public boolean processOnline(String CCType, String CCNumber, String CCVV, String CCExp, int C_PaymentProcessor_ID)
{
processMsg = null;
@ -441,7 +490,6 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
else if (isCreditMemo)
{
mpt.setTrxType(MPayment.TRXTYPE_CreditPayment);
// mpt.setOrig_TrxID(kPGOrderIDField.getValue());
}
else if (C_Invoice_ID != 0)
{
@ -504,11 +552,23 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
return !error;
}
/**
*
* @param CCType
* @param PayAmt
* @return true if online payment processor have been configured for tender type credit card
*/
public boolean isBankAccountProcessorExist(String CCType, BigDecimal PayAmt)
{
return isBankAccountProcessorExist(Env.getCtx(), MPayment.TENDERTYPE_CreditCard, CCType, Env.getAD_Client_ID(Env.getCtx()), m_C_Currency_ID, PayAmt, null);
}
/**
* Get online payment processor configuration for tender type credit card
* @param CCType
* @param PayAmt
* @return {@link MBankAccountProcessor}
*/
public MBankAccountProcessor getBankAccountProcessor(String CCType, BigDecimal PayAmt)
{
return getBankAccountProcessor(Env.getCtx(), MPayment.TENDERTYPE_CreditCard, CCType, Env.getAD_Client_ID(Env.getCtx()), m_C_Currency_ID, PayAmt, null);
@ -519,6 +579,17 @@ public abstract class PaymentFormCreditCard extends PaymentForm {
return m_mPayment.isApproved();
}
/**
*
* @param CCType credit card type
* @param CCNumber credit card number
* @param CCVV credit card ccv
* @param CCExp credit card expire
* @param C_BP_BankAccount_ID
* @param CustomerPaymentProfileID
* @return error message if credit card doesn't pass validation
* @throws IllegalArgumentException
*/
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))

View File

@ -26,6 +26,7 @@ import org.compiere.model.MBankAccountProcessor;
import org.compiere.model.MInvoice;
import org.compiere.model.MOrder;
import org.compiere.model.MPayment;
import org.compiere.model.MRole;
import org.compiere.process.DocAction;
import org.compiere.util.DB;
import org.compiere.util.Env;
@ -41,10 +42,16 @@ public abstract class PaymentFormDirect extends PaymentForm {
private String PAYMENTRULE;
/** Start Payment */
public int m_C_Payment_ID = 0;
public MPayment m_mPayment = null;
public MPayment m_mPaymentOriginal = null;
protected int m_C_Payment_ID = 0;
protected MPayment m_mPayment = null;
protected MPayment m_mPaymentOriginal = null;
/**
*
* @param windowNo
* @param mTab
* @param isDebit
*/
public PaymentFormDirect(int windowNo, GridTab mTab, boolean isDebit) {
super(windowNo, mTab);
PAYMENTRULE = isDebit ? MInvoice.PAYMENTRULE_DirectDebit : MInvoice.PAYMENTRULE_DirectDeposit;
@ -71,23 +78,27 @@ public abstract class PaymentFormDirect extends PaymentForm {
}
}
public ArrayList<KeyNamePair> getBPBankAccountList() {
/**
*
* @return List of active bank accounts
*/
public ArrayList<KeyNamePair> getBankAccountList() {
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
/**
* Load Accounts
* Load Bank Accounts
*/
String SQL = "SELECT a.C_BP_BankAccount_ID, NVL(b.Name, ' ')||'_'||NVL(a.AccountNo, ' ') AS Acct "
+ "FROM C_BP_BankAccount a"
+ " LEFT OUTER JOIN C_Bank b ON (a.C_Bank_ID=b.C_Bank_ID) "
+ "WHERE C_BPartner_ID=?"
+ "AND a.IsActive='Y' AND a.IsACH='Y'";
String SQL = MRole.getDefault().addAccessSQL(
"SELECT C_BankAccount_ID, ba.Name || ' ' || ba.AccountNo, ba.IsDefault "
+ "FROM C_BankAccount ba"
+ " INNER JOIN C_Bank b ON (ba.C_Bank_ID=b.C_Bank_ID) "
+ "WHERE b.IsActive='Y' AND ba.IsActive='Y' ORDER BY ba.IsDefault DESC ",
"ba", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, m_C_BPartner_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
@ -121,8 +132,17 @@ public abstract class PaymentFormDirect extends PaymentForm {
return ok;
}
public String processMsg;
public boolean save(int newC_BankAccount_ID, String routing, String number, String trxName)
protected String processMsg;
/**
*
* @param C_BankAccount_ID
* @param routing routing number
* @param number account number
* @param trxName
* @return true if save successfully
*/
public boolean save(int C_BankAccount_ID, String routing, String number, String trxName)
{
// set trxname for class objects
if (m_mPayment != null)
@ -211,13 +231,12 @@ public abstract class PaymentFormDirect extends PaymentForm {
*/
// Set Amount
m_mPayment.setAmount(m_C_Currency_ID, payAmount);
m_mPayment.setBankACH(newC_BankAccount_ID, m_isSOTrx, PAYMENTRULE, routing, number);
m_mPayment.setBankACH(C_BankAccount_ID, m_isSOTrx, PAYMENTRULE, routing, number);
m_mPayment.setC_BPartner_ID(m_C_BPartner_ID);
m_mPayment.setC_Invoice_ID(C_Invoice_ID);
if (order != null)
{
m_mPayment.setC_Order_ID(C_Order_ID);
m_needSave = true;
}
m_mPayment.setDateTrx(m_DateAcct);
m_mPayment.setDateAcct(m_DateAcct);
@ -240,10 +259,25 @@ public abstract class PaymentFormDirect extends PaymentForm {
else
if (log.isLoggable(Level.FINE)) log.fine("NotDraft " + m_mPayment);
return true;
}
@Override
protected void afterSave(boolean success)
{
if (!success)
return;
/**********************
* Save Values to mTab
*/
log.config("Saving changes");
//refresh
getGridTab().dataRefresh(false);
Object paymentIdValue = getGridTab().getValue("C_Payment_ID");
if (paymentIdValue != null && paymentIdValue instanceof Number)
m_C_Payment_ID = ((Number)paymentIdValue).intValue();
else
m_C_Payment_ID = 0;
// Set Payment
if (m_mPayment.getC_Payment_ID() != m_C_Payment_ID)
{
@ -251,17 +285,24 @@ public abstract class PaymentFormDirect extends PaymentForm {
getGridTab().setValue("C_Payment_ID", null);
else
getGridTab().setValue("C_Payment_ID", Integer.valueOf(m_mPayment.getC_Payment_ID()));
m_needSave = true;
}
}
return true;
}
/**
*
* @return true if online payment processor have been configured for direct* tender type
*/
public boolean isBankAccountProcessorExist()
{
String tender = PAYMENTRULE.equals(MInvoice.PAYMENTRULE_DirectDebit) ? MPayment.TENDERTYPE_DirectDebit : MPayment.TENDERTYPE_DirectDeposit;
return isBankAccountProcessorExist(Env.getCtx(), tender, "", Env.getAD_Client_ID(Env.getCtx()), m_C_Currency_ID, m_Amount, null);
}
/**
* Get online payment processor configured for direct* tender type
* @return {@link MBankAccountProcessor}
*/
public MBankAccountProcessor getBankAccountProcessor()
{
String tender = PAYMENTRULE.equals(MInvoice.PAYMENTRULE_DirectDebit) ? MPayment.TENDERTYPE_DirectDebit : MPayment.TENDERTYPE_DirectDeposit;

View File

@ -23,6 +23,11 @@ import org.compiere.model.GridTab;
*/
public abstract class PaymentFormMixedPOS extends PaymentForm {
/**
*
* @param windowNo
* @param mTab
*/
public PaymentFormMixedPOS(int windowNo, GridTab mTab) {
super(windowNo, mTab);
}

View File

@ -33,8 +33,13 @@ import org.compiere.util.Env;
public abstract class PaymentFormOnCredit extends PaymentForm {
/** Start Payment Term */
public int m_C_PaymentTerm_ID = 0;
protected int m_C_PaymentTerm_ID = 0;
/**
*
* @param windowNo
* @param mTab
*/
public PaymentFormOnCredit(int windowNo, GridTab mTab) {
super(windowNo, mTab);
}
@ -45,7 +50,12 @@ public abstract class PaymentFormOnCredit extends PaymentForm {
m_C_PaymentTerm_ID = ((Integer)getGridTab().getValue("C_PaymentTerm_ID")).intValue();
}
public KeyNamePair selectedPaymentTerm = null;
protected KeyNamePair selectedPaymentTerm = null;
/**
* set selected payment term and return list of payment term records
* @return list of active payment terms
*/
public ArrayList<KeyNamePair> getPaymentTermList() {
selectedPaymentTerm = null;
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
@ -98,10 +108,22 @@ public abstract class PaymentFormOnCredit extends PaymentForm {
return list;
}
public boolean save(int newC_PaymentTerm_ID)
/**
* Update payment term of parent grid tab, doesn't create payment record
* @param C_PaymentTerm_ID
* @return true if save successfully
*/
public boolean save(int C_PaymentTerm_ID)
{
if (newC_PaymentTerm_ID != m_C_PaymentTerm_ID)
getGridTab().setValue("C_PaymentTerm_ID", Integer.valueOf(newC_PaymentTerm_ID));
if (C_PaymentTerm_ID != m_C_PaymentTerm_ID)
{
getGridTab().setValue("C_PaymentTerm_ID", Integer.valueOf(C_PaymentTerm_ID));
m_needSave = true;
}
return true;
}
@Override
protected void afterSave(boolean success) {
}
}

View File

@ -0,0 +1,538 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - hengsin *
**********************************************************************/
package org.idempiere.test.form;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.util.ArrayList;
import org.compiere.grid.PaymentFormCheck;
import org.compiere.grid.PaymentFormCreditCard;
import org.compiere.grid.PaymentFormDirect;
import org.compiere.grid.PaymentFormOnCredit;
import org.compiere.model.GridTab;
import org.compiere.model.GridWindow;
import org.compiere.model.MBPartner;
import org.compiere.model.MBankAccountProcessor;
import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
import org.compiere.model.MPayment;
import org.compiere.model.MPaymentProcessor;
import org.compiere.model.MProduct;
import org.compiere.model.MQuery;
import org.compiere.model.PO;
import org.compiere.model.SystemIDs;
import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfo;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.TimeUtil;
import org.compiere.util.Util;
import org.compiere.wf.MWorkflow;
import org.idempiere.test.AbstractTestCase;
import org.idempiere.test.DictionaryIDs;
import org.junit.jupiter.api.Test;
/**
*
* @author hengsin
*
*/
public class PaymentFormTest extends AbstractTestCase {
public PaymentFormTest() {
}
@Test
public void testPaymentFormCheck() {
MOrder order = new MOrder(Env.getCtx(), 0, getTrxName());
order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id));
order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard);
order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
order.setPaymentRule(MOrder.PAYMENTRULE_Check);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line1 = new MOrderLine(order);
line1.setLine(10);
//Azalea Bush
line1.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.AZALEA_BUSH.id));
line1.setQty(new BigDecimal("1"));
line1.setDatePromised(today);
line1.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(getTrxName());
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_SALES_ORDER);
assertNotNull(gridWindow, "Failed to load grid window of Sales Order");
gridWindow.initTab(0);
GridTab gridTab = gridWindow.getTab(0);
MQuery query = new MQuery(MOrder.Table_Name);
query.addRestriction(MOrder.COLUMNNAME_C_Order_ID,"=", order.get_ID());
gridTab.setQuery(query);
gridTab.getTableModel().setImportingMode(false, getTrxName());
gridTab.query(false);
assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB");
assertEquals(order.get_ID(), gridTab.getRecord_ID(), "Wrong record id");
PaymentFormCheckImpl form = new PaymentFormCheckImpl(0, gridTab);
form.loadData();
ArrayList<KeyNamePair> bankAccounts = form.getBankAccountList();
assertTrue(bankAccounts.size() > 0, "Failed to retrieve list of active bank accounts");
assertTrue(form.getSelectedBankAccountId() > 0, "Failed to set default selected bank account");
form.routingNumber = "routingNumber1";
form.accountNumber = "customerAccountNumber1";
form.checkNumber = "checkNumber1";
form.paymentAmount = order.getGrandTotal();
boolean ok = form.saveChangesInTrx(getTrxName());
assertTrue(ok, "Save failed: " + form.getProcessMessage());
assertNotNull(form.getPayment(), "Payment not created");
assertTrue(form.getPayment().get_ID() > 0, "Payment not save successfully");
}
@Test
public void testPaymentFormDirect() {
MOrder order = new MOrder(Env.getCtx(), 0, getTrxName());
order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id));
order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard);
order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
order.setPaymentRule(MOrder.PAYMENTRULE_DirectDebit);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line1 = new MOrderLine(order);
line1.setLine(10);
//Azalea Bush
line1.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.AZALEA_BUSH.id));
line1.setQty(new BigDecimal("1"));
line1.setDatePromised(today);
line1.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(getTrxName());
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_SALES_ORDER);
assertNotNull(gridWindow, "Failed to load grid window of Sales Order");
gridWindow.initTab(0);
GridTab gridTab = gridWindow.getTab(0);
MQuery query = new MQuery(MOrder.Table_Name);
query.addRestriction(MOrder.COLUMNNAME_C_Order_ID,"=", order.get_ID());
gridTab.setQuery(query);
gridTab.getTableModel().setImportingMode(false, getTrxName());
gridTab.query(false);
assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB");
assertEquals(order.get_ID(), gridTab.getRecord_ID(), "Wrong record id");
PaymentFormDirectImpl form = new PaymentFormDirectImpl(0, gridTab, true);
try {
form.dynInit();
} catch (Exception e) {
fail(e);
}
ArrayList<KeyNamePair> bankAccounts = form.getBankAccountList();
assertTrue(bankAccounts.size() > 0, "Failed to retrieve list of active bank accounts");
form.C_BankAccount_ID = bankAccounts.get(0).getKey();
form.routingNumber = "routingNumber1";
form.accountNumber = "customerAccountNumber1";
assertEquals(order.getGrandTotal().setScale(2, RoundingMode.HALF_EVEN), form.getPaymentAmount().setScale(2, RoundingMode.HALF_EVEN), "Wrong Payment Form Amount");
boolean ok = form.saveChangesInTrx(getTrxName());
assertTrue(ok, "Save failed: " + form.getProcessMessage());
assertNotNull(form.getPayment(), "Payment not created");
assertTrue(form.getPayment().get_ID() > 0, "Payment not save successfully");
assertEquals(order.getGrandTotal().setScale(2, RoundingMode.HALF_EVEN), form.getPayment().getPayAmt().setScale(2, RoundingMode.HALF_EVEN), "Wrong Payment Document Amount");
}
@Test
public void testPaymentFormOnCredit() {
MOrder order = new MOrder(Env.getCtx(), 0, getTrxName());
order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id));
order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard);
order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
order.setPaymentRule(MOrder.PAYMENTRULE_DirectDebit);
order.setC_PaymentTerm_ID(DictionaryIDs.C_PaymentTerm.TWO_PERCENT_10_NET_30.id);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line1 = new MOrderLine(order);
line1.setLine(10);
//Azalea Bush
line1.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.AZALEA_BUSH.id));
line1.setQty(new BigDecimal("1"));
line1.setDatePromised(today);
line1.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(getTrxName());
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_SALES_ORDER);
assertNotNull(gridWindow, "Failed to load grid window of Sales Order");
gridWindow.initTab(0);
GridTab gridTab = gridWindow.getTab(0);
MQuery query = new MQuery(MOrder.Table_Name);
query.addRestriction(MOrder.COLUMNNAME_C_Order_ID,"=", order.get_ID());
gridTab.setQuery(query);
gridTab.getTableModel().setImportingMode(false, getTrxName());
gridTab.query(false);
assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB");
assertEquals(order.get_ID(), gridTab.getRecord_ID(), "Wrong record id");
PaymentFormOnCreditImpl form = new PaymentFormOnCreditImpl(0, gridTab);
try {
form.dynInit();
} catch (Exception e) {
fail(e);
}
ArrayList<KeyNamePair> terms = form.getPaymentTermList();
assertTrue(terms.size() > 0, "Failed to retrieve list of active payment terms");
for(KeyNamePair term : terms) {
if (term.getKey() == DictionaryIDs.C_PaymentTerm.NET_30.id) {
form.setPaymentTerm(term.getKey());
}
}
form.saveChangesInTrx(getTrxName());
assertEquals(((Number)gridTab.getValue("C_PaymentTerm_ID")).intValue(), form.getPaymentTerm(), "Wrong Payment Term");
}
@Test
public void testPaymentFormCreditCard() {
MOrder order = new MOrder(Env.getCtx(), 0, getTrxName());
order.setBPartner(MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id));
order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard);
order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
order.setPaymentRule(MOrder.PAYMENTRULE_CreditCard);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line1 = new MOrderLine(order);
line1.setLine(10);
//Azalea Bush
line1.setProduct(MProduct.get(Env.getCtx(), DictionaryIDs.M_Product.AZALEA_BUSH.id));
line1.setQty(new BigDecimal("1"));
line1.setDatePromised(today);
line1.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(getTrxName());
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
GridWindow gridWindow = GridWindow.get(Env.getCtx(), 1, SystemIDs.WINDOW_SALES_ORDER);
assertNotNull(gridWindow, "Failed to load grid window of Sales Order");
gridWindow.initTab(0);
GridTab gridTab = gridWindow.getTab(0);
MQuery query = new MQuery(MOrder.Table_Name);
query.addRestriction(MOrder.COLUMNNAME_C_Order_ID,"=", order.get_ID());
gridTab.setQuery(query);
gridTab.getTableModel().setImportingMode(false, getTrxName());
gridTab.query(false);
assertEquals(1, gridTab.getRowCount(), "Unexpected number of row retrieve from DB");
assertEquals(order.get_ID(), gridTab.getRecord_ID(), "Wrong record id");
PaymentFormCreditCardImpl form = new PaymentFormCreditCardImpl(0, gridTab);
try {
form.dynInit();
} catch (Exception e) {
fail(e);
}
assertEquals(order.getGrandTotal().setScale(2, RoundingMode.HALF_EVEN), form.getPaymentAmount().setScale(2, RoundingMode.HALF_EVEN), "Wrong Payment Form Amount");
form.setCCType(MPayment.CREDITCARDTYPE_MasterCard);
form.CCNumber = "5555555555554444";
form.CCVV = "123";
form.CCExp = "1199";
MBankAccountProcessor[] processors = MBankAccountProcessor.find(Env.getCtx(), MPayment.TENDERTYPE_CreditCard, form.getCCType(), getAD_Client_ID(), order.getC_Currency_ID(), form.getPaymentAmount(), getTrxName());
assertTrue(processors.length > 0, "Fail to retrieve default bank account processor for credit card");
MPaymentProcessor mpp = null;
String payProcessorClass = null;
for(MBankAccountProcessor processor : processors) {
if (processor.accepts(MPayment.TENDERTYPE_CreditCard, form.getCCType())) {
mpp = new MPaymentProcessor(Env.getCtx(), processor.getC_PaymentProcessor_ID(), null);
break;
}
}
assertNotNull(mpp, "Failed to find default payment processor for credit card");
try {
payProcessorClass = mpp.getPayProcessorClass();
mpp.setPayProcessorClass("org.compiere.model.PP_Dummy");
try {
PO.setCrossTenantSafe();
mpp.saveEx();
} finally {
PO.clearCrossTenantSafe();
}
boolean ok = form.saveChangesInTrx(getTrxName());
assertTrue(ok, "Save failed: " + form.getProcessMessage());
assertNotNull(form.getPayment(), "Payment not created");
assertTrue(form.getPayment().get_ID() > 0, "Payment not save successfully");
assertEquals(order.getGrandTotal().setScale(2, RoundingMode.HALF_EVEN), form.getPayment().getPayAmt().setScale(2, RoundingMode.HALF_EVEN), "Wrong Payment Document Amount");
} finally {
mpp.setPayProcessorClass(payProcessorClass);
try {
PO.setCrossTenantSafe();
mpp.saveEx();
} finally {
PO.clearCrossTenantSafe();
}
}
}
private class PaymentFormCheckImpl extends PaymentFormCheck {
private String routingNumber;
private String accountNumber;
private String checkNumber;
private BigDecimal paymentAmount;
public PaymentFormCheckImpl(int windowNo, GridTab mTab) {
super(windowNo, mTab);
try {
dynInit();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public boolean checkMandatory() {
return true;
}
public int getSelectedBankAccountId() {
if (selectedBankAccount != null) {
return selectedBankAccount.getKey();
}
return 0;
}
@Override
public boolean saveChangesInTrx(String trxName) {
return save(getSelectedBankAccountId(), routingNumber, accountNumber,
checkNumber, paymentAmount, trxName);
}
public String getProcessMessage() {
return processMsg;
}
public MPayment getPayment() {
return m_mPayment;
}
@Override
public void showWindow() {
}
@Override
public void closeWindow() {
}
@Override
public Object getWindow() {
return null;
}
}
private class PaymentFormDirectImpl extends PaymentFormDirect {
private String routingNumber;
private String accountNumber;
private int C_BankAccount_ID;
public PaymentFormDirectImpl(int windowNo, GridTab mTab, boolean isDebit) {
super(windowNo, mTab, isDebit);
}
@Override
public boolean checkMandatory() {
return true;
}
@Override
public boolean saveChangesInTrx(String trxName) {
return save(C_BankAccount_ID, routingNumber, accountNumber, trxName);
}
@Override
public void showWindow() {
}
@Override
public void closeWindow() {
}
@Override
public Object getWindow() {
return null;
}
public BigDecimal getPaymentAmount() {
return m_Amount;
}
public String getProcessMessage() {
return processMsg;
}
public MPayment getPayment() {
return m_mPayment;
}
}
private class PaymentFormOnCreditImpl extends PaymentFormOnCredit {
public PaymentFormOnCreditImpl(int windowNo, GridTab mTab) {
super(windowNo, mTab);
}
public int getPaymentTerm() {
return m_C_PaymentTerm_ID;
}
public void setPaymentTerm(int key) {
m_C_PaymentTerm_ID = key;
}
@Override
public boolean checkMandatory() {
return true;
}
@Override
public boolean saveChangesInTrx(String trxName) {
return save(m_C_PaymentTerm_ID);
}
@Override
public void showWindow() {
}
@Override
public void closeWindow() {
}
@Override
public Object getWindow() {
return null;
}
}
private class PaymentFormCreditCardImpl extends PaymentFormCreditCard {
private String CCNumber;
private String CCExp;
private String CCVV;
public PaymentFormCreditCardImpl(int windowNo, GridTab mTab) {
super(windowNo, mTab);
}
public MPayment getPayment() {
return m_mPayment;
}
public String getProcessMessage() {
return processMsg;
}
public BigDecimal getPaymentAmount() {
return m_Amount;
}
public void setCCType(String cctype) {
m_CCType = cctype;
}
public String getCCType() {
return m_CCType;
}
@Override
public boolean checkMandatory() {
return true;
}
@Override
public boolean saveChangesInTrx(String trxName) {
String msg = validateCreditCard(m_CCType, CCNumber, CCVV, CCExp, 0, null);
if (!Util.isEmpty(msg, true)) {
processMsg = msg;
return false;
}
if (!processOnline(m_CCType, CCNumber, CCVV, CCExp))
return false;
return save(m_CCType, CCNumber, CCExp, m_Amount, trxName);
}
@Override
public void showWindow() {
}
@Override
public void closeWindow() {
}
@Override
public Object getWindow() {
return null;
}
}
}