From 5c2effc5545d375049109ff528f32cddde2c29e3 Mon Sep 17 00:00:00 2001 From: hengsin Date: Tue, 7 Dec 2021 18:56:26 +0800 Subject: [PATCH] IDEMPIERE-5085 Credit card fields of Payment should be clear after change of tender type (#1037) --- .../src/org/compiere/model/MPayment.java | 31 +++++++++ .../org/idempiere/test/model/PaymentTest.java | 68 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 org.idempiere.test/src/org/idempiere/test/model/PaymentTest.java diff --git a/org.adempiere.base/src/org/compiere/model/MPayment.java b/org.adempiere.base/src/org/compiere/model/MPayment.java index 30ee7b39b5..b501045c14 100644 --- a/org.adempiere.base/src/org/compiere/model/MPayment.java +++ b/org.adempiere.base/src/org/compiere/model/MPayment.java @@ -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; } // beforeSave diff --git a/org.idempiere.test/src/org/idempiere/test/model/PaymentTest.java b/org.idempiere.test/src/org/idempiere/test/model/PaymentTest.java new file mode 100644 index 0000000000..8552f332c7 --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/model/PaymentTest.java @@ -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()); + } +}