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) »
  • Add Surcharge to Event Registration
Pages: [1]

Author Topic: Add Surcharge to Event Registration  (Read 2352 times)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Add Surcharge to Event Registration
November 30, 2009, 06:54:10 am
With Drupal 6 CiviCRM 3.0.2, using hook_civicrm_buildForm I can adjust a priceset's price values to add a surcharge for CC processing. This code I setup to work whether the charge is initiated by the event participant or by the site admin, using the Create Event Registration feature.

The feature requested now is to only add the surcharge when the admin adds a registration paid for by Credit Card and to not add it if the admin selects Check.

I do not see any way to do this via the API.

Is there one?

Thanks.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Add Surcharge to Event Registration
November 30, 2009, 08:08:14 am

the buildAmount hook is called by both the GET and the POST request. You can detect if its a POST and if paid by cheque, then you can remove the credit card charges from the final amount

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Add Surcharge to Event Registration
November 30, 2009, 12:59:51 pm
As discussed on IRC, the civicrm_buildAmount hook does not appear be called when submitting an Event Registration from a URL like:

 civicrm/contact/view/participant?reset=1&action=add&cid=43&context=participant.

Lobo, you suggested I use hook_civicrm_buildForm after this form is submitted, but I don't see in $form (i.e. after the form is submitted) where it is that I could adjust the price set values. Here is the code I use in buildForm when that URL is requested via GET:

Code: [Select]
function mymodule_civicrm_buildForm( $formName, &$form ) {
  if ('CRM_Event_Form_Registration_Register' == $formName ||
      ('CRM_Event_Form_Participant' == $formName && isset($form->_priceSet))
      ) {
  foreach($form->_values['fee']['fields'] as $k => $fields) {
    foreach($fields['options'] as $k2 => $options) {
      $form->_priceSet['fields'][$k]['options'][$k2]['value'] = (1*$form->_priceSet['fields'][$k]['options'][$k2]['value'])+2.5;
      $form->_priceSet['fields'][$k]['options'][$k2]['name'] = (1*$form->_priceSet['fields'][$k]['options'][$k2]['name'])+2.5;
      $form->_values['fee']['fields'][$k]['options'][$k2]['value'] = (1*$form->_values['fee']['fields'][$k]['options'][$k2]['value'])+2.5;
      $form->_values['fee']['fields'][$k]['options'][$k2]['name'] = (1*$form->_values['fee']['fields'][$k]['options'][$k2]['name'])+2.5;
    }
  }
  foreach($form->_elements as $k => $element) {
    if (isset($element->_attributes['price'])) {
      $t = split('_',$element->_attributes['price']);
      $form->_elements[$k]->_attributes['price'] = $t[0] . '_' . ((1*$t[1])+2.5);
    }
  }

  return true;

I looked through print_r($form) in that hook after the form is submitted, but I haven't yet found where the price is located. Perhaps you know where it is?

I will look again tomorrow with fresh eyes also.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Add Surcharge to Event Registration

This forum was archived on 2017-11-26.