Skip to content

Commit

Permalink
Merge pull request #164 from fnf-org/158-mark-payment-received
Browse files Browse the repository at this point in the history
Allow admins to record manual payments
  • Loading branch information
beingmattlevy authored May 13, 2024
2 parents f1111b2 + a9e2ef6 commit ffb1248
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Style/IfUnlessModifier:
RSpecRails/InferredSpecType:
Enabled: false

Metrics/ClassLength:
Max: 300

Layout/HashAlignment:
Enabled: true
EnforcedColonStyle: table
Expand Down
63 changes: 36 additions & 27 deletions app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/ticket_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -305,5 +304,3 @@ def permitted_params
.with_indifferent_access
end
end

# rubocop: enable Metrics/ClassLength
5 changes: 0 additions & 5 deletions app/models/ticket_request.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

#
# rubocop: disable Metrics/ClassLength

# == Schema Information
#
# Table name: ticket_requests
Expand Down Expand Up @@ -284,5 +281,3 @@ def set_defaults
self.guests = Array(guests).map { |guest| guest&.strip }.select(&:present?).compact
end
end

# rubocop: enable Metrics/ClassLength
2 changes: 1 addition & 1 deletion app/views/payments/other.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 11 additions & 6 deletions app/views/ticket_requests/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffb1248

Please sign in to comment.