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-20608: IPN thinks Paypal Pro is Standard. #11777

Merged

Conversation

twomice
Copy link
Contributor

@twomice twomice commented Mar 7, 2018

Overview

As described in the ticket, regardless of whether the old way (extern/ipn.php) or new way (civicrm/payment/ipn/#) is used, the IPN interprets the IPN message as if it's Paypal Standard. As a result, IPN notifications for recurring payments are not processed properly.

Before

All incoming PayPal Pro IPN notifications for recurring contributions are successfully recorded in civicrm_system_log, but never make it as far as being recorded as payments in CiviCRM.

After

All incoming PayPal Pro IPN notifications for recurring contributions are correctly recorded as payments in CiviCRM.

Technical Details

As far as I can see, the existing code gets it backwards when asking "is this paypal pro or standard?". This PR reframes the question by querying the API for the given payment processor and testing against paymentprocessor.name instead of the slightly less clearly meaningful paymentprocessor.class_name.

Comments

I guess we want unit tests for this?


@mlutfy
Copy link
Member

mlutfy commented Mar 9, 2018

ping @eileenmcnaughton Any thoughts?

Allen and I are working with the same client (JV), so I would rather not same-shop-merge, but this is a bug that has been causing a few IPN headaches. I'll make sure we are running it in production before merging.

'sequential' => 1,
'id' => $params['processor_id'],
'api.PaymentProcessorType.getvalue' => array('return' => "name"),
));
Copy link
Contributor

Choose a reason for hiding this comment

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

As there should only be one processor returned when specifying an id why not use PaymentProcessor.getsingle, or drop the sequential and check that the ID exists in the returned values array. Currently with this change, it will generate a PHP notice if [values][0] is undefined for some reason (eg. payment processor has been deleted).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point. What should happen if the given payment processor has been deleted? I guess a fatal "not found" error is the best we could do, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

@twomice I'd suggest using Civi::log()->error() with a suitable error message. Then return/exit or throw an exception rather than trigger a fatal error. @eileenmcnaughton You'll probably have an opinion on this :-)

Copy link
Member

Choose a reason for hiding this comment

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

I think it should fatal, either through an exception or a call to fatal(), so that PayPal can detect that the IPN is failing (and the reporterror extension can detect it and notify admins). In other words, I'm a bit uncomfortable with Civi::log()->error(), because it can easily go unnoticed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mlutfy Could the reporterror extension not pick up Civi::log() style errors too? I find it a real pain when you get lot's of fatal error info in the log files which is not always clear what the actual error is. A single-line Civi::log()->error() can show exactly what the issue is if the message is written in a sensible way.

Copy link
Member

Choose a reason for hiding this comment

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

For the extension, currently it doesn't, but you're right I should add support for it. However, I still think it should fatal so that PayPal can detect the error. It's not an error that should ever happen, and if it does, it should fail badly. It's not something where we're telling something polite to the user and logging more details under the hood.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mlutfy Ok, makes sense

Copy link
Contributor

Choose a reason for hiding this comment

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

Just on the error side of things - I think throwing an exception is generally better than 'fatal' because fatal should be seen as deprecated & Civi::Log-> is better than CRM_Core_Error::debug_log_message but I see the point that people aren't used to looking there & also Civi::Log should be pluggable in output. In general I'm not strongly on any side here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced calls to CRM_Core_Error::debug_log_message() with exception; also added an exception if the processor can't be found by ID.

@eileenmcnaughton
Copy link
Contributor

@mlutfy I have looked at this enough that I want to give you my blessing to go ahead & merge it when you are happy. I feel confident the code makes enough sense that the same-shop-merge side is covered off & there are enough people engaged that I don't think I need to get heavily involved on this one

@twomice twomice force-pushed the CRM-20608_paypal_ipn_confuses_pro_vs_standard branch from 1e200a0 to b501170 Compare March 12, 2018 16:15
@mlutfy mlutfy merged commit 1937e8f into civicrm:master Mar 12, 2018
@mlutfy
Copy link
Member

mlutfy commented Mar 12, 2018

Merging based on:

  • Code has been running in production for some time now.
  • Review/feedback from Matt and Eileen
  • I spent some time debugging this issue as well.

@mlutfy mlutfy added this to the 4.7.32 milestone Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants