summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--billing/app/controllers/billing_base_controller.rb7
-rw-r--r--billing/app/controllers/customer_controller.rb22
-rw-r--r--billing/app/helpers/billing_helper.rb3
-rw-r--r--billing/app/views/customer/show.html.haml45
-rw-r--r--billing/app/views/payments/index.html.haml2
5 files changed, 48 insertions, 31 deletions
diff --git a/billing/app/controllers/billing_base_controller.rb b/billing/app/controllers/billing_base_controller.rb
index dc15194..67dff72 100644
--- a/billing/app/controllers/billing_base_controller.rb
+++ b/billing/app/controllers/billing_base_controller.rb
@@ -4,8 +4,13 @@ class BillingBaseController < ApplicationController
helper 'billing'
# required for navigation to work.
+ #TODO doesn't work for admins
def assign_user
- @user = current_user
+ if params[:id]
+ @user = User.find_by_param(params[:id])
+ else
+ @user = current_user #TODO not always correct for admins viewing another user!
+ end
end
end
diff --git a/billing/app/controllers/customer_controller.rb b/billing/app/controllers/customer_controller.rb
index 14ea8a7..f38f77e 100644
--- a/billing/app/controllers/customer_controller.rb
+++ b/billing/app/controllers/customer_controller.rb
@@ -1,10 +1,13 @@
class CustomerController < BillingBaseController
before_filter :authorize
+
def show
- customer.with_braintree_data!
- @default_cc = customer.default_credit_card #TODO not actually right way
- @active_subscription = customer.subscriptions
- @transactions = customer.braintree_customer.transactions
+ if customer = fetch_customer
+ customer.with_braintree_data!
+ @default_cc = customer.default_credit_card #TODO not actually right way
+ @active_subscription = customer.subscriptions
+ @transactions = customer.braintree_customer.transactions
+ end
end
def new
@@ -50,12 +53,13 @@ class CustomerController < BillingBaseController
:customer_id => customer.braintree_customer_id) ##??
end
- def customer
- @customer ||= Customer.find(params[:id]) if params[:id] # edit, show
- @customer ||= Customer.find_by_user_id(current_user.id) # confirm
- @customer ||= Customer.new(user: current_user)
+ def fetch_customer
+ @customer = Customer.find_by_user_id(@user.id)
+ if @user == current_user
+ @customer ||= Customer.new(user: @user)
+ end
# TODO will want case for admins, presumably
- access_denied unless @customer.user == current_user
+ access_denied unless (@customer and (@customer.user == current_user)) or admin?
return @customer
end
end
diff --git a/billing/app/helpers/billing_helper.rb b/billing/app/helpers/billing_helper.rb
index 7ec9285..5272eab 100644
--- a/billing/app/helpers/billing_helper.rb
+++ b/billing/app/helpers/billing_helper.rb
@@ -10,7 +10,8 @@ module BillingHelper
end
def show_or_new_customer_link(user)
- if (customer = Customer.find_by_user_id(user.id)) and customer.has_payment_info?
+ # Link to show if user is admin viewing another user, or user is already a customer. Otherwise link to create a new customer.
+ if (admin? and (user != current_user)) or ((customer = Customer.find_by_user_id(user.id)) and customer.has_payment_info?)
show_customer_path(user)
else
new_customer_path
diff --git a/billing/app/views/customer/show.html.haml b/billing/app/views/customer/show.html.haml
index 639d180..38b1cb2 100644
--- a/billing/app/views/customer/show.html.haml
+++ b/billing/app/views/customer/show.html.haml
@@ -1,22 +1,27 @@
-.form-actions
- = link_to t(:make_payment), new_payment_path, :class => 'btn btn-primary'
-= render :partial => 'payments/customer_data'
-%legend= t(:last_three_transactions)
-- counter = 0
-= # these will be ordered with most recently created first, per http://stackoverflow.com/questions/16425475/
-- @transactions.each do |t|
- - break if counter > 2 # not ruby-like, but object is a Braintree::ResourceCollection so limited methods available
- = render :partial => "payments/transaction_details", :locals => {:transaction => t}
- - counter += 1
-= link_to t(:transaction_history), payments_path
-%legend= t(:subscriptions)
-- if @active_subscription
- = render :partial => "subscriptions/subscription_details", :locals => {:subscription => @active_subscription}
+- if admin? and !@customer
+ = t(:no_saved_customer)
- else
- %p
- = t(:no_active_subscription)
- %p
+ - if current_user == @user
.form-actions
- = link_to t(:subscribe_to_plan), new_subscription_path, :class => :btn
-%p
- = link_to t(:all_subscriptions), subscriptions_path
+ = link_to t(:make_payment), new_payment_path, :class => 'btn btn-primary'
+ = render :partial => 'payments/customer_data'
+ %legend= t(:last_three_transactions)
+ - counter = 0
+ = # these will be ordered with most recently created first, per http://stackoverflow.com/questions/16425475/
+ - @transactions.each do |t|
+ - break if counter > 2 # not ruby-like, but object is a Braintree::ResourceCollection so limited methods available
+ = render :partial => "payments/transaction_details", :locals => {:transaction => t}
+ - counter += 1
+ = link_to t(:transaction_history), payments_path
+ %legend= t(:subscriptions)
+ - if @active_subscription
+ = render :partial => "subscriptions/subscription_details", :locals => {:subscription => @active_subscription}
+ - else
+ %p
+ = t(:no_active_subscription)
+ - if current_user == @user
+ %p
+ .form-actions
+ = link_to t(:subscribe_to_plan), new_subscription_path, :class => :btn
+ %p
+ = link_to t(:all_subscriptions), subscriptions_path
diff --git a/billing/app/views/payments/index.html.haml b/billing/app/views/payments/index.html.haml
index a3ad067..f994fe5 100644
--- a/billing/app/views/payments/index.html.haml
+++ b/billing/app/views/payments/index.html.haml
@@ -1,2 +1,4 @@
+- if (@transactions.count == 0)
+ = t(:no_transaction_history)
- @transactions.each do |t|
= render :partial => "transaction_details", :locals => {:transaction => t} \ No newline at end of file