diff --git a/.rubocop.yml b/.rubocop.yml index 072e91f8..3384ae48 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,9 @@ Style/IfUnlessModifier: RSpecRails/InferredSpecType: Enabled: false +Metrics/ClassLength: + Max: 300 + Layout/HashAlignment: Enabled: true EnforcedColonStyle: table diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 91107873..70447178 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -26,9 +26,7 @@ def create # init the payment, user from ticket request initialize_payment - # check to see if we have an existing stripe payment intent - # if so, use that one and do not create a new one - # if not, call save payment which generates a new payment intent + # check to see if we have an existing stripe payment intent. retrieve or save @payment.retrieve_or_save_payment_intent if @payment.payment_in_progress? @@ -52,7 +50,6 @@ def create end # create new payment and stripe payment intent using existing payment - def confirm redirect_path, options = validate_payment_confirmation if redirect_path @@ -62,6 +59,39 @@ def confirm Rails.logger.info("#confirm() => marking payment id #{@payment.id} as received") end + mark_payment_completed + end + + # init and mark the payment as completed. + # Annotate that manual was set + def manual_confirmation + initialize_payment + @payment.update(explanation: 'manual confirm') + @payment.reload + Rails.logger.info("#manual_confirm() => @payment #{@payment.inspect}") + mark_payment_completed + redirect_to event_ticket_requests_path(@event, @ticket_request) + end + + def other + @user = @ticket_request.user + end + + # handle other forms of payment than credit card / stripe + def sent + initialize_payment + @payment.update(explanation: permitted_params[:explanation], status: Payment::STATUS_IN_PROGRESS) + @payment.reload + + Rails.logger.info("#sent() => @payment #{@payment.inspect}") + + flash[:notice] = "We've recorded that your payment is en route" + redirect_to edit_event_ticket_request_path(@event, @ticket_request) + end + + private + + def mark_payment_completed Payment.transaction do @payment.mark_received @payment.ticket_request.mark_complete @@ -72,33 +102,12 @@ def confirm # Deliver the email asynchronously PaymentMailer.payment_received(@payment).deliver_later rescue StandardError => e - Rails.logger.error("#confirm() => error marking payment as received: #{e.message}") + Rails.logger.error("#mark_payment_completed() => error marking payment as received: #{e.message}") flash.now[:error] = "ERROR: #{e.message}" render_flash(flash) end end - def other - @user = @ticket_request.user - end - - def sent - return redirect_to root_path unless @ticket_request.can_view?(current_user) - - @payment = Payment.new(ticket_request_id: @ticket_request.id, - explanation: permitted_params[:explanation], - status: Payment::STATUS_IN_PROGRESS) - if @payment.save - flash[:notice] = "We've recorded that your payment is en route" - redirect_to event_ticket_request_payment_path(@event, @ticket_request, @payment) - else - flash[:error] = 'There was a problem recording your intent to pay' - redirect_to :back - end - end - - private - def ticket_request_id permitted_params[:ticket_request_id] end @@ -190,12 +199,12 @@ def permitted_params :ticket_request_id, :stripe_payment_id, :payment_intent, + :explanation, payment: %i[ ticket_request ticket_request_id ticket_request_attributes status - explanation ] ) .to_hash diff --git a/app/controllers/ticket_requests_controller.rb b/app/controllers/ticket_requests_controller.rb index 0e3f0fd2..59c90758 100644 --- a/app/controllers/ticket_requests_controller.rb +++ b/app/controllers/ticket_requests_controller.rb @@ -4,7 +4,6 @@ require 'csv' # Manage all pages related to ticket requests. -# rubocop: disable Metrics/ClassLength class TicketRequestsController < ApplicationController before_action :authenticate_user!, except: %i[new create] @@ -305,5 +304,3 @@ def permitted_params .with_indifferent_access end end - -# rubocop: enable Metrics/ClassLength diff --git a/app/models/ticket_request.rb b/app/models/ticket_request.rb index 588cbf1f..4662cd20 100644 --- a/app/models/ticket_request.rb +++ b/app/models/ticket_request.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -# -# rubocop: disable Metrics/ClassLength - # == Schema Information # # Table name: ticket_requests @@ -284,5 +281,3 @@ def set_defaults self.guests = Array(guests).map { |guest| guest&.strip }.select(&:present?).compact end end - -# rubocop: enable Metrics/ClassLength diff --git a/app/views/payments/other.html.haml b/app/views/payments/other.html.haml index a342cddd..895276b5 100644 --- a/app/views/payments/other.html.haml +++ b/app/views/payments/other.html.haml @@ -11,7 +11,7 @@ new_event_ticket_request_payment_path(@event, @ticket_request) is not an option, we can accept check or other forms of payment. - = form_tag sent_event_ticket_request_payment_path(@event, @ticket_request) do + = form_tag sent_event_ticket_request_payments_path(@event, @ticket_request) do %p Briefly describe below how you intend to pay for your ticket. Confirm that your email address in our system is correct so we can contact you. diff --git a/app/views/ticket_requests/index.html.haml b/app/views/ticket_requests/index.html.haml index b4d7d7c5..4075e21c 100644 --- a/app/views/ticket_requests/index.html.haml +++ b/app/views/ticket_requests/index.html.haml @@ -156,24 +156,29 @@ - if ticket_request.declined? = button_to revert_to_pending_event_ticket_request_path(@event, ticket_request), method: :post, - class: 'btn btn-link btn-primary btn-sm ' do + class: 'btn btn-danger btn-sm ' do %span.hover-tooltip{ title: 'Reset status of request to Pending', data: { placement: 'left' } } Revert - elsif !ticket_request.completed? = button_to resend_approval_event_ticket_request_path(@event, ticket_request), method: :post, - class: 'btn btn-link btn-primary btn-sm ' do + class: 'btn btn-primary btn-sm ' do Resend Approval = button_to decline_event_ticket_request_path(@event, ticket_request), method: :post, - class: 'btn btn-link btn-primary btn-sm ', + class: 'btn btn-primary btn-sm ', data: { confirm: "Are you sure you want to decline #{ticket_request.user.name}'s already approved request?" } do %span.text-error Decline + = button_to manual_confirmation_event_ticket_request_payments_path(@event, ticket_request), + method: :post, + class: 'btn btn-primary btn-sm ' do + Mark Payment Received + %i.icon-ok - - elsif ticket_request.payment && !ticket_request.payment.received? + - elsif ticket_request.payment && ticket_request.awaiting_payment? && !ticket_request.payment_received? .btn-group.pull-right - = button_to confirm_event_ticket_request_payment_path(@event, ticket_request, ticket_request.payment), + = button_to manual_confirmation_event_ticket_request_payments_path(@event, ticket_request), method: :post, - class: 'btn btn-primary' do + class: 'btn btn-primary btn-sm ' do Mark Payment Received %i.icon-ok diff --git a/config/routes.rb b/config/routes.rb index b35625f1..58429228 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -60,14 +60,15 @@ resources :payments do collection do get :confirm + post :sent + post :manual_confirmation end member do get :new post :create get :show - get :other - post :sent + get :other end end end