Class: Conekta::Customer

Instance Attribute Summary collapse

Attributes inherited from Resource

#id

Attributes inherited from ConektaObject

#values

Instance Method Summary collapse

Methods included from Operations::CreateMember

#create_member

Methods included from Operations::CustomAction

#custom_action

Methods included from Operations::Update

#update

Methods included from Operations::Delete

#delete, #delete_member

Methods included from Operations::Create

included

Methods included from Operations::Where

handle_type_of_paging, included

Methods included from Operations::Find

included

Methods inherited from Resource

_url, #_url, #create_member_with_relation, underscored_class

Methods inherited from ConektaObject

#class_name, class_name, #create_attr, #first, #inspect, #last, #set_val, #to_s, #unset_key

Constructor Details

#initialize(id = nil) ⇒ Customer

Returns a new instance of Customer.



16
17
18
19
20
21
22
# File 'lib/conekta/customer.rb', line 16

def initialize(id=nil)
  @id = id
  @payment_sources ||= List.new("PaymentSource", {})
  @fiscal_entities ||= List.new("FiscalEntity", {})
  @shipping_contacts ||= List.new("ShippingContacts", {})
  super(id)
end

Instance Attribute Details

#account_ageObject

Returns the value of attribute account_age.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def 
  @account_age
end

#cardsObject

Returns the value of attribute cards.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def cards
  @cards
end

#corporateObject

Returns the value of attribute corporate.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def corporate
  @corporate
end

#default_fiscal_entity_idObject

Returns the value of attribute default_fiscal_entity_id.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def default_fiscal_entity_id
  @default_fiscal_entity_id
end

#default_payment_source_idObject

Returns the value of attribute default_payment_source_id.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def default_payment_source_id
  @default_payment_source_id
end

#default_shipping_contact_idObject

Returns the value of attribute default_shipping_contact_id.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def default_shipping_contact_id
  @default_shipping_contact_id
end

#emailObject

Returns the value of attribute email.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def email
  @email
end

#first_paid_atObject

Returns the value of attribute first_paid_at.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def first_paid_at
  @first_paid_at
end

#fiscal_entitiesObject

Returns the value of attribute fiscal_entities.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def fiscal_entities
  @fiscal_entities
end

#livemodeObject

Returns the value of attribute livemode.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def livemode
  @livemode
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def name
  @name
end

Returns the value of attribute paid_transactions.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def paid_transactions
  @paid_transactions
end

#payment_sourcesObject

Returns the value of attribute payment_sources.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def payment_sources
  @payment_sources
end

#phoneObject

Returns the value of attribute phone.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def phone
  @phone
end

#referrerObject

Returns the value of attribute referrer.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def referrer
  @referrer
end

#shipping_contactsObject

Returns the value of attribute shipping_contacts.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def shipping_contacts
  @shipping_contacts
end

#subscriptionObject

Returns the value of attribute subscription.



11
12
13
# File 'lib/conekta/customer.rb', line 11

def subscription
  @subscription
end

Instance Method Details

#create_card(params) ⇒ Object



53
54
55
# File 'lib/conekta/customer.rb', line 53

def create_card(params)
  self.create_member_with_relation('cards', params, self)
end

#create_fiscal_entity(params) ⇒ Object



65
66
67
# File 'lib/conekta/customer.rb', line 65

def create_fiscal_entity(params)
  self.create_member_with_relation('fiscal_entities', params, self)
end

#create_payment_source(params) ⇒ Object



57
58
59
# File 'lib/conekta/customer.rb', line 57

def create_payment_source(params)
  self.create_member_with_relation('payment_sources', params, self)
end

#create_shipping_contact(params) ⇒ Object



69
70
71
# File 'lib/conekta/customer.rb', line 69

def create_shipping_contact(params)
  self.create_member_with_relation('shipping_contacts', params, self)
end

#create_submodels_lists(customer, submodels) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/conekta/customer.rb', line 73

def create_submodels_lists(customer, submodels)
  submodels.each do |submodel|
    self.send(submodel).each do |k, v|
      v.create_attr('customer', customer)

      self.send(submodel).set_val(k,v)
    end if self.respond_to?(submodel) && !self.send(submodel).nil?
  end
end

#create_subscription(params) ⇒ Object



61
62
63
# File 'lib/conekta/customer.rb', line 61

def create_subscription(params)
  self.create_member('subscription', params)
end

#load_from(response = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/conekta/customer.rb', line 24

def load_from(response=nil)
  if response
    super
  end

  customer = self

  if Conekta.api_version == "2.0.0"
    submodels = [:fiscal_entities, :payment_sources, :shipping_contacts]
    create_submodels_lists(customer, submodels)
  else
    submodels = [:cards]

    submodels.each do |submodel|
      self.send(submodel).each do |k,v|
        if !v.respond_to? :deleted or !v.deleted
          v.create_attr('customer', customer)

          self.send(submodel).set_val(k,v)
        end
      end
    end
  end

  if self.respond_to? :subscription and self.subscription
     self.subscription.create_attr('customer', customer)
  end
end