banorte_payworks 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +5 -1
- data/banorte_payworks.gemspec +12 -10
- data/lib/banorte_payworks.rb +4 -0
- data/lib/banorte_payworks/banorte_transaction.rb +48 -0
- data/lib/banorte_payworks/simple_tpv.rb +51 -77
- data/lib/banorte_payworks/version.rb +1 -1
- data/spec/banorte_payworks_simpletpv_spec.rb +17 -7
- data/spec/spec_helper.rb +2 -1
- metadata +28 -26
- data/spec/banorte_payworks_spec.rb +0 -5
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6f87eeddc4388c2138183fa961ddabfb7a8ca12a
|
4
|
+
data.tar.gz: ed6a7b90600cafd5f082fb7b617b07948cfbee01
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72cea3f7058949899ba5bdc18e7e940b44f999337e5ea5c9c85896eedc2d4da1af07edf0adaa3f811675b6d7db51e68eb4983b920c75ed0a551f68ef3657d7ee
|
7
|
+
data.tar.gz: 4fb22db5b147bc1c9747554b75f2567524fcfa6ec2632d21734e64d340ba12415baf494045da000e81a9a52de5642063e8ee976237230db5a89d4b8d9797063d
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
banorte_payworks (0.9.
|
4
|
+
banorte_payworks (0.9.4)
|
5
|
+
faraday
|
5
6
|
httpclient (>= 2.3.3)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
11
|
diff-lcs (1.2.4)
|
12
|
+
faraday (0.8.7)
|
13
|
+
multipart-post (~> 1.1)
|
11
14
|
httpclient (2.3.3)
|
15
|
+
multipart-post (1.2.0)
|
12
16
|
rake (10.1.0)
|
13
17
|
rspec (2.13.0)
|
14
18
|
rspec-core (~> 2.13.0)
|
data/banorte_payworks.gemspec
CHANGED
@@ -5,23 +5,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require 'banorte_payworks/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'banorte_payworks'
|
9
9
|
spec.version = BanortePayworks::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email =
|
10
|
+
spec.authors = ['Jonathan Garay']
|
11
|
+
spec.email = %w(jonathan@devmask.net)
|
12
12
|
spec.description = %q{Simple TPV for Banorte Payworks Mexican Gateway}
|
13
13
|
spec.summary = %q{Simple TPV implementation for Banorte Payworks}
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = 'http://devmask.net/banorte_payworks/'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files`.split($/)
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
-
spec.require_paths =
|
20
|
+
spec.require_paths = %w(lib)
|
21
21
|
|
22
|
-
spec.add_dependency
|
22
|
+
spec.add_dependency 'httpclient', '>= 2.3.3'
|
23
|
+
spec.add_dependency 'faraday'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rspec'
|
23
28
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
27
29
|
end
|
data/lib/banorte_payworks.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
class BanorteTransaction
|
2
|
+
attr_accessor :error_code, :message, :authnum, :order_id, :amount,
|
3
|
+
:card_number, :cvv, :exp_date, :_original_post,
|
4
|
+
:e, :time_in, :time_out, :card_type, :issuing_bank,
|
5
|
+
:transaction_type, :transaction_status
|
6
|
+
|
7
|
+
def self.from_post(post)
|
8
|
+
#TODO this big huge method needs to be abstracted to an a class and we need to cas the proper primitive types
|
9
|
+
parsed_post = CGI::parse(post)
|
10
|
+
create_with_properties self do |transaction|
|
11
|
+
transaction._original_post = post
|
12
|
+
transaction.error_code = parsed_post['CcErrCode'][0]
|
13
|
+
transaction.message = parsed_post['Text'][0]
|
14
|
+
transaction.authnum = parsed_post['AuthCode'][0]
|
15
|
+
transaction.order_id = parsed_post['OrderId'][0]
|
16
|
+
transaction.amount = parsed_post['Total'][0]
|
17
|
+
transaction.time_in = parsed_post['TimeIn'][0]
|
18
|
+
transaction.time_out = parsed_post['TimeOut'][0]
|
19
|
+
|
20
|
+
transaction.e = [parsed_post['E1'][0],
|
21
|
+
parsed_post['E2'][0],
|
22
|
+
parsed_post['E3'][0]]
|
23
|
+
|
24
|
+
transaction.card_type = parsed_post['CardType'][0]
|
25
|
+
transaction.issuing_bank = parsed_post['IssuingBank'][0]
|
26
|
+
transaction.transaction_type = parsed_post['TransType'][0]
|
27
|
+
transaction.transaction_status = parsed_post['TransStat'][0]
|
28
|
+
|
29
|
+
transaction.card_number = parsed_post['Number'][0]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def valid?
|
34
|
+
error_code.eql? '1'
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate!
|
38
|
+
raise BpayworksException.new("Error::#{error_code}: #{message}") unless valid?
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def self.create_with_properties(clazz, &block)
|
43
|
+
instance = clazz.new
|
44
|
+
yield instance
|
45
|
+
instance
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -1,85 +1,70 @@
|
|
1
|
-
|
1
|
+
require 'httpclient'
|
2
|
+
require 'cgi'
|
2
3
|
|
3
|
-
|
4
|
+
module BanortePayworks
|
4
5
|
|
5
|
-
PAYWORKS_URL =
|
6
|
-
PAYWORKS_3DS_URL =
|
6
|
+
PAYWORKS_URL = 'https://eps.banorte.com/recibo'
|
7
|
+
PAYWORKS_3DS_URL = 'https://eps.banorte.com/secure3d/Solucion3DSecure.htm'
|
7
8
|
|
8
9
|
MODE = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
production: 'P',
|
11
|
+
reject: 'R',
|
12
|
+
accept: 'Y',
|
13
|
+
random: 'R'
|
13
14
|
}
|
14
15
|
|
15
16
|
TYPE = {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
auth: 'Auth',
|
18
|
+
pre_auth: 'PreAuth',
|
19
|
+
post_auth: 'PostAuth',
|
20
|
+
void: 'Void',
|
21
|
+
credit: 'Credit',
|
22
|
+
force_insert_auth: 'ForceInsertAuth',
|
23
|
+
verify: 'Verify'
|
23
24
|
}
|
24
25
|
|
25
|
-
|
26
|
-
class BpayworksException < Exception
|
27
|
-
end
|
28
|
-
|
29
|
-
class BanorteTransaction
|
30
|
-
require 'cgi'
|
31
|
-
|
32
|
-
attr_accessor :error_code, :message, :authnum, :order_id, :amount, :card_number, :cvv, :exp_date
|
33
|
-
|
34
|
-
|
35
|
-
def self.from_post(post)
|
36
|
-
parsed_post = CGI::parse(post)
|
37
|
-
protocol = BanorteTransaction.new
|
38
|
-
protocol.error_code = parsed_post['CcErrCode'][0]
|
39
|
-
protocol.message = parsed_post['Text'][0]
|
40
|
-
protocol.authnum = parsed_post['AuthCode'][0]
|
41
|
-
protocol.order_id = parsed_post['OrderId'][0]
|
42
|
-
protocol.amount = parsed_post['Total'][0]
|
43
|
-
protocol.card_number = parsed_post['Number'][0]
|
44
|
-
protocol
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
26
|
class SimpleTPV
|
27
|
+
attr_accessor :config
|
51
28
|
|
52
|
-
def initialize(config={})
|
53
|
-
|
29
|
+
def initialize(config = {})
|
30
|
+
self.config = config
|
54
31
|
end
|
55
32
|
|
56
|
-
#Simple call to payment
|
57
33
|
def do_payment(order_id, card_number, exp_date, cvv, amount)
|
58
|
-
do_transaction :
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
34
|
+
do_transaction card_number: card_number,
|
35
|
+
exp_date: exp_date,
|
36
|
+
cvv: cvv,
|
37
|
+
amount: amount,
|
38
|
+
order_id: order_id,
|
39
|
+
response_path: 'http://sample.net/',
|
40
|
+
type: BanortePayworks::TYPE[:auth]
|
65
41
|
end
|
66
42
|
|
67
43
|
def void(transaction)
|
68
|
-
|
69
|
-
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:type => BanortePayworks::TYPE[:void]
|
44
|
+
do_transaction order_id: transaction.order_id,
|
45
|
+
amount: transaction.amount,
|
46
|
+
authnum: transaction.authnum,
|
47
|
+
card_number: transaction.card_number,
|
48
|
+
exp_date: transaction.exp_date,
|
49
|
+
cvv: transaction.cvv,
|
50
|
+
response_path: 'http://sample.net/',
|
51
|
+
type: BanortePayworks::TYPE[:void]
|
77
52
|
|
78
53
|
end
|
79
54
|
|
80
55
|
def do_transaction(properties = {})
|
56
|
+
return_eval BanorteTransaction.from_post payworks_request(properties).first do |protocol|
|
57
|
+
protocol.card_number = properties[:card_number]
|
58
|
+
protocol.cvv = properties[:cvv]
|
59
|
+
protocol.exp_date = properties[:exp_date]
|
60
|
+
protocol.validate!
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
81
65
|
|
82
|
-
|
66
|
+
def payworks_request(properties)
|
67
|
+
HTTPClient.new.post(PAYWORKS_URL, {
|
83
68
|
'Name' => @config[:username],
|
84
69
|
'Password' => @config[:password],
|
85
70
|
'ClientId' => @config[:client_id],
|
@@ -93,26 +78,15 @@ module BanortePayworks
|
|
93
78
|
'ResponsePath' => properties[:response_path],
|
94
79
|
'OrderId' => properties[:order_id],
|
95
80
|
'AuthCode' => properties[:authnum].to_s
|
81
|
+
}).header['Location']
|
82
|
+
end
|
96
83
|
|
97
|
-
|
98
|
-
|
99
|
-
puts location.inspect if properties[:verbose]
|
100
|
-
|
101
|
-
protocol = BanorteTransaction.from_post location
|
102
|
-
|
103
|
-
#hack ?
|
104
|
-
protocol.card_number = properties[:card_number]
|
105
|
-
protocol.cvv = properties[:cvv]
|
106
|
-
protocol.exp_date = properties[:exp_date]
|
107
|
-
|
108
|
-
if protocol.error_code != '1'
|
109
|
-
raise BpayworksException.new("Error::#{protocol.error_code}: #{protocol.message}")
|
110
|
-
else
|
111
|
-
protocol
|
112
|
-
end
|
84
|
+
private
|
113
85
|
|
86
|
+
def return_eval(object, &block)
|
87
|
+
yield object
|
88
|
+
object
|
114
89
|
end
|
115
|
-
|
116
90
|
end
|
117
91
|
|
118
92
|
end
|
@@ -1,14 +1,24 @@
|
|
1
1
|
require 'banorte_payworks'
|
2
2
|
|
3
3
|
describe BanortePayworks::SimpleTPV do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
describe '#transaction' do
|
5
|
+
let(:credit_card_number){ 4916098986962263 }
|
6
|
+
let(:expiration_date){ '12/14' }
|
7
|
+
let(:cvv){ 123 }
|
8
|
+
let(:amount){ 1.0 }
|
9
|
+
let(:order_id){ rand(10000) }
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
let(:tpv) do
|
12
|
+
BanortePayworks::SimpleTPV.new :username => 'tienda19',
|
13
|
+
:password => '2006',
|
14
|
+
:client_id=>'19',
|
15
|
+
:mode=>BanortePayworks::MODE[:accept]
|
16
|
+
end
|
12
17
|
|
18
|
+
let(:result){tpv.do_payment(rand(100000), credit_card_number, expiration_date, '123', 1.0)}
|
19
|
+
|
20
|
+
it{ expect(result.valid?).to be_true }
|
21
|
+
it{ expect(result.card_number).to_not be_nil }
|
22
|
+
it{ expect(tpv.void(result).valid?).to be_true }
|
13
23
|
end
|
14
24
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
3
4
|
require 'rspec'
|
4
5
|
require 'banorte_payworks'
|
5
6
|
|
@@ -8,5 +9,5 @@ require 'banorte_payworks'
|
|
8
9
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
10
|
|
10
11
|
RSpec.configure do |config|
|
11
|
-
|
12
|
+
|
12
13
|
end
|
metadata
CHANGED
@@ -1,36 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banorte_payworks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jonathan Garay
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: httpclient
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 2.3.3
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 2.3.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
42
|
name: bundler
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
45
|
- - ~>
|
36
46
|
- !ruby/object:Gem::Version
|
@@ -38,7 +48,6 @@ dependencies:
|
|
38
48
|
type: :development
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
52
|
- - ~>
|
44
53
|
- !ruby/object:Gem::Version
|
@@ -46,33 +55,29 @@ dependencies:
|
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: rake
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - '>='
|
52
60
|
- !ruby/object:Gem::Version
|
53
61
|
version: '0'
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
|
-
- -
|
66
|
+
- - '>='
|
60
67
|
- !ruby/object:Gem::Version
|
61
68
|
version: '0'
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
70
|
name: rspec
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
|
-
- -
|
73
|
+
- - '>='
|
68
74
|
- !ruby/object:Gem::Version
|
69
75
|
version: '0'
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
79
|
requirements:
|
75
|
-
- -
|
80
|
+
- - '>='
|
76
81
|
- !ruby/object:Gem::Version
|
77
82
|
version: '0'
|
78
83
|
description: Simple TPV for Banorte Payworks Mexican Gateway
|
@@ -92,38 +97,35 @@ files:
|
|
92
97
|
- VERSION
|
93
98
|
- banorte_payworks.gemspec
|
94
99
|
- lib/banorte_payworks.rb
|
100
|
+
- lib/banorte_payworks/banorte_transaction.rb
|
95
101
|
- lib/banorte_payworks/simple_tpv.rb
|
96
102
|
- lib/banorte_payworks/version.rb
|
97
103
|
- spec/banorte_payworks_simpletpv_spec.rb
|
98
|
-
- spec/banorte_payworks_spec.rb
|
99
104
|
- spec/spec_helper.rb
|
100
105
|
homepage: http://devmask.net/banorte_payworks/
|
101
106
|
licenses:
|
102
107
|
- MIT
|
108
|
+
metadata: {}
|
103
109
|
post_install_message:
|
104
110
|
rdoc_options: []
|
105
111
|
require_paths:
|
106
112
|
- lib
|
107
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
-
none: false
|
109
114
|
requirements:
|
110
|
-
- -
|
115
|
+
- - '>='
|
111
116
|
- !ruby/object:Gem::Version
|
112
117
|
version: '0'
|
113
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
119
|
requirements:
|
116
|
-
- -
|
120
|
+
- - '>='
|
117
121
|
- !ruby/object:Gem::Version
|
118
122
|
version: '0'
|
119
123
|
requirements: []
|
120
124
|
rubyforge_project:
|
121
|
-
rubygems_version:
|
125
|
+
rubygems_version: 2.0.3
|
122
126
|
signing_key:
|
123
|
-
specification_version:
|
127
|
+
specification_version: 4
|
124
128
|
summary: Simple TPV implementation for Banorte Payworks
|
125
129
|
test_files:
|
126
130
|
- spec/banorte_payworks_simpletpv_spec.rb
|
127
|
-
- spec/banorte_payworks_spec.rb
|
128
131
|
- spec/spec_helper.rb
|
129
|
-
has_rdoc:
|