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.
-
#request_xml ⇒ Object
Returns the value of attribute request_xml.
-
#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.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cobro_digital.rb', line 31 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 = [] @request_xml = nil end |
Instance Attribute Details
#boletas ⇒ Object
Returns the value of attribute boletas.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def boletas @boletas end |
#client_to_use ⇒ Object
Returns the value of attribute client_to_use.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def client_to_use @client_to_use end |
#http_method ⇒ Object
Returns the value of attribute http_method.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def http_method @http_method end |
#id_comercio ⇒ Object
Returns the value of attribute id_comercio.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def id_comercio @id_comercio end |
#micrositios ⇒ Object
Returns the value of attribute micrositios.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def micrositios @micrositios end |
#pagadores ⇒ Object
Returns the value of attribute pagadores.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def pagadores @pagadores end |
#request_xml ⇒ Object
Returns the value of attribute request_xml.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def request_xml @request_xml end |
#requests ⇒ Object
Returns the value of attribute requests.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def requests @requests end |
#sid ⇒ Object
Returns the value of attribute sid.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def sid @sid end |
#transacciones ⇒ Object
Returns the value of attribute transacciones.
29 30 31 |
# File 'lib/cobro_digital.rb', line 29 def transacciones @transacciones end |
Instance Method Details
#call(request) ⇒ Object
80 81 82 |
# File 'lib/cobro_digital.rb', line 80 def call(request) send("#{client_to_use}_client", comercio.merge(request)) end |
#comercio ⇒ Object
84 85 86 |
# File 'lib/cobro_digital.rb', line 84 def comercio { 'idComercio' => @id_comercio, 'sid' => @sid, 'handshake' => Digest::MD5.hexdigest(Time.now.to_f.to_s) } end |
#https_client(params) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cobro_digital.rb', line 58 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, open_timeout: CobroDigital::TIMEOUT, read_timeout: CobroDigital::TIMEOUT ) do |http| http.request(req) end end |
#soap_client(params) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cobro_digital.rb', line 43 def soap_client(params) client = Savon.client( wsdl: CobroDigital::WSDL, log_level: :debug, pretty_print_xml: true, open_timeout: CobroDigital::TIMEOUT, read_timeout: CobroDigital::TIMEOUT ) operation = client.operation(:webservice_cobrodigital) request = operation.build(message: { 'parametros_de_entrada' => params.to_json }) @request_xml = request.pretty client.call(:webservice_cobrodigital, message: { 'parametros_de_entrada' => params.to_json }) end |