Skip to content

Fix double store credits creation when performing refunds#3989

Merged
kennyadsl merged 3 commits intosolidusio:v2.11from
nebulab:spaghetticode/double-store-credit-refund
Apr 1, 2021
Merged

Fix double store credits creation when performing refunds#3989
kennyadsl merged 3 commits intosolidusio:v2.11from
nebulab:spaghetticode/double-store-credit-refund

Conversation

@spaghetticode
Copy link
Copy Markdown
Member

Description

This PR aims at solving a very specific bug that happens when refunding a store credit payment by creating a new store credit record (i.e. when the preference credit_to_new_allocation is true).

Under these circumstances, performing the refund will generate 2 identical store credits records instead of one, so the customer ends up getting store credits for twice the refund amount. This happens because the method process! ends up being called twice.

The issue does not exist in master as the code that enables the bug has already been removed.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

Success and failure messages are hardcoded in multiple methods, they
can be easily DRYed up by using constants, with the extra benefit that
these can be referenced also in subclasses and tests.
Stubs can make tests britte, especially ones that, although
presented in a unit test file, are actually integrating the
behavior of many classes. Specifically, being this stub defined
at the top level, it prevents writing specs that actually want
to hit the real implementation of the stubbed method. These seem
good enough reasons for removing it.
@spaghetticode spaghetticode added the type:bug Error, flaw or fault label Mar 12, 2021
@spaghetticode spaghetticode self-assigned this Mar 12, 2021
action: Spree::StoreCredit::CAPTURE_ACTION,
amount_remaining: credit.amount - payment.amount,
authorization_code: payment.transaction_id
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the same line as the last argument when opening brace is on the same line as the first argument.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is actually fixed, it seems hound didn't catch up with the changes 🤷


let!(:credit_event) do
create(:store_credit_event,
store_credit: credit,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Layout/AlignArguments: Align the arguments of a method call if they span more than one line.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is actually fixed, it seems hound didn't catch up with the changes 🤷

@spaghetticode spaghetticode force-pushed the spaghetticode/double-store-credit-refund branch from 0761f86 to f4aa847 Compare March 12, 2021 13:40
Under certain specific circumstances, store credit refunds were
creating 2 new store credits instead of one, in fact doubling the
amount of credit returned to the customer.
@spaghetticode spaghetticode force-pushed the spaghetticode/double-store-credit-refund branch from f4aa847 to 3dc064f Compare March 12, 2021 13:40
@aldesantis aldesantis requested a review from a team March 12, 2021 14:30
@kennyadsl
Copy link
Copy Markdown
Member

Hey @spaghetticode, thanks for fixing this regression. I'm concerned about one thing though. If we merge the first two commits in 2.11 only, the code in 3.0 will be quite different and I'd prefer this not to happen. What about moving them into a PR for master that we will backport in 2.11 and then we can apply this change safely?

@spaghetticode
Copy link
Copy Markdown
Member Author

@kennyadsl sure, that makes totally sense 👍

@kennyadsl kennyadsl merged commit 642c49d into solidusio:v2.11 Apr 1, 2021
@kennyadsl kennyadsl deleted the spaghetticode/double-store-credit-refund branch April 1, 2021 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Error, flaw or fault

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants