buckaruby 1.7.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -54
  3. data/README.md +54 -18
  4. data/lib/buckaruby/action.rb +4 -4
  5. data/lib/buckaruby/amount.rb +25 -0
  6. data/lib/buckaruby/configuration.rb +35 -40
  7. data/lib/buckaruby/currency.rb +3 -3
  8. data/lib/buckaruby/exception.rb +9 -8
  9. data/lib/buckaruby/gateway.rb +64 -72
  10. data/lib/buckaruby/operation.rb +5 -5
  11. data/lib/buckaruby/payment_method.rb +20 -12
  12. data/lib/buckaruby/request.rb +62 -68
  13. data/lib/buckaruby/response.rb +69 -67
  14. data/lib/buckaruby/signature.rb +26 -7
  15. data/lib/buckaruby/transaction_type.rb +24 -21
  16. data/lib/buckaruby/version.rb +1 -1
  17. data/lib/buckaruby.rb +1 -2
  18. metadata +16 -97
  19. data/.github/workflows/test.yml +0 -23
  20. data/.gitignore +0 -19
  21. data/.rubocop.yml +0 -107
  22. data/Gemfile +0 -12
  23. data/Gemfile.lock +0 -71
  24. data/Rakefile +0 -10
  25. data/buckaruby.gemspec +0 -28
  26. data/lib/buckaruby/iban.rb +0 -29
  27. data/lib/buckaruby/ideal.rb +0 -21
  28. data/spec/buckaruby/configuration_spec.rb +0 -113
  29. data/spec/buckaruby/field_mapper_spec.rb +0 -69
  30. data/spec/buckaruby/gateway_spec.rb +0 -803
  31. data/spec/buckaruby/iban_spec.rb +0 -75
  32. data/spec/buckaruby/signature_spec.rb +0 -89
  33. data/spec/buckaruby/support/case_insensitive_hash_spec.rb +0 -74
  34. data/spec/fixtures/responses/callback_invalid_signature.txt +0 -1
  35. data/spec/fixtures/responses/callback_payment_amex.txt +0 -1
  36. data/spec/fixtures/responses/callback_payment_cancelled.txt +0 -1
  37. data/spec/fixtures/responses/callback_payment_empty_transaction_type.txt +0 -1
  38. data/spec/fixtures/responses/callback_payment_failed.txt +0 -1
  39. data/spec/fixtures/responses/callback_payment_giropay.txt +0 -1
  40. data/spec/fixtures/responses/callback_payment_pending.txt +0 -1
  41. data/spec/fixtures/responses/callback_payment_rejected.txt +0 -1
  42. data/spec/fixtures/responses/callback_payment_sepa.txt +0 -1
  43. data/spec/fixtures/responses/callback_payment_sofort.txt +0 -1
  44. data/spec/fixtures/responses/callback_payment_success.txt +0 -1
  45. data/spec/fixtures/responses/callback_payment_visa.txt +0 -1
  46. data/spec/fixtures/responses/callback_recurrent_sepa.txt +0 -1
  47. data/spec/fixtures/responses/callback_recurrent_visa.txt +0 -1
  48. data/spec/fixtures/responses/callback_refund_amex.txt +0 -1
  49. data/spec/fixtures/responses/callback_refund_ideal.txt +0 -1
  50. data/spec/fixtures/responses/callback_refund_paypal.txt +0 -1
  51. data/spec/fixtures/responses/callback_reversal_paypal.txt +0 -1
  52. data/spec/fixtures/responses/callback_reversal_sepa.txt +0 -1
  53. data/spec/fixtures/responses/callback_valid_signature.txt +0 -1
  54. data/spec/fixtures/responses/cancel_success.txt +0 -1
  55. data/spec/fixtures/responses/recurrent_transaction_success.txt +0 -1
  56. data/spec/fixtures/responses/refund_info_error.txt +0 -1
  57. data/spec/fixtures/responses/refund_info_success.txt +0 -1
  58. data/spec/fixtures/responses/refund_transaction_success.txt +0 -1
  59. data/spec/fixtures/responses/setup_transaction_success.txt +0 -1
  60. data/spec/fixtures/responses/specify_transaction_success.txt +0 -1
  61. data/spec/fixtures/responses/status_cancellable.txt +0 -1
  62. data/spec/fixtures/responses/status_noncancellable.txt +0 -1
  63. data/spec/fixtures/responses/status_success.txt +0 -1
  64. data/spec/spec_helper.rb +0 -16
