-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow cancelling orders that have been fully refunded #1355
Conversation
6beb77c
to
8bf08e0
Compare
core/app/models/spree/payment.rb
Outdated
@@ -145,6 +145,11 @@ def can_credit? | |||
credit_allowed > 0 | |||
end | |||
|
|||
# @return [Boolean] true when this payment has been fully refunded | |||
def fully_refunded? | |||
refunds.sum(:amount) >= amount |
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.
should ==
instead of >=
be sufficient? If you refunded more then the amount paid there are some other issues going on IMHO.
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.
Fair enough. I don't like when we try to catch problems tangentially, but in that case we would raise an error during a cancel, which would probably be useful. I'm cool with swicthing to ==
.
This makes a lot of sense, curious why we do not have a |
I agree that this makes sense. I can't think of anywhere else I would prefer to deal with this. 👍 |
Also ran into this issue on a store. 👍 for getting this in. Seems reasonable to me. |
8bf08e0
to
a295466
Compare
👍 @jhawthorn any opinions? |
a295466
to
a8e4c36
Compare
@Sinetheta Thoughts on testing this? |
a8e4c36
to
23c255c
Compare
23c255c
to
2c3d182
Compare
core/app/models/spree/payment.rb
Outdated
@@ -146,6 +146,11 @@ def can_credit? | |||
credit_allowed > 0 | |||
end | |||
|
|||
# @return [Boolean] true when this payment has been fully refunded | |||
def fully_refunded? | |||
refunds.sum(:amount) == amount |
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 think we can save a DB lookup here by using the in-memory refunds:
refunds.map(&:amount).sum == amount
Cancelling a payment can result in a refund, which will fail if the payment has already been fully refunded.
2c3d182
to
9928a9e
Compare
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.
👍
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.
We decided to take this as is, it might have been an improvement to do the check during cancel! instead of doing it in the after_cancel, but we agree this is an improvement as is.
This fixes #1066 but I could use some feedback.
After an order is cancelled, all completed payments are also cancelled here. Each payment then tries to call cancel on it's payment method here, the implementation of which is left to the provider here.
I can't speak for the other gateways, but Braintree's cancel looks like this in solidus_gateway
The reason why it's sufficient to simply check whether a payment is "settled" or not, is because the Braintree provider docs say that
and
but there's one more case, where a payment has already been fully refunded (through one or many refunds). In that case we get an error. This error is what causes the order cancellation to fail.
We could address this anywhere along the chain, but here are my thoughts.
payment
when calling cancel on the gateway and I'm not sure we should.Any ideas how I might add a regression test for this? The behaviour seems specific to one (albeit an important) gateway.