summaryrefslogtreecommitdiff
path: root/billing/app/models
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-03-19 15:54:24 -0700
committerAzul <azul@leap.se>2013-07-17 10:46:25 +0200
commita1837914b8f989e2c45fb7b78fc648f0d3f957d6 (patch)
tree0f43e54764acaad1ba8af6265432fe5606e6fbec /billing/app/models
parent925534524317d0b6e7786d5a891e2b462b897d0a (diff)
Start to adding customers to braintree vault.
Diffstat (limited to 'billing/app/models')
-rw-r--r--billing/app/models/customer.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/billing/app/models/customer.rb b/billing/app/models/customer.rb
new file mode 100644
index 0000000..611b9d1
--- /dev/null
+++ b/billing/app/models/customer.rb
@@ -0,0 +1,38 @@
+class Customer < CouchRest::Model::Base
+
+ #FIELDS = [:first_name, :last_name, :phone, :website, :company, :fax, :addresses, :credit_cards, :custom_fields]
+
+ use_database "customers"
+ belongs_to :user
+ property :braintree_customer_id
+
+ design do
+ view :by_user_id
+ view :by_braintree_customer_id
+ end
+
+ def has_payment_info?
+ !!braintree_customer_id
+ end
+
+ # from braintree_ruby_examples/rails3_tr_devise and should be tweaked
+ def with_braintree_data!
+ return self unless has_payment_info?
+ braintree_data = Braintree::Customer.find(braintree_customer_id)
+
+ debugger
+ #FIELDS.each do |field|
+ # send(:"#{field}=", braintree_data.send(field))
+ #end
+ self
+ end
+
+ ##??
+ def default_credit_card
+ return unless has_payment_info?
+
+ credit_cards.find { |cc| cc.default? }
+ end
+
+
+end