2019-07-30 21:29:24 +00:00
# frozen_string_literal: true
2020-06-12 20:03:43 +00:00
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
2018-03-25 17:30:42 +00:00
module Nonprofits
2019-07-30 21:29:24 +00:00
class BankAccountsController < 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_admin!
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
# post /nonprofits/:nonprofit_id/bank_account
# must pass in the user's password as params[:password]
def create
if password_was_confirmed ( params [ :pw_token ] )
render_json { InsertBankAccount . with_stripe ( current_nonprofit , current_user , params [ :bank_account ] ) }
else
render json : [ 'Please confirm your password' ] , status : :unprocessable_entity
end
end
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
# get /nonprofits/:nonprofit_id/bank_account/confirmation
def confirmation
@nonprofit = Nonprofit . find ( params [ :nonprofit_id ] )
@bank_account = @nonprofit . bank_account
end
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
# post /nonprofits/:nonprofit_id/bank_account/confirmation
def confirm
npo = current_nonprofit
ba = npo . bank_account
if params [ :token ] == ba . confirmation_token
ba . update_attribute ( :pending_verification , false )
flash [ :notice ] = 'Your bank account is now confirmed!'
redirect_to nonprofits_payouts_path ( npo )
else
redirect_to ( nonprofits_donations_path ( npo ) , flash : { error : 'We could not confirm this bank account. Please follow the exact link provided in the confirmation email.' } )
end
end
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
# get /nonprofits/:nonprofit_id/bank_account/cancellation
def cancellation
@nonprofit = Nonprofit . find ( params [ :nonprofit_id ] )
@bank_account = @nonprofit . bank_account
end
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
# post /nonprofits/:nonprofit_id/bank_account/cancel
def cancel
npo = current_nonprofit
ba = npo . bank_account
if params [ :token ] == ba . confirmation_token
ba . destroy
flash [ :notice ] = 'Your bank account has been removed.'
redirect_to nonprofits_donations_path ( npo )
else
redirect_to ( nonprofits_donations_path ( npo ) , flash : { error : 'We could not remove this bank account. Please follow the exact link provided in the email.' } )
end
end
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
def resend_confirmation
npo = current_nonprofit
ba = npo . bank_account
2019-11-07 19:58:09 +00:00
BankAccountCreateJob . perform_later ( ba ) if ba . valid?
2019-07-30 21:29:24 +00:00
respond_to { | format | format . json { render json : { } } }
end
2019-08-06 12:23:53 +00:00
private
def required_params
params . permit ( :name , :confirmation_token , :account_number , :bank_name , :pending_verification , :status , :email , :deleted , :stripe_bank_account_token , :stripe_bank_account_id , :nonprofit_id )
end
2019-07-30 21:29:24 +00:00
end
2018-03-25 17:30:42 +00:00
end