From ee351d91a9e0fb11cc53b6dbffdc9ef11bfcaef4 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Thu, 18 Feb 2021 13:50:58 -0800 Subject: [PATCH] show authorization links in separate table --- app/controllers/spree/users_controller.rb | 1 + app/queries/payments_requiring_action.rb | 14 +++++++++++ app/views/spree/users/_fat.html.haml | 2 -- app/views/spree/users/_transactions.html.haml | 24 +++++++++++++++++++ config/locales/en.yml | 1 + 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 app/queries/payments_requiring_action.rb diff --git a/app/controllers/spree/users_controller.rb b/app/controllers/spree/users_controller.rb index c9ee2e15fe..93350cd187 100644 --- a/app/controllers/spree/users_controller.rb +++ b/app/controllers/spree/users_controller.rb @@ -13,6 +13,7 @@ module Spree before_action :enable_embedded_shopfront def show + @payments_requiring_action = PaymentsRequiringAction.new(spree_current_user).query @orders = orders_collection customers = spree_current_user.customers diff --git a/app/queries/payments_requiring_action.rb b/app/queries/payments_requiring_action.rb new file mode 100644 index 0000000000..ce5bf5721d --- /dev/null +++ b/app/queries/payments_requiring_action.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class PaymentsRequiringAction + def initialize(user) + @user = user + end + + attr_reader :user + + def query + Spree::Payment.joins(order: [:user]).where.not(cvv_response_message: nil). + where("spree_users.id = ?", user.id) + end +end diff --git a/app/views/spree/users/_fat.html.haml b/app/views/spree/users/_fat.html.haml index 56439d0e19..dfbcfade38 100644 --- a/app/views/spree/users/_fat.html.haml +++ b/app/views/spree/users/_fat.html.haml @@ -16,8 +16,6 @@ %td.order3.show-for-large-up %i{"ng-class" => "{'ofn-i_012-warning': payment.state == 'invalid' || payment.state == 'void' || payment.state == 'failed'}"} %span{"ng-bind" => "::'spree.payment_states.' + payment.state | t | capitalize"} - %span{"ng-if" => "payment.cvv_response_message.length > 0" } - %a{"ng-href" => "{{payment.cvv_response_message}}", "ng-bind" => "::'spree.payment_states.authorise' | t | capitalize" } %td.order4.show-for-large-up %td.order5.text-right{"ng-class" => "{'credit' : payment.amount > 0, 'debit' : payment.amount < 0, 'paid' : payment.amount == 0}","ng-bind" => "::payment.amount | localizeCurrency"} %td.order6.show-for-large-up diff --git a/app/views/spree/users/_transactions.html.haml b/app/views/spree/users/_transactions.html.haml index 6c8bea5353..7343eef31c 100644 --- a/app/views/spree/users/_transactions.html.haml +++ b/app/views/spree/users/_transactions.html.haml @@ -1,4 +1,28 @@ %script{ type: "text/ng-template", id: "account/transactions.html" } + - if @payments_requiring_action.present? + .active_table + %h3.requiring-authorization= t(".authorization_required") + .small-12.columns + %table + %tr + %th.order1= t :transaction + %th.order2= t :transaction_date + %th.order3.show-for-large-up= t :payment_state + %th.order5.text-right= t :value + %tbody + - @payments_requiring_action.each do |payment| + %tr + %td.order1 + = link_to payment.order.number, main_app.order_path(payment.order) + %td.order2 + = payment.updated_at.strftime("%Y-%m-%d") + %td.order3 + %a{ href: "#{payment.cvv_response_message}" } + %button.bright + Authorize + %td.order5 + = payment.display_amount + .active_table.orders{"ng-controller" => "OrdersCtrl", "ng-cloak" => true} %h3.my-orders= t(".transaction_history") %distributor.active_table_node.row.animate-repeat{"ng-if" => "Orders.shops.length > 0", "ng-repeat" => "shop in Orders.shops", diff --git a/config/locales/en.yml b/config/locales/en.yml index 113c4f672a..675e219eea 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3732,6 +3732,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using past_orders: Past Orders transactions: transaction_history: Transaction History + authorisation_required: Authorisation Required open_orders: order: Order shop: Shop