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

Include completed payment amounts when summing totals for store credit #2129

Merged
merged 2 commits into from
Aug 23, 2017

Conversation

luukveenis
Copy link

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 all checkout or pending
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 dummy ActiveMerchant::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.

Luuk Veenis added 2 commits August 1, 2017 15:53
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.

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 all `checkout` or `pending`
payments and adds an error if it doesn't match the order total. Since
our payment is `completed`, it doesn't get included and the totals don't
match, which incorrectly raises an error.
The issue this fixes is described in the previous commit that adds the
failing example.

In short, some payment methods require us to complete the payment before
the confirm step, in which case the total doesn't get included in the
sum here and it incorrectly raise an error.
Copy link
Contributor

@cbrunsdon cbrunsdon left a comment

Choose a reason for hiding this comment

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

Looks good to me. None of the stuff with auto-captured payments is ideal, but I can't imagine this harming anyone and is more correct for what that method is trying to do.

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

👍

@mamhoff mamhoff merged commit 39f7903 into solidusio:master Aug 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants