buckaroo-ideal 0.0.1

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,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Buckaroo::Ideal::ResponseSignature do
4
+ let(:response) {
5
+ mock transaction_id: 'transaction_id',
6
+ timestamp: 'timestamp',
7
+ invoice_number: 'invoice_number',
8
+ reference: 'reference',
9
+ currency: 'EUR',
10
+ amount: 12.50,
11
+ status: mock(code: '101'),
12
+ test_mode: true
13
+ }
14
+
15
+ let(:signature) {
16
+ Buckaroo::Ideal::ResponseSignature.new(response, '282538ee4f56f9a1ef8f146b18e2003c')
17
+ }
18
+
19
+ before do
20
+ Buckaroo::Ideal::Config.stub(:merchant_key)
21
+ .and_return('merchant_key')
22
+
23
+ Buckaroo::Ideal::Config.stub(:secret_key)
24
+ .and_return('secret_key')
25
+ end
26
+
27
+ describe '#valid?' do
28
+ it 'returns true if the given signature matches the generated signature' do
29
+ signature.should be_valid
30
+ end
31
+
32
+ it 'returns false if the given signature does not match the generated signature' do
33
+ signature = Buckaroo::Ideal::ResponseSignature.new(response, 'wrong')
34
+ signature.should_not be_valid
35
+ end
36
+ end
37
+
38
+ describe '#generated_signature' do
39
+ it 'generates a signature for the given response' do
40
+ expected_salt = [
41
+ 'transaction_id', # response.transaction_id
42
+ 'timestamp', # response.timestamp
43
+ 'merchant_key', # config.merchant_key
44
+ 'invoice_number', # response.invoice_number
45
+ 'reference', # response.reference
46
+ 'EUR', # response.currency
47
+ 1250, # response.amount (in cents)
48
+ '101', # response.status.code
49
+ '1', # response.test_mode
50
+ 'secret_key' # config.secret_key
51
+ ].join
52
+
53
+ Digest::MD5.should_receive(:hexdigest)
54
+ .with(expected_salt)
55
+
56
+ signature.generate_signature
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Buckaroo::Ideal::Response do
4
+ let(:parameters) {
5
+ {
6
+ 'bpe_trx' => 'transaction_id',
7
+ 'bpe_result' => '801',
8
+ 'bpe_invoice' => 'inv001',
9
+ 'bpe_reference' => 'ref001',
10
+ 'bpe_signature' => 'response_signature_1',
11
+ 'bpe_signature2' => 'response_signature_2',
12
+ 'bpe_amount' => '2695',
13
+ 'bpe_currency' => 'EUR',
14
+ 'bpe_mode' => '1',
15
+ 'bpe_timestamp' => '22-05-2012 12:58:13'
16
+ }
17
+ }
18
+
19
+ let(:response) { Buckaroo::Ideal::Response.new(parameters) }
20
+
21
+ it 'has a transaction_id' do
22
+ response.transaction_id.should == 'transaction_id'
23
+ end
24
+
25
+ it 'has a status' do
26
+ response.status.should == Buckaroo::Ideal::Status.new('801')
27
+ end
28
+
29
+ it 'has an invoice_number' do
30
+ response.invoice_number.should == 'inv001'
31
+ end
32
+
33
+ it 'has a reference' do
34
+ response.reference.should == 'ref001'
35
+ end
36
+
37
+ it 'has a signature' do
38
+ response.signature.should be_a Buckaroo::Ideal::ResponseSignature
39
+ response.signature.signature.should == 'response_signature_2'
40
+ end
41
+
42
+ it 'has an amount' do
43
+ response.amount.should == 26.95
44
+ end
45
+
46
+ it 'has a currency' do
47
+ response.currency.should == 'EUR'
48
+ end
49
+
50
+ it 'has a test_mode' do
51
+ response.test_mode.should == true
52
+ end
53
+
54
+ it 'has a time' do
55
+ response.time.should == Time.new(2012, 05, 22, 12, 58, 13)
56
+ end
57
+
58
+ it 'has a timestamp' do
59
+ response.timestamp.should == '22-05-2012 12:58:13'
60
+ end
61
+
62
+ describe '#valid?' do
63
+ it 'returns true if the signature is valid' do
64
+ response.signature.stub(:valid?)
65
+ .and_return(true)
66
+
67
+ response.should be_valid
68
+ end
69
+
70
+ it 'returns false if the signature if not valid' do
71
+ response.signature.stub(:valid?)
72
+ .and_return(false)
73
+
74
+ response.should_not be_valid
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ describe Buckaroo::Ideal::Status do
4
+ let(:status) { Buckaroo::Ideal::Status.new('000') }
5
+
6
+ describe '.status_codes' do
7
+ let(:csv_file) { File.expand_path('../../fixtures/statuscodes.csv', __FILE__) }
8
+
9
+ it 'reads and returns the status codes from the given csv file' do
10
+ codes = Buckaroo::Ideal::Status.status_codes(csv_file)
11
+
12
+ codes['000'].should == 'De credit card transactie is pending.'
13
+ codes['001'].should == 'De credit card transactie is pending. De MPI-status van de klant wordt gecheckt.'
14
+ codes['007'].should be_nil
15
+ end
16
+
17
+ it 'reads and returns the status codes from the bundled csv file' do
18
+ codes = Buckaroo::Ideal::Status.status_codes
19
+ codes['000'].should == 'De credit card transactie is pending.'
20
+ codes['104'].should == 'De kaart is verlopen.'
21
+ codes['999'].should == 'Er is een fout opgetreden waarvan de oorzaak vooralsnog onbekend is. We zullen de storing zo snel mogelijk verhelpen.'
22
+ end
23
+ end
24
+
25
+ describe '#initialize' do
26
+ it 'returns a Status with the code given' do
27
+ status = Buckaroo::Ideal::Status.new('000')
28
+ status.code.should == '000'
29
+ end
30
+
31
+ it 'returns a Status with the message of the given code' do
32
+ status = Buckaroo::Ideal::Status.new('000')
33
+ status.message.should == 'De credit card transactie is pending.'
34
+ end
35
+
36
+ it 'throws an UnknownStatusCode exception if the given code is invalid' do
37
+ expect {
38
+ Buckaroo::Ideal::Status.new('007')
39
+ }.to raise_error Buckaroo::Ideal::Status::UnknownStatusCode
40
+ end
41
+ end
42
+
43
+ describe '#==' do
44
+ it 'returns true if the statuses have the same code' do
45
+ Buckaroo::Ideal::Status.new('000').should == Buckaroo::Ideal::Status.new('000')
46
+ end
47
+ end
48
+
49
+ describe '#state' do
50
+ %w(071 121 151 171 190 242 243 244 245 246 247 254 255 301 401 461 462 463
51
+ 464 551 601 701 801).each do |code|
52
+ message = Buckaroo::Ideal::Status.status_codes[code]
53
+
54
+ it "returns :completed for code #{code} (#{message})" do
55
+ status = Buckaroo::Ideal::Status.new(code)
56
+ status.state.should == :completed
57
+ end
58
+ end
59
+
60
+ %w(000 001 070 090 091 100 105 120 126 135 136 150 156 157 170 176 177 253
61
+ 300 400 460 500 550 600 700 710 790 791 792 793 800 811 814 815 831 834).each do |code|
62
+ message = Buckaroo::Ideal::Status.status_codes[code]
63
+
64
+ it "returns :pending for code #{code} (#{message})" do
65
+ status = Buckaroo::Ideal::Status.new(code)
66
+ status.state.should == :pending
67
+ end
68
+ end
69
+
70
+ %w(264 541 345 372 390 392).each do |code|
71
+ message = Buckaroo::Ideal::Status.status_codes[code]
72
+
73
+ it "returns :unknown for code #{code} (#{message})" do
74
+ status = Buckaroo::Ideal::Status.new(code)
75
+ status.state.should == :unknown
76
+ end
77
+ end
78
+
79
+ %w(072 073 074 075 076 101 102 103 104 106 122 123 124 125 137 138 139 152
80
+ 153 155 158 159 172 173 175 178 179 201 203 204 205 206 207 251 252 260
81
+ 261 262 302 303 304 305 306 309 402 409 410 411 414 421 422 425 466 468
82
+ 490 491 492 501 552 553 554 555 556 560 581 590 602 605 609 610 612 690
83
+ 702 703 704 705 706 707 708 711 712 720 721 802 803 804 810 812 813 816
84
+ 820 821 822 823 824 830 833 835 836 890 891 900 901 910 931 932 933 934
85
+ 935 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
86
+ 960 961 962 963 964 971 972 973 974 975 976 977 978 980 981 982 983 990
87
+ 991 992 993 999).each do |code|
88
+ message = Buckaroo::Ideal::Status.status_codes[code]
89
+
90
+ it "returns :unknown for code #{code} (#{message})" do
91
+ status = Buckaroo::Ideal::Status.new(code)
92
+ status.state.should == :failed
93
+ end
94
+ end
95
+ end
96
+
97
+ describe '#completed?' do
98
+ it 'returns true if the state is completed' do
99
+ status.stub(:state).and_return(:completed)
100
+ status.should be_completed
101
+ end
102
+
103
+ it 'returns false if the state is not completed' do
104
+ status.stub(:state).and_return(:unknown)
105
+ status.should_not be_completed
106
+ end
107
+ end
108
+
109
+ describe '#pending?' do
110
+ it 'returns true if the state is pending' do
111
+ status.stub(:state).and_return(:pending)
112
+ status.should be_pending
113
+ end
114
+
115
+ it 'returns false if the state is not pending' do
116
+ status.stub(:state).and_return(:unknown)
117
+ status.should_not be_pending
118
+ end
119
+ end
120
+
121
+ describe '#failed?' do
122
+ it 'returns true if the state is failed' do
123
+ status.stub(:state).and_return(:failed)
124
+ status.should be_failed
125
+ end
126
+
127
+ it 'returns false if the state is not failed' do
128
+ status.stub(:state).and_return(:unknown)
129
+ status.should_not be_failed
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Buckaroo::Ideal::Util do
5
+ describe '#to_normalized_string' do
6
+ it 'translates utf-8 characters to ASCII equivalents' do
7
+ result = Buckaroo::Ideal::Util.to_normalized_string('îñtërnâtiônàlizâtiôn')
8
+ result.should == 'internationalization'
9
+ end
10
+ end
11
+
12
+ describe '#to_cents' do
13
+ it 'converts integer amounts to cents' do
14
+ Buckaroo::Ideal::Util.to_cents(10).should == 1000
15
+ end
16
+
17
+ it 'converts float amounts to cents' do
18
+ Buckaroo::Ideal::Util.to_cents(12.4954321).should == 1250
19
+ end
20
+ end
21
+
22
+ describe '#from_cents' do
23
+ it 'converts cents to their real amount' do
24
+ Buckaroo::Ideal::Util.from_cents(1995).should == 19.95
25
+ end
26
+ end
27
+
28
+ describe '#to_numeric_boolean' do
29
+ it 'converts "true" to "1"' do
30
+ Buckaroo::Ideal::Util.to_numeric_boolean(true).should == 1
31
+ end
32
+
33
+ it 'converts "false" to "0"' do
34
+ Buckaroo::Ideal::Util.to_numeric_boolean(false).should == 0
35
+ end
36
+ end
37
+
38
+ describe '#from_numeric_boolean' do
39
+ it 'converts "1" to "true"' do
40
+ Buckaroo::Ideal::Util.from_numeric_boolean(1).should be_true
41
+ Buckaroo::Ideal::Util.from_numeric_boolean('1').should be_true
42
+ end
43
+
44
+ it 'converts "0" to "false"' do
45
+ Buckaroo::Ideal::Util.from_numeric_boolean(0).should be_false
46
+ Buckaroo::Ideal::Util.from_numeric_boolean('0').should be_false
47
+ end
48
+ end
49
+
50
+ describe '#compact' do
51
+ it 'removes keys from hashes if they do not have a value' do
52
+ result = Buckaroo::Ideal::Util.compact({ 'key' => nil })
53
+ result.keys.should_not include 'key'
54
+ end
55
+
56
+ it 'preserves keys and values in hashes if they have a value' do
57
+ result = Buckaroo::Ideal::Util.compact({ 'key' => 'value' })
58
+ result.keys.should include 'key'
59
+ result['key'].should == 'value'
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,2 @@
1
+ 000;De credit card transactie is pending.
2
+ 001;De credit card transactie is pending. De MPI-status van de klant wordt gecheckt.
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require File.expand_path('../../lib/buckaroo-ideal', __FILE__)
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
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+ config.mock_with :rspec
15
+
16
+ config.before do
17
+ Buckaroo::Ideal::Config.reset
18
+ end
19
+ end
File without changes
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buckaroo-ideal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tom-Eric Gerritsen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70309503982320 !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: *70309503982320
25
+ - !ruby/object:Gem::Dependency
26
+ name: transliterator
27
+ requirement: &70309503981860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70309503981860
36
+ description: A simple Ruby library that aids you in handling iDEAL transactions via
37
+ the Buckaroo iDEAL gateway.
38
+ email:
39
+ - tomeric@eet.nu
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - .rspec
46
+ - .rvmrc
47
+ - .travis.yml
48
+ - .yardopts
49
+ - Gemfile
50
+ - Guardfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - buckaroo-ideal.gemspec
55
+ - files/statuscodes.csv
56
+ - lib/buckaroo-ideal.rb
57
+ - lib/buckaroo-ideal/config.rb
58
+ - lib/buckaroo-ideal/order.rb
59
+ - lib/buckaroo-ideal/request.rb
60
+ - lib/buckaroo-ideal/request_signature.rb
61
+ - lib/buckaroo-ideal/response.rb
62
+ - lib/buckaroo-ideal/response_signature.rb
63
+ - lib/buckaroo-ideal/status.rb
64
+ - lib/buckaroo-ideal/util.rb
65
+ - lib/buckaroo-ideal/version.rb
66
+ - spec/buckaroo-ideal/config_spec.rb
67
+ - spec/buckaroo-ideal/order_spec.rb
68
+ - spec/buckaroo-ideal/request_signature_spec.rb
69
+ - spec/buckaroo-ideal/request_spec.rb
70
+ - spec/buckaroo-ideal/response_signature_spec.rb
71
+ - spec/buckaroo-ideal/response_spec.rb
72
+ - spec/buckaroo-ideal/status_spec.rb
73
+ - spec/buckaroo-ideal/util_spec.rb
74
+ - spec/fixtures/statuscodes.csv
75
+ - spec/spec_helper.rb
76
+ - spec/support/.gitkeep
77
+ homepage: http://github.com/eet-nu/buckaroo-ideal
78
+ licenses: []
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.17
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Integrate with the Buckaroo iDEAL API.
101
+ test_files:
102
+ - spec/buckaroo-ideal/config_spec.rb
103
+ - spec/buckaroo-ideal/order_spec.rb
104
+ - spec/buckaroo-ideal/request_signature_spec.rb
105
+ - spec/buckaroo-ideal/request_spec.rb
106
+ - spec/buckaroo-ideal/response_signature_spec.rb
107
+ - spec/buckaroo-ideal/response_spec.rb
108
+ - spec/buckaroo-ideal/status_spec.rb
109
+ - spec/buckaroo-ideal/util_spec.rb
110
+ - spec/fixtures/statuscodes.csv
111
+ - spec/spec_helper.rb
112
+ - spec/support/.gitkeep
113
+ has_rdoc: