houdini/app/controllers/nonprofits/payouts_controller.rb
Bradley M. Kuhn 6772312ea7 Relicense all .rb files under new project license.
The primary license of the project is changing to:
  AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later

with some specific files to be licensed under the one of two licenses:
   CC0-1.0
   LGPL-3.0-or-later

This commit is one of the many steps to relicense the entire codebase.

Documentation granting permission for this relicensing (from all past
contributors who hold copyrights) is on file with Software Freedom
Conservancy, Inc.
2018-03-25 15:10:40 -04:00

49 lines
1.7 KiB
Ruby

# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
module Nonprofits
class PayoutsController < ApplicationController
include NonprofitHelper
before_filter :authenticate_nonprofit_admin!, only: :create
before_filter :authenticate_nonprofit_user!, only: [:index, :show]
def create
payout = InsertPayout.with_stripe(current_nonprofit.id, {
stripe_account_id: current_nonprofit.stripe_account_id,
email: current_user.email,
user_ip: current_user.current_sign_in_ip,
bank_name: current_nonprofit.bank_account.name
}, {before_date: params[:before_date]})
if payout['failure_message'].present?
flash[:notice] = "The payout failed: #{payout['failure_message']}"
render json: payout, status: :unprocessable_entity
else
flash[:notice] = 'We successfully submitted your payout! View status and receipts below.'
render json: payout, status: :ok
end
end
def index
@nonprofit = Nonprofit.find(params[:nonprofit_id])
@payouts = @nonprofit.payouts.order('created_at DESC')
balances = QueryPayments.nonprofit_balances(params[:nonprofit_id])
@available_total = balances['available_gross']
@pending_total = balances['pending_gross']
@can_make_payouts = @nonprofit.can_make_payouts
end
# get /nonprofits/:nonprofit_id/payouts/:id
def show
payout = current_nonprofit.payouts.find(params[:id])
respond_to do |format|
format.json{render json: payout}
format.csv do
payments = QueryPayments.for_payout(params[:nonprofit_id], params[:id])
filename = "payout-#{payout.created_at.strftime("%m-%d-%Y")}"
send_data(Format::Csv.from_vectors(payments), filename: "#{filename}.csv")
end
end
end
end
end