-
Notifications
You must be signed in to change notification settings - Fork 69
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
Handle failed refunds #411
Conversation
@jrodger tried twice but wasn't able to reproduce the test (see screenshots below). Despite the server is running the correct branch I'm not sure the webhook reached my local site. Tried to set a breakpoint in P.s. Tried with localhost and ngrok, no difference. |
🤔 We can see that the refund is failing from your first screenshot, so that's good. That failure triggers a If that's returning |
Forgot to mention, please don't spend too long on this if there are other PRs needing review that are required for beta. |
Here is the link to refund_update event: According to the server response was
Will try again on Monday. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrodger I was able to set up stripe CLI and reproduce testing instruction with webhooks forwarded to the sandbox. Well done!
Some general thoughts:
- What about tests for webhook controller class?
- As @RadoslavGeorgiev noticed we have a successful confirmation note first and a failure note afterwards. So it's probably a good idea to update existing messaging for order notes to avoid confusion in case of refund failure. E.g.
Refund request was successfully sent
as an alternative to existing success message.
if ( $order_id ) { | ||
return wc_get_order( $order_id ); | ||
} | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious is returning false is better than returning NULL? AFAIK NULL is intended for informing about missing value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I much prefer having a single return type, so yeah, I prefer returning null
to indicate a missing value. However, I thought I'd leave this as is since I was just moving it from another class.
It's only used in one other place, so we could take the opportunity to change it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only used in one other place
Actually there are two. And this one leads to an error if false or null is returned. IMO we should fix it either here on in another PR.
so we could take the opportunity to change it now
Now I see that wc_get_order
can return a boolean value, and forcing it to return null without explicit benefit feels weird. So let's leave it as is now.
59ebee2
to
1d1ee4d
Compare
FYI - I've updated the testing instructions so that both the local and sandbox configurations can be tested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress @jrodger, thank you ! 🎉 I've tested it both in sandbox mode and with a local server in docker. Changes work as expected. Left some note regarding the changes!
This logic is required by other parts of the code base, so extracting it out allows it to be shared. The unit tests have been left as is for now, but this also allows for database access to be mocked more easily.
The initial implementation just handles refund updated events and adds an order note in the event of a failure.
This rule is generating some false positives. We can try turning it on again if it gets fixed in a later PHPCS version. Alternatively we could start relying on a static code analyser for more robust checks on how we're using exceptions.
1d1ee4d
to
e2fcaff
Compare
Thanks for the detailed review @vbelolapotkov. I think I've addressed all your comments now. A lot of my comments boil down to "let's do this later", absolutely feel free to push back on any of those!
I've raised #601 to discuss this point because the more I thought about it the more work it seemed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave it a final round of tests, works as expected! Thank you @jrodger !
Fixes #312
Changes proposed in this Pull Request
Local Environment Testing instructions
./local/bin/listen-to-webhooks.sh
functions.php - wcpay_server_remote_request
match your local setup. This replaces the Jetpack call with a simple HTTP request.4000 0000 0000 5126
(docs)Sandbox Testing instructions
4000 0000 0000 5126
(docs)