diff options
author | Azul <azul@leap.se> | 2013-07-01 13:13:02 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2013-07-17 10:47:14 +0200 |
commit | 1c40963194aa6f1dc985b949fb3c05e70f7530c0 (patch) | |
tree | d03cb2b420f0b8d5dfec2f0b2c875d157782c275 /billing/app/models/customer.rb | |
parent | a49c63eb117abf47ca1804493c25ae34804f8ee1 (diff) |
use fake_braintree, fix and test customer with braintree info
Diffstat (limited to 'billing/app/models/customer.rb')
-rw-r--r-- | billing/app/models/customer.rb | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/billing/app/models/customer.rb b/billing/app/models/customer.rb index 7d35756..4788118 100644 --- a/billing/app/models/customer.rb +++ b/billing/app/models/customer.rb @@ -1,10 +1,11 @@ class Customer < CouchRest::Model::Base - #FIELDS = [:first_name, :last_name, :phone, :website, :company, :fax, :addresses, :credit_cards, :custom_fields] + FIELDS = [:first_name, :last_name, :phone, :website, :company, :fax, :addresses, :credit_cards, :custom_fields] + attr_accessor *FIELDS use_database "customers" belongs_to :user - property :braintree_customer_id + belongs_to :braintree_customer, class: Braintree::Customer validates :user, presence: true @@ -18,35 +19,27 @@ class Customer < CouchRest::Model::Base end # from braintree_ruby_examples/rails3_tr_devise and should be tweaked -=begin def with_braintree_data! return self unless has_payment_info? - braintree_data = Braintree::Customer.find(braintree_customer_id) - #FIELDS.each do |field| - # send(:"#{field}=", braintree_data.send(field)) - #end + FIELDS.each do |field| + send(:"#{field}=", braintree_customer.send(field)) + end self end -=end - #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 + credit_cards.find { |cc| cc.default? } + end # 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) subscriptions = [] - braintree_data.credit_cards.first.subscriptions.each do |sub| + credit_cards.first.subscriptions.each do |sub| if only_active and sub.status == 'Active' return sub else |