summaryrefslogtreecommitdiff
path: root/billing
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-10-01 13:56:59 -0700
committerjessib <jessib@riseup.net>2013-10-01 13:56:59 -0700
commit0fe1678cd37c8e917cb28eed9eb28777d3a92283 (patch)
tree751e6eaaceef1d81a3bce020871a6b004f795f2d /billing
parent6b35a71db66e61c04747bf82feded014687cc528 (diff)
Allow admins to view past-due subscriptions.
Diffstat (limited to 'billing')
-rw-r--r--billing/app/controllers/billing_admin_controller.rb14
-rw-r--r--billing/app/helpers/billing_helper.rb27
-rw-r--r--billing/app/views/billing_admin/show.html.haml17
-rw-r--r--billing/app/views/subscriptions/_subscription_details.html.haml11
-rw-r--r--billing/config/routes.rb1
5 files changed, 69 insertions, 1 deletions
diff --git a/billing/app/controllers/billing_admin_controller.rb b/billing/app/controllers/billing_admin_controller.rb
new file mode 100644
index 0000000..2a5165c
--- /dev/null
+++ b/billing/app/controllers/billing_admin_controller.rb
@@ -0,0 +1,14 @@
+class BillingAdminController < BillingBaseController
+ before_filter :authorize_admin
+
+ def show
+ @past_due_atleast_90_days = Braintree::Subscription.search do |search|
+ search.days_past_due >= 90
+ end
+
+ @all_past_due = Braintree::Subscription.search do |search|
+ search.status.is Braintree::Subscription::Status::PastDue
+ end
+ end
+
+end
diff --git a/billing/app/helpers/billing_helper.rb b/billing/app/helpers/billing_helper.rb
index 3c0691f..1dd3f38 100644
--- a/billing/app/helpers/billing_helper.rb
+++ b/billing/app/helpers/billing_helper.rb
@@ -9,6 +9,15 @@ module BillingHelper
form_for object, options, &block
end
+ def billing_top_link(user)
+ # for admins, top link will show special admin information, which has link to show their own customer information
+ if (admin? and user == current_user)
+ billing_admin_path
+ else
+ show_or_new_customer_link(user)
+ end
+ end
+
def show_or_new_customer_link(user)
# Link to show if user is admin viewing another user, or user is already a customer.
# Otherwise link to create a new customer.
@@ -19,4 +28,22 @@ module BillingHelper
end
end
+ # a bit strange to put here, but we don't have a subscription model
+ def user_for_subscription(subscription)
+
+ if (transaction = subscription.transactions.first)
+ # much quicker, but will only work if there is already a transaction associated with subscription (should generally be)
+ braintree_customer = transaction.customer_details
+ else
+ search_results = Braintree::Customer.search do |search|
+ search.payment_method_token.is subscription.payment_method_token
+ end
+ braintree_customer = search_results.first
+ end
+
+ customer = Customer.find_by_braintree_customer_id(braintree_customer.id)
+ user = User.find(customer.user_id)
+
+ end
+
end
diff --git a/billing/app/views/billing_admin/show.html.haml b/billing/app/views/billing_admin/show.html.haml
new file mode 100644
index 0000000..78843e5
--- /dev/null
+++ b/billing/app/views/billing_admin/show.html.haml
@@ -0,0 +1,17 @@
+- # todo: move into helper, as following 2 are pretty much identical
+%legend= t(:more_than_90_days_past_due)
+- if @past_due_atleast_90_days.empty?
+ = t(:none)
+- else
+ - @past_due_atleast_90_days.each do |past_due_subscription|
+ = render :partial => "subscriptions/subscription_details", :locals => {:subscription => past_due_subscription, :show_user => user_for_subscription(past_due_subscription)}
+
+%legend= t(:all_past_due)
+- if @all_past_due.empty?
+ = t(:none)
+- else
+ - @all_past_due.each do |past_due_subscription|
+ = render :partial => "subscriptions/subscription_details", :locals => {:subscription => past_due_subscription, :show_user => user_for_subscription(past_due_subscription)}
+
+%legend= t(:your_settings)
+= link_to 'view own billing settings', show_or_new_customer_link(current_user) \ No newline at end of file
diff --git a/billing/app/views/subscriptions/_subscription_details.html.haml b/billing/app/views/subscriptions/_subscription_details.html.haml
index 6eda7ca..27b00c7 100644
--- a/billing/app/views/subscriptions/_subscription_details.html.haml
+++ b/billing/app/views/subscriptions/_subscription_details.html.haml
@@ -1,7 +1,16 @@
%p
+ - if local_assigns[:show_user]
+ User:
+ = link_to show_user.login, user_overview_path(show_user)
+ ID:
= link_to subscription.id, user_subscription_path(@user, subscription.id)
Balance:
- = number_to_currency(subscription.balance)
+ - subscription_balance_currency = number_to_currency(subscription.balance)
+ - if subscription.balance > 0
+ %font{:color => "red"}
+ = subscription_balance_currency
+ - else
+ = subscription_balance_currency
Bill on:
= subscription.billing_day_of_month
Start date:
diff --git a/billing/config/routes.rb b/billing/config/routes.rb
index e024f43..dbdc24b 100644
--- a/billing/config/routes.rb
+++ b/billing/config/routes.rb
@@ -15,6 +15,7 @@ Rails.application.routes.draw do
match 'credit_card_info/confirm' => 'credit_card_info#confirm', :as => :confirm_credit_card_info
resources :subscriptions, :only => [:new, :create, :update] # index, show & destroy are within users path
+ match 'billing_admin' => 'billing_admin#show', :as => :billing_admin
#match 'transactions/:product_id/new' => 'transactions#new', :as => :new_transaction
#match 'transactions/confirm/:product_id' => 'transactions#confirm', :as => :confirm_transaction