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) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Setting up recurring payments with fixed amount, interval and number of payments
Pages: [1]

Author Topic: Setting up recurring payments with fixed amount, interval and number of payments  (Read 2002 times)

Carole Vandermark

  • Guest
Setting up recurring payments with fixed amount, interval and number of payments
January 04, 2010, 08:40:57 pm
I want to set up membership payment options for:
1) a single payment
2) 4 fixed quarterly payments
3) 10 fixed monthly payments  or
4) 20 fixed monthly payments.

I am using civiContribute page definition and do not see how I can specify the number and interval of the payments.  When I enable recurring payments, the interval and number of payments are fill-in boxes for the new member to complete.  Ideally, when a person chooses a payment option, the number of payments, the amount and the interval would be automatically defined.  Please advise how I can control this.

Thanks, Carole

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: Setting up recurring payments with fixed amount, interval and number of payments
January 05, 2010, 07:10:47 am

you can do this via hooks:

1. you can freeze a payment field and basically make that the only option

2. you can set the period to be quarterly or monthly via the UI

3. the 4/10/20 can be checked via a validation rules

the following piece of code freezes a single payment and recurring interval and month. You can go this route and do 3 contribution pages, one for each of your cases

Code: [Select]
function civitest_civicrm_buildForm( $formName, &$form ) {
    if ( $formName == 'CRM_Contribute_Form_Contribution_Main' &&
         $form->getVar( '_id' ) == 1 ) {
        // 358 is the "option value id" of the only  value in the amount table,                                                                                                                           
        // you can get this id, by doing a view source on the HTML                                                                                                                                       
        $defaults = array( 'amount'   => 358,
                           'is_recur' => 1,
                           'frequency_interval' => 1,
                           'frequency_unit' => 'month',
                           'installments' => 12 );
        $form->setDefaults( $defaults );

        // also freeze these elements                                                                                                                                                                     
        $elementNames = array_keys( $defaults );
        foreach ( $elementNames as $element ) {
            $elm =& $form->getElement( $element );
            $elm->freeze( );
        }
    }
}
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

melissam

  • Guest
Re: Setting up recurring payments with fixed amount, interval and number of payments
January 05, 2010, 01:15:34 pm
Quote from: Donald Lobo on January 05, 2010, 07:10:47 am

you can do this via hooks:

1. you can freeze a payment field and basically make that the only option

2. you can set the period to be quarterly or monthly via the UI

3. the 4/10/20 can be checked via a validation rules

the following piece of code freezes a single payment and recurring interval and month. You can go this route and do 3 contribution pages, one for each of your cases

Code: [Select]
function civitest_civicrm_buildForm( $formName, &$form ) {
    if ( $formName == 'CRM_Contribute_Form_Contribution_Main' &&
         $form->getVar( '_id' ) == 1 ) {
        // 358 is the "option value id" of the only  value in the amount table,                                                                                                                           
        // you can get this id, by doing a view source on the HTML                                                                                                                                       
        $defaults = array( 'amount'   => 358,
                           'is_recur' => 1,
                           'frequency_interval' => 1,
                           'frequency_unit' => 'month',
                           'installments' => 12 );
        $form->setDefaults( $defaults );

        // also freeze these elements                                                                                                                                                                     
        $elementNames = array_keys( $defaults );
        foreach ( $elementNames as $element ) {
            $elm =& $form->getElement( $element );
            $elm->freeze( );
        }
    }
}

Where should this code be placed?

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: Setting up recurring payments with fixed amount, interval and number of payments
January 05, 2010, 01:29:41 pm

check:

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification

the first 3 sections detail the hows/whys etc

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

melissam

  • Guest
Re: Setting up recurring payments with fixed amount, interval and number of payments
January 05, 2010, 02:27:12 pm
Thanks for the help. For future reference, here is the end code I used. I created a module with a .info and a .module file per the instructions. In the .module file I put this code
Code: [Select]
<?php

function civicrm_civicrm_buildForm( $formName, &$form ) {
    if ( 
$formName == 'CRM_Contribute_Form_Contribution_Main' &&
         
$form->getVar( '_id' ) == 1 ) {
        
// 268 is the "option value id" of the only  value in the amount table,                                                                                                                           
        // you can get this id, by doing a view source on the HTML                                                                                                                                        
        
$defaults = array( 'amount'   => 268,
                           
'is_pledge' => 1,
                           
'pledge_frequency_interval' => 1,
                           
'pledge_frequency_unit' => 'month',
                           
'pledge_installments' => 12 );
        
$form->setDefaults( $defaults );

        
// also freeze these elements                                                                                                                                                                     
        
$elementNames = array_keys( $defaults );
        foreach ( 
$elementNames as $element ) {
            
$elm =& $form->getElement( $element );
            
$elm->freeze( );
        }
    }
}

Arjan

  • Guest
Re: Setting up recurring payments with fixed amount, interval and number of payments
February 09, 2010, 06:04:05 pm
Lobo, you said "2. you can set the period to be quarterly or monthly via the UI". I'm not seeing a 'quarterly' or 'every 3 months' option through the UI (only day, week, month, year).
Or do you mean the "Allow frequency intervals" option? But I don't want to allow the donater to choose every 2 or 4 months as interval, only every quarter, preferably as an option between every month and every year. Is that possible through the UI (in one form, not multiple)?

Arjan

  • Guest
Re: Setting up recurring payments with fixed amount, interval and number of payments
February 10, 2010, 07:36:26 am
(Again) after talking with Lobo on irc:

Quote
u should be able to do it in one page
and tweak the pledge fields to only allow values you want in the form elements (via hook_buildForm)
and use hook_validate to ensure that the selection is valid
or you can use javascript to do so

jday

  • I post occasionally
  • **
  • Posts: 62
  • Karma: 6
  • CiviCRM version: 4.2
  • CMS version: 7.15
Re: Setting up recurring payments with fixed amount, interval and number of payments
March 15, 2010, 06:43:25 pm
I'm trying to make a dedicated pledge page where the 'is_pledge' is the default but not having luck with this snippet, is it still valid for 3.1.3?

Code: [Select]

function civicrmMods_civicrm_buildForm($formName, &$form) {

if ( $formName == 'CRM_Contribute_Form_Contribution_Main'  && $form->getVar( '_id' ) == 7 ) {
       $defaults = array( 'is_pledge' => 1 );
       $form->setDefaults( $defaults );
}

}

I want the default checked value to be 'I pledge to contribute this amount every'
and hide or unset the 'I want to make a one-time contribution' option
« Last Edit: March 15, 2010, 07:29:35 pm by jday »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Setting up recurring payments with fixed amount, interval and number of payments

This forum was archived on 2017-11-26.