Class: CobroDigital::Client
- Inherits:
-
Object
- Object
- CobroDigital::Client
- Defined in:
- lib/cobro_digital.rb
Instance Attribute Summary collapse
-
#boletas ⇒ Object
Returns the value of attribute boletas.
-
#client_to_use ⇒ Object
Returns the value of attribute client_to_use.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#id_comercio ⇒ Object
Returns the value of attribute id_comercio.
-
#micrositios ⇒ Object
Returns the value of attribute micrositios.
-
#pagadores ⇒ Object
Returns the value of attribute pagadores.
-
#requests ⇒ Object
Returns the value of attribute requests.
-
#sid ⇒ Object
Returns the value of attribute sid.
-
#transacciones ⇒ Object
Returns the value of attribute transacciones.
Instance Method Summary collapse
- #call(request) ⇒ Object
- #comercio ⇒ Object
- #https_client(params) ⇒ Object
-
#initialize(attrs = {}) ⇒ Client
constructor
A new instance of Client.
- #soap_client(params) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Client
Returns a new instance of Client.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cobro_digital.rb', line 29 def initialize(attrs={}) @id_comercio = attrs[:id_comercio] @sid = attrs[:sid] @client_to_use = attrs[:con_client].present? ? attrs[:con_client] : CobroDigital::SOAP # @with_handshake = attrs[:handshake].present? ? attrs[:handshake] : true @pagadores = [] @boletas = [] @transacciones = [] @micrositios = [] end |
Instance Attribute Details
#boletas ⇒ Object
Returns the value of attribute boletas.
27 28 29 |
# File 'lib/cobro_digital.rb', line 27 def boletas @boletas end |
#client_to_use ⇒ Object
Returns the value of attribute client_to_use.
27 28 29 |
# File 'lib/cobro_digital.rb', line 27 def client_to_use @client_to_use end |
#http_method ⇒ Object
Returns the value of attribute http_method.
27 28 29 |
# File 'lib/cobro_digital.rb', line 27 def http_method @http_method end |
#id_comercio ⇒ Object
Returns the value of attribute id_comercio.
27 28 29 |
# File 'lib/cobro_digital.rb', line 27 def id_comercio @id_comercio end |
#micrositios ⇒ Object
Returns the value of attribute micrositios.
27 28 29 |
# File 'lib/cobro_digital.rb', line 27 def micrositios @micrositios end |
#pagadores ⇒ Object
Returns the value of attribute pagadores.
27 28 29 |
# File 'lib/cobro_digital.rb', line 27 def pagadores @pagadores end |
#requests ⇒ Object
Returns the value of attribute requests.
27 28 29 |
# File 'lib/cobro_digital.rb', line 27 def requests @requests end |
#sid ⇒ Object
Returns the value of attribute sid.
27 28 29 |
# File 'lib/cobro_digital.rb', line 27 def sid @sid end |
#transacciones ⇒ Object
Returns the value of attribute transacciones.
27 28 29 |
# File 'lib/cobro_digital.rb', line 27 def transacciones @transacciones end |
Instance Method Details
#call(request) ⇒ Object
59 60 61 |
# File 'lib/cobro_digital.rb', line 59 def call(request) send("#{client_to_use}_client", comercio.merge(request)) end |
#comercio ⇒ Object
63 64 65 |
# File 'lib/cobro_digital.rb', line 63 def comercio { 'idComercio' => @id_comercio, 'sid' => @sid, 'handshake' => Digest::MD5.hexdigest(Time.now.to_f.to_s) } end |
#https_client(params) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cobro_digital.rb', line 45 def https_client(params) case http_method when CobroDigital::Https::POST uri = URI(CobroDigital::URI) req = "Net::HTTP::#{http_method}".constantize.new(uri) req.set_form_data(params) when CobroDigital::Https::GET uri = URI([CobroDigital::URI, URI.encode_www_form(data)].join('?')) req = "Net::HTTP::#{http_method}".constantize.new(uri) end Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == CobroDigital::HTTPS) { |http| http.request(req) } end |
#soap_client(params) ⇒ Object
40 41 42 43 |
# File 'lib/cobro_digital.rb', line 40 def soap_client(params) client = Savon.client( wsdl: CobroDigital::WSDL, log_level: :debug, pretty_print_xml: true) client.call(:webservice_cobrodigital, message: { 'parametros_de_entrada' => params.to_json }) end |