Class: Workarea::Payment::Profile
- Inherits:
-
Object
- Object
- Workarea::Payment::Profile
- Includes:
- ApplicationDocument
- Defined in:
- app/models/workarea/payment/profile.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#default_credit_card ⇒ SavedCreditCard
Finds the default saved credit card for a user.
-
#purchase_on_store_credit(cents) ⇒ Object
Use store credit to make a purchase.
-
#reload_store_credit(cents) ⇒ Object
Reload store credit to refund a purchase.
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
Methods included from Mongoid::Document
Class Method Details
.lookup(reference) ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/models/workarea/payment/profile.rb', line 19 def self.lookup(reference) find_by(reference: reference.id) rescue Mongoid::Errors::DocumentNotFound create!(reference: reference.id) do |profile| profile.email = reference.email end end |
.update_email(reference, new_email) ⇒ Object
27 28 29 |
# File 'app/models/workarea/payment/profile.rb', line 27 def self.update_email(reference, new_email) lookup(reference).update_attribute(:email, new_email) end |
Instance Method Details
#default_credit_card ⇒ SavedCreditCard
Finds the default saved credit card for a user.
35 36 37 38 39 |
# File 'app/models/workarea/payment/profile.rb', line 35 def default_credit_card credit_cards.find_by(default: true) rescue credit_cards.desc(:created_at).first end |
#purchase_on_store_credit(cents) ⇒ Object
Use store credit to make a purchase
45 46 47 48 |
# File 'app/models/workarea/payment/profile.rb', line 45 def purchase_on_store_credit(cents) raise InsufficientFunds if store_credit.cents < cents inc('store_credit.cents' => 0 - cents) end |
#reload_store_credit(cents) ⇒ Object
Reload store credit to refund a purchase
54 55 56 |
# File 'app/models/workarea/payment/profile.rb', line 54 def reload_store_credit(cents) inc('store_credit.cents' => cents) end |