banorte_payworks 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'httpclient'
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.8.0"
7
+ gem "yard", "~> 0.7"
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.8.3"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ httpclient (2.2.4)
7
+ jeweler (1.8.3)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ rdoc
12
+ json (1.6.5)
13
+ rake (0.9.2.2)
14
+ rdoc (3.12)
15
+ json (~> 1.4)
16
+ rspec (2.8.0)
17
+ rspec-core (~> 2.8.0)
18
+ rspec-expectations (~> 2.8.0)
19
+ rspec-mocks (~> 2.8.0)
20
+ rspec-core (2.8.0)
21
+ rspec-expectations (2.8.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.8.0)
24
+ yard (0.7.5)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.0.0)
31
+ httpclient
32
+ jeweler (~> 1.8.3)
33
+ rspec (~> 2.8.0)
34
+ yard (~> 0.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Jonathan Garay
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = banorte_payworks
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to banorte_payworks
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Jonathan Garay. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "banorte_payworks"
18
+ gem.homepage = "http://github.com/netmask/banorte_payworks"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Simple TPV for Banorte Payworks Mexican Gateway}
21
+ gem.description = %Q{}
22
+ gem.email = "jonathan@devmask.net"
23
+ gem.authors = ["Jonathan Garay"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ task :default => :spec
35
+
36
+ require 'yard'
37
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.9.2
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'banorte_payworks/simple_tpv')
@@ -0,0 +1,118 @@
1
+ module BanortePayworks
2
+
3
+ require 'httpclient'
4
+
5
+ PAYWORKS_URL = "https://eps.banorte.com/recibo"
6
+ PAYWORKS_3DS_URL = "https://eps.banorte.com/secure3d/Solucion3DSecure.htm"
7
+
8
+ MODE = {
9
+ :production => 'P',
10
+ :reject => 'R',
11
+ :accept => 'Y',
12
+ :random => 'R'
13
+ }
14
+
15
+ TYPE = {
16
+ :auth => 'Auth',
17
+ :pre_auth => 'PreAuth',
18
+ :post_auth => 'PostAuth',
19
+ :void => 'Void',
20
+ :credit => 'Credit',
21
+ :force_insert_auth => 'ForceInsertAuth',
22
+ :verify => 'Verify'
23
+ }
24
+
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
+ class SimpleTPV
51
+
52
+ def initialize(config={})
53
+ @config = config
54
+ end
55
+
56
+ #Simple call to payment
57
+ def do_payment(order_id, card_number, exp_date, cvv, amount)
58
+ do_transaction :card_number => card_number,
59
+ :exp_date => exp_date,
60
+ :cvv => cvv,
61
+ :amount => amount,
62
+ :order_id => order_id,
63
+ :response_path => 'http://sample.net/',
64
+ :type => BanortePayworks::TYPE[:auth]
65
+ end
66
+
67
+ def void(transaction)
68
+
69
+ do_transaction :order_id => transaction.order_id,
70
+ :amount => transaction.amount,
71
+ :authnum => transaction.authnum,
72
+ :card_number => transaction.card_number,
73
+ :exp_date => transaction.exp_date,
74
+ :cvv => transaction.cvv,
75
+ :response_path => 'http://sample.net/',
76
+ :type => BanortePayworks::TYPE[:void]
77
+
78
+ end
79
+
80
+ def do_transaction(properties = {})
81
+
82
+ location = HTTPClient.new.post(PAYWORKS_URL, {
83
+ 'Name' => @config[:username],
84
+ 'Password' => @config[:password],
85
+ 'ClientId' => @config[:client_id],
86
+ 'Mode' => @config[:mode],
87
+ 'TransType' => properties[:type],
88
+ 'Expires' => properties[:exp_date],
89
+ 'Number' => properties[:card_number],
90
+ 'Cvv2Indicator' => (properties[:cvv] == nil ? 0 : 1),
91
+ 'Cvv2Val' => properties[:cvv],
92
+ 'Total' => properties[:amount],
93
+ 'ResponsePath' => properties[:response_path],
94
+ 'OrderId' => properties[:order_id],
95
+ 'AuthCode' => properties[:authnum].to_s
96
+
97
+ }).header['Location'].to_s
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
113
+
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -0,0 +1,14 @@
1
+ require 'banorte_payworks'
2
+
3
+ describe BanortePayworks::SimpleTPV do
4
+ it "Call do transaction" do
5
+ tpv = BanortePayworks::SimpleTPV.new :username => 'tienda19',
6
+ :password => '2006',
7
+ :client_id=>'19',
8
+ :mode=>BanortePayworks::MODE[:accept]
9
+
10
+ transaction = tpv.do_payment(rand(100000),4916098986962263,'12/12','123',1.0)
11
+ tpv.void transaction
12
+
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "BanortePayworks" do
4
+
5
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'banorte_payworks'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: banorte_payworks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonathan Garay
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httpclient
16
+ requirement: &70205906377380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70205906377380
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70205906376900 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70205906376900
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &70205906376420 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.7'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70205906376420
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70205906375940 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70205906375940
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70205906375460 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.8.3
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70205906375460
69
+ description: ''
70
+ email: jonathan@devmask.net
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE.txt
75
+ - README.rdoc
76
+ files:
77
+ - .document
78
+ - .rspec
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - VERSION
85
+ - lib/banorte_payworks.rb
86
+ - lib/banorte_payworks/simple_tpv.rb
87
+ - spec/banorte_payworks_simpletpv_spec.rb
88
+ - spec/banorte_payworks_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: http://github.com/netmask/banorte_payworks
91
+ licenses:
92
+ - MIT
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: 116759024664583736
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.15
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Simple TPV for Banorte Payworks Mexican Gateway
118
+ test_files: []