cuenta_digital 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a0c2487585c5747ffe39b8b0daef1b42fc1974117ea7f1e37c82cca281dd2d2f
4
+ data.tar.gz: 195b851af758e3c583ff56d859f37473107fc177cfdf49159f0027bf1f632207
5
+ SHA512:
6
+ metadata.gz: c68001731a9fe709488640e21fc300918e2b1588c316651753b4076f158f7a8aa5c3a31de4ecea51191fc50c6a3054fcd826a88d3d2d1c9d8a2ffae47427260b
7
+ data.tar.gz: 7f8cdc540d32f962747c38a8634b8175ab14bf4c3e51eade1b0842381d6b128ba3e4dd6ed715a5a033729a42479aeb7891c04f7cbe5702930c2419562fccf015
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.1
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at gab.edera@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cuenta_digital.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 ga6ix
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # CuentaDigital
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cuenta_digital`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cuenta_digital'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cuenta_digital
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gedera/cuenta_digital. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the CuentaDigital project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gedera/cuenta_digital/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cuenta_digital"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "cuenta_digital/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "cuenta_digital"
7
+ spec.version = CuentaDigital::VERSION
8
+ spec.authors = ["ga6ix"]
9
+ spec.email = ["gab.edera@gmail.com"]
10
+
11
+ spec.summary = %q{Cuenta Digital API.}
12
+ spec.description = %q{Cuenta Digital API gem.}
13
+ spec.homepage = "https://github.com/gedera/cuenta_digital"
14
+ spec.license = "MIT"
15
+
16
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
+
18
+ # spec.metadata["homepage_uri"] = spec.homepage
19
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency 'nokogiri', '~> 1.10'
32
+ spec.add_dependency 'nori', '~> 2.6'
33
+
34
+ spec.add_development_dependency "bundler", "~> 2.0"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "minitest", "~> 5.0"
37
+ end
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CuentaDigital
4
+ class Coupon
5
+ ATTRIBUTES_PRECENSE = %i[id price first_due_date code concept currency].freeze
6
+
7
+ attr_accessor :id, # Su numero de CuentaDigital
8
+ :site,
9
+ :price, # El monto a cobrar (Debe de incluir 2 cifras adicionales que indicaran los centavos)
10
+ :first_due_date, # Dias desde la fecha actual hasta el vencimiento del cupon
11
+ :code, # Codigo para referencia del pago para integracion con sus sistemas, referencia del vendedor. (La referencia no puede superar el maximo de 50 caracteres alfanumericos)
12
+ :email_from, # Envio del cupon desde el email ingresado
13
+ :email_to, # Envio del cupon hacia el email ingresado
14
+ :concept, # Concepto de la venta que aparecera en el cupon
15
+ :currency, # La moneda base en codigo ISO en mayusculas en la cual el sistema se basara para calcular el precio correcto, dejandolo vacio la base es ARS (Pesos Argentinos), ejemplos: ARS,CLP,RBL,MXN,USD,EUR
16
+ :hash, # Hash opcional para control de generacion de cupones
17
+ :price_second_due_date, # El segundo monto a cobrar luego del primer vencimiento (Debe de incluir 2 cifras adicionales que indicaran los centavos)
18
+ :second_due_date, # Cantidad de dias al segundo vencimiento
19
+ :m0, # 1: Habilita todos los medios disponibles, 0: sin usar para deshabilitar. Default: '0'
20
+ :m2, # 1: Habilita Tarjetas de Credito, 0: sin usar para deshabilitar. Default: '0'
21
+ :m4, # 1: Para mantener habilitado medios en efectivo y Link, 0: Deshabilita Medios en Efectivo y Link. Default '1'.
22
+ :errors,
23
+ :response_code,
24
+ :response_body
25
+
26
+ def initialize(params = {})
27
+ @id = params[:id]
28
+ @price = params[:price]
29
+ @site = params[:site]
30
+ @first_due_date = params[:first_due_date]
31
+ @code = params[:code]
32
+ @email_from = params[:email_from].nil? || params[:email_from].empty? ? nil : params[:email_from]
33
+ @email_to = params[:email_to].nil? || params[:email_to].empty? ? nil : params[:email_to]
34
+ @concept = params[:concept]
35
+ @currency = params[:currency] ? params[:currency].to_sym : nil
36
+ @hash = Digest::MD5.hexdigest(params[:key_hash]) if params[:key_hash]
37
+ @price_second_due_date = params[:price_second_due_date]
38
+ @second_due_date = params[:second_due_date]
39
+ @m0 = params[:m0] || 0
40
+ @m2 = params[:m2] || 0
41
+ @m4 = params[:m4] || 1
42
+ @errors = {}
43
+ end
44
+
45
+ def params
46
+ attr_params = { id: @id,
47
+ precio: @price,
48
+ site: @site,
49
+ venc: @first_due_date,
50
+ codigo: @code,
51
+ concepto: @concept.to_sym,
52
+ moneda: CuentaDigital::CURRENCIES[@currency],
53
+ m0: @m0,
54
+ m2: @m2,
55
+ m4: @m4,
56
+ desde: @email_from,
57
+ hacia: @email_to,
58
+ precio2: @price_second_due_date,
59
+ vence2: @second_due_date,
60
+ hash: @hash }
61
+
62
+ attr_params.delete_if { |k, v| v.nil? }
63
+ end
64
+
65
+ def uri(xml: true)
66
+ uri_params = params
67
+ uri_params[:xml] = 1 if xml
68
+
69
+ uri_request = CuentaDigital.uri_coupon_generation
70
+
71
+ uri_request.query = URI.encode_www_form(uri_params.to_a)
72
+
73
+ uri_request
74
+ end
75
+
76
+ def generate(xml: true, wget: false)
77
+ retries = 0
78
+ begin
79
+ if wget
80
+ @response_code = '200'
81
+ @response_body = `wget -O- "#{uri(xml: xml).to_s}"`
82
+ else
83
+ partial_response = Net::HTTP.get_response(uri(xml: xml))
84
+ @response_code = partial_response.code
85
+ @response_body = partial_response.body
86
+ end
87
+ rescue => e
88
+ if retries < 3
89
+ retries += 1
90
+ retry
91
+ end
92
+ raise e
93
+ end
94
+ end
95
+
96
+ def response
97
+ @response = CuentaDigital::Response.new(@response_body)
98
+ end
99
+
100
+ def generated?
101
+ response.invoice_generated?
102
+ end
103
+
104
+ def valid?
105
+ validate!
106
+ errors.empty?
107
+ end
108
+
109
+ private
110
+
111
+ def validate!
112
+ @errors = {}
113
+ validate_attributes_presence
114
+ validate_standar_values
115
+ validate_format_values
116
+ end
117
+
118
+ def validate_attributes_presence
119
+ missing_attributes = []
120
+ ATTRIBUTES_PRECENSE.each do |attr|
121
+ missing_attributes << attr if send(attr).nil?
122
+ end
123
+
124
+ missing_attributes.uniq.each do |attr|
125
+ @errors[attr.to_sym] = [] unless errors.key?(attr)
126
+ @errors[attr.to_sym] << CuentaDigital::Exception::MissingAttributes.new(attr).message
127
+ end
128
+ end
129
+
130
+ def validate_standar_values
131
+ return if CuentaDigital::CURRENCIES.keys.include?(@currency)
132
+
133
+ @errors[:currency] = [] unless errors.key?(:currency)
134
+
135
+ @errors[:currency] << CuentaDigital::Exception::InvalidValueAttribute.new("currency, Possible values #{CuentaDigital::CURRENCIES.keys}").message
136
+ end
137
+
138
+ def validate_format_values
139
+ return if @email_to.nil? || !@email_to.match(CuentaDigital::VALID_EMAIL_REGEX).nil?
140
+
141
+ @errors[:email_to] = [] unless errors.key?(:email_to)
142
+ @errors[:email_to] << CuentaDigital::Exception::InvalidFormat.new(attr).message
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,33 @@
1
+ module CuentaDigital
2
+ module Exception
3
+ class Exception < ::StandardError
4
+ attr_accessor :backtrace
5
+
6
+ def initialize(msg, backtrace)
7
+ @backtrace = backtrace
8
+ super(msg)
9
+ end
10
+ end
11
+
12
+ class MissingAttributes < Exception
13
+ def initialize(attributes, backtrace = nil)
14
+ @backtrace = backtrace
15
+ super("Missing attributes: #{attributes}", backtrace)
16
+ end
17
+ end
18
+
19
+ class InvalidValueAttribute < Exception
20
+ def initialize(attribute, backtrace = nil)
21
+ @backtrace = backtrace
22
+ super("Invalid value for: #{attribute}", backtrace)
23
+ end
24
+ end
25
+
26
+ class InvalidFormat < Exception
27
+ def initialize(attribute, backtrace = nil)
28
+ @backtrace = backtrace
29
+ super("Invalid format for: #{attribute}", backtrace)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CuentaDigital
4
+ # Codigo de operacion: 1: credito (ingreso de fondos,recaudaciones), 2: debito (retiros, pagos a terceros, pago de servicios, contracargos,etc)
5
+ # 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.
6
+
7
+ class Payment
8
+ attr_accessor :operation_kind,
9
+ :payment_date,
10
+ :gross_amount,
11
+ :net_amount,
12
+ :commission,
13
+ :reference,
14
+ :payment_method,
15
+ :operation_id,
16
+ :payment_number,
17
+ :checksum,
18
+ :operation_event_number,
19
+ :bar_code
20
+
21
+ def initialize(params = {})
22
+ @operation_id = params[:operation_id]
23
+ @operation_kind = params[:operation_kind]
24
+ @payment_date = params[:payment_date]
25
+ @gross_amount = params[:gross_amount]
26
+ @net_amount = params[:net_amount]
27
+ @commission = params[:commission]
28
+ @reference = params[:reference]
29
+ @payment_method = params[:payment_method]
30
+ @payment_number = params[:payment_number]
31
+ @checksum = params[:checksum]
32
+ @bar_code = params[:bar_code]
33
+ end
34
+
35
+ # Linea de operaciones:
36
+ # 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
37
+ # Linea final:
38
+ # 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
39
+ def self.process_webhook(csv)
40
+ csv_splitted = csv.split("\n")
41
+ _final_line = csv_splitted.pop
42
+
43
+ csv_splitted.map do |result|
44
+ args = result.split(',')
45
+
46
+ params = {
47
+ operation_kind: args[0],
48
+ payment_date: Time.parse(
49
+ [
50
+ args[1].insert(2, '-').insert(5, '-'),
51
+ args[2].insert(2, ':').insert(5, ':')
52
+ ].join(' ')
53
+ ),
54
+ net_amount: args[3],
55
+ bar_code: args[4],
56
+ reference: args[5],
57
+ payment_method: args[6],
58
+ operation_id: args[7],
59
+ checksum: args[8],
60
+ operation_event_number: args[9]
61
+ }
62
+
63
+ CuentaDigital::Payment.new(params)
64
+ end
65
+ end
66
+
67
+ def self.uri(control:, sandbox: false, date: Time.now, from: nil, to: nil)
68
+ uri_request = if sandbox
69
+ CuentaDigital.sandbox_uri_payment_export
70
+ else
71
+ CuentaDigital.uri_payment_export
72
+ end
73
+
74
+ from = {
75
+ hour: (from.nil? ? '00' : from.strftime('%H')),
76
+ min: (from.nil? ? '00' : from.strftime('%M'))
77
+ }
78
+
79
+ to = {
80
+ hour: (to.nil? ? '23' : to.strftime('%H')),
81
+ min: (to.nil? ? '59' : to.strftime('%M'))
82
+ }
83
+
84
+ uri_params = {
85
+ control: control,
86
+ fecha: date.strftime('%Y%m%d'),
87
+ hour1: from[:hour],
88
+ min1: from[:min],
89
+ hour2: to[:hour],
90
+ min2: to[:min]
91
+ }
92
+
93
+ uri_request.query = URI.encode_www_form(uri_params.to_a)
94
+
95
+ uri_request
96
+ end
97
+
98
+ # only get transactions completed
99
+ # Explicacion de la estructura
100
+ # 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
101
+ # Ejemplo de una linea del archivo:
102
+ # 30122008|221500|1000.50|999.50|1.00|cliente9879|PagoFacil|23a0f1c7b636c08660abbe4f02360633-de70dbb3f907c613ddce6566667f92c6|1
103
+ def self.request(control:, date: Time.now, from: nil, to: nil, opts: { wget: false, sandbox: false })
104
+ retries = 0
105
+
106
+ uri_request = uri(control: control, sandbox: opts[:sandbox], date: date, from: from, to: to)
107
+
108
+ begin
109
+ results = if opts[:wget]
110
+ `wget -O- "#{uri_request.to_s}"`
111
+ else
112
+ partial_response = Net::HTTP.get_response(uri_request)
113
+
114
+ if partial_response.code == '200'
115
+ partial_response.body
116
+ else
117
+ raise StandardError, partial_response.body
118
+ end
119
+ end
120
+ rescue SocketError => e
121
+ if retries < 3
122
+ retries += 1
123
+ retry
124
+ end
125
+ raise e
126
+ end
127
+
128
+ results.split("\n").map do |result|
129
+ puts result
130
+ args = result.split('|')
131
+
132
+ params = {
133
+ operation_kind: 1, # Credit
134
+ payment_date: Time.parse(
135
+ [
136
+ args[0].insert(2, '-').insert(5, '-'),
137
+ args[1].insert(2, ':').insert(5, ':')
138
+ ].join(' ')
139
+ ),
140
+ gross_amount: args[2],
141
+ net_amount: args[3],
142
+ commission: args[4],
143
+ reference: args[5],
144
+ payment_method: args[6],
145
+ operation_id: args[7],
146
+ payment_number: args[8]
147
+ }
148
+
149
+ CuentaDigital::Payment.new(params)
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CuentaDigital
4
+ class Response
5
+ attr_accessor :request,
6
+ :action,
7
+ :merchant_id, # Su numero de CuentaDigital
8
+ :ipaddress, # IP del cliente
9
+ :payment_code_1, # Numero de codigo de barras
10
+ :payment_code_2, # Codigo de pago para la red LinkPagos.
11
+ :payment_code_3, # Campo reservado para futuros codigos de pago
12
+ :payment_code_4, # Campo reservado para futuros codigos de pago
13
+ :payment_code_5, # Campo reservado para futuros codigos de pago
14
+ :payment_code_6, # Campo reservado para futuros codigos de pago
15
+ :payment_code_7, # Campo reservado para futuros codigos de pago
16
+ :payment_code_8, # Campo reservado para futuros codigos de pago
17
+ :payment_code_9, # Campo reservado para futuros codigos de pago
18
+ :payment_code_10, # Campo reservado para futuros codigos de pago
19
+ :barcode_image, # URL de la imagen del codigo de barras
20
+ :barcode_base_64, # La imagen del codigo de barras codificada en base24
21
+ :invoice_url, # URL donde se encuentra el cupon de pago
22
+ :site, # Su Website
23
+ :merchant_reference, # Su referencia de pago
24
+ :concept, # Concepto de compra
25
+ :curr, # Moneda
26
+ :amount, # Monto a pagar (ultimas 2 cifras son decimales, ejemplo: $100.50 son 10050, 100.00 son 10000
27
+ :second_amount, # Monto luego del primer vencimiento
28
+ :date, # Fecha de generacion
29
+ :due_date, # Fecha de vencimiento
30
+ :second_due_date, # Segunda fecha de vencimiento
31
+ :email_to, # Enviado hacia un email.
32
+ :country, # Pais (codigos iso)
33
+ :lang, # Idioma (codigos iso)
34
+ :error,
35
+ :exception
36
+
37
+ def initialize(params)
38
+ parser = Nori.new(convert_tags_to: proc { |tag| tag.snakecase.to_sym })
39
+ @request = parser.parse(params)[:request]
40
+ @action = @request[:action].gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr('-', '_').downcase.to_sym
41
+ @merchant_id = @request[:invoice][:merchantid]
42
+ @ipaddress = @request[:invoice][:ipaddress]
43
+ @payment_code_1 = @request[:invoice][:paymentcode1]
44
+ @payment_code_2 = @request[:invoice][:paymentcode2]
45
+ @payment_code_3 = @request[:invoice][:paymentcode3]
46
+ @payment_code_4 = @request[:invoice][:paymentcode4]
47
+ @payment_code_5 = @request[:invoice][:paymentcode5]
48
+ @payment_code_6 = @request[:invoice][:paymentcode6]
49
+ @payment_code_7 = @request[:invoice][:paymentcode7]
50
+ @payment_code_8 = @request[:invoice][:paymentcode8]
51
+ @payment_code_9 = @request[:invoice][:paymentcode9]
52
+ @payment_code_10 = @request[:invoice][:paymentcode10]
53
+ @barcode_image = @request[:invoice][:barcodeimage]
54
+ @barcode_base_64 = @request[:invoice][:barcodebase64]
55
+ @invoice_url = @request[:invoice][:invoiceurl]
56
+ @site = @request[:invoice][:site]
57
+ @merchant_reference = @request[:invoice][:merchantreference]
58
+ @concept = @request[:invoice][:concept]
59
+ @curr = @request[:invoice][:curr]
60
+ @amount = @request[:invoice][:amount]
61
+ @secondamount = @request[:invoice][:secondamount]
62
+ @date = @request[:invoice][:date]
63
+ @due_date = Time.parse(@request[:invoice][:duedate]) rescue nil
64
+ @second_due_date = Time.parse(@request[:invoice][:secondduedate]) rescue nil
65
+ @email_to = @request[:invoice][:emailto]
66
+ @country = @request[:invoice][:country]
67
+ @lang = @request[:invoice][:lang]
68
+ rescue => e
69
+ @exception = e
70
+ @error = params
71
+ @action = :error unless @action == :invoice_generated
72
+ end
73
+
74
+ def invoice_generated?
75
+ @action == :invoice_generated
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module CuentaDigital
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cuenta_digital/version'
4
+ require 'cuenta_digital/coupon'
5
+ require 'cuenta_digital/response'
6
+ require 'cuenta_digital/payment'
7
+ require 'cuenta_digital/exception'
8
+
9
+ require 'digest'
10
+ require 'net/http'
11
+ require 'uri'
12
+ require 'nokogiri'
13
+ require 'nori'
14
+
15
+ module CuentaDigital
16
+ class Error < StandardError; end
17
+
18
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
19
+
20
+ CURRENCIES = { ars: 'ARS',
21
+ clp: 'CLP',
22
+ rbl: 'RBL',
23
+ mxn: 'MXN',
24
+ usd: 'USD',
25
+ eur: 'EUR' }.freeze
26
+
27
+ URL = 'https://www.cuentadigital.com'
28
+ CUOPON_GENERATION_URL = [URL, 'api.php'].join('/').freeze
29
+ URL_EXP_SANDBOX = [URL, 'exportacionsandbox.php'].join('/').freeze
30
+ URL_EXP_PRODUCTION = [URL, 'exportacion.php'].join('/').freeze
31
+
32
+ def self.uri_coupon_generation
33
+ URI.parse(CUOPON_GENERATION_URL)
34
+ end
35
+
36
+ def self.sandbox_uri_payment_export
37
+ URI.parse(URL_EXP_SANDBOX)
38
+ end
39
+
40
+ def self.uri_payment_export
41
+ URI.parse(URL_EXP_PRODUCTION)
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuenta_digital
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ga6ix
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nori
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Cuenta Digital API gem.
84
+ email:
85
+ - gab.edera@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - cuenta_digital.gemspec
100
+ - lib/cuenta_digital.rb
101
+ - lib/cuenta_digital/coupon.rb
102
+ - lib/cuenta_digital/exception.rb
103
+ - lib/cuenta_digital/payment.rb
104
+ - lib/cuenta_digital/response.rb
105
+ - lib/cuenta_digital/version.rb
106
+ homepage: https://github.com/gedera/cuenta_digital
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.0.4
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Cuenta Digital API.
129
+ test_files: []