Class: Workarea::Payment::Profile

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument
Defined in:
app/models/workarea/payment/profile.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

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

#embedded_children

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_cardSavedCreditCard

Finds the default saved credit card for a user.

Returns:



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

Raises:



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