Class: CatarseCompraFacil::CompraFacil

Inherits:
Object
  • Object
show all
Defined in:
lib/catarse_compra_facil.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ CompraFacil

Returns a new instance of CompraFacil.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/catarse_compra_facil.rb', line 31

def initialize(attrs = {})
  attrs.each {|key, value| self.send("#{key}=", value)}
  @user_id_back_office = -1
  self.payment_company = "multibanco"
  if Rails.env.development? || Rails.env.test?
    self.user_type = 10241
  else
    self.user_type = 11249
  end

  self.insert_mode = "SaveCompraToBDValor1"
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def address
  @address
end

#cityObject

Returns the value of attribute city.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def city
  @city
end

#emailObject

Returns the value of attribute email.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def email
  @email
end

#entityObject

Returns the value of attribute entity.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def entity
  @entity
end

#errorObject

Returns the value of attribute error.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def error
  @error
end

#external_referenceObject

Returns the value of attribute external_reference.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def external_reference
  @external_reference
end

#infoObject

Returns the value of attribute info.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def info
  @info
end

#insert_modeObject

Returns the value of attribute insert_mode.



29
30
31
# File 'lib/catarse_compra_facil.rb', line 29

def insert_mode
  @insert_mode
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def name
  @name
end

#nifObject

Returns the value of attribute nif.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def nif
  @nif
end

#originObject

Returns the value of attribute origin.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def origin
  @origin
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def password
  @password
end

#payedObject

Returns the value of attribute payed.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def payed
  @payed
end

#payment_companyObject

Returns the value of attribute payment_company.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def payment_company
  @payment_company
end

#phoneObject

Returns the value of attribute phone.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def phone
  @phone
end

#referenceObject

Returns the value of attribute reference.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def reference
  @reference
end

#server_addressObject (readonly)

Returns the value of attribute server_address.



29
30
31
# File 'lib/catarse_compra_facil.rb', line 29

def server_address
  @server_address
end

#stateObject

Returns the value of attribute state.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def state
  @state
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def user
  @user
end

#user_id_back_officeObject

Returns the value of attribute user_id_back_office.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def user_id_back_office
  @user_id_back_office
end

#user_typeObject

Returns the value of attribute user_type.



29
30
31
# File 'lib/catarse_compra_facil.rb', line 29

def user_type
  @user_type
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def value
  @value
end

#zip_codeObject

Returns the value of attribute zip_code.



8
9
10
# File 'lib/catarse_compra_facil.rb', line 8

def zip_code
  @zip_code
end

Instance Method Details

#get_order_information!Object



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/catarse_compra_facil.rb', line 88

def get_order_information!
  client = Savon.client(wsdl: self.server_address)
  message = { "referencia" => self.reference,
              "IDCliente" => self.user,
              :password => self.password
  }
  response = client.call(:get_info_compra, message: message)
  if response.success?
    self.payed = response.to_hash[:get_info_compra_response][:pago]
    self.state = response.to_hash[:get_info_compra_response][:estado]
  end
  puts response.to_hash;
end

#send_order!Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/catarse_compra_facil.rb', line 71

def send_order!
  client = Savon.client(wsdl: self.server_address)
  message = { :origem => self.origin,
              "IDCliente" => self.user,
              :password => self.password,
              :valor => self.value,
              :informacao => self.info,
              "IDUserBackoffice" => self.user_id_back_office.to_s
              }
  response = client.call(:save_compra_to_bd_valor1, message: message)
  if response.success?
    self.reference = response.to_hash[:save_compra_to_bd_valor1_response][:referencia]
    self.entity = response.to_hash[:save_compra_to_bd_valor1_response][:entidade]
  end
  puts response.to_hash;
end