IDEMPIERE-5085 Credit card fields of Payment should be clear after change of tender type (#1037)

This commit is contained in:
hengsin 2021-12-07 18:56:26 +08:00 committed by GitHub
parent 1f1797ce5b
commit 5c2effc554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 0 deletions

View File

@ -846,6 +846,37 @@ public class MPayment extends X_C_Payment
} }
} }
if (!isProcessed())
{
if (!TENDERTYPE_CreditCard.equals(getTenderType()))
{
if (!Util.isEmpty(getCreditCardType(), true))
{
setCreditCardType(null);
}
if (!Util.isEmpty(getCreditCardNumber(), true))
{
setCreditCardNumber(null);
}
if (!Util.isEmpty(getCreditCardVV(), true))
{
setCreditCardVV(null);
}
if (getCreditCardExpMM() > 0)
{
set_Value(COLUMNNAME_CreditCardExpMM, null);
}
if (getCreditCardExpYY() > 0)
{
set_Value(COLUMNNAME_CreditCardExpYY, null);
}
}
}
return true; return true;
} // beforeSave } // beforeSave

View File

@ -0,0 +1,68 @@
/***********************************************************************
* 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.model;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.compiere.model.MPayment;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Util;
import org.idempiere.test.AbstractTestCase;
import org.junit.jupiter.api.Test;
/**
*
* @author hengsin
*
*/
public class PaymentTest extends AbstractTestCase {
private final static int BP_JOE_BLOCK = 118;
public PaymentTest() {
}
@Test
public void testClearCreditCardFields() {
MPayment payment = new MPayment(Env.getCtx(), 0, getTrxName());
payment.setC_DocType_ID(true);
payment.setC_BPartner_ID(BP_JOE_BLOCK);
payment.setTenderType(MPayment.TENDERTYPE_CreditCard);
payment.setCreditCard(MPayment.TRXTYPE_Sales, MPayment.CREDITCARDTYPE_MasterCard, "5555555555554444", "123", "0122");
int C_BankAccount_ID = DB.getSQLValueEx(getTrxName(), "SELECT C_BankAccount_ID FROM C_BankAccount WHERE IsActive='Y' AND AD_Client_ID=? "
+ "AND IsDefault='Y' ORDER BY C_BankAccount_ID", getAD_Client_ID());
payment.setC_BankAccount_ID(C_BankAccount_ID);
payment.setC_Currency_ID(Env.getContextAsInt(Env.getCtx(), Env.C_CURRENCY_ID));
payment.saveEx();
assertEquals("123", payment.getCreditCardVV());
payment.setTenderType(MPayment.TENDERTYPE_Check);
payment.saveEx();
assertTrue(Util.isEmpty(payment.getCreditCardVV()), "Credit card verification code not clear after change of tender type: "+payment.getCreditCardVV());
}
}