drastik / com.drastikbydesign.stripe

CMS Independent Stripe payment processor for CiviCRM 4.x
Other
35 stars 48 forks source link

Cannot access protected property #247

Open adevapp opened 6 years ago

adevapp commented 6 years ago

( ! ) Fatal error: Uncaught Error: Cannot access protected property CRM_Contribute_Form_AdditionalPayment::$_paymentProcessors in ...../civicrm/ext/com.drastikbydesign.stripe/CRM/Core/Form/Stripe.php on line 13 ( ! ) Error: Cannot access protected property CRM_Contribute_Form_AdditionalPayment::$_paymentProcessors in .....//civicrm/ext/com.drastikbydesign.stripe/CRM/Core/Form/Stripe.php on line 13

This occurs when attempting to record a CC payment against an existing offline contribution.

CiviCRM appear to have changed access to the variables used, so obtaining the variables from the class doesn't work.

Potential work around is using a function like:

function dashboard_civicrm_accessProtected($obj, $prop) { $reflection = new ReflectionClass($obj); $property = $reflection->getProperty($prop); $property->setAccessible(true); return $property->getValue($obj); }

chrisfromredfin commented 6 years ago

Verified.

h-c-c commented 6 years ago

Hey @adam-devapp, could you possibly walk me through how to trigger this error? Personally, I never used this workflow, so I just have no idea.

Thanks for the suggestion! I hope that works. If so, using the ReflectionClass could be a better bet in the long run for maintaining this code instead of extending a subclass every time this happens.

Apparently, to access this protected _paymentProcessors array, we'd have to extend CRM/Contribute/Form/AbstractEditPayment.php.

chrisfromredfin commented 6 years ago

The way that I was seeing it (and we are no longer using this workflow), was to go and create a new contribution for, say, $500 and mark it "Pending (from pay later)" by marking it as pending status with a pay by check method or something (in my case it was a custom payment method called "pledge to be paid").

Then go and try to, through the back end, record a credit card payment, and it whitescreens there.

h-c-c commented 6 years ago

Thanks @chrisfromredfin, I see now this is a new feature in 4.7. Are you guys using any unmerged patches by chance? With a fresh 4.7.31 install I'm getting "Stripe.js token not passed".

mattwire commented 6 years ago

@adam-devapp @chrisfromredfin @h-c-c You may wish to try my branch which completely does away with the CRM/Core/Form.php hack that this issue is caused by as well as resolving all known "Stripe.js token not passed" issues: https://github.com/mattwire/com.drastikbydesign.stripe/tree/4.7-mjwconsulting-dev-squashed

h-c-c commented 6 years ago

Hey @mattwire. Thanks for pointing us at this. I had a chance to take a quick glance over it, and was wondering if you could talk about your approach. I saw that you're overriding all CC fields, but wasn't sure how that helps.

I guess the question I want to ask is this. Did you find something in common relating to all the known causes of "Stripe.js token not passed."?

mattwire commented 6 years ago

@h-c-c Hey, as you've probably seen it's a fairly substantial rewrite of parts of the extension. The "Stripe.js token not passed" is caused by a whole range of different things (eg. failing to include stripe.js, failing to submit token values if payment form is loaded via ajax etc). I followed the guidance from stripe and include the stripe js code a lot more liberally (even when it may not be required on the page). In addition, I switched to the newer "Civi way" of implementing payment processor fields as modern browsers (eg. chrome/firefox) don't always include fields added by js in a POST request, but they do when added in the original form.