data/.rubocop.yml DELETED
@@ -1,107 +0,0 @@
1
- # Buckaruby RuboCop configuration
2
-
3
- require:
4
- - rubocop-performance
5
- - rubocop-rspec
6
-
7
- AllCops:
8
- TargetRubyVersion: 2.4
9
- DisplayCopNames: true
10
- DisplayStyleGuide: true
11
-
12
-
13
- # We target 2.3, but still want to support 2.0.
14
- Gemspec/RequiredRubyVersion:
15
- Enabled: false
16
-
17
-
18
- Layout/LineLength:
19
- Enabled: false
20
-
21
-
22
- Lint/RaiseException:
23
- Enabled: true
24
-
25
- Lint/StructNewOverride:
26
- Enabled: true
27
-
28
-
29
- Metrics/AbcSize:
30
- Max: 30
31
-
32
- Metrics/BlockLength:
33
- Exclude:
34
- - 'spec/**/*.rb'
35
-
36
- Metrics/ClassLength:
37
- Enabled: false
38
-
39
- Metrics/CyclomaticComplexity:
40
- Max: 9
41
-
42
- Metrics/MethodLength:
43
- Enabled: false
44
-
45
- Metrics/ModuleLength:
46
- Enabled: false
47
-
48
- Metrics/PerceivedComplexity:
49
- Max: 9
50
-
51
-
52
- Naming/AccessorMethodName:
53
- Enabled: false
54
-
55
- Naming/MemoizedInstanceVariableName:
56
- Enabled: false
57
-
58
-
59
- RSpec/DescribedClass:
60
- EnforcedStyle: explicit
61
-
62
- RSpec/ExampleLength:
63
- Max: 17
64
-
65
- RSpec/MultipleExpectations:
66
- Max: 12
67
-
68
- RSpec/NamedSubject:
69
- Enabled: false
70
-
71
- RSpec/NestedGroups:
72
- Max: 4
73
-
74
-
75
- Style/BlockDelimiters:
76
- Exclude:
77
- - 'spec/**/*.rb'
78
-
79
- Style/ConditionalAssignment:
80
- Enabled: false
81
-
82
- Style/ExpandPathArguments:
83
- Enabled: false
84
-
85
- Style/GuardClause:
86
- Enabled: false
87
-
88
- Style/HashEachMethods:
89
- Enabled: true
90
-
91
- Style/HashTransformKeys:
92
- Enabled: true
93
-
94
- Style/HashTransformValues:
95
- Enabled: true
96
-
97
- Style/IfUnlessModifier:
98
- Enabled: false
99
-
100
- Style/StringLiterals:
101
- Enabled: false
102
-
103
- Style/SafeNavigation:
104
- Enabled: false
105
-
106
- Style/SymbolArray:
107
- Enabled: false
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in buckaruby.gemspec
6
- gemspec
7
-
8
- group :test do
9
- gem 'rubocop', '~> 0.81.0'
10
- gem 'rubocop-performance', '~> 1.5.2'
11
- gem 'rubocop-rspec', '~> 1.38.1'
12
- end
data/Gemfile.lock DELETED
@@ -1,71 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- buckaruby (1.7.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- addressable (2.8.0)
10
- public_suffix (>= 2.0.2, < 5.0)
11
- ast (2.4.0)
12
- crack (0.4.3)
13
- safe_yaml (~> 1.0.0)
14
- diff-lcs (1.4.4)
15
- hashdiff (1.0.0)
16
- jaro_winkler (1.5.4)
17
- parallel (1.19.1)
18
- parser (2.7.0.5)
19
- ast (~> 2.4.0)
20
- public_suffix (4.0.6)
21
- rainbow (3.0.0)
22
- rake (12.3.3)
23
- rexml (3.2.4)
24
- rspec (3.10.0)
25
- rspec-core (~> 3.10.0)
26
- rspec-expectations (~> 3.10.0)
27
- rspec-mocks (~> 3.10.0)
28
- rspec-core (3.10.0)
29
- rspec-support (~> 3.10.0)
30
- rspec-expectations (3.10.0)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.10.0)
33
- rspec-mocks (3.10.0)
34
- diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.10.0)
36
- rspec-support (3.10.0)
37
- rubocop (0.81.0)
38
- jaro_winkler (~> 1.5.1)
39
- parallel (~> 1.10)
40
- parser (>= 2.7.0.1)
41
- rainbow (>= 2.2.2, < 4.0)
42
- rexml
43
- ruby-progressbar (~> 1.7)
44
- unicode-display_width (>= 1.4.0, < 2.0)
45
- rubocop-performance (1.5.2)
46
- rubocop (>= 0.71.0)
47
- rubocop-rspec (1.38.1)
48
- rubocop (>= 0.68.1)
49
- ruby-progressbar (1.10.1)
50
- safe_yaml (1.0.5)
51
- unicode-display_width (1.7.0)
52
- webmock (2.3.2)
53
- addressable (>= 2.3.6)
54
- crack (>= 0.3.2)
55
- hashdiff
56
-
57
- PLATFORMS
58
- ruby
59
-
60
- DEPENDENCIES
61
- buckaruby!
62
- bundler (~> 1.7)
63
- rake (~> 12.3)
64
- rspec (~> 3.0)
65
- rubocop (~> 0.81.0)
66
- rubocop-performance (~> 1.5.2)
67
- rubocop-rspec (~> 1.38.1)
68
- webmock (~> 2.3)
69
-
70
- BUNDLED WITH
71
- 1.17.3
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
- require "rubocop/rake_task"
6
-
7
- RSpec::Core::RakeTask.new(:spec)
8
- RuboCop::RakeTask.new(:rubocop)
9
-
10
- task default: [:spec, :rubocop]
data/buckaruby.gemspec DELETED
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'buckaruby/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = "buckaruby"
9
- spec.version = Buckaruby::VERSION
10
- spec.authors = ["Kentaa"]
11
- spec.email = ["support@kentaa.nl"]
12
- spec.summary = "Ruby library for communicating with the Buckaroo Payment Engine 3.0."
13
- spec.description = "The Buckaruby gem provides a Ruby library for communicating with the Buckaroo Payment Engine 3.0."
14
- spec.homepage = "https://github.com/KentaaNL/buckaruby"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^spec/})
20
- spec.require_paths = ["lib"]
21
-
22
- spec.required_ruby_version = ">= 2.0.0"
23
-
24
- spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "rake", "~> 12.3"
26
- spec.add_development_dependency "rspec", "~> 3.0"
27
- spec.add_development_dependency "webmock", "~> 2.3"
28
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Buckaruby
4
- # Helper for calculating the IBAN for a given account number, bank code and country code.
5
- module Iban
6
- module_function
7
-
8
- def calculate_iban(account_number, bank_code, country_code = "NL")
9
- if account_number.nil? || account_number.to_s.empty?
10
- raise ArgumentError, "Invalid account number"
11
- end
12
-
13
- if bank_code.nil? || bank_code.to_s.empty?
14
- raise ArgumentError, "Invalid bank code"
15
- end
16
-
17
- if country_code.nil? || !country_code.match(/^[A-Z]{2}$/)
18
- raise ArgumentError, "Invalid or unknown country code"
19
- end
20
-
21
- account_identification = bank_code + account_number.rjust(10, '0')
22
- country_code_added = account_identification + country_code
23
- all_numbers = country_code_added.gsub(/[A-Z]/) { |p| (p.respond_to?(:ord) ? p.ord : p[0]) - 55 } + '00'
24
- verification_number = (98 - (all_numbers.to_i % 97)).to_s.rjust(2, '0')
25
-
26
- country_code + verification_number + account_identification
27
- end
28
- end
29
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Buckaruby
4
- module Ideal
5
- ISSUERS = {
6
- "ABNANL2A" => "ABN AMRO",
7
- "ASNBNL21" => "ASN Bank",
8
- "BUNQNL2A" => "bunq",
9
- "HANDNL2A" => "Handelsbanken",
10
- "INGBNL2A" => "ING",
11
- "KNABNL2H" => "Knab",
12
- "MOYONL21" => "Moneyou",
13
- "RABONL2U" => "Rabobank",
14
- "RBRBNL21" => "Regiobank",
15
- "REVOLT21" => "Revolut",
16
- "SNSBNL2A" => "SNS Bank",
17
- "TRIONL2U" => "Triodos",
18
- "FVLBNL22" => "Van Lanschot"
19
- }.freeze
20
- end
21
- end
@@ -1,113 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Buckaruby::Configuration do
6
- describe '#website' do
7
- it 'sets the website from options' do
8
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D")
9
- expect(config.website).to eq("12345678")
10
- end
11
-
12
- it 'raises an exception when website is missing' do
13
- expect {
14
- Buckaruby::Configuration.new(secret: "7C222FB2927D828AF22F592134E8932480637C0D")
15
- }.to raise_error(ArgumentError)
16
- end
17
- end
18
-
19
- describe '#secret' do
20
- it 'sets the secret from options' do
21
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D")
22
- expect(config.secret).to eq("7C222FB2927D828AF22F592134E8932480637C0D")
23
- end
24
-
25
- it 'raises an exception when secret is missing' do
26
- expect {
27
- Buckaruby::Configuration.new(website: "12345678")
28
- }.to raise_error(ArgumentError)
29
- end
30
- end
31
-
32
- describe '#mode' do
33
- it 'returns test when no mode is passed' do
34
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D")
35
- expect(config.mode).to eq(:test)
36
- end
37
-
38
- it 'returns test when mode test is passed' do
39
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :test)
40
- expect(config.mode).to eq(:test)
41
- end
42
-
43
- it 'returns production when mode production is passed' do
44
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :production)
45
- expect(config.mode).to eq(:production)
46
- end
47
-
48
- it 'raises an exception when an invalid mode is passed' do
49
- expect {
50
- Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :invalid)
51
- }.to raise_error(ArgumentError)
52
- end
53
- end
54
-
55
- describe '#hash_method' do
56
- it 'raises an exception when an invalid hash method is passed' do
57
- expect {
58
- Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: :invalid)
59
- }.to raise_error(ArgumentError)
60
- end
61
-
62
- it 'accepts SHA-1 as hash method' do
63
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: 'SHA1')
64
- expect(config.hash_method).to eq(:sha1)
65
- end
66
-
67
- it 'accepts SHA-256 as hash method' do
68
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: :SHA256)
69
- expect(config.hash_method).to eq(:sha256)
70
- end
71
-
72
- it 'accepts SHA-512 as hash method' do
73
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: :sha512)
74
- expect(config.hash_method).to eq(:sha512)
75
- end
76
- end
77
-
78
- describe '#test?' do
79
- it 'returns true when mode is test' do
80
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :test)
81
- expect(config.test?).to be true
82
- end
83
-
84
- it 'returns false when mode is production' do
85
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :production)
86
- expect(config.test?).to be false
87
- end
88
- end
89
-
90
- describe '#production?' do
91
- it 'returns false when mode is test' do
92
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :test)
93
- expect(config.production?).to be false
94
- end
95
-
96
- it 'returns true when mode is production' do
97
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :production)
98
- expect(config.production?).to be true
99
- end
100
- end
101
-
102
- describe '#api_url' do
103
- it 'returns the test URL when mode is test' do
104
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :test)
105
- expect(config.api_url).to eq("https://testcheckout.buckaroo.nl/nvp/")
106
- end
107
-
108
- it 'returns the production URL when mode is production' do
109
- config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :production)
110
- expect(config.api_url).to eq("https://checkout.buckaroo.nl/nvp/")
111
- end
112
- end
113
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Buckaruby::FieldMapper do
6
- describe '.map_fields' do
7
- let(:fields) do
8
- {
9
- brq_services_1_description: "iDEAL",
10
- brq_services_1_name: "ideal",
11
- brq_services_1_version: "2",
12
- brq_services_1_supportedcurrencies_1_code: "EUR",
13
- brq_services_1_supportedcurrencies_1_isonumber: "978",
14
- brq_services_1_supportedcurrencies_1_name: "Euro",
15
- brq_services_2_description: "Visa",
16
- brq_services_2_name: "visa",
17
- brq_services_2_version: "1",
18
- brq_services_2_supportedcurrencies_1_code: "GBP",
19
- brq_services_2_supportedcurrencies_1_isonumber: "826",
20
- brq_services_2_supportedcurrencies_1_name: "Pond",
21
- brq_services_2_supportedcurrencies_2_code: "USD",
22
- brq_services_2_supportedcurrencies_2_isonumber: "840",
23
- brq_services_2_supportedcurrencies_2_name: "US Dollar"
24
- }
25
- end
26
-
27
- it 'maps NVP fields to arrays and hashes' do
28
- services = Buckaruby::FieldMapper.map_fields(fields, :brq_services)
29
- expect(services).to be_an_instance_of(Array)
30
- expect(services.count).to eq(2)
31
-
32
- ideal = services.first
33
- expect(ideal).to be_an_instance_of(Buckaruby::Support::CaseInsensitiveHash)
34
- expect(ideal[:description]).to eq("iDEAL")
35
- expect(ideal[:name]).to eq("ideal")
36
- expect(ideal[:version]).to eq("2")
37
-
38
- visa = services.last
39
- expect(visa).to be_an_instance_of(Buckaruby::Support::CaseInsensitiveHash)
40
- expect(visa[:description]).to eq("Visa")
41
- expect(visa[:name]).to eq("visa")
42
- expect(visa[:version]).to eq("1")
43
- end
44
-
45
- it 'maps NVP subfields to arrays and hashes' do
46
- services = Buckaruby::FieldMapper.map_fields(fields, :brq_services)
47
-
48
- currencies = services.first[:supportedcurrencies]
49
- expect(currencies).to be_an_instance_of(Array)
50
- expect(currencies.count).to eq(1)
51
-
52
- currency = currencies.first
53
- expect(currency).to be_an_instance_of(Buckaruby::Support::CaseInsensitiveHash)
54
- expect(currency[:code]).to eq("EUR")
55
- expect(currency[:isonumber]).to eq("978")
56
- expect(currency[:name]).to eq("Euro")
57
-
58
- currencies = services.last[:supportedcurrencies]
59
- expect(currencies).to be_an_instance_of(Array)
60
- expect(currencies.count).to eq(2)
61
-
62
- currency = currencies.first
63
- expect(currency).to be_an_instance_of(Buckaruby::Support::CaseInsensitiveHash)
64
- expect(currency[:code]).to eq("GBP")
65
- expect(currency[:isonumber]).to eq("826")
66
- expect(currency[:name]).to eq("Pond")
67
- end
68
- end
69
- end