Skip to content

Commit

Permalink
Merge pull request #164 from Crowdtilt/update_bank_account
Browse files Browse the repository at this point in the history
Added ability to update bank account
  • Loading branch information
mattlebel committed Dec 18, 2013
2 parents 7f4c531 + c612b21 commit 6a28d75
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
60 changes: 41 additions & 19 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class AdminController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :verify_admin
before_filter :set_ct_env, only: [:admin_bank_setup, :ajax_verify]
before_filter :set_ct_env, only: [:admin_bank_account, :create_admin_bank_account, :delete_admin_bank_account, :ajax_verify]

def admin_website
#Handle the form submission if request is PUT
Expand Down Expand Up @@ -30,28 +30,33 @@ def admin_processor_setup
end
end

def admin_bank_setup
redirect_to admin_processor_setup_url, flash: { error: "Please set up your payment processor before providing your bank details" } and return unless @settings.payments_activated?
def create_admin_bank_account
if params[:ct_bank_id].blank?
flash = { :error => "Looks like you have JavaScript disabled. JavaScript is required for bank account setup." }
else
begin
bank = {
id: params[:ct_bank_id]
}
Crowdtilt.post('/users/' + @ct_admin_id + '/banks/default', {bank: bank})
rescue => exception
flash = { :error => "An error occurred, please contact [email protected]: #{exception.message}" }
else
flash = { :success => "Your bank account is all set up!" }
end
end
redirect_to admin_bank_account_url, :status => 303, :flash => flash
end

def admin_bank_account
unless @settings.payments_activated?
redirect_to admin_processor_setup_url, flash: { error: "Please set up your payment processor before providing your bank details" } and return
end
@bank = {}
begin
response = Crowdtilt.get('/users/' + @ct_admin_id + '/banks/default')
rescue => exception # response threw an error, default bank may not be set up
if request.post?
if params[:ct_bank_id].blank?
flash.now[:error] = "An error occurred, please try again" and return
else
begin
bank = {
id: params[:ct_bank_id]
}
response = Crowdtilt.post('/users/' + @ct_admin_id + '/banks/default', {bank: bank})
rescue => exception
flash.now[:error] = exception.message and return
else
@bank = response['bank']
end
end
end
# do nothing
else # response is good, check for default bank
if response['bank'] # default bank is already set up
@bank = response['bank']
Expand All @@ -61,6 +66,23 @@ def admin_bank_setup
end
end

def delete_admin_bank_account
begin
response = Crowdtilt.get('/users/' + @ct_admin_id + '/banks/default')
rescue => exception
flash = { :error => "No default bank account" }
else
begin
Crowdtilt.delete('/users/' + @ct_admin_id + '/banks/' + response['bank']['id'])
rescue => exception
flash = { :error => "An error occurred, please contact [email protected]: #{exception.message}" }
else
flash = { :info => "Bank account deleted successfully" }
end
end
redirect_to admin_bank_account_url, :status => 303, :flash => flash
end

def ajax_verify
if params[:name].blank? || params[:phone].blank? || params[:street_address].blank? || params[:postal_code].blank? || params[:dob].blank?
render text: "error" and return #not all fields filled out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<ul class="nav nav-tabs nav-bank-setup">
<li><a href="<%= admin_processor_setup_path %>">Payment Processor</a></li>
<li class="active"><a href="<%= admin_bank_setup_path %>">Bank Setup</a></li>
<li class="active"><a href="<%= admin_bank_account_path %>">Bank Setup</a></li>
</ul>

<div id="admin_bank_setup">
Expand All @@ -21,12 +21,12 @@
</div>
<div class="more_info">
<p>Campaign funds are transferred automatically to your account within 2 business days of campaign expiration. </p>
<p>Need to change your bank account? <a href="mailto:[email protected]?subject=Please reset my bank account info&body=Hi! I'd like to change my bank account. Please reset it for the Crowdhoster site named:">Send us an email</a>.</p>
<p>Need to change your bank account? <%= link_to 'Delete bank account', delete_admin_bank_account_path, :confirm => 'Are you sure you want to delete this bank account?', :method => :delete %></p>
</div>

<% else %>

<%= form_tag(admin_bank_setup_path, method: "post", id: "admin_bank_form") %>
<%= form_tag(create_admin_bank_account_path, method: "post", id: "admin_bank_form") %>

<h4>Personal Information <span class="label show_tooltip" data-placement="right" data-title="BUSINESS ACCOUNTS: <br>To prevent fraud, we verify your personal identity independently of your business bank account. <br> DO NOT ENTER YOUR BUSINESS ADDRESS / PHONE. Please enter your personal details here and your business account routing and account numbers in the 'Banking Information' section below.">Using a business account?</span></h4>
<fieldset>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/admin_processor_setup.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<ul class="nav nav-tabs nav-processor-setup">
<li class="active"><a href="<%= admin_processor_setup_path %>">Payment Processor</a></li>
<li><a href="<%= admin_bank_setup_path %>">Bank Setup</a></li>
<li><a href="<%= admin_bank_account_path %>">Bank Setup</a></li>
</ul>

<div id="admin_processor_setup">
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
match '/admin/campaigns/:id/copy', to: 'admin/campaigns#copy', as: :admin_campaigns_copy
match '/admin/campaigns/:id/payments', to: 'admin/campaigns#payments', as: :admin_campaigns_payments
match '/admin/processor-setup', to: 'admin#admin_processor_setup', as: :admin_processor_setup
match '/admin/bank-setup', to: 'admin#admin_bank_setup', as: :admin_bank_setup
post '/admin/bank-setup', to: 'admin#create_admin_bank_account', as: :create_admin_bank_account
get '/admin/bank-setup', to: 'admin#admin_bank_account', as: :admin_bank_account
delete '/admin/bank-setup', to: 'admin#delete_admin_bank_account', as: :delete_admin_bank_account
match '/admin/notification-setup', to: 'admin#admin_notification_setup', as: :admin_notification_setup
match '/ajax/verify', to: 'admin#ajax_verify', as: :ajax_verify

Expand Down

0 comments on commit 6a28d75

Please sign in to comment.