2019-07-30 21:29:24 +00:00
# frozen_string_literal: true
2018-03-25 16:15:39 +00:00
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
2018-03-25 17:30:42 +00:00
module Nonprofits
2019-07-30 21:29:24 +00:00
class PaymentsController < ApplicationController
2020-05-11 18:38:50 +00:00
include Controllers :: Nonprofit :: Current
include Controllers :: Nonprofit :: Authorization
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
before_action :authenticate_nonprofit_user!
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
# get /nonprofit/:nonprofit_id/payments
def index
@nonprofit = current_nonprofit
respond_to do | format |
format . html do
2018-03-25 17:30:42 +00:00
@panels_layout = true
end
2019-07-30 21:29:24 +00:00
format . json do
@response = QueryPayments . full_search ( params [ :nonprofit_id ] , params )
2018-03-25 17:30:42 +00:00
render json : @response , status : :ok
2019-07-30 21:29:24 +00:00
end
end
end # def index
2018-03-25 17:30:42 +00:00
def export
begin
@nonprofit = current_nonprofit
@user = current_user_id
2019-07-30 21:29:24 +00:00
ExportPayments . initiate_export ( @nonprofit . id , params , @user )
rescue StandardError = > e
2018-03-25 17:30:42 +00:00
e
end
if e . nil?
flash [ :notice ] = " Your export was successfully initiated and you'll be emailed at #{ current_user . email } as soon as it's available. Feel free to use the site in the meantime. "
render json : { } , status : :ok
else
render json : e , status : :ok
end
end
2019-07-30 21:29:24 +00:00
def show
@nonprofit = current_nonprofit
@payment = @nonprofit . payments . find ( params [ :id ] )
end # def show
2018-03-25 17:30:42 +00:00
def update
@payment = current_nonprofit . payments . find ( params [ :id ] )
2020-05-20 21:03:16 +00:00
@payment . update ( payment_params )
2018-03-25 17:30:42 +00:00
json_saved @payment
end
def destroy
@payment = current_nonprofit . payments . find ( params [ :id ] )
if @payment . offsite_payment . nil?
render json : { } , status : :unprocessable_entity
return # You may only destroy offline payments
else
@payment . donation . destroy if @payment . donation . present?
@payment . tickets . destroy_all if @payment . tickets . present?
@payment . offsite_payment . destroy
@payment . destroy
Qx . delete_from ( :activities ) . where ( attachment_id : params [ :id ] ) . execute
render json : @payment , status : :ok
end
end
# post /nonprofits/:nonprofit_id/payments/:id/resend_donor_receipt
def resend_donor_receipt
PaymentMailer . resend_donor_receipt ( params [ :id ] )
render json : { }
end
2019-07-30 21:29:24 +00:00
2018-03-25 17:30:42 +00:00
# post /nonprofits/:nonprofit_id/payments/:id/resend_admin_receipt
# pass user_id of the admin to send to
def resend_admin_receipt
PaymentMailer . resend_admin_receipt ( params [ :id ] , current_user . id )
render json : { }
end
2019-08-06 14:07:18 +00:00
private
def payment_params
params . require ( :payment ) . permit ( :towards , :gross_amount , :refund_total , :fee_total , :kind , :date )
end
2019-07-30 21:29:24 +00:00
end # class PaymentsController
2018-03-25 17:30:42 +00:00
end # module Nonprofits