Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21436 - Fix fatal error on pay later #11286

Merged
merged 2 commits into from
Nov 17, 2017

Conversation

jitendrapurohit
Copy link
Contributor

@jitendrapurohit jitendrapurohit commented Nov 16, 2017

Overview

This PR fixes fatal error on pay later contribution page regressed from previous versions.

Before

Errors with the message

Fatal error: Call to a member function getPaymentFormFields() on null in /Users/jitendra/src/civicrm/CRM/Contribute/Form/ContributionBase.php on line 589

After

works fine

Technical Details

This change adds pay later processor to $this->_paymentProcessors object. Git blame of this line shows it has not been changed from a very long time. So, it was never assigned, but it came to our notice after changes made in CRM-21134.

Comments

Can this be considered for 4.7.2-rc merge?



@jitendrapurohit jitendrapurohit changed the title Fix fatal error on pay later CRM-21436 - Fix fatal error on pay later Nov 16, 2017
@jitendrapurohit
Copy link
Contributor Author

jenkins, retest this please

@@ -580,7 +580,7 @@ public function assignToTemplate() {

// The concept of contributeMode is deprecated.
// The payment processor object can provide info about the fields it shows.
if ($assignCCInfo) {
if ($assignCCInfo && $this->_paymentProcessor) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed here for the fix, added just to be safe.

@eileenmcnaughton
Copy link
Contributor

@jitendrapurohit this looks good - I'm less inclined to include the extra 'just in case' because they can be hard to reverse engineer later.

In the first one

 if ($isMonetary &&
  •    (!$isPayLater || !empty($this->_values['payment_processor']))
    
  •    ($isPayLater || !empty($this->_values['payment_processor']))
    

Could it not just be $isMonetary? it seems that if it is monetary there MUST be a payment processor or else it must be pay later.

In the second case I think perhaps we can rename $assignCCInfo to $isMonetary for clarity?

@jitendrapurohit
Copy link
Contributor Author

Thanks @eileenmcnaughton. I've tested the above suggestion and updated the PR.

While testing I also saw that when no payment processor or pay later is enabled for a contribution page - instead of throwing an exception, the online contribution page(tested on dmaster) actually loads and lets user to complete the contribution process with pay later processor. Fix included.

CRM_Core_DAO::VALUE_SEPARATOR,
CRM_Utils_Array::value('payment_processor', $this->_values)
);
));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explode(' ', NULL); returns array(0 => NULL) which loads processor key 0(pay later) on the contribution page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

}
}

// The concept of contributeMode is deprecated.
// The payment processor object can provide info about the fields it shows.
if ($assignCCInfo) {
if ($isMonetary) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do need the && $this->_paymentProcessor here. Prior to CRM-21134 it had code that did that, and it breaks if you use CiviDiscount with 100% discount as no payment processor will be submitted - there may be other cases too.
Agree with the variable name change.

CRM_Core_DAO::VALUE_SEPARATOR,
CRM_Utils_Array::value('payment_processor', $this->_values)
);
));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

@mattwire
Copy link
Contributor

@jitendrapurohit @eileenmcnaughton Follow on PR once this is merged. I found similar issues, but caused by a slightly different trigger: #11292

@eileenmcnaughton
Copy link
Contributor

I feel confident about the changes in here being correct / improvements. There is an outstanding question raised by @mattwire about CiviDiscount which I will review next

@Linux249
Copy link

Linux249 commented Dec 13, 2017

Hey,

is still have this issue with the current 4.7.28 update. I see this error with a contribution page where "Pay later option" is enabled with "Require Membership Signup" also checked and a priceset is used.

Here i try to rebuild my settings: http://dmaster.demo.civicrm.org/civicrm/contribute/transact?reset=1&id=4 (the name of the contributionpage is "pay later test")

I'm sorry for asking here for help - i cannot get a account on the issue/jira system. Any Ideas where to fix it? Would save me the go back to a previous version with a 4 weeks old backup :|

Edit: I try to disable the hole block of code via the $isMonetary flag
If i delete line 570 it looks like working correct for me but the 'amount' (get from the price set) is a multiplied by a billion...

@petednz
Copy link

petednz commented Dec 13, 2017

@jitendrapurohit is away this week so unlikely to get a quick response/fix from him

@eileenmcnaughton
Copy link
Contributor

There is follow on discussion here #11292

To get help with JIRA accounts please ask on chat.civicrm.org

sluc23 pushed a commit to ixiam/civicrm-core that referenced this pull request Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants