2

I'm trying to debug a contribution page and I see that one of the contribution parameters is not set properly. I would like to see where exactly this parameter is being set so I can understand why it is not getting the proper value.

I've been looking inside the CRM_Contribute_Form_ContributionBase class and trying to figure out where its $_params variable is being set. But I have had no success.

What I've done so far (note: I'm referring to the code for 4.6.8):
1) Determined that one of the parameters in my payment processor (Stripe) is not being correctly set, and this is the cause of the error that I am getting ("Stripe.js token was not passed! Report this message to the site administrator.").
2) Saw that the contribution parameters are being passed to my payment proc.
3) Therefore, go one level up. The class CRM_Contribute_BAO_Contribution_Utils is calling the doDirectPayment() method of my payment proc. And it is passing the parameters. This calling happens in the processConfirm() method. But the processConfirm() method is itself passed the contribution params.
4) So, one level up. Now we find ourselves in CRM_Contribute_Form_Contribution_Confirm->postProcess(). So where does this postProcess() method get the contribution params from? It gets them from $this->_params (line 1037). But the CRM_Contribute_Form_Contribution_Confirm class does not have such a field. Then let's go to its parent.
5) The parent is CRM_Contribute_Form_ContributionBase. It has a $_params field. But I have not been able to ascertain where that field is set. I only saw that later on some parameters are added, however the params that I'm interested in were already set.

P.S. If someone has any tips or resources on how to more efficiently debug situations like these, please let me know. Finding out the above took me hours. I found it quite difficult to follow these parameters that are being passed around mountains of code, and most of all I could not get to the source (i.e. where they are first being set).

1

I highly recommend setting up an IDE with debugger so you can easily step through the code while it is executing. Yes it's a little bit of work to install and learn to use those tools, but worth it!

My IDE tells me that the $_params variable is an array declared in CRM_Contribute_Form_ContributionBase but mostly populated during CRM_Contribute_Form_Contribution_Confirm::preProcess().

  • Thanks, Coleman. I'm using Netbeans+XDebug. You say "my IDE tells me". Which IDE are you using and where does it tell you that? – Borislav Zlatanov Sep 14 '15 at 9:26
  • 1
    I use PHPStorm + XDebug. Not an endorsement, but it works for me. I could have put in breakpoints and stepped backwards through function calls to see the variable being populated, but in this case all I did was highlight the variable and I could see in the code that the preProcess function writes to it a lot. – Coleman Sep 15 '15 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.