fatal error in "make pledge payment" if previous payment had soft credit AND contribution page has no "honoree" profile
Reproduced on https://dmaster.demo.civicrm.org/ ("Powered by CiviCRM 5.23.alpha1", also on versions as early as 5.19.2) with these steps:
- Log in as 'demo' user.
- Check configuration the existing "help support CiviCRM" contribution page, and ensure it's configured to allow pledges, and that the Honoree Section is not enabled.
- Visit the live contribution page and submit a pledge for multiple installments
- Visit the contact record for the 'demo' user and observe that the pledge was correctly created, with one completed payment in the correct amount.
- Edit this completed payment and make no other change except to assign a soft credit (I did it for the full amount, but probably this bug repro will happen for any partial amount) to some other contact. Save that edit.
- Extra credit: record as many payments on this pledge as you like, some with soft credits and some without; but ensure that the most recent payment has a soft credit.
- Visit the user dashboard at [url]/civicrm/user; there, find the pledge under "My Pledges", and click the "Make a payment" link for that pledge.
- Observe the fatal error:
Sorry, due to an error, we are unable to fulfill your request at the moment. You may want to contact your administrator or service provider with more details about what action you were performing when this occurred. One of parameters (value: ) is not of the type Positive
Analysis:
At around this line https://lab.civicrm.org/dev/core/blob/master/CRM/Contribute/Form/Contribution/Main.php#L163, the code assumes that if there are soft credits, then there must be an "honoree" profile on the contribution page. Oddly, it actually makes that decision based only on one completed contribution, which by chance is usually the one with the greatest contribution id, thus normally the most recent one.
Possible solution:
It's probably enough to test whether $this->_honoreeProfileId
is set (maybe around https://lab.civicrm.org/dev/core/blob/master/CRM/Contribute/Form/Contribution/Main.php#L171) before trying to use it in this way. But I do wonder if we should also try and clean up that odd foreach logic in lines 163 through 166: the foreach()
is checking all completed contributions, but the if()
is only acting on the last one checked.