CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Notice when creating a failed contribution via api
Pages: [1]

Author Topic: Notice when creating a failed contribution via api  (Read 391 times)

adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Notice when creating a failed contribution via api
January 24, 2014, 01:35:45 pm
As per the subject when creating a failed contribution via the api (Drupal 7, CiviCRM 4.3.8) the error I get is:

Code: [Select]
Notice: Undefined variable: itemStatus in CRM_Financial_BAO_FinancialItem::add() (line 97 of [whatever] /modules/civicrm/CRM/Financial/BAO/FinancialItem.php).
What I see is that this is where it's trying to add the corresponding entry in the financial_items table for this contribution. At the beginning of the code, there's this logic:

Code: [Select]
    if ($contribution->contribution_status_id == array_search('Completed', $contributionStatuses)) {
      $itemStatus = array_search('Paid', $financialItemStatus);
    }
    elseif ($contribution->contribution_status_id == array_search('Pending', $contributionStatuses)) {
      $itemStatus = array_search('Unpaid', $financialItemStatus);
    }

In other words, this code only expects Completed or Pending contributions, and the reason it's getting this notice is because it's neither, so the itemStatus doesn't get set.

So:

1. This code could be improved to deal with the unexpected.
2. I assume whoever wrote this decided it should never be called except for these two cases, which means that the api is probably incorrectly calling this. At least, I assume that a failed contribution should not create an item like this.

Alternatively, maybe there's a required workflow that hasn't come to my attention - e.g. maybe all contributions need to be created as pending and then updated to failed?

I'm happy to provide a patch if these issues can be clarified.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Notice when creating a failed contribution via api

This forum was archived on 2017-11-26.