buckaruby 1.2.0 → 1.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4513790fda002b5a98011b97768f0e4daad118822dc2d8acfbb0eabe259f86b
4
- data.tar.gz: 86fcda3eaf10ff9129d074c236e0e1b4037a3c905ab48cc72c8769e1bae22fd2
3
+ metadata.gz: cd18b05ba430e3bacfcc57c185fbd9816bab502952952b29779e77020b0b0434
4
+ data.tar.gz: 907f88a18e966207aaf0bed93ec129c5e8a7768470fe9604fab99d8058823269
5
5
  SHA512:
6
- metadata.gz: b50d76de5cebb6bae5c698b7f052619657a2afb9745e1c7dcf235d9be21e83ca4f05dc23be13dede2881c82fda4b47a1d117dfe90629a7b3d942b54dbab9a2ab
7
- data.tar.gz: d6a9032e3b38d91ff1d4353aec269c558dbb0a034282ece2fbd512f69e000ccb65e2c738c0f2992bf040b0315bb8024bb932c7000c212a8c62846aff178dd75c
6
+ metadata.gz: 00fcdbc6d4459d0af2762b1ca738f4970d50e50421db3a1409c6ff681cc8c46a05a62e34d3544a9d0642337fc37feed302c0412b390498f2a3dc97b3a0f22808
7
+ data.tar.gz: bdcb6e097e78763a40ee8ac317021ba730be60da19984c0a58b7b0ee2d0c38593a460f39e061ef5aa10e0596db6f9415d73df83446c2e05ec31c1d6314ea2a3a
data/.rubocop.yml CHANGED
@@ -5,7 +5,7 @@ require:
5
5
  - rubocop-rspec
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 2.3
8
+ TargetRubyVersion: 2.4
9
9
  DisplayCopNames: true
10
10
  DisplayStyleGuide: true
11
11
 
@@ -15,6 +15,17 @@ Gemspec/RequiredRubyVersion:
15
15
  Enabled: false
16
16
 
17
17
 
18
+ Layout/LineLength:
19
+ Enabled: false
20
+
21
+
22
+ Lint/RaiseException:
23
+ Enabled: true
24
+
25
+ Lint/StructNewOverride:
26
+ Enabled: true
27
+
28
+
18
29
  Metrics/AbcSize:
19
30
  Max: 30
20
31
 
@@ -28,9 +39,6 @@ Metrics/ClassLength:
28
39
  Metrics/CyclomaticComplexity:
29
40
  Max: 9
30
41
 
31
- Metrics/LineLength:
32
- Enabled: false
33
-
34
42
  Metrics/MethodLength:
35
43
  Enabled: false
36
44
 
@@ -52,7 +60,7 @@ RSpec/DescribedClass:
52
60
  EnforcedStyle: explicit
53
61
 
54
62
  RSpec/ExampleLength:
55
- Max: 15
63
+ Max: 17
56
64
 
57
65
  RSpec/MultipleExpectations:
58
66
  Max: 12
@@ -77,6 +85,15 @@ Style/ExpandPathArguments:
77
85
  Style/GuardClause:
78
86
  Enabled: false
79
87
 
88
+ Style/HashEachMethods:
89
+ Enabled: true
90
+
91
+ Style/HashTransformKeys:
92
+ Enabled: true
93
+
94
+ Style/HashTransformValues:
95
+ Enabled: true
96
+
80
97
  Style/IfUnlessModifier:
81
98
  Enabled: false
82
99
 
data/.travis.yml CHANGED
@@ -5,7 +5,7 @@ before_install:
5
5
  - gem update --system
6
6
  - gem install bundler -v '< 2'
7
7
  rvm:
8
- - 2.3.8
9
- - 2.4.6
10
- - 2.5.5
11
- - 2.6.3
8
+ - 2.4.10
9
+ - 2.5.9
10
+ - 2.6.7
11
+ - 2.7.3
data/CHANGELOG.md CHANGED
@@ -1,19 +1,41 @@
1
1
  # Buckaruby changelog
2
2
 
3
- ## 1.2.0 (2019-08-11)
3
+ ## 1.6.0 (2021-04-15)
4
4
 
5
- - Added support for sending custom & additional variables with the request.
5
+ - Add Revolut to the list of iDEAL issuers.
6
+
7
+ ## 1.5.0 (2020-11-17)
8
+
9
+ - Add payment method Sofort.
10
+
11
+ ## 1.4.0 (2020-04-06)
12
+
13
+ - Add `payment_methods` to retrieve all payment methods enabled by Buckaroo and supported by this library.
14
+ - Add `specify_transaction` to get a specification for setting up a transaction.
15
+ - Fix calculating the signature for long responses and indexed fields.
16
+
17
+ ## 1.3.1 (2019-12-04)
18
+
19
+ - Update list of credit card transaction types.
20
+
21
+ ## 1.3.0 (2019-10-08)
22
+
23
+ - Add payment method American Express.
24
+
25
+ ## 1.2.0 (2019-08-06)
26
+
27
+ - Add support for sending custom & additional variables with the request.
6
28
 
