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) »
  • Contribution source being overwritten in online pay-later contribution
Pages: [1]

Author Topic: Contribution source being overwritten in online pay-later contribution  (Read 935 times)

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Contribution source being overwritten in online pay-later contribution
January 06, 2011, 03:37:10 am
I think I've found a defect in 3.3.2. It is reproducible on the 3.3 demo.

Steps to reproduce.
  • Create a profile which includes the Contribution Source field
  • Create a contribution page which includes that profile and allows pay later contributions
  • Create a contribution that is "pay now" and enter a value for the Contribution Source
  • This works as expected: the contribution and the receipt show the entered source
  • Create a contribution that is "pay later" and enter a value for the Contribution Source
  • This fails - the source reverts to the default: "Online Contribution: <page title>"

See the first comment below for a patch.

The problem lies in CRM/Contribute/BAO/Contribution/Utils.php and is due to the 'source' variable not being set equal to the 'contribution_source' before the contribution is processed via CRM_Contribute_Form_Contribution_Confirm::processContribution.

This is the case that works, on lines 236-252, and 'source' is set beforehand ...

Code: [Select]
           if ( isset( $paymentParams['contribution_source'] ) ) {
                $form->_params['source'] = $paymentParams['contribution_source'];
            }
            
            // check if pending was set to true by payment processor
            $pending = false;
            if ( CRM_Utils_Array::value( 'contribution_status_pending',
                                         $form->_params ) ) {
                $pending = true;
            }
            if ( !($paymentParams['is_recur'] && $form->_contributeMode == 'direct') ) {
                $contribution =
                    CRM_Contribute_Form_Contribution_Confirm::processContribution( $form,
                                                                                   $form->_params, $result,
                                                                                   $contactID, $contributionType,
                                                                                   true, $pending, true );
            }

This is the code that fails, on lines 102-142. Not only is $paymentParams['contribution_source'] copied *after* the payment is processed, but it is copied into $form->_params['source'] (if the cases are symmetrical it should be copied into $paymentparams['source'] since that is the argument to processContribution()) ...

Code: [Select]
           $contribution =
                CRM_Contribute_Form_Contribution_Confirm::processContribution(
                                                                              $form,
                                                                              $paymentParams,
                                                                              null,
                                                                              $contactID,
                                                                              $contributionType,
                                                                              true, true, true );
            $form->_params['contributionID'    ] = $contribution->id;
            $form->_params['contributionTypeID'] = $contributionType->id;
            $form->_params['item_name'         ] = $form->_params['description'];
            $form->_params['receive_date'      ] = $now;
            
            if ( $form->_values['is_recur'] &&
                 $contribution->contribution_recur_id ) {
                $form->_params['contributionRecurID'] = $contribution->contribution_recur_id;
            }
            
            $form->set( 'params', $form->_params );
            $form->postProcessPremium( $premiumParams, $contribution );
          
            if ( $form->_values['is_monetary'] && $form->_amount > 0.0 ) {
                // add qfKey so we can send to paypal
                $form->_params['qfKey'] = $form->controller->_key;
                if ( $component == 'membership' ) {
                    $membershipResult = array( 1 => $contribution );
                    return $membershipResult;
                } else {
                    if ( ! $form->_params['is_pay_later'] ) {
                        $result =& $payment->doTransferCheckout( $form->_params, 'contribute' );
                    } else {
                        // follow similar flow as IPN
                        // send the receipt mail
                        $form->set( 'params', $form->_params );
                        if ( $contributionType->is_deductible ) {
                            $form->assign('is_deductible',  true );
                            $form->set('is_deductible',  true);
                        }
                        if( isset( $paymentParams['contribution_source'] ) ) {
                            $form->_params['source'] = $paymentParams['contribution_source'];
                        }
« Last Edit: January 06, 2011, 09:01:55 pm by ken »

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: Contribution source being overwritten in online pay-later contribution
January 06, 2011, 09:00:03 pm
The following patch corrects the problem on my 3.3.2 drupal install.

Code: [Select]
--- /data/Download/CiviCRM/civicrm-3.3.2-drupal/./CRM/Contribute/BAO/Contribution/Utils.php 2010-12-23 03:54:12.000000000 +1100
+++ /data/Work/IT/CiviCRM/Local/3.3.2/php/./CRM/Contribute/BAO/Contribution/Utils.php 2011-01-07 14:00:36.163410001 +1100
@@ -99,6 +99,9 @@
             // when we get a callback from the payment processor
             // also add the contact ID and contribution ID to the params list
             $paymentParams['contactID'] = $form->_params['contactID'] = $contactID;
+            if ( isset( $paymentParams['contribution_source'] ) ) {
+                $paymentParams['source'] = $paymentParams['contribution_source'];
+            }
             $contribution =
                 CRM_Contribute_Form_Contribution_Confirm::processContribution(
                                                                               $form,

This raises some further questions I'm not qualified to answer...
  • There are other calls to 'processContribution' in this file - should they have a similar change made?
  • Why are 'source' and 'contribution_source' separate variables? If they were merged would the code be simplified, or would something be lost?
  • Does this change have any side-effects?

Ken
« Last Edit: January 06, 2011, 09:02:57 pm by ken »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Contribution source being overwritten in online pay-later contribution

This forum was archived on 2017-11-26.