Class: CuentaDigital::Payment
- Inherits:
-
Object
- Object
- CuentaDigital::Payment
- Defined in:
- lib/cuenta_digital/payment.rb
Overview
Codigo de operacion: 1: credito (ingreso de fondos,recaudaciones), 2: debito (retiros, pagos a terceros, pago de servicios, contracargos,etc) El Checksum de la operacion (firma) corresponde a una encriptacion SHA256 concatenando la clase de operacion, la fecha de la operacion, hora de la operacion, Monto, Codigo de Barras, Referencia, Codigo unico de operacion y la clave de seguridad ash(‘sha256’,ClaseDDMMYYYHHMMSSMontoBarraReferenciaUnicoClave), su finalidad es la validacion de la operacion.
Instance Attribute Summary collapse
-
#bar_code ⇒ Object
Returns the value of attribute bar_code.
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#commission ⇒ Object
Returns the value of attribute commission.
-
#csv_line ⇒ Object
Returns the value of attribute csv_line.
-
#gross_amount ⇒ Object
Returns the value of attribute gross_amount.
-
#net_amount ⇒ Object
Returns the value of attribute net_amount.
-
#operation_event_number ⇒ Object
Returns the value of attribute operation_event_number.
-
#operation_id ⇒ Object
Returns the value of attribute operation_id.
-
#operation_kind ⇒ Object
Returns the value of attribute operation_kind.
-
#payment_date ⇒ Object
Returns the value of attribute payment_date.
-
#payment_method ⇒ Object
Returns the value of attribute payment_method.
-
#payment_number ⇒ Object
Returns the value of attribute payment_number.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#secret ⇒ Object
Returns the value of attribute secret.
Class Method Summary collapse
-
.collector(control:, date: Time.now, from: nil, to: nil, opts: { wget: false, sandbox: false }) ⇒ Object
only get transactions completed Explicacion de la estructura Fecha del cobro|Horario de la operacion (HHmmss)|Monto Bruto|Monto neto recibido|Comision|Su referencia|Medio de pago usado|Codigo interno unico de operacion|Cobro numero 1 del archivo Ejemplo de una linea del archivo: 30122008|221500|1000.50|999.50|1.00|cliente9879|PagoFacil|23a0f1c7b636c08660abbe4f02360633-de70dbb3f907c613ddce6566667f92c6|1.
- .uri(control:, sandbox: false, date: Time.now, from: nil, to: nil) ⇒ Object
Instance Method Summary collapse
- #credit? ⇒ Boolean
- #debit? ⇒ Boolean
-
#initialize(params = {}) ⇒ Payment
constructor
A new instance of Payment.
- #secret_valid? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Payment
Returns a new instance of Payment.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cuenta_digital/payment.rb', line 23 def initialize(params = {}) @operation_id = params[:operation_id] @operation_kind = params[:operation_kind] @payment_date = params[:payment_date] @gross_amount = params[:gross_amount] @net_amount = params[:net_amount] @commission = params[:commission] @reference = params[:reference] @payment_method = params[:payment_method] @payment_number = params[:payment_number] @checksum = params[:checksum] @bar_code = params[:bar_code] @csv_line = params[:csv_line] @secret = params[:secret] end |
Instance Attribute Details
#bar_code ⇒ Object
Returns the value of attribute bar_code.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def @bar_code end |
#checksum ⇒ Object
Returns the value of attribute checksum.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def checksum @checksum end |
#commission ⇒ Object
Returns the value of attribute commission.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def commission @commission end |
#csv_line ⇒ Object
Returns the value of attribute csv_line.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def csv_line @csv_line end |
#gross_amount ⇒ Object
Returns the value of attribute gross_amount.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def gross_amount @gross_amount end |
#net_amount ⇒ Object
Returns the value of attribute net_amount.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def net_amount @net_amount end |
#operation_event_number ⇒ Object
Returns the value of attribute operation_event_number.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def operation_event_number @operation_event_number end |
#operation_id ⇒ Object
Returns the value of attribute operation_id.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def operation_id @operation_id end |
#operation_kind ⇒ Object
Returns the value of attribute operation_kind.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def operation_kind @operation_kind end |
#payment_date ⇒ Object
Returns the value of attribute payment_date.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def payment_date @payment_date end |
#payment_method ⇒ Object
Returns the value of attribute payment_method.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def payment_method @payment_method end |
#payment_number ⇒ Object
Returns the value of attribute payment_number.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def payment_number @payment_number end |
#reference ⇒ Object
Returns the value of attribute reference.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def reference @reference end |
#secret ⇒ Object
Returns the value of attribute secret.
8 9 10 |
# File 'lib/cuenta_digital/payment.rb', line 8 def secret @secret end |
Class Method Details
.collector(control:, date: Time.now, from: nil, to: nil, opts: { wget: false, sandbox: false }) ⇒ Object
only get transactions completed Explicacion de la estructura Fecha del cobro|Horario de la operacion (HHmmss)|Monto Bruto|Monto neto recibido|Comision|Su referencia|Medio de pago usado|Codigo interno unico de operacion|Cobro numero 1 del archivo Ejemplo de una linea del archivo: 30122008|221500|1000.50|999.50|1.00|cliente9879|PagoFacil|23a0f1c7b636c08660abbe4f02360633-de70dbb3f907c613ddce6566667f92c6|1
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/cuenta_digital/payment.rb', line 87 def self.collector(control:, date: Time.now, from: nil, to: nil, opts: { wget: false, sandbox: false }) retries = 0 uri_request = uri(control: control, sandbox: opts[:sandbox], date: date, from: from, to: to) begin results = if opts[:wget] `wget -O- "#{uri_request.to_s}"` else partial_response = Net::HTTP.get_response(uri_request) if partial_response.code == '200' partial_response.body else raise StandardError, partial_response.body end end rescue SocketError => e if retries < 3 retries += 1 retry end raise e end results.split("\n").map do |result| puts result args = result.split('|') params = { csv_line: result, operation_kind: 1, # Credit payment_date: Time.parse( [ args[0].insert(2, '-').insert(5, '-'), args[1].insert(2, ':').insert(5, ':') ].join(' ') ), gross_amount: args[2], net_amount: args[3], commission: args[4], reference: args[5], payment_method: args[6], operation_id: args[7], payment_number: args[8] } CuentaDigital::Payment.new(params) end end |
.uri(control:, sandbox: false, date: Time.now, from: nil, to: nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cuenta_digital/payment.rb', line 51 def self.uri(control:, sandbox: false, date: Time.now, from: nil, to: nil) uri_request = if sandbox CuentaDigital.sandbox_uri_payment_export else CuentaDigital.uri_payment_export end from = { hour: (from.nil? ? '00' : from.strftime('%H')), min: (from.nil? ? '00' : from.strftime('%M')) } to = { hour: (to.nil? ? '23' : to.strftime('%H')), min: (to.nil? ? '59' : to.strftime('%M')) } uri_params = { control: control, fecha: date.strftime('%Y%m%d'), hour1: from[:hour], min1: from[:min], hour2: to[:hour], min2: to[:min] } uri_request.query = URI.encode_www_form(uri_params.to_a) uri_request end |
Instance Method Details
#credit? ⇒ Boolean
39 40 41 |
# File 'lib/cuenta_digital/payment.rb', line 39 def credit? @operation_kind == 1 end |
#debit? ⇒ Boolean
43 44 45 |
# File 'lib/cuenta_digital/payment.rb', line 43 def debit? @operation_kind == 0 end |
#secret_valid? ⇒ Boolean
47 48 49 |
# File 'lib/cuenta_digital/payment.rb', line 47 def secret_valid? secret.nil? || Digest::SHA256.hexdigest(@secret) == @checksum end |