Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent financial transactions from being saved with no payment instr… #12502

Merged
merged 1 commit into from
Jul 18, 2018

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Prevent financial transactions from being saved with no payment instrument

https://lab.civicrm.org/dev/core/issues/264

Before

Create a completed contribution.
Edit contribution by increasing contribution amount and net amount.
This will create a new financial transaction with NO Payment Instrument.

After

Payment instrument saved

Technical Details

This is a very small fix targetted to be included in 5.4 & the 5.3 security drop. I'm not a fan of how we are passing around the contribution in params / handling this but loading when not loaded is
going to prevent the issue

Comments

In the big picture we want to freeze total_amount and leave people with 2 options

  1. delete & recreate
  2. use lineitemeditor extension
    https://github.com/JMAConsulting/biz.jmaconsulting.lineitemedit/blob/master/README.md

I think this is not a recent regression but recent changes (the payment edit block) made it more visible.

I also think this fix is safe and we should include it ASAP (

@civibot
Copy link

civibot bot commented Jul 17, 2018

(Standard links)

@@ -3400,6 +3400,9 @@ public static function recordFinancialAccounts(&$params, $financialTrxnValues =
// change Payment Instrument for a Completed contribution
// first handle special case when contribution is changed from Pending to Completed status when initial payment
// instrument is null and now new payment instrument is added along with the payment
if (!$params['contribution']->payment_instrument_id) {
$params['contribution']->find(TRUE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using $params['prevContribution']->payment_instrument_id ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pradpnayak yeah I tossed that up - TBH I was 6 one way half a dozen the other on it - I think in the end I chose this as loading the object could reduce other unpredictabilities - but I could have equally gone with the trivial performance benefit of prevContribution

@pradpnayak
Copy link
Contributor

pradpnayak commented Jul 17, 2018

Eileen, I did QA on current state of code.

Test case:
Create a completed $122 contribution.
Edit contribution amount and net amount to $120.

Before: civicrm_financial_trxn.payment_instrument_id is set to NULL

before

After: civicrm_financial_trxn.payment_instrument_id is set to
civicrm_contribution.payment_instrument_id
after

@eileenmcnaughton
Copy link
Contributor Author

@pradpnayak should that second be AFTER not 2 befores? - Is that an endorsement to merge?

@pradpnayak
Copy link
Contributor

@eileenmcnaughton Sorry it should be after, I have updated my comment. I will do QA one more time with actual db check. Give me some time i will add my results soon.

@eileenmcnaughton
Copy link
Contributor Author

@pradpnayak related discussion on #12506 too

@pradpnayak
Copy link
Contributor

@eileenmcnaughton i have added my notes on #12506 (comment)

@eileenmcnaughton
Copy link
Contributor Author

Merging per discussion on #12506

@eileenmcnaughton eileenmcnaughton merged commit ea4ad8b into civicrm:5.4 Jul 18, 2018
@eileenmcnaughton eileenmcnaughton deleted the no_pay branch July 18, 2018 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants