diff options
author | jessib <jessib@riseup.net> | 2013-10-01 13:56:59 -0700 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-10-01 13:56:59 -0700 |
commit | 0fe1678cd37c8e917cb28eed9eb28777d3a92283 (patch) | |
tree | 751e6eaaceef1d81a3bce020871a6b004f795f2d /billing/app/helpers | |
parent | 6b35a71db66e61c04747bf82feded014687cc528 (diff) |
Allow admins to view past-due subscriptions.
Diffstat (limited to 'billing/app/helpers')
-rw-r--r-- | billing/app/helpers/billing_helper.rb | 27 |
1 files changed, 27 insertions, 0 deletions
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 |