diff options
Diffstat (limited to 'billing/app/models/customer.rb')
-rw-r--r-- | billing/app/models/customer.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/billing/app/models/customer.rb b/billing/app/models/customer.rb index 8085d32..c7f216c 100644 --- a/billing/app/models/customer.rb +++ b/billing/app/models/customer.rb @@ -5,7 +5,7 @@ class Customer < CouchRest::Model::Base use_database "customers" belongs_to :user property :braintree_customer_id - + design do view :by_user_id view :by_braintree_customer_id @@ -35,5 +35,22 @@ class Customer < CouchRest::Model::Base braintree_data.credit_cards.find { |cc| cc.default? } end + #todo will this be plural? + def active_subscriptions(braintree_data=nil) + subscriptions = Array.new + 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' + end + end + subscriptions + end + + def single_subscription(braintree_data=nil) + self.active_subscriptions(braintree_data).first + end + + end |