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

Do not allow successful checkout when order has only a void payment #3123

Merged

Conversation

spaghetticode
Copy link
Member

When a payment has been marked for some reason as void, the customer should
not be able to complete the checkout process successfully.

The customer is now redirected to the payment page, where they can add another
payment to the order in order to complete it successfully.

This scope for Spree::Payment model:

scope :valid, -> { where.not(state: %w(failed invalid)) }

now includes also void, first because adding it there fixes the issue during the checkout, second because the word void means quite the opposite of valid.

One spec in the backend is currently failing (spec/features/admin/orders/payments_spec.rb:65) so I'd like to understand from the community if its behavior can be changed there or other solutions make more sense.

The reasoning behind this change is that, when an order with payment gets stale, admins may want to set the payment as void for some reason. When the customer resumes the checkout after some days they should not be able to complete it with that voided payment.

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change (if needed)

When a payment has been marked for some reason as `void`, the customer should
not be able to complete the checkout process successfully.

The customer is now redirected to the payment page, where they can add another
payment to the order in order to complete it successfully.
@spaghetticode spaghetticode force-pushed the spaghetticode/void-payments-checkout branch from f8f8d9a to 5eb0bdd Compare February 26, 2019 08:46
When a single payment exists for the order, and the payment is marked as void,
then the order payment state changes to `Failed`.

When there are multiple pending payments for the order, if only one is marked
as void the order payment state is still `Balance Due`. If all the payments are
marked as void then the order payment state changes to `Failed`.
@spaghetticode
Copy link
Member Author

After some input from @aitbw about the possible behavior regarding the failing spec, it seems reasonable that when a single payment exists and it is marked as void then the order payment status changes to Failed.

On the other hand, when there are other pending payments, the state remains as Balance Due.

So I added one more spec (and did some refactoring later) in order to properly expose this behavior.

Copy link
Contributor

@aitbw aitbw left a comment

Choose a reason for hiding this comment

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

Fantastic work, @spaghetticode! 🎉

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

I'm ok with this solution, I'd just change the last commit message with something more descriptive. I know you added some lines in the commit description but sometimes you only have the commit message visible and it would be great to have some more information about what it does.

Utility method `create_payment` was extracted in order to DRY up the code a
bit.
@spaghetticode spaghetticode force-pushed the spaghetticode/void-payments-checkout branch from a4ec39a to e663b24 Compare February 28, 2019 13:09
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks, @spaghetticode, great work!

Copy link
Contributor

@jacobherrington jacobherrington left a comment

Choose a reason for hiding this comment

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

Thanks Andrea! 🥇

@jacobherrington jacobherrington merged commit 4894bc0 into solidusio:master Mar 1, 2019
@aitbw aitbw deleted the spaghetticode/void-payments-checkout branch March 1, 2019 20:30
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.

5 participants