Fix Payment.create with a negative value to create the correct financial items
authoreileen <emcnaughton@wikimedia.org>
Sat, 2 Nov 2019 02:39:16 +0000 (15:39 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 5 Nov 2019 21:01:48 +0000 (10:01 +1300)
commit6ac768e7c3f499c062029c29f87bc06c29706a85
tree829ede2b0418f24bde68d5fa0de488d9ac9f47a2
parent8140300b85c7bfdce8a777778164c4f044c9766f
Fix Payment.create with a negative value to create the correct financial items

The job of a refund in this function turns out to be exactly the same as the a payment. I originally thought the
from & to accounts would be reversed but in fact because we are recording a negative amount that is not the case.
We need the from-to accounts to be the same. The only difference turns out to be the status
of the financialTrxn (Completed vs Refunded it seems).

Without this change the refund code is calling the recordFinancialAccounts function but after stepping
through it I'm sure the only thing that function is doing for it is creating the
FinancialTrxn. It *should* be creating the EntityFinancialItem too but it is not
and the best place for that to be done is in the payment class not in a spaghetti function.

Note that after this we need some robust testing & probably a follow up
patch on the handling of tax items - which is unlikely to be correct since it wasn't in the past
AFAIK and is unchanged.....

However, this fixes an important bug & should be merged as soon as it is confirmed non-regressive
to allow the next one to be investigated

m
CRM/Financial/BAO/Payment.php
api/v3/Payment.php
tests/phpunit/api/v3/PaymentTest.php