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

Risk analysis box update #4883

Merged
merged 7 commits into from
Feb 3, 2023

Conversation

elia
Copy link
Member

@elia elia commented Jan 26, 2023

Summary

While investigating how an order and its payments are marked as risky as part of the solidus_stripe rewrite I bumped into AVS/CCV codes.

Any modern payment provider and risk analysis tool will probably provide some structured data and a score (with thresholds) as the outcome of a risk analysis.

This is a first step toward distancing ourselves from the ruins of solidus_gateway toward per payment-method and per-order risk analysis tools.


Changes

  • The original risk banner was showing information for the last payment, despite Spree::Order#is_risky? was based on having any of the payments to be considered risky → now it lists information for all risky payments
  • The fieldset was changed to an expandable details/summary box → vanilla HTML FTW

image

image

image

image

image

before image image image

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

  • I have written a thorough PR description.
  • I have kept my commits small and atomic.
  • I have used clear, explanatory commit messages.
  • I have documented new code with YARD.

The following are not always needed (cross them out if they are not):

  • I have added automated tests to cover my changes.
  • I have attached screenshots to demo visual changes.
  • I have opened a PR to update the guides.
  • I have updated the README to account for my changes.

@elia elia self-assigned this Jan 26, 2023
@github-actions github-actions bot added changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem labels Jan 26, 2023
@elia elia marked this pull request as ready for review January 26, 2023 17:37
@elia elia requested a review from a team as a code owner January 26, 2023 17:37
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks, @elia; I left some comments to understand it better and a non-blocking suggestion about moving the query up.

core/README.md Show resolved Hide resolved
core/app/models/spree/payment.rb Show resolved Hide resolved
core/spec/models/spree/payment_spec.rb Outdated Show resolved Hide resolved
@elia elia marked this pull request as draft January 27, 2023 11:08
@elia elia force-pushed the elia+kennyadsl/risky-business branch from 4510546 to ed88c13 Compare January 27, 2023 18:53
Copy link
Member Author

@elia elia left a comment

Choose a reason for hiding this comment

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

@waiting-for-dev did a few changes, mostly pushing details of the risk analysis to the partial that is specific to the payment method, so we can stop assuming all payments will have AVS and CVV informations returned by payment providers.

core/app/models/spree/payment.rb Show resolved Hide resolved
core/spec/models/spree/payment_spec.rb Outdated Show resolved Hide resolved
@elia elia force-pushed the elia+kennyadsl/risky-business branch from ed88c13 to fcb58ac Compare January 27, 2023 19:10
@elia elia marked this pull request as ready for review January 27, 2023 19:39
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

@elia, it looks cohesive now 👍 Please, see my comment, I'm not sure if there's a line that is commented by error.

backend/app/views/spree/admin/payments/_list.html.erb Outdated Show resolved Hide resolved
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.

Left a couple of questions, but overall this change works for me, thanks Elia.

backend/app/views/spree/admin/payments/_list.html.erb Outdated Show resolved Hide resolved
@elia elia force-pushed the elia+kennyadsl/risky-business branch from fcb58ac to 384fafc Compare February 1, 2023 09:44
@elia elia requested a review from kennyadsl February 1, 2023 09:48
@kennyadsl
Copy link
Member

@elia a rebase is needed here after merging #4891 🙏

There's no point in providing the latest payment from outside when the
partial is accessing `@order` directly.
`Order#is_risky?` is currently based on whether a payment is risky,
but over time the API could be expanded and allow customization.
Should not be false when a CVV message is present; that's just a
field to collect descriptions from the payment gateway, the code is
what matters

This makes it consistent with both Payment.risky and
OrdersHelper#cvv_response_code.
Use AR and existing scopes to build the query instead of SQL.

Add a spec ensuring failed payments are considered risky.
Match the behavior of Payment.risky.
AVS and CVV are a legacy coming from an age in which everything could
be done with ActiveMerchant and PCI compliance didn't exist.

Moving away from specific risk checks paves the way for payment-method
specific risky checks and display, although the underlying tables
didn't change.
@elia elia force-pushed the elia+kennyadsl/risky-business branch from 384fafc to 8f8a331 Compare February 2, 2023 10:45
@elia elia requested a review from gsmendoza February 2, 2023 15:43
<fieldset class="no-border-bottom" id="risk_analysis">
<legend><%= "#{t('spree.risk_analysis')}: #{t('spree.not') unless @order.is_risky?} #{t('spree.risky')}" %></legend>
<details id="risk_analysis">
<summary><%= t('spree.risk_analysis') %>: <%= t('spree.risky') %></summary>
Copy link
Contributor

Choose a reason for hiding this comment

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

As a side note, if you say the translation very fast, it sounds like "spreeesky" 😆

@kennyadsl kennyadsl merged commit 1050ca0 into solidusio:master Feb 3, 2023
@kennyadsl kennyadsl deleted the elia+kennyadsl/risky-business branch February 3, 2023 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants