ogone-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,85 @@
1
- ogone-rails
2
- ===========
1
+ #Ogone for Rails
3
2
 
4
- Add Ogone payments functionality to a Rails application
3
+
4
+ ##What is it
5
+
6
+ A Ruby gem to simplify the use of [Ogone](http://www.ogone.com) online payments service.
7
+
8
+
9
+ ##Usage
10
+
11
+ ### Installation
12
+ gem install ogone-rails
13
+
14
+ ### Configuration
15
+ Define:
16
+
17
+ * PSPID
18
+ * sha_in
19
+ * sha_out
20
+ * currency | default: "EUR"
21
+ * language | default: "nl_NL"
22
+ * test | default = "live"
23
+
24
+
25
+
26
+ # config/initializers/ogone-rails.rb
27
+
28
+ OgoneRails::config ({
29
+ :pspid => "myPSPID",
30
+ :sha_in => "0123456789abcdefghijklmnopqrstuv",
31
+ :sha_out => "vutsrqponmlkjihgfedcba9876543210",
32
+ :mode => "test""
33
+ })
34
+
35
+
36
+
37
+ ### Helpers
38
+ Generate an **ogone_form**:
39
+
40
+ ogone_form({
41
+ :order_id => 12345,
42
+ :amount => 299.99,
43
+ :customer_name => "Jan Janssen",
44
+ :customer_email => "jan@email.com",
45
+ :customer_address => "highstreet 101",
46
+ :customer_zip => "1000",
47
+ :customer_city => "Brussel",
48
+ :customer_country => "Belgium",
49
+ :customer_phone => "0412345678"
50
+ })
51
+
52
+ ### Check Ogone feedback
53
+
54
+ Create a new object to check the feedback Ogone gives you:
55
+
56
+ # app/controllers/feedback_controller.rb
57
+ @check = OgoneRails::CheckAuth.new( request.GET )
58
+
59
+ Check valid authorization:
60
+
61
+ @check.valid?
62
+ #return true or false
63
+
64
+ Get parameters, returned in a hash format. The keys are renamed to be much more readable:
65
+
66
+ @check.get_parameters
67
+
68
+ … will return …
69
+
70
+ {
71
+ "order_id" => "46185",
72
+ "amount" => "299.38",
73
+ "currency" => "EUR",
74
+ "payment_method" => "CreditCard",
75
+ "acceptance" => "test123",
76
+ "status" => "5",
77
+ "card_number" => "XXXXXXXXXXXX1111",
78
+ "pay_id" => "14838904",
79
+ "error" => nil,
80
+ "brand" => "VISA",
81
+ "sha_sign" => "51AF71351E79DD0186816289AD53C57213978E32"
82
+ }
83
+
84
+ ### Copyright
85
+ Copyright © 2012 Robin Houdmeyers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -0,0 +1,56 @@
1
+ module OgoneRails
2
+
3
+ class CheckAuth
4
+
5
+ def initialize request
6
+ @request = request
7
+ @params = {}
8
+ get_params
9
+ end
10
+
11
+
12
+ def valid?
13
+ # Check authentication
14
+ # sha_sign == sha_out_phrase
15
+ sha_sign, sha_out_phrase, ogone_return = @request['SHASIGN'], "", {}
16
+
17
+ # Upcase and sort paramaters to params
18
+ @request.each do |key, value|
19
+ ogone_return[key.upcase] = value unless key == 'SHASIGN' # exclude SHASIGN
20
+ end
21
+
22
+ # Generate sha_out_hash
23
+ ogone_return.sort.each do |key, value|
24
+ sha_out_phrase << "#{key.upcase}=#{value}#{OgoneRails::sha_out}"
25
+ end
26
+
27
+ # Digest sha_out_phrase
28
+ sha_check = Digest::SHA1.hexdigest(sha_out_phrase).upcase
29
+
30
+ # Compare sha_sign with digested phrase
31
+ if sha_check == sha_sign
32
+ return true
33
+ else
34
+ return false
35
+ end
36
+ end
37
+
38
+
39
+ def get_params
40
+ # return values in readable format
41
+ @params = {
42
+ :order_id => (@request['orderID']).to_i,
43
+ :amount => (@request['amount']).to_f,
44
+ :currency => @request['currency'],
45
+ :payment_method => @request['PM'],
46
+ :acceptance => @request['ACCEPTANCE'],
47
+ :status => STATUS_CODES[@request['STATUS'].to_i],
48
+ :card_number => @request['CARDNO'],
49
+ :pay_id => @request['PAYID'],
50
+ :error => @request['NC ERROR'],
51
+ :brand => @request['BRAND'],
52
+ :sha_sign => @request['SHASIGN']
53
+ }
54
+ end
55
+ end
56
+ end
@@ -1,65 +1,98 @@
1
1
  module OgoneRails
2
+ extend self
2
3
 
3
- module Config
4
-
5
- TEST_SERVICE_URL = 'https://secure.ogone.com/ncol/test/orderstandard.asp'
6
- LIVE_SERVICE_URL = 'https://secure.ogone.com/ncol/prod/orderstandard.asp'
7
-
8
- # sha_in
9
- def self.sha_in= sha
10
- @sha_in = sha
11
- end
12
-
13
- def self.sha_in
14
- @sha_in
15
- end
16
-
17
- # sha_out
18
- def self.sha_out= sha
19
- @sha_out = sha
20
- end
21
-
22
- def self.sha_out
23
- @sha_out
24
- end
25
-
26
-
27
- # PSPID
28
- def self.pspid= id
29
- @pspid = id
30
- end
31
-
32
- def self.pspid
33
- @pspid
34
- end
35
-
36
-
37
- # currency
38
- def self.currency= currency
39
- @currency = currency
40
- end
41
-
42
- def self.currency
43
- @currency
44
- end
45
-
46
-
47
- # language
48
- def self.language= language
49
- @language = language
50
- end
51
-
52
- def self.language
53
- @language
54
- end
4
+ TEST_SERVICE_URL = 'https://secure.ogone.com/ncol/test/orderstandard.asp'
5
+ LIVE_SERVICE_URL = 'https://secure.ogone.com/ncol/prod/orderstandard.asp'
6
+ STATUS_CODES = {
7
+ 0 => "Incomplete or invalid",
8
+ 1 => "Cancelled by client",
9
+ 2 => "Authorization refused",
10
+ 4 => "Order stored",
11
+ 40 => "Stored waitingexternal result",
12
+ 41 => "Waiting client payment",
13
+ 5 => "Authorized",
14
+ 50 => "Authorized waiting external result",
15
+ 51 => "Authorization waiting",
16
+ 52 => "Authorization not known",
17
+ 55 => "Stand-by",
18
+ 56 => "OK with scheduled payments",
19
+ 57 => "Error in scheduled payments",
20
+ 59 => "Authoriz. to get manually",
21
+ 6 => "Authorized and cancelled",
22
+ 61 => "Author. deletion waiting",
23
+ 62 => "Author. deletion uncertain",
24
+ 63 => "Author. deletion refused",
25
+ 64 => "Authorized and cancelled",
26
+ 7 => "Payment deleted",
27
+ 71 => "Payment deletion pending",
28
+ 72 => "Payment deletion uncertain",
29
+ 73 => "Payment deletion refused",
30
+ 74 => "Payment deleted",
31
+ 75 => "Deletion processed by merchant",
32
+ 8 => "Refund",
33
+ 81 => "Refund pending",
34
+ 82 => "Refund uncertain",
35
+ 83 => "Refund refused",
36
+ 84 => "Payment declined by the acquirer",
37
+ 85 => "Refund processed by merchant",
38
+ 9 => "Payment requested",
39
+ 91 => "Payment processing",
40
+ 92 => "Payment uncertain",
41
+ 93 => "Payment refused",
42
+ 94 => "Refund declined by the acquirer",
43
+ 95 => "Payment processed by merchant",
44
+ 99 => "Being processed"
45
+ }
46
+
47
+ @pspid = nil
48
+ @sha_in = nil
49
+ @sha_out = nil
50
+ @currency = "EUR"
51
+ @language = "nl_NL"
52
+ @mode = "live"
53
+
54
+ def config c = {}
55
55
 
56
- # debug
57
- def self.debug= bool = false # default to production url
58
- @test = bool
56
+ c.each do |key, value|
57
+ case key
58
+ when :pspid
59
+ @pspid = value
60
+ when :sha_in
61
+ @sha_in = value
62
+ when :sha_out
63
+ @sha_out = value
64
+ when :currency
65
+ @currency = value
66
+ when :language
67
+ @language = value
68
+ when :mode
69
+ @mode = value
70
+ end
59
71
  end
72
+ end
60
73
 
61
- def self.debug
62
- @test
63
- end
74
+
75
+ def self.sha_in
76
+ @sha_in
77
+ end
78
+
79
+ def self.sha_out
80
+ @sha_out
81
+ end
82
+
83
+ def self.pspid
84
+ @pspid
85
+ end
86
+
87
+ def self.currency
88
+ @currency
89
+ end
90
+
91
+ def self.language
92
+ @language
93
+ end
94
+
95
+ def self.mode
96
+ @mode
64
97
  end
65
98
  end
@@ -5,58 +5,66 @@ module OgoneRails
5
5
  def ogone_form options={}
6
6
  form = ""
7
7
 
8
- if OgoneRails::Config.debug
9
- form = "<form method='post' action='#{OgoneRails::Config::TEST_SERVICE_URL}'>\n"
10
- else
11
- form = "<form method='post' action='#{OgoneRails::Config::LIVE_SERVICE_URL}'>\n"
12
- end
8
+ OgoneRails::mode == "live" ? action = OgoneRails::LIVE_SERVICE_URL : action = OgoneRails::TEST_SERVICE_URL
9
+
10
+ form << "<form method='post' action='#{action}'>\n"
13
11
 
14
12
  # REQUIRED VALUES
15
13
  StringToHash::reset
16
14
  # pspid
17
- form << "\t<input type='hidden' name='PSPID' value='#{OgoneRails::Config.pspid}'>\n"
18
- StringToHash::add_parameter 'PSPID', OgoneRails::Config.pspid
15
+ form << "\t<input type='hidden' name='PSPID' value='#{OgoneRails::pspid}'>\n"
16
+ StringToHash::add_parameter 'PSPID', OgoneRails::pspid
19
17
  # currency
20
- form << "\t<input type='hidden' name='currency' value='#{OgoneRails::Config.currency}'>\n"
21
- StringToHash::add_parameter 'currency', OgoneRails::Config.currency
18
+ form << "\t<input type='hidden' name='currency' value='#{OgoneRails::currency}'>\n"
19
+ StringToHash::add_parameter 'currency', OgoneRails::currency
22
20
  # language
23
- form << "\t<input type='hidden' name='language' value='#{OgoneRails::Config.language}'>\n"
24
- StringToHash::add_parameter 'language', OgoneRails::Config.language
21
+ form << "\t<input type='hidden' name='language' value='#{OgoneRails::language}'>\n"
22
+ StringToHash::add_parameter 'language', OgoneRails::language
25
23
 
26
24
 
27
25
 
28
26
  # OPTIONAL VALUES
29
27
  options.each do |option, value|
30
28
  case option
29
+
31
30
  when :order_id
32
31
  form << "\t<input type='hidden' name='orderID' value='#{value}'>\n"
33
32
  StringToHash::add_parameter 'orderID', value
33
+
34
34
  when :amount
35
35
  #amount 15.00 -> 1500
36
36
  value = (value.to_f * 100).to_i
37
37
  form << "\t<input type='hidden' name='amount' value='#{value}'>\n"
38
38
  StringToHash::add_parameter 'amount', value
39
+
39
40
  when :customer_name
40
41
  form << "\t<input type='hidden' name='CN' value='#{value}'>\n"
41
42
  StringToHash::add_parameter 'CN', value
43
+
42
44
  when :customer_email
43
45
  form << "\t<input type='hidden' name='EMAIL' value='#{value}'>\n"
44
46
  StringToHash::add_parameter 'EMAIL', value
47
+
45
48
  when :customer_address
46
49
  form << "\t<input type='hidden' name='owneraddress' value='#{value}'>\n"
47
50
  StringToHash::add_parameter 'owneraddress', value
51
+
48
52
  when :customer_zip
49
53
  form << "\t<input type='hidden' name='ownerZIP' value='#{value}'>\n"
50
54
  StringToHash::add_parameter 'ownerZIP', value
55
+
51
56
  when :customer_city
52
57
  form << "\t<input type='hidden' name='ownertown' value='#{value}'>\n"
53
58
  StringToHash::add_parameter 'ownertown', value
59
+
54
60
  when :customer_country
55
61
  form << "\t<input type='hidden' name='ownercty' value='#{value}'>\n"
56
62
  StringToHash::add_parameter 'ownercty', value
63
+
57
64
  when :customer_phone
58
65
  form << "\t<input type='hidden' name='ownertelno' value='#{value}'>\n"
59
66
  StringToHash::add_parameter 'ownertelno', value
67
+
60
68
  else
61
69
  form << "\t<input type='hidden' name='#{option}' value='#{value}'>\n"
62
70
  end
@@ -10,7 +10,7 @@ module OgoneRails
10
10
 
11
11
  def generate_sha_in
12
12
  @params.sort.each do |key, value|
13
- @sha_in_phrase << "#{key.upcase}=#{value}#{OgoneRails::Config.sha_in}"
13
+ @sha_in_phrase << "#{key.upcase}=#{value}#{OgoneRails::sha_in}"
14
14
  end
15
15
 
16
16
  Digest::SHA1.hexdigest(@sha_in_phrase).upcase
data/lib/ogone-rails.rb CHANGED
@@ -4,50 +4,6 @@ require 'digest'
4
4
 
5
5
  require 'ogone-rails/config'
6
6
  require 'ogone-rails/rails'
7
- require 'ogone-rails/string_to_hash'
7
+ require 'ogone-rails/string-to-hash'
8
8
  require 'ogone-rails/helpers'
9
-
10
-
11
- module OgoneRails
12
- extend self
13
-
14
- def check_auth feedback
15
- sha_sign = feedback['SHASIGN']
16
-
17
- params = {}
18
-
19
- # upcase and sort paramaters to params
20
- # exclude SHASIGN
21
- feedback.each do |key, value|
22
- params[key.upcase] = value unless key == 'SHASIGN'
23
- end
24
-
25
-
26
- sha_out_phrase = ""
27
- # generate sha_out_hash
28
- params.sort.each do |key, value|
29
- sha_out_phrase << "#{key.upcase}=#{value}#{OgoneRails::Config.sha_out}"
30
- end
31
-
32
- sha_check = Digest::SHA1.hexdigest(sha_out_phrase).upcase
33
-
34
- if sha_check == sha_sign
35
- # return values in readable format
36
- {
37
- 'order_id' => feedback['orderID'],
38
- 'amount' => feedback['amount'],
39
- 'currency' => feedback['currency'],
40
- 'payment_method' => feedback['PM'],
41
- 'acceptance' => feedback['ACCEPTANCE'],
42
- 'status' => feedback['STATUS'],
43
- 'card_number' => feedback['CARDNO'],
44
- 'pay_id' => feedback['PAYID'],
45
- 'error' => feedback['NC ERROR'],
46
- 'brand' => feedback['BRAND'],
47
- 'sha_sign' => feedback['SHASIGN']
48
- }
49
- else
50
- false
51
- end
52
- end
53
- end
9
+ require 'ogone-rails/check-auth'
data/ogone-rails.gemspec CHANGED
@@ -5,17 +5,16 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ogone-rails"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robin Houdmeyers"]
12
- s.date = "2012-05-10"
12
+ s.date = "2012-05-14"
13
13
  s.description = "Add Ogone payments functionality to your Rails application"
14
14
  s.email = "houdmeyers@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
- "README.md",
18
- "README.rdoc"
17
+ "README.md"
19
18
  ]
20
19
  s.files = [
21
20
  ".document",
@@ -23,14 +22,14 @@ Gem::Specification.new do |s|
23
22
  "Gemfile.lock",
24
23
  "LICENSE.txt",
25
24
  "README.md",
26
- "README.rdoc",
27
25
  "Rakefile",
28
26
  "VERSION",
29
27
  "lib/ogone-rails.rb",
28
+ "lib/ogone-rails/check-auth.rb",
30
29
  "lib/ogone-rails/config.rb",
31
30
  "lib/ogone-rails/helpers.rb",
32
31
  "lib/ogone-rails/rails.rb",
33
- "lib/ogone-rails/string_to_hash.rb",
32
+ "lib/ogone-rails/string-to-hash.rb",
34
33
  "ogone-rails.gemspec",
35
34
  "test/helper.rb",
36
35
  "test/test_ogone-rails.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ogone-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-10 00:00:00.000000000 Z
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
16
- requirement: &70279657186260 !ruby/object:Gem::Requirement
16
+ requirement: &70331864054080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70279657186260
24
+ version_requirements: *70331864054080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &70279657183380 !ruby/object:Gem::Requirement
27
+ requirement: &70331864052940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.12'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70279657183380
35
+ version_requirements: *70331864052940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70279657182660 !ruby/object:Gem::Requirement
38
+ requirement: &70331864007560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.1.3
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70279657182660
46
+ version_requirements: *70331864007560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70279657181700 !ruby/object:Gem::Requirement
49
+ requirement: &70331864006060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.8.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70279657181700
57
+ version_requirements: *70331864006060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70279657180860 !ruby/object:Gem::Requirement
60
+ requirement: &70331864004080 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70279657180860
68
+ version_requirements: *70331864004080
69
69
  description: Add Ogone payments functionality to your Rails application
70
70
  email: houdmeyers@gmail.com
71
71
  executables: []
@@ -73,21 +73,20 @@ extensions: []
73
73
  extra_rdoc_files:
74
74
  - LICENSE.txt
75
75
  - README.md
76
- - README.rdoc
77
76
  files:
78
77
  - .document
79
78
  - Gemfile
80
79
  - Gemfile.lock
81
80
  - LICENSE.txt
82
81
  - README.md
83
- - README.rdoc
84
82
  - Rakefile
85
83
  - VERSION
86
84
  - lib/ogone-rails.rb
85
+ - lib/ogone-rails/check-auth.rb
87
86
  - lib/ogone-rails/config.rb
88
87
  - lib/ogone-rails/helpers.rb
89
88
  - lib/ogone-rails/rails.rb
90
- - lib/ogone-rails/string_to_hash.rb
89
+ - lib/ogone-rails/string-to-hash.rb
91
90
  - ogone-rails.gemspec
92
91
  - test/helper.rb
93
92
  - test/test_ogone-rails.rb
@@ -106,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
105
  version: '0'
107
106
  segments:
108
107
  - 0
109
- hash: -2064012355136434449
108
+ hash: 3204021684087159827
110
109
  required_rubygems_version: !ruby/object:Gem::Requirement
111
110
  none: false
112
111
  requirements:
data/README.rdoc DELETED
@@ -1,19 +0,0 @@
1
- = ogone-rails
2
-
3
- Description goes here.
4
-
5
- == Contributing to ogone-rails
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 Robin Houdmeyers. See LICENSE.txt for
18
- further details.
19
-