summaryrefslogtreecommitdiff
path: root/billing/app/models
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-04-15 12:13:33 -0700
committerAzul <azul@leap.se>2013-07-17 10:47:12 +0200
commit2829e7020abcf6d2f708fbc7dfb3db98ad174255 (patch)
tree4d389dbb892211bdb3f0305403a45c38e9d5a1c7 /billing/app/models
parent29f1de49083d57895bdf8f999448678934fbeffc (diff)
Displaying of user's subscription. Still not committed to whether user can have multiple subscriptions at a time or not.
Diffstat (limited to 'billing/app/models')
-rw-r--r--billing/app/models/customer.rb19
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