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) »
  • Contribute update API
Pages: [1]

Author Topic: Contribute update API  (Read 1801 times)

ruid

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 4
Contribute update API
May 11, 2009, 06:59:45 pm
I am going to use contribute API function "civicrm_contribution_add" to create a pending contribute then using "civicrm_contribution_get" function to get the contribute id and then update the contribute status to "completed"  by using "civicrm_contribution_add" again.

However, even I provide a 'contribution_id' to the params it keeps adding new contributions. This is a part of my codes.

Code: [Select]
$crm_contribute_id=61;
$params       = array(
                      'contribution_id' => $crm_contribute_id,
                      'contact_id' => $contact_id,
                      'total_amount'    => $amount,
                      'receive_date'           => date('Ymd'),
                      'contribution_type_id'   => 1,
                      'contribution_status_id' => 1, //Completed
                      );
$contribution =& civicrm_contribution_add($params);

It created a new contribute with "id"=62 and the old one wasn't updated.

I suppose the "contact_id" and 'contribution_type_id' are not necessary in the params since I only need to update the status, but it returned with error saying these values are required.

Any ideas?



Sunil

  • I post frequently
  • ***
  • Posts: 131
  • Karma: 23
  • The community around a product more important than the product itself?
    • CiviCRM
Re: Contribute update API
May 11, 2009, 10:31:42 pm
Hi

for updating the contribution record through api

Quote
'contribution_id' => $crm_contribute_id
use
Quote
'id' => $crm_contribute_id

currently
'contact_id', 'total_amount', 'contribution_type_id' are the required fields for the create/update contribution record
HTH
sunil
« Last Edit: May 11, 2009, 10:33:28 pm by Sunil »
The community around a product more important than the product itself?

ruid

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 4
Re: Contribute update API
May 17, 2009, 04:55:07 pm
Thanks for your reply.

However, no matter 'contribution_id' or 'id' it still created a new record.

My current solution is add
Code: [Select]
$params_del       = array(
                      'contribution_id' => $crm_contribute_id
                      );
$contribution_del =& civicrm_contribution_delete($params_del);

to my api code to remove the pending status contribute. It is working so I suspect "add" and "delete" are using the same params key "contribution_id".


torenware

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 4
Re: Contribute update API
October 22, 2009, 11:04:26 pm
This appears to be an "According To Hoyle" bug.  civicrm_contribution_add is NOT setting the "create" parameter in any of the APIs it calls.  Moreover, it will check for duplicates if you set enough of the parameters, and throw a "duplicate contribution found" error.

The test case in the /v3.0/tests/phpunit/api/v2 needs looking at;  the update test is likely invalid.

I'll see if I can fix the API when used for this purpose.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Contribute update API

This forum was archived on 2017-11-26.