Skip to content

Commit

Permalink
Push the risk analysis details to the payment partial
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elia committed Jan 27, 2023
1 parent 754b7f9 commit ed88c13
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 46 deletions.
60 changes: 17 additions & 43 deletions backend/app/views/spree/admin/orders/_risk_analysis.html.erb
Original file line number Diff line number Diff line change
@@ -1,52 +1,26 @@
<% latest_payment = @order.payments.reorder("created_at DESC").first %>
<details id="risk_analysis">
<summary><%= t('spree.risk_analysis') %>: <%= t('spree.risky') %></summary>

<fieldset class="no-border-bottom" id="risk_analysis">
<legend><%= "#{t('spree.risk_analysis')}: #{t('spree.not') unless @order.is_risky?} #{t('spree.risky')}" %></legend>
<table>
<thead>
<th><%= t('spree.payment')%></th>
<th><%= t('spree.risk')%></th>
<th><%= t('spree.status')%></th>
</thead>
<tbody id="risk-analysis" data-hook="order_details_adjustments" class="with-border">
<tr class="">
<td><strong>
<%= t('spree.failed_payment_attempts') %>:
</strong></td>
<td>
<span class="pill pill-<%= @order.payments.failed.count > 0 ? 'warning' : 'complete' %>">
<%= t(
'spree.payments_failed_count',
count: @order.payments.failed.count
) %>
</span>
</td>
</tr>

<tr>
<td><strong><%= t('spree.avs_response') %>:</strong></td>
<td>
<span class="pill pill-<%= latest_payment.is_avs_risky? ? 'warning' : 'complete' %>">
<% if latest_payment.is_avs_risky? %>
<%= avs_response_code[latest_payment.avs_response] %>
<% else %>
<%= t('spree.success') %>
<% end %>
</span>
</td>
</tr>

<tr>
<td><strong><%= t('spree.cvv_response') %>:</strong></td>
<td>
<span class="pill pill-<%= latest_payment.is_cvv_risky? ? 'warning' : 'complete' %>">
<% if latest_payment.is_cvv_risky? %>
<%= cvv_response_code[latest_payment.cvv_response_code] %>
<% else %>
<%= t('spree.success') %>
<% end %>
</span>
</td>
</tr>
<% @order.payments.risky.each do |payment| %>
<tr class="">
<td><%= link_to payment.number, admin_order_payment_path(@order, payment) %></td>
<td>
<span class="pill pill-warning"><%= t('spree.risky') %></span>
</td>
<td>
<span class="pill pill-<%= payment.state %>">
<%= t(payment.state, scope: 'spree.payment_states') %>
</span>
</td>
</tr>
<% end %>
</tbody>
</table>
</fieldset>
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,53 @@

<dt><%= Spree::CreditCard.human_attribute_name(:expiration) %>:</dt>
<dd><%= payment.source.month %>/<%= payment.source.year %></dd>

<% if payment.source.address %>
<dt><%= Spree::CreditCard.human_attribute_name(:source_address) %>:</dt>
<dd><%= render partial: 'spree/admin/shared/address', locals: {address: payment.source.address} %></dd>
<% end %>
</dl>
</div>

<div class="col-2">
</div>

<div class="col-4">
<dl>
<dt><%= Spree::CreditCard.human_attribute_name(:code) %>:</dt>
<dd><%= payment.number %></dd>

<dt><%= t('spree.risk_analysis') %></dt>
<dd>
<span class="pill pill-<%= payment.risky? ? 'error' : 'complete' %>">
<%= "#{t('spree.not') unless payment.risky?} #{t('spree.risky').downcase}".capitalize %>
</span>
</dd>

<dt><%= t('spree.status')%></dt>
<dd><span class="pill pill-<%= payment.state %>"><%= t(payment.state, scope: 'spree.payment_states') %></span></dd>


<dt><%= Spree::CreditCard.human_attribute_name(:avs_response) %>:</dt>
<dd>
<%= content_tag(
:span,
payment.is_avs_risky? ? t('spree.failure') : t('spree.success'),
class: "pill pill-#{payment.is_avs_risky? ? 'warning' : 'complete'}",
title: avs_response_code[payment.avs_response],
) %>
</dd>

<dt><%= Spree::CreditCard.human_attribute_name(:cvv_response_code) %>:</dt>
<dd>
<%= content_tag(
:span,
payment.is_cvv_risky? ? t('spree.failure') : t('spree.success'),
class: "pill pill-#{payment.is_cvv_risky? ? 'warning' : 'complete'}",
title: cvv_response_code[payment.cvv_response_code],
) %>
</dd>
</dl>
<% if payment.source.address %>
<%= render partial: 'spree/admin/shared/address', locals: {address: payment.source.address} %>
<% end %>
</div>
</div>
</fieldset>

0 comments on commit ed88c13

Please sign in to comment.