Include completed payment amounts when summing totals for store credit #2129
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.
Some payment methods that redirect to a third-party site don't have the concept of "capturing" a payment. It is expected that after the user completes their checkout flow, the payment is completed. For these types of payments, we'd prefer to complete them as soon as we return to our Solidus site, since the provider considers them complete.
One example is PayBright as implemented in the
solidus_paybright
extension. When the user gets redirected back from PayBright, the payment is updated, and the order advanced to complete:https://github.com/StemboltHQ/solidus_paybright/blob/master/app/controllers/spree/paybright_controller.rb#L39-L62
For this case, when we call
Spree::Order#add_store_credit_payments
, the store credits will be created successfully, but there is a check at the end that sums the payment amount of allcheckout
orpending
payments and adds an error if it doesn't match the order total:
https://github.com/solidusio/solidus/blob/master/core/app/models/spree/order.rb#L660-L662
Since our payment is
completed
, it doesn't get included and the totals don't match, which incorrectly raises an error. I couldn't think of a reason not to include completed payments here, but would appreciate if anyone can think of one.I've worked with other payment methods with similar behaviour, such as SOFORT as implemented in solidus-adyen. The workaround for this same issue there was to implement
Spree::PaymentMethod#authorize
to return a dummyActiveMerchant::BillingResponse
:https://github.com/StemboltHQ/solidus-adyen/blob/master/app/models/spree/gateway/adyen_hpp.rb#L27-L33
The problem with this approach is that it's possible to end up with payments that are authorized in Solidus, but the provider already considers completed.