Module: MuckCommerce::Models::MuckUser

Extended by:
ActiveSupport::Concern
Defined in:
lib/muck-commerce/models/user.rb

Instance Method Summary collapse

Instance Method Details

#billing_informationObject

Get the user’s default billing information



35
36
37
38
39
40
# File 'lib/muck-commerce/models/user.rb', line 35

def billing_information
  bi = self.billing_informations.default.first
  # In case this is a new user the above call will return nil. Try to get billing information object from array:
  bi ||= self.billing_informations.first if self.billing_informations.length == 1
  bi
end

#build_billing_information(billing_information) ⇒ Object

Build but do not save billing information for the user



58
59
60
# File 'lib/muck-commerce/models/user.rb', line 58

def build_billing_information(billing_information)
  BillingInformation.new(billing_information.merge(:default => true, :user_id => self.id))  
end

#cim_descriptionObject

This is the description that will be passed to the CIM system



26
27
28
# File 'lib/muck-commerce/models/user.rb', line 26

def cim_description
  self.display_name
end

#create_update_billing_information!(billing_information) ⇒ Object

Setup or update billing information for the user



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/muck-commerce/models/user.rb', line 43

def create_update_billing_information!(billing_information)
  if self.billing_information
    @default_billing_information = self.billing_information
    @default_billing_information.update_attributes!(billing_information)
  else
    @default_billing_information = BillingInformation.create!(billing_information.merge(:default => true))
    self.billing_informations << @default_billing_information
  end

  @default_billing_information.update_remote_storage

  @default_billing_information
end

#referral_codeObject



62
63
64
# File 'lib/muck-commerce/models/user.rb', line 62

def referral_code
  self.referral_coupon_code ||= Coupon.create(:code => Coupon.random_code, :unlimited => true, :coupon_type => CouponType.user_referral)
end

#subscriptionObject



30
31
32
# File 'lib/muck-commerce/models/user.rb', line 30

def subscription
  @default_subscription ||= self.subscriptions.default.first
end