diff options
author | claucece <soficeli0@gmail.com> | 2015-09-27 23:04:55 -0500 |
---|---|---|
committer | claucece <soficeli0@gmail.com> | 2015-10-05 22:41:21 -0500 |
commit | 6c4f02fd2d530c28899561fac40ca76075975dc8 (patch) | |
tree | 575f0aa91e189a6894f3bd1bce7fb5e83f02a6f7 /engines/billing/app/models | |
parent | b26d10fe7d87b570bd888fa2a2543f3675278f8b (diff) |
update to haml, created translations, deleted files
Diffstat (limited to 'engines/billing/app/models')
-rw-r--r-- | engines/billing/app/models/customer.rb | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/engines/billing/app/models/customer.rb b/engines/billing/app/models/customer.rb deleted file mode 100644 index 1acc7a5..0000000 --- a/engines/billing/app/models/customer.rb +++ /dev/null @@ -1,58 +0,0 @@ -class Customer < CouchRest::Model::Base - - FIELDS = [:first_name, :last_name, :phone, :website, :company, :fax, :addresses, :credit_cards, :custom_fields] - attr_accessor *FIELDS - - use_database "customers" - belongs_to :user - belongs_to :braintree_customer - - # Braintree::Customer - stored on braintrees servers - we only have the id. - def braintree_customer - @braintree_customer ||= Braintree::Customer.find(braintree_customer_id) - end - - validates :user, presence: true - - 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? - - FIELDS.each do |field| - send(:"#{field}=", braintree_customer.send(field)) - end - self - end - - def default_credit_card - return unless has_payment_info? - - 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_pending_active_pastdue=true) - self.with_braintree_data! - return unless has_payment_info? - - subscriptions = [] - self.default_credit_card.subscriptions.each do |sub| - if only_pending_active_pastdue and ['Pending', 'Active','Past Due'].include? sub.status - return sub - else - subscriptions << sub - end - end - only_pending_active_pastdue ? nil : subscriptions - end - -end |