summaryrefslogtreecommitdiff
path: root/billing/app/models
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-05-06 12:58:34 -0700
committerAzul <azul@leap.se>2013-07-17 10:47:13 +0200
commit62b32320f38627dad870c7b3157576c48674c42b (patch)
tree3f64557604995d84a1477b7e66f820baffd3ed59 /billing/app/models
parentfe0ac266a797523492fe3b2c750e7862f51b152f (diff)
Show single active subscription from user's page, with link to index showing all the user's subscriptions.
Diffstat (limited to 'billing/app/models')
-rw-r--r--billing/app/models/customer.rb26
1 files changed, 13 insertions, 13 deletions
diff --git a/billing/app/models/customer.rb b/billing/app/models/customer.rb
index fa43b96..161f763 100644
--- a/billing/app/models/customer.rb
+++ b/billing/app/models/customer.rb
@@ -30,28 +30,28 @@ class Customer < CouchRest::Model::Base
#slow to get Braintree Customer data, so pass it if have already retrieved it
# won't really have multiple credit cards on file
+ # instead of having method, should just be able to call braintree_data.credit_cards.first if just one is allowed
def default_credit_card(braintree_data = nil)
return unless has_payment_info?
braintree_data = braintree_data || Braintree::Customer.find(braintree_customer_id)
braintree_data.credit_cards.find { |cc| cc.default? }
end
- #todo will this be plural?
- def active_subscriptions(braintree_data=nil)
- subscriptions = Array.new
+
+ # based on 2nd parameter, either returns the single active subscription (or nil if there isn't one), or an array of all subsciptions
+ def subscriptions(braintree_data=nil, only_active=true)
+ return unless has_payment_info?
braintree_data = braintree_data || Braintree::Customer.find(braintree_customer_id)
- braintree_data.credit_cards.each do |cc|
- cc.subscriptions.each do |sub|
- subscriptions << sub if sub.status == 'Active'
+
+ subscriptions = []
+ braintree_data.credit_cards.first.subscriptions.each do |sub|
+ if only_active and sub.status == 'Active'
+ return sub
+ else
+ subscriptions << sub
end
end
- subscriptions
+ only_active ? nil : subscriptions
end
- def single_subscription(braintree_data=nil)
- self.active_subscriptions(braintree_data).first
- end
-
-
-
end