credomatic-payments 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 107083818dcedecd37e506e69402ec0091fd381a
4
+ data.tar.gz: f0cce75be8db234d0627ff06f5aac3f31149a0e1
5
+ SHA512:
6
+ metadata.gz: 59bcf7de59b66a68c217ecbb952270e2996c1566c6e8bf7e8299f876b79d2e21ebdde38523741e937c3950032ef4a6f8ccaa22179976b03a1ccb69106d4b0b52
7
+ data.tar.gz: c9f84a74e280bab70235432b458791bfb1ae9932296f7844abf9892d4e1efcba7d5ea40f265ead0459d17c825e4c3ba5cf752a5284c77024df96b9b6004528fa
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.0
7
+ before_install: gem install bundler -v 1.16.6
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in credomatic-payments.gemspec
6
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ credomatic-payments (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ credomatic-payments!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.2)
33
+
34
+ BUNDLED WITH
35
+ 1.16.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 David Cortes
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.
@@ -0,0 +1,122 @@
1
+ # Credomatic Payments
2
+
3
+ Gema para la conexion al servicio de pagos de Credomatic Costa Rica. Encapsula el endpoint de pagos de Credomatic, y permite crear ventas y autorizaciones.
4
+
5
+ ## Instalación
6
+
7
+ Agregar la siguiente linea en su Gemfile:
8
+
9
+ ```ruby
10
+ gem 'credomatic-payments'
11
+ ```
12
+
13
+ Luego ejecute:
14
+
15
+ $ bundle
16
+
17
+ O instalelo usted mismo:
18
+
19
+ $ gem install credomatic-payments
20
+
21
+ ## Uso
22
+
23
+ Para poder utilizar la geme debe crear una instancia de la clase Transactions, dicha clase se encuentra dentro del modulo Credomatic::Payments
24
+
25
+ ```ruby
26
+ transaction = Transactions.new(KEY_ID, KEY)
27
+ ```
28
+
29
+ Una vez creada la instancia basta con llamar al metodo generate_transaction, con los parametros adecuados para recibir una respuesta por parte del servidor de Credomatic.
30
+
31
+ ```ruby
32
+ transaction.generate_transaction(TRANSACTION_TYPE, REDIRECT_URL, CARD_NUMBER, CARD_EXPERATION, AMOUNT, ORDERID, CVV, ADDRESS, PROCESSOR_ID)
33
+ ```
34
+
35
+ A continuacion se describen cada uno de los parametros:
36
+
37
+ - TRANSACTION_TYPE: tipo de transaccion, actualmente se soportan el tipo "sale" y "auth"
38
+ - REDIRECT_URL: opcional, si utiliza el redirect url, su pagina web debera tener un url que soporte get donde el servidor de credomatic, brindara la respuesta. Si no se pasa un redirect url, se activara el modo api, y el response sera procesado por la gema.
39
+ - CARD_NUMBER: Número de tarjeta.
40
+ - AMOUNT: valor de la venta.
41
+ - ORDERID: valor opcional, es un id que se le quiera dar a la orden.
42
+ - CVV: código de seguridad de la tarjeta.
43
+ - ADDRESS: valor opcional, direccion del dueño de la tarjeta.
44
+ - PROCESSOR_ID: valor opcional, Identificador de la terminal con la cual desea realizar la autorización, credomatic determinará si se debe pasar algun valor en este parámetro.
45
+
46
+ ### Respuesta modo API
47
+
48
+ En caso de no utilizar un redirect url, la gema sera la encargada de procesar la respuesta del servidor, acontinuacion se detalla la respuesta.
49
+
50
+ ```ruby
51
+ response = transaction.generate_transaction(TRANSACTION_TYPE, REDIRECT_URL, CARD_NUMBER, CARD_EXPERATION, AMOUNT, ORDERID, CVV, ADDRESS, PROCESSOR_ID)
52
+ ```
53
+
54
+ La variable response es un hash, con las siguientes llaves:
55
+
56
+ - response
57
+ - responsetext
58
+ - authcode
59
+ - transactionid
60
+ - avsresponse
61
+ - cvvresponse
62
+ - orderid
63
+ - type
64
+ - response_code
65
+
66
+ Basándonos en la documentación de credomatic, los valores de dichas variables se resumen en la siguiente tabla:
67
+
68
+ Response
69
+
70
+ | Codigo | Valor |
71
+ |:------: |:-----------------------------------------------------: |
72
+ | 1 | Transacción Aprobada |
73
+ | 2 | Transacción Denegada |
74
+ | 3 | Error en datos de la transacción o error del sistema. |
75
+
76
+ Response Code
77
+
78
+ | Codigo | Valor |
79
+ |:------: |:-----------------------------------------: |
80
+ | 100 | Transacción Aprobada |
81
+ | 200 | Transacción declinada por el Autorizador. |
82
+ | 300 | Transacción declinada por el Sistema. |
83
+
84
+ CVV Response
85
+
86
+ | Codigo | Valor |
87
+ |:------: |:--------------------------------------------------------------------: |
88
+ | M | CVV2/CVC2 Match |
89
+ | N | CVV2/CVC2 No Match |
90
+ | P | Not Processed |
91
+ | S | Merchant has indicated that CVV2/CVC2 is not present on card |
92
+ | U | Issuer is not certified and/or has not provided Visa encryption keys |
93
+
94
+ AVS Response
95
+
96
+ | Codigo | Valor |
97
+ |:------: |:------------------------------------: |
98
+ | X | Exact match, 9-character numeric ZIP |
99
+ | Y | Exact match, 5-character numeric ZIP |
100
+ | D | " |
101
+ | M | " |
102
+ | A | Address match only |
103
+ | B | " |
104
+ | W | 9-character numeric ZIP match only |
105
+ | Z | 5-character Zip match only |
106
+ | P | " |
107
+ | L | " |
108
+ | N | No address or ZIP match |
109
+ | C | " |
110
+ | U | Address unavailable |
111
+ | G | Non-U.S. Issuer does not participate |
112
+ | I | " |
113
+ | R | Issuer system unavailable |
114
+ | E | Not a mail/phone order |
115
+ | S | Service not supported |
116
+ | 0 | AVS Not Available |
117
+ | O | " |
118
+ | B | " |
119
+
120
+ ## Licencia
121
+
122
+ Esta gema es open source bajo los estatutos de la licencia [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "credomatic/payments"
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__)
@@ -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,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "credomatic/payments/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "credomatic-payments"
8
+ spec.version = Credomatic::Payments::VERSION
9
+ spec.authors = ["David Cortes"]
10
+ spec.email = ["dcortes22@gmail.com"]
11
+
12
+ spec.summary = %q{Manejo de pagos Credomatic Costa Rica}
13
+ spec.description = %q{Realice pagos desde su sitio web con Credomatic Gateway.}
14
+ spec.homepage = "https://github.com/dcortes22/credomatic-payments"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.2"
29
+
30
+ spec.files = `git ls-files`.split("\n")
31
+ end
@@ -0,0 +1,76 @@
1
+ require "credomatic/payments/version"
2
+ require 'digest'
3
+ require "net/http"
4
+ require "uri"
5
+ require "json"
6
+ require 'cgi'
7
+
8
+ module Credomatic
9
+ module Payments
10
+ class Transactions
11
+
12
+ def initialize(key_id, key)
13
+ @key_id = key_id
14
+ @key = key
15
+ @redirect_url = "https://credomatic.compassmerchantsolutions.com/api/transact.php"
16
+ @api_url = "https://credomatic.compassmerchantsolutions.com/api/transact.php"
17
+ end
18
+
19
+ def input_hash(orderid, amount, time)
20
+ value = "#{orderid}|#{'%.2f' % amount}|#{time}|#{@key}"
21
+ Digest::MD5.hexdigest(value)
22
+ end
23
+
24
+ def response_hash(orderid, amount, response, transactionid, avsresponse, cvvresponse, time)
25
+ value = "#{orderid}|#{'%.2f' % amount}|#{response}|#{transactionid}|#{avsresponse}|#{cvvresponse}|#{time}|#{@key}"
26
+ Digest::MD5.hexdigest(value)
27
+ end
28
+
29
+
30
+ def generate_transaction(type, redirect_url, ccnumber, ccexp, amount, orderid, cvv, avs, processor_id)
31
+ @time = Time.now.getutc.to_i
32
+ if type == "sale"
33
+ @input_hash = input_hash("", amount, @time)
34
+ else
35
+ @input_hash = input_hash(orderid, amount, @time)
36
+ end
37
+
38
+ if redirect_url == nil
39
+ uri = URI(@api_url)
40
+ params = {
41
+ type: type,
42
+ key_id: @key_id,
43
+ hash: @input_hash,
44
+ time: @time,
45
+ ccnumber: ccnumber,
46
+ ccexp: ccexp,
47
+ amount: "#{'%.2f' % amount}",
48
+ orderid: orderid,
49
+ cvv: cvv,
50
+ avs: avs,
51
+ processor_id: processor_id
52
+ }
53
+ response = Net::HTTP.post_form( uri, params )
54
+
55
+ if( response.is_a?( Net::HTTPSuccess ) )
56
+ # your request was successful
57
+ responseValue = CGI::parse(response.body)
58
+ responseValue = responseValue.each { |key, value| responseValue[key] = value.first}
59
+ responseValue
60
+ else
61
+ # your request failed
62
+ responseValue = CGI::parse(response.body)
63
+ responseValue = responseValue.each { |key, value| responseValue[key] = value.first}
64
+ responseValue
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ def key_id
71
+ @key_id
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ module Credomatic
2
+ module Payments
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ RSpec.describe Credomatic::Payments do
2
+ it "has a version number" do
3
+ expect(Credomatic::Payments::VERSION).not_to be nil
4
+ end
5
+
6
+ it "initializes a transaction with a key id" do
7
+ transaction = Credomatic::Payments::Transactions.new(123, 23232332222222222222222222222222)
8
+ expect(transaction.key_id).to eq(123)
9
+ end
10
+
11
+ it "generates a correct input hash" do
12
+ transaction = Credomatic::Payments::Transactions.new(123, 23232332222222222222222222222222)
13
+
14
+ orderid = "test"
15
+ amount = 1.00
16
+ time = 1279302634
17
+
18
+ expect(transaction.input_hash(orderid, amount, time)).to eq("416ed27036d4276a267818c530527acf")
19
+ end
20
+
21
+ it "generates a correct response hash" do
22
+ transaction = Credomatic::Payments::Transactions.new(123, 23232332222222222222222222222222)
23
+
24
+ orderid = "test"
25
+ amount= 1.00
26
+ response=1
27
+ transactionid = 273247169
28
+ avsresponse="N"
29
+ cvvresponse="N"
30
+ time = 1279302634
31
+
32
+ expect(transaction.response_hash(orderid, amount, response, transactionid, avsresponse, cvvresponse, time)).to eq("2f4f1c087cfd908903647823064da9bc")
33
+ end
34
+
35
+ it "generates a sale but declined by system" do
36
+ transaction = Credomatic::Payments::Transactions.new(123, 23232332222222222222222222222222)
37
+ response = transaction.generate_transaction("sale", nil, "4012001011000771", 1022, 1.00, "", 4223, "Desamparados", "")
38
+ expect(response["response_code"]).to eq("200")
39
+ end
40
+
41
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "credomatic/payments"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: credomatic-payments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Cortes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: Realice pagos desde su sitio web con Credomatic Gateway.
56
+ email:
57
+ - dcortes22@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - credomatic-payments.gemspec
73
+ - lib/credomatic/payments.rb
74
+ - lib/credomatic/payments/version.rb
75
+ - spec/credomatic/payments_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: https://github.com/dcortes22/credomatic-payments
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.6.10
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Manejo de pagos Credomatic Costa Rica
101
+ test_files: []