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) »
  • Contribution action functions
Pages: [1]

Author Topic: Contribution action functions  (Read 397 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Contribution action functions
July 23, 2014, 05:12:53 pm
I'm looking at the fact that there are some contribution updates that have actions associated with them & wondering how that fits in our api model.

For example - there is a difference between updating a contribution to having a status of refunded or completed and refunding or completing the transaction. We currently have a specific action for completetransaction which, in addition to updating the status, also ensures related entities are updated and sends out confirmation emails. This leverages the actions taken when updating from IPN.

I'm fairly sure, however, that updating a transaction to cancelled or refunded does not trigger the business actions in the baseIPN class for that sort of transaction. We also would want having the ability to pass a refund request to the payment processor at some point.

So, at the very semantic level - we have said the action should always be 'create' with status_id  = 3 (e.g) but then we would be staring in the face of more magic params ('action_status_update_with_processor', 'send_emails', 'update_related_entities') since I'm not sure we can start adding that as std business logic.

Which leaves the other path of having things like 'recurring_contribution.cancel' as it's own action. Obviously the question is - where would it stop. At this stage it seems possible that we would have actions for change-of-status within reserved statuses.

Thoughts ? Is our current 'everything is a create' too brittle for more nuanced business logic?
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

nicolas

  • I post occasionally
  • **
  • Posts: 92
  • Karma: 6
    • cividesk
  • CiviCRM version: 4.4 LTS
  • CMS version: Standalone (yep)
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Contribution action functions
July 25, 2014, 11:12:59 am
Eileen,

This is a very interesting point, and there is no easy answer as it depends on the use case for which the API is used.

If you are using the API to implement a contribution form, you would want all business logic to be executed on creation and status change for the contribution.
If however you are using the API to implement a synchronization with an outside giving system, you would not want this business logic to be executed as logically confirmation emails, payment processor updates, etc would have been executed by the other giving system.

So ... could the CompleteTransaction action be extended to accept different statuses and perform specified business logic, ie.
      civicrm_api3( 'Contribution', 'CompleteTransaction', array(
          'id' => 728,
          'status' => 'Canceled',
      ));
would cancel the contribution and perform all business logic actions? (maybe rename 'CompleteTransaction'  to 'Execute' or similar)

Could this principle be needed for other entities as well? What about Pledge? Participant? Mailing?

--Nicolas.
cividesk -- CiviCRM delivered ... your way!

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Contribution action functions
July 25, 2014, 01:19:00 pm
Is it perhaps worth adding a new param to the API to indicate whether business logic actions should be run or not?  I realize that currently the actions taken may not be consistent, which means that this might be an API v4-focused suggestion.  It seems inevitable that support for both triggering and bypassing business logic will be needed for a variety of API activities. 

I can even think of some oddball cases right now - for instance, updating civicrm_address.master_id (for shared addresses) with an address that belongs to an organization triggers a function to set the Current Employer relationship.  Bypassing business logic would allow you to update the master_id without creating a relationship.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

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

This forum was archived on 2017-11-26.