7
29
  ## 1.1.1 (2018-11-30)
8
30
 
9
- - Added Handelsbanken to the list of iDEAL issuers.
31
+ - Add Handelsbanken to the list of iDEAL issuers.
10
32
 
11
33
  ## 1.1.0 (2018-06-01)
12
34
 
13
- - Added payment method iDEAL processing.
14
- - Added Moneyou to the list of iDEAL issuers.
15
- - Implemented refund transaction.
16
- - Implemented cancel transaction.
35
+ - Add payment method iDEAL processing.
36
+ - Add Moneyou to the list of iDEAL issuers.
37
+ - Implement refund transaction.
38
+ - Implement cancel transaction.
17
39
 
18
40
  ## 1.0.2 (2017-08-25)
19
41
 
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  group :test do
9
- gem 'rubocop', '~> 0.74.0'
10
- gem 'rubocop-performance', '~> 1.4.0'
11
- gem 'rubocop-rspec', '~> 1.35.0'
9
+ gem 'rubocop', '~> 0.81.0'
10
+ gem 'rubocop-performance', '~> 1.5.2'
11
+ gem 'rubocop-rspec', '~> 1.38.1'
12
12
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- buckaruby (1.2.0)
4
+ buckaruby (1.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -11,42 +11,44 @@ GEM
11
11
  ast (2.4.0)
12
12
  crack (0.4.3)
13
13
  safe_yaml (~> 1.0.0)
14
- diff-lcs (1.3)
14
+ diff-lcs (1.4.4)
15
15
  hashdiff (1.0.0)
16
- jaro_winkler (1.5.3)
17
- parallel (1.17.0)
18
- parser (2.6.3.0)
16
+ jaro_winkler (1.5.4)
17
+ parallel (1.19.1)
18
+ parser (2.7.0.5)
19
19
  ast (~> 2.4.0)
20
20
  public_suffix (3.1.1)
21
21
  rainbow (3.0.0)
22
- rake (10.5.0)
23
- rspec (3.8.0)
24
- rspec-core (~> 3.8.0)
25
- rspec-expectations (~> 3.8.0)
26
- rspec-mocks (~> 3.8.0)
27
- rspec-core (3.8.2)
28
- rspec-support (~> 3.8.0)
29
- rspec-expectations (3.8.4)
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)
30
31
  diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.8.0)
32
- rspec-mocks (3.8.1)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-mocks (3.10.0)
33
34
  diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.8.0)
35
- rspec-support (3.8.2)
36
- rubocop (0.74.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.0)
37
+ rubocop (0.81.0)
37
38
  jaro_winkler (~> 1.5.1)
38
39
  parallel (~> 1.10)
39
- parser (>= 2.6)
40
+ parser (>= 2.7.0.1)
40
41
  rainbow (>= 2.2.2, < 4.0)
42
+ rexml
41
43
  ruby-progressbar (~> 1.7)
42
- unicode-display_width (>= 1.4.0, < 1.7)
43
- rubocop-performance (1.4.1)
44
+ unicode-display_width (>= 1.4.0, < 2.0)
45
+ rubocop-performance (1.5.2)
44
46
  rubocop (>= 0.71.0)
45
- rubocop-rspec (1.35.0)
46
- rubocop (>= 0.60.0)
47
+ rubocop-rspec (1.38.1)
48
+ rubocop (>= 0.68.1)
47
49
  ruby-progressbar (1.10.1)
48
50
  safe_yaml (1.0.5)
49
- unicode-display_width (1.6.0)
51
+ unicode-display_width (1.7.0)
50
52
  webmock (2.3.2)
51
53
  addressable (>= 2.3.6)
52
54
  crack (>= 0.3.2)
@@ -58,11 +60,11 @@ PLATFORMS
58
60
  DEPENDENCIES
59
61
  buckaruby!
60
62
  bundler (~> 1.7)
61
- rake (~> 10.0)
63
+ rake (~> 12.3)
62
64
  rspec (~> 3.0)
63
- rubocop (~> 0.74.0)
64
- rubocop-performance (~> 1.4.0)
65
- rubocop-rspec (~> 1.35.0)
65
+ rubocop (~> 0.81.0)
66
+ rubocop-performance (~> 1.5.2)
67
+ rubocop-rspec (~> 1.38.1)
66
68
  webmock (~> 2.3)
67
69
 
68
70
  BUNDLED WITH
data/README.md CHANGED
@@ -51,6 +51,14 @@ gateway = Buckaruby::Gateway.new(
51
51
 
52
52
  You can override the default mode with the parameter `mode`.
53
53
 
54
+ ### Payment methods
55
+
56
+ To retrieve the payment methods enabled in Buckaroo and supported by this library, you can use the method `payment_methods`. This method will return an array with all payment methods that can be used. See also `Buckaruby::PaymentMethod` for predefined constants.
57
+
58
+ ```ruby
59
+ payment_methods = gateway.payment_methods
60
+ ```
61
+
54
62
  ### Start transaction
55
63
 
56
64
  To start a new transaction, use the method `setup_transaction`:
@@ -203,6 +211,18 @@ puts response.custom[:foo]
203
211
  puts response.additional[:myreference]
204
212
  ````
205
213
 
214
+ ### Transaction request specification
215
+
216
+ To retrieve a specification about what needs to be sent with transaction request, you can use the method `specify_transaction`. The parameter `payment_method` is optional. When supplied it will only send the specification for that payment method.
217
+
218
+ This request is also used by the `payment_methods` method to determine which services (payment methods) are enabled in Buckaroo.
219
+
220
+ ```ruby
221
+ response = gateway.specify_transaction(payment_method: Buckaruby::PaymentMethod::IDEAL)
222
+ ```
223
+
224
+ See `Buckaruby::TransactionSpecificationResponse` for more details.
225
+
206
226
  ### Error handling
207
227
 
208
228
  When missing or invalid parameters are passed to any method, an `ArgumentError` will be raised.
data/buckaruby.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.required_ruby_version = ">= 2.0.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rake", "~> 12.3"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  spec.add_development_dependency "webmock", "~> 2.3"
28
28
  end
data/lib/buckaruby.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'buckaruby/support/case_insensitive_hash'
4
-
5
3
  require_relative 'buckaruby/action'
6
4
  require_relative 'buckaruby/currency'
7
5
  require_relative 'buckaruby/ideal'
@@ -13,6 +11,7 @@ require_relative 'buckaruby/transaction_type'
13
11
 
14
12
  require_relative 'buckaruby/configuration'
15
13
  require_relative 'buckaruby/exception'
14
+ require_relative 'buckaruby/field_mapper'
16
15
  require_relative 'buckaruby/gateway'
17
16
  require_relative 'buckaruby/iban'
18
17
  require_relative 'buckaruby/request'
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'support/case_insensitive_hash'
4
+
5
+ module Buckaruby
6
+ # Map NVP fields to hashes and multiple values (with index) to arrays.
7
+ module FieldMapper
8
+ module_function
9
+
10
+ def map_fields(params, prefix)
11
+ results = []
12
+ index = 1
13
+
14
+ loop do
15
+ index_key = "#{prefix}_#{index}_" # brq_services_1_
16
+ index_length = index_key.split(/_[0-9]*_/).length # 1
17
+
18
+ # Get all fields starting with prefix and index.
19
+ fields = params.select { |key| key.to_s.start_with?(index_key) }
20
+
21
+ break if fields.empty?
22
+
23
+ result = Support::CaseInsensitiveHash.new
24
+
25
+ fields.each do |key, value|
26
+ splitted_key = key.to_s.split(/_[0-9]*_/) # ["brq_services", "name"]
27
+ key_length = splitted_key.length # 2
28
+ new_key = splitted_key[index_length] # name
29
+
30
+ if key_length == index_length + 1
31
+ # Add normal fields to the result.
32
+ result[new_key] = value
33
+ else
34
+ # Recursively map indexed fields.
35
+ result[new_key] ||= begin
36
+ new_prefix = [index_key, new_key].join
37
+ map_fields(fields, new_prefix)
38
+ end
39
+ end
40
+ end
41
+
42
+ break if result.empty?
43
+
44
+ results << result
45
+
46
+ index += 1
47
+ end
48
+
49
+ results
50
+ end
51
+ end
52
+ end
@@ -17,7 +17,21 @@ module Buckaruby
17
17
  @logger = config.logger
18
18
  end
19
19
 
20
- # Get a list with payment issuers.
20
+ # Returns the payment methods enabled by Buckaroo and supported by this library.
21
+ def payment_methods
22
+ valid_payment_methods = [
23
+ PaymentMethod::IDEAL, PaymentMethod::IDEAL_PROCESSING, PaymentMethod::VISA, PaymentMethod::MASTER_CARD,
24
+ PaymentMethod::MAESTRO, PaymentMethod::AMERICAN_EXPRESS, PaymentMethod::SEPA_DIRECT_DEBIT,
25
+ PaymentMethod::PAYPAL, PaymentMethod::BANCONTACT_MISTER_CASH, PaymentMethod::SOFORT
26
+ ]
27
+
28
+ response = execute_request(:specify_transaction)
29
+ services = response.services.map { |service| service[:name] }
30
+
31
+ services & valid_payment_methods
32
+ end
33
+
34
+ # Get a list with payment issuers (currently only iDEAL).
21
35
  def issuers(payment_method)
22
36
  if payment_method != PaymentMethod::IDEAL && payment_method != PaymentMethod::IDEAL_PROCESSING
23
37
  raise ArgumentError, "Invalid payment method, only iDEAL is supported."
@@ -46,6 +60,13 @@ module Buckaruby
46
60
  execute_request(:recurrent_transaction, options)
47
61
  end
48
62
 
63
+ # Retrieve the specification for setting up a transaction.
64
+ def specify_transaction(options = {})
65
+ @logger.debug("[specify_transaction] options=#{options.inspect}")
66
+
67
+ execute_request(:specify_transaction, options)
68
+ end
69
+
49
70
  # Checks if a transaction is refundable.
50
71
  def refundable?(options = {})
51
72
  @logger.debug("[refundable?] options=#{options.inspect}")
@@ -150,8 +171,9 @@ module Buckaruby
150
171
  validate_amount!(options)
151
172
 
152
173
  valid_payment_methods = [
153
- PaymentMethod::IDEAL, PaymentMethod::IDEAL_PROCESSING, PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO,
154
- PaymentMethod::SEPA_DIRECT_DEBIT, PaymentMethod::PAYPAL, PaymentMethod::BANCONTACT_MISTER_CASH
174
+ PaymentMethod::IDEAL, PaymentMethod::IDEAL_PROCESSING, PaymentMethod::VISA, PaymentMethod::MASTER_CARD,
175
+ PaymentMethod::MAESTRO, PaymentMethod::AMERICAN_EXPRESS, PaymentMethod::SEPA_DIRECT_DEBIT,
176
+ PaymentMethod::PAYPAL, PaymentMethod::BANCONTACT_MISTER_CASH, PaymentMethod::SOFORT
155
177
  ]
156
178
  validate_payment_method!(options, valid_payment_methods)
157
179
 
@@ -191,7 +213,7 @@ module Buckaruby
191
213
  validate_amount!(options)
192
214
 
193
215
  valid_payment_methods = [
194
- PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO,
216
+ PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO, PaymentMethod::AMERICAN_EXPRESS,
195
217
  PaymentMethod::SEPA_DIRECT_DEBIT, PaymentMethod::PAYPAL
196
218
  ]
197
219
  validate_payment_method!(options, valid_payment_methods)
@@ -223,7 +245,7 @@ module Buckaruby
223
245
  end
224
246
 
225
247
  # Build and execute a request.
226
- def execute_request(request_type, options)
248
+ def execute_request(request_type, options = {})
227
249
  request = build_request(request_type)
228
250
  response = request.execute(options)
229
251
 
@@ -232,6 +254,8 @@ module Buckaruby
232
254
  SetupTransactionResponse.new(response, config)
233
255
  when :recurrent_transaction
234
256
  RecurrentTransactionResponse.new(response, config)
257
+ when :specify_transaction
258
+ TransactionSpecificationResponse.new(response, config)
235
259
  when :refund_transaction
236
260
  RefundTransactionResponse.new(response, config)
237
261
  when :refund_info
@@ -250,6 +274,8 @@ module Buckaruby
250
274
  SetupTransactionRequest.new(config)
251
275
  when :recurrent_transaction
252
276
  RecurrentTransactionRequest.new(config)
277
+ when :specify_transaction
278
+ TransactionSpecificationRequest.new(config)
253
279
  when :refund_transaction
254
280
  RefundTransactionRequest.new(config)
255
281
  when :refund_info
@@ -2,8 +2,10 @@
2
2
 
3
3
  module Buckaruby
4
4
  # Helper for calculating the IBAN for a given account number, bank code and country code.
5
- class Iban
6
- def self.calculate_iban(account_number, bank_code, country_code = "NL")
5
+ module Iban
6
+ module_function
7
+
8
+ def calculate_iban(account_number, bank_code, country_code = "NL")
7
9
  if account_number.nil? || account_number.to_s.empty?
8
10
  raise ArgumentError, "Invalid account number"
9
11
  end