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

[REF] Deprecate calls to createCreditNoteId #15492

Merged
merged 1 commit into from
Oct 14, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Code cleanup - createCreditNoteId is called from 3 places but only one is necessary, deprecate the other 2.

Before

Calls to createCreditNoteId are distributed & confusing

After

Only one 'active' place - in Contribution::add when the status is updated. The others are deprecated

Technical Details

createCreditNoteId is called from BAO_Contribution::add whenever the contribution
status is 'Cancelled' or 'Refunded. If was not previously called for 'ChargeBack' but it turned out it was later set so ChargeBack handling is move to be included in that call for no change in behaviour.

A few lines later recordFinancialAccounts is called, so by the time recordFinancialAccounts is called
it is already set & the empty check will prevent these lines being hit.

All 4 places where updateFinancialAccounts are called in the
code are from recordFinancialAccounts.

Record financial accounts is called from Contribution Create & Payment create.

contribution.create does not rely on these lines to set the creditnote_id, as discussed.

In the BAO_Payment there are 2 scenarios

  1. payment is positive
  2. payment is negative - in this case recordRefundPayment is called.

It's logically OK for the code to NOT to create a credit note when being called from payment.create
because payment.create is NOT cancelling the contribution or refunding it and the funtion NEVER changes
the contribution status to Refunded, Cancelled, Chargeback (those are 'business' statuses).

Payment.create updates contribution status to reflect a payment has been made - eg change from
Pending to partially paid or various payment-related-statuses to 'Completed'.

ie Payment.create is

  • only adding payments (or refunds) to an order
  • and the decision as to whether something is being credited back & warrants a credit note id or
    whether the payment is being returned due to overpayment or other payment related concerns does
    not belong in the payment code.

Payment create never changes contribution
status to Refunded, Cancelled or ChargeBack so the lines would never be hit from payment.create

This leaves us with the conclusion the lines are never hit. For safety/sanity we can deprectate them rather
than remove them by now. That way if the above analysis is wrong a test will fail.

Less likely (given financial test coverage) the deprecation notice will show up in the wild in the next few months.

(It's rather unclear how it DOES fit in since it feels like creditnote_id only applies if the entire
contribution is being refunded & really should be generated at the point at which, for example, the event
fees associated with it are changed - however, complaints to date about creditnote_id have all focussed
on performance issues, not logic issues

Comments

@bjendres @monishdeb it turns out we can get the createCreditNoteID to being something that could just be called from a pre hook as the other places in the code are not needed after some digging

@civibot
Copy link

civibot bot commented Oct 13, 2019

(Standard links)

@civibot civibot bot added the master label Oct 13, 2019
@mattwire
Copy link
Contributor

@eileenmcnaughton test fail is related

@eileenmcnaughton
Copy link
Contributor Author

@mattwire thanks - looks like it's test setup related - will fix

createCreditNoteId is called from BAO_Contribution::add whenever the contribution
status is 'Cancelled' or 'Refunded.

A few lines later recordFinancialAccounts is called, so by the time recordFinancialAccounts is called
it is already set & the empty check will prevent these lines being hit.

All 4 places where updateFinancialAccounts are called in the
code are from recordFinancialAccounts.

Record financial accounts is called from Contribution Create & Payment create.

contribution.create does not rely on these lines to set the creditnote_id, as discussed.

In the BAO_Payment there are 2 scenarios
1) payment is positive
2) payment is negative - in this case recordRefundPayment is called.

It's logically OK for the code to  NOT to create a credit note when being called from payment.create
 because payment.create is NOT cancelling the contribution or refunding it and the funtion NEVER changes
 the contribution status to Refunded, Cancelled, Chargeback (those are 'business' statuses).

Payment.create updates contribution status to reflect a payment has been made - eg change from
Pending to partially paid or various payment-related-statuses to 'Completed'.

ie Payment.create is
- only adding payments (or refunds) to an order
- and the decision as to whether something is being credited back & warrants a credit note id or
whether the payment is being returned due to overpayment or other payment related concerns does
not belong in the payment code.

Payment create never changes contribution
status to Refunded, Cancelled or ChargeBack so the lines would never be hit from payment.create

This leaves us with the conclusion the lines are never hit. For safety/sanity we can deprectate them rather
than remove them by now. That way if the above analysis is wrong a test will fail.

Less likely (given financial test coverage) the deprecation notice will show up in the wild in the next few months.

(It's rather unclear how it DOES fit in since it feels like creditnote_id only applies if the entire
contribution is being refunded & really should be generated at the point at which, for example, the event
fees associated with it are changed - however, complaints to date about creditnote_id have all focussed
on performance issues, not logic issues
@eileenmcnaughton
Copy link
Contributor Author

It's passing now

@mattwire mattwire merged commit 8b82f57 into civicrm:master Oct 14, 2019
@eileenmcnaughton eileenmcnaughton deleted the credit branch October 14, 2019 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants