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

dev/core#659 Catch payment processor exceptions, log, hide, do not return 500 error #13796

Merged
merged 1 commit into from
Mar 14, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Prevent 500 errors being returned to processors

Before

When an error occurs in our processing a 500 http error may be returned. This can cause the processor to mistrust the url

After

Errors are caught & logged but do not affect processor response

Technical Details

Comments

@kcristiano

@civibot
Copy link

civibot bot commented Mar 9, 2019

(Standard links)

@kcristiano
Copy link
Member

@eileenmcnaughton I'll test and add to a client site that has the issue. The code changes make sense and it would be good to get in an rc early.

@kcristiano
Copy link
Member

@eileenmcnaughton I applied the patch, and have made payments with multiple processors. All succeed. I have set up recurring with PayPal and will monitor that.

@@ -1401,7 +1410,7 @@ public static function handlePaymentMethod($method, $params = array()) {
if (!$extension_instance_found) {
$message = "No extension instances of the '%1' payment processor were found.<br />" .
"%2 method is unsupported in legacy payment processors.";
CRM_Core_Error::fatal(ts($message, array(1 => $params['processor_name'], 2 => $method)));
throw new CRM_Core_Exception(ts($message, array(1 => $params['processor_name'], 2 => $method)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the new array syntax 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.

done

@mattwire
Copy link
Contributor

@eileenmcnaughton Can you give a bit more background here. The changes are probably ok but will affect EVERY payment processor that implements standard IPNs. It should, at least in part, be up to the processor to set the error code - eg. in stripe I use http_response_code(xxx) to explicitly set it as required.

@eileenmcnaughton
Copy link
Contributor Author

@mattwire this wouldn't stop processors setting their own code. What it would do is stop core from going into the fatal routine as a result of an uncaught exception - that routine lands it in 'abend' with a status other than 0 - hence a 500 error is triggered.

);
}
catch (CRM_Core_Exception $e) {
Civi::log()->error('payment_callback_exception', [
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have "ipn" somewhere in the name? Makes tracing the source a bit easier when found in logs

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 added it - I was a little loath as ipn feels like a paypal term rather than a generic term but I guess we do tend to use it generically

Copy link
Contributor

Choose a reason for hiding this comment

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

Great :-) Maybe this: https://bitpay.com/docs/invoice-callbacks or https://stripe.com/docs/charges makes you feel more comfortable about the term IPN?

@mattwire
Copy link
Contributor

@kcristiano is happy with this. I think I am based on your reply @eileenmcnaughton - Can you just make two minor changes per my comments and then we can merge?

@eileenmcnaughton
Copy link
Contributor Author

I've just pushed @mattwire 's changes

@kcristiano do you think we should merge this to master or to the 5.12 rc?

@kcristiano
Copy link
Member

@eileenmcnaughton while this has not solved the issue @Stoob has, it is an important improvement.I think we should put in 5.12rc

@eileenmcnaughton eileenmcnaughton changed the base branch from master to 5.12 March 14, 2019 22:30
@civibot civibot bot added 5.12 and removed master labels Mar 14, 2019
@eileenmcnaughton
Copy link
Contributor Author

Ok - it's on the rc now - @seamuslee001 I think we should merge this on pass & consider for 5.11.x

@seamuslee001
Copy link
Contributor

Added merge on pass and will consider the issue around the 5.11 backport as well, however this makes sense to be in the RC

@eileenmcnaughton
Copy link
Contributor Author

unrelated fail - merging

@eileenmcnaughton eileenmcnaughton merged commit 3bfd7fa into civicrm:5.12 Mar 14, 2019
@eileenmcnaughton eileenmcnaughton deleted the exceptions branch March 14, 2019 23:36
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.

4 participants