cuenta_digital 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -10
- data/lib/cuenta_digital/coupon.rb +53 -5
- data/lib/cuenta_digital/payment.rb +5 -32
- data/lib/cuenta_digital/version.rb +1 -1
- data/lib/cuenta_digital/webhook.rb +62 -0
- data/lib/cuenta_digital.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b78d57edda1b829e9ea2ee6d352a0f91fd409c3c0516b460cf1dea191b7c2a7
|
4
|
+
data.tar.gz: 2dc9a771ced4160f5ae186304e520535880a41a0f750f39210acf392617caeed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6162c9bd7d524991c27f0dbed6d984fa4ab16f227b0407061c8857b9b488e81fe50c88733fd3baf598bc6a249887db408ce0db9af5cf325d92fc72d170aa9558
|
7
|
+
data.tar.gz: ef26033d936568136c8445ed28057282d149cdcfcbb483b4320fab21dcfee55ce9bb35c70215e93e226a6879c5ecda3e4f48e8adf88fc4bf734f29cf6dc4562e
|
data/README.md
CHANGED
@@ -131,16 +131,6 @@ This method return `CuentaDigital::Response` object
|
|
131
131
|
- **bar_code**
|
132
132
|
- **csv_line**
|
133
133
|
|
134
|
-
#### Methods
|
135
|
-
|
136
|
-
- [class method] `process_webhook`:
|
137
|
-
|
138
|
-
```ruby
|
139
|
-
CuentaDigital::Payment.process_webhook(csv) # String csv separated by ','
|
140
|
-
```
|
141
|
-
|
142
|
-
return arrays of `CuentaDigital::Payment`
|
143
|
-
|
144
134
|
- [class method] `request`. Only get transactions completed
|
145
135
|
|
146
136
|
|
@@ -164,6 +154,19 @@ return arrays of `CuentaDigital::Payment`
|
|
164
154
|
CuentaDigital::Payment.request(control: 'e9161bfccfba345237fb1311b890203f', date: Time.new(2019, 07, 01), opts: { wget: false, sandbox: true })
|
165
155
|
```
|
166
156
|
|
157
|
+
### Webhook
|
158
|
+
|
159
|
+
#### Methods
|
160
|
+
|
161
|
+
- [class method] `process`:
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
CuentaDigital::Payment.process(csv) # String csv separated by ','
|
165
|
+
```
|
166
|
+
|
167
|
+
return arrays of `CuentaDigital::Payment`
|
168
|
+
|
169
|
+
|
167
170
|
## Development
|
168
171
|
|
169
172
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -74,6 +74,8 @@ module CuentaDigital
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def generate(xml: true, wget: false)
|
77
|
+
return false unless valid?
|
78
|
+
|
77
79
|
retries = 0
|
78
80
|
begin
|
79
81
|
if wget
|
@@ -118,6 +120,8 @@ module CuentaDigital
|
|
118
120
|
validate_attributes_presence
|
119
121
|
validate_standar_values
|
120
122
|
validate_format_values
|
123
|
+
validate_dates
|
124
|
+
valideate_lengths
|
121
125
|
end
|
122
126
|
|
123
127
|
def validate_attributes_presence
|
@@ -128,23 +132,67 @@ module CuentaDigital
|
|
128
132
|
|
129
133
|
missing_attributes.uniq.each do |attr|
|
130
134
|
@errors[attr.to_sym] = [] unless errors.key?(attr)
|
131
|
-
@errors[attr.to_sym] <<
|
135
|
+
@errors[attr.to_sym] << [
|
136
|
+
:cant_be_blank,
|
137
|
+
CuentaDigital::Exception::MissingAttributes.new(attr).message
|
138
|
+
]
|
139
|
+
end
|
140
|
+
|
141
|
+
if @first_due_date.blank? && !@second_due_date.blank?
|
142
|
+
@errors[:first_due_date] = [] unless errors.key?(:first_due_date)
|
143
|
+
@errors[:first_due_date] << [
|
144
|
+
:cant_be_blank,
|
145
|
+
CuentaDigital::Exception::MissingAttributes.new(:first_due_date).message
|
146
|
+
]
|
147
|
+
end
|
148
|
+
|
149
|
+
if @amount.blank? && !@second_amount.blank?
|
150
|
+
@errors[:amount] = [] unless errors.key?(:amount)
|
151
|
+
@errors[:amount] << [
|
152
|
+
:cant_be_blank,
|
153
|
+
CuentaDigital::Exception::MissingAttributes.new(:amount).message
|
154
|
+
]
|
132
155
|
end
|
133
156
|
end
|
134
157
|
|
135
158
|
def validate_standar_values
|
136
|
-
return if CuentaDigital::CURRENCIES.
|
159
|
+
return if CuentaDigital::CURRENCIES.key?(@currency)
|
137
160
|
|
138
161
|
@errors[:currency] = [] unless errors.key?(:currency)
|
139
|
-
|
140
|
-
|
162
|
+
@errors[:currency] << [
|
163
|
+
:unsupported_value,
|
164
|
+
CuentaDigital::Exception::InvalidValueAttribute.new("currency, Possible values #{CuentaDigital::CURRENCIES.keys}").message
|
165
|
+
]
|
141
166
|
end
|
142
167
|
|
143
168
|
def validate_format_values
|
144
169
|
return if @email_to.nil? || !@email_to.match(CuentaDigital::VALID_EMAIL_REGEX).nil?
|
145
170
|
|
146
171
|
@errors[:email_to] = [] unless errors.key?(:email_to)
|
147
|
-
@errors[:email_to] <<
|
172
|
+
@errors[:email_to] << [
|
173
|
+
:invalid_format,
|
174
|
+
CuentaDigital::Exception::InvalidFormat.new(attr).message
|
175
|
+
]
|
176
|
+
end
|
177
|
+
|
178
|
+
def validate_dates
|
179
|
+
return unless (@first_due_date && @second_due_date) && @second_due_date <= @first_due_date
|
180
|
+
|
181
|
+
@errors[:second_due_date] = [] unless errors.key?(:second_due_date)
|
182
|
+
@errors[:second_due_date] << [
|
183
|
+
:second_due_date_must_be_greater_than_first_due_date,
|
184
|
+
CuentaDigital::Exception::InvalidValueAttribute.new('second due date cant be greater than or equal to first due date').message
|
185
|
+
]
|
186
|
+
end
|
187
|
+
|
188
|
+
def valideate_lengths
|
189
|
+
return if code.size <= 50
|
190
|
+
|
191
|
+
@errors[:code] = [] unless errors.key?(:code)
|
192
|
+
@errors[:code] << [
|
193
|
+
:code_must_be_greater_than_50_characters,
|
194
|
+
CuentaDigital::Exception::InvalidValueAttribute.new('code cant be greater than 50 chars').message
|
195
|
+
]
|
148
196
|
end
|
149
197
|
end
|
150
198
|
end
|
@@ -17,6 +17,7 @@ module CuentaDigital
|
|
17
17
|
:checksum,
|
18
18
|
:operation_event_number,
|
19
19
|
:bar_code,
|
20
|
+
:secret,
|
20
21
|
:csv_line
|
21
22
|
|
22
23
|
def initialize(params = {})
|
@@ -32,6 +33,7 @@ module CuentaDigital
|
|
32
33
|
@checksum = params[:checksum]
|
33
34
|
@bar_code = params[:bar_code]
|
34
35
|
@csv_line = params[:csv_line]
|
36
|
+
@secret = params[:secret]
|
35
37
|
end
|
36
38
|
|
37
39
|
def credit?
|
@@ -42,37 +44,8 @@ module CuentaDigital
|
|
42
44
|
@operation_kind == 0
|
43
45
|
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
# Linea final:
|
48
|
-
# CSV: Valor fijo 3 indicando linea final,Fecha actual,Horario actual,Monto total de creditos en evento,Monto total de debitos en evento,Cantidad de operaciones,Checksum
|
49
|
-
def self.process_webhook(csv)
|
50
|
-
csv_splitted = csv.split("\n")
|
51
|
-
_final_line = csv_splitted.pop
|
52
|
-
|
53
|
-
csv_splitted.map do |result|
|
54
|
-
args = result.split(',')
|
55
|
-
|
56
|
-
params = {
|
57
|
-
csv_line: result,
|
58
|
-
operation_kind: args[0],
|
59
|
-
payment_date: Time.parse(
|
60
|
-
[
|
61
|
-
args[1].insert(2, '-').insert(5, '-'),
|
62
|
-
args[2].insert(2, ':').insert(5, ':')
|
63
|
-
].join(' ')
|
64
|
-
),
|
65
|
-
net_amount: args[3],
|
66
|
-
bar_code: args[4],
|
67
|
-
reference: args[5],
|
68
|
-
payment_method: args[6],
|
69
|
-
operation_id: args[7],
|
70
|
-
checksum: args[8],
|
71
|
-
operation_event_number: args[9]
|
72
|
-
}
|
73
|
-
|
74
|
-
CuentaDigital::Payment.new(params)
|
75
|
-
end
|
47
|
+
def secret_valid?
|
48
|
+
secret.nil? || Digest::SHA256.hexdigest(@secret) == @checksum
|
76
49
|
end
|
77
50
|
|
78
51
|
def self.uri(control:, sandbox: false, date: Time.now, from: nil, to: nil)
|
@@ -111,7 +84,7 @@ module CuentaDigital
|
|
111
84
|
# 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
|
112
85
|
# Ejemplo de una linea del archivo:
|
113
86
|
# 30122008|221500|1000.50|999.50|1.00|cliente9879|PagoFacil|23a0f1c7b636c08660abbe4f02360633-de70dbb3f907c613ddce6566667f92c6|1
|
114
|
-
def self.
|
87
|
+
def self.collector(control:, date: Time.now, from: nil, to: nil, opts: { wget: false, sandbox: false })
|
115
88
|
retries = 0
|
116
89
|
|
117
90
|
uri_request = uri(control: control, sandbox: opts[:sandbox], date: date, from: from, to: to)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CuentaDigital
|
4
|
+
# Linea de operaciones:
|
5
|
+
# CSV: Clase de operacion,Fecha de la operacion,Hora de la operacion,Monto,Codigo de Barras,Referencia,Medio de pago,Codigo unico de operacion,Checksum de operacion,Numero de operacion en evento
|
6
|
+
# Linea final:
|
7
|
+
# CSV: Valor fijo 3 indicando linea final,Fecha actual,Horario actual,Monto total de creditos en evento,Monto total de debitos en evento,Cantidad de operaciones,Checksum
|
8
|
+
|
9
|
+
# El Checksum de la operacion (firma) corresponde a una encriptacion SHA256 concatenando:
|
10
|
+
# - la clase de operacion,
|
11
|
+
# - la fecha de la operacion,
|
12
|
+
# - hora de la operacion,
|
13
|
+
# - Monto,
|
14
|
+
# - Codigo de Barras,
|
15
|
+
# - Referencia,
|
16
|
+
# - Codigo unico de operacion
|
17
|
+
# - clave de seguridad
|
18
|
+
# ash('sha256',ClaseDDMMYYYHHMMSSMontoBarraReferenciaUnicoClave),
|
19
|
+
# su finalidad es la validacion de la operacion.
|
20
|
+
class Webhook
|
21
|
+
def self.process(csv, secret = nil)
|
22
|
+
csv_splitted = csv.split("\n")
|
23
|
+
_final_line = csv_splitted.pop
|
24
|
+
|
25
|
+
csv_splitted.map do |result|
|
26
|
+
args = result.split(',')
|
27
|
+
|
28
|
+
params = {
|
29
|
+
csv_line: result,
|
30
|
+
secret: secret,
|
31
|
+
operation_kind: args[0],
|
32
|
+
payment_date: Time.parse(
|
33
|
+
[
|
34
|
+
args[1].insert(2, '-').insert(5, '-'),
|
35
|
+
args[2].insert(2, ':').insert(5, ':')
|
36
|
+
].join(' ')
|
37
|
+
),
|
38
|
+
net_amount: args[3],
|
39
|
+
bar_code: args[4],
|
40
|
+
reference: args[5],
|
41
|
+
payment_method: args[6],
|
42
|
+
operation_id: args[7],
|
43
|
+
checksum: args[8],
|
44
|
+
operation_event_number: args[9]
|
45
|
+
}
|
46
|
+
|
47
|
+
params[:secret] = if secret
|
48
|
+
[args[0],
|
49
|
+
args[1].delete('-'),
|
50
|
+
args[2].delete(':'),
|
51
|
+
args[3],
|
52
|
+
args[4],
|
53
|
+
args[5],
|
54
|
+
args[7],
|
55
|
+
secret].sum
|
56
|
+
end
|
57
|
+
|
58
|
+
CuentaDigital::Payment.new(params)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/cuenta_digital.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuenta_digital
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ga6ix
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/cuenta_digital/payment.rb
|
104
104
|
- lib/cuenta_digital/response.rb
|
105
105
|
- lib/cuenta_digital/version.rb
|
106
|
+
- lib/cuenta_digital/webhook.rb
|
106
107
|
homepage: https://github.com/gedera/cuenta_digital
|
107
108
|
licenses:
|
108
109
|
- MIT
|