summaryrefslogtreecommitdiff
path: root/billing/app/helpers
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-12-17 12:02:07 -0800
committerjessib <jessib@riseup.net>2013-12-17 12:02:07 -0800
commit98a247acb4d1be484c2982d48ec038eed3de3d55 (patch)
treef176092fa43145b9d8ce00a180fab70cf62da456 /billing/app/helpers
parent634db9875cc8f6f6b9a4a83dfc6b8d53728eb2b5 (diff)
parent83cd3d95b78b6df9ac33a8ee169e570f4d3e2eeb (diff)
Merge branch 'develop' into feature/billing-no-authenticated-payments
Conflicts: billing/config/locales/en.yml
Diffstat (limited to 'billing/app/helpers')
-rw-r--r--billing/app/helpers/billing_helper.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/billing/app/helpers/billing_helper.rb b/billing/app/helpers/billing_helper.rb
index 3c0691f..b9e5e2e 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,24 @@ 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_id = transaction.customer_details.id
+ else
+ credit_card = Braintree::CreditCard.find(subscription.payment_method_token)
+ braintree_customer_id = credit_card.customer_id
+ end
+
+ customer = Customer.find_by_braintree_customer_id(braintree_customer_id)
+ user = User.find(customer.user_id)
+
+ end
+
+ def allow_cancel_subscription(subscription)
+ ['Active', 'Pending'].include? subscription.status or (admin? and subscription.status == 'Past Due')
+ end
+
end