Make charges update method update the first pending payment #5798
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What? Why?
Closes #5774
In the order workflow there's a step where the fees are recalculated, charge_shipping_and_payment_fees! (there are multiple places where the fees are updated, this is one of them see_no_evil). In this method we are updating the payment amount based on the order total, but the process is selecting the first payment of the order (not the first pending payment) which can result in updating the total in a past failed payment, not the payment that will be processed.
For some reason in rails 3 the first payment was the pending one and now in rails 4 the first one is coming up as one of the previous/failed payments. The amount of the previous/failed payment is updated and the pending payment that will be charged now keeps the amount without fees and thus the issue reported.
This PR updates the code to look at pending payments only heavy_check_mark
I could replicate the problem locally with live AUS data and I could verify the PR fixes the issue. This has been deployed in AUS live as v3.1.2 and it has fixed the issue.
There are auto specs missing (I didnt have time to add them this week). I think we can create an issue to add them next week.
What should we test?
Try to replicate the issue. I am not sure exactly how (I couldnt replicate this with sample data, only with live aus data with a broken stripe setup) but it's all about making the first checkout attempt fail and then try again and see that the payment in the second checkout attempt doesn't include fees.
Sorry, not very specific instructions.
Release notes
Changelog Category: Fixed
Several checkout attempts will now always charge all the fees of the order.