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

Author Topic: New Pledge API  (Read 1289 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
New Pledge API
January 14, 2011, 02:21:54 pm
I am using the new Pledge API as follows:
 $p = array(
                        'contact_id'             => $this->_individualId,
                        'pledge_create_date'    => date('Ymd'),
                        'start_date'    => date('Ymd'),
                        'scheduled_date'    => date('Ymd',$dayaftertomorrow), 
                        'pledge_amount'         => 100.00,
                        'pledge_status_id'         => '2',
                        'contribution_type_id'  => '1',
                        'pledge_original_installment_amount' => 20,
                        'frequency_interval'             => 1,
                        'frequency_unit'             => 'month',
                        'frequency_day'            => 1,
                        'installments'            =>5,
         
                  );                       
        $this->_pledge =& civicrm_pledge_create($p);

I am using the code from:  http://svn.civicrm.org/civicrm/branches/trunk.api/api/v2/Pledge.php

I have successfully loaded all the pledges using this API. However, when I am in the staff area and looking at the scheduled installments for one of the imported pledges, there is no "Submit Payment" link or "Edit Scheduled Payment" link.

I have looked at the records in "civicrm_pledge" and do not see any difference between an imported pledge as compared to one I created in the UI.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: New Pledge API
January 14, 2011, 02:53:27 pm
Is the difference in the pledge_payment table?

Try passing in status_id as well - it might need it to set the pledge_payments status
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: New Pledge API
January 14, 2011, 03:42:07 pm
I was able to manually fix the issue with SQL by updating the "status_id" field in the civicrm_pledge_payment table.   I will try adding the new parameter that you suggest to the API call.

A slightly related question: Which API should I call to import past transactions that are related to the pledge that I created via the API.  Such as a pledge with 12 installments, 5 of which have already been paid.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: New Pledge API
January 15, 2011, 11:16:34 am
Hi Sarah,

Check out

https://svn.fuzion.co.nz/repos/fuzion-code/trunk/drupal/modules/custom/civimigrate/civimigrate.pledge.inc
https://svn.fuzion.co.nz/repos/fuzion-code/trunk/drupal/modules/custom/civimigrate/civimigrate.contribution.inc

These are the 2 files in the civimigrate swag I have been using to import pledges. Migrate + civimigrate basically just take a view & convert the data into something to pass into the api

By the time you see this

  $errors = migrate_destination_invoke_all('prepare_pledge', $params, $tblinfo, $row);

the $params object has been populated (this line calls hooks from anycustom modules you add)

Basically I import the pledges & then use a views relationship to ensure the contributions table holds a pledge id & then I pass in a contribution create with the pledge_id as a param & the code in the civimigrate.contribution.inc table deals with it
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: New Pledge API
January 15, 2011, 08:40:43 pm
I added  "status_id"  => 2

to the array passed to the API call, but it did not help. The status id on the pledge payment was still null.

My workaround is to run the following SQL statement, after running the batch program:

update `civicrm_pledge_payment`
set status_id = 2
where status_id is null
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: New Pledge API
January 16, 2011, 11:37:47 am
Hi Sarah,

I'll take another look @ what I did to make this work - in the meantime - do you want to document what you found on the wiki?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

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

This forum was archived on 2017-11-26.