buckaruby 1.1.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46d2621253829070076f927150389b8dcf796576689e6b3a623a87777c31ddde
4
- data.tar.gz: 73bf6810bb4b140331c5cebd8c5635daff496579e0950a495f2192fd5299914f
3
+ metadata.gz: '0919fe881e55079692ccd64dc45cae08ce54073ec33e2176b0bbfada27a333de'
4
+ data.tar.gz: b4b3a163d7365c76191d6b7988d82a40f50686adb318dac85f37f2baca9cae10
5
5
  SHA512:
6
- metadata.gz: dacaf86700c9f959c9b888e4fa428d00eecc828aa20ea778973c507b9891d94c292243d3ff6dea9823dc48016549748257fa6888e1f64195ae836b6f975f471b
7
- data.tar.gz: b07ac9a4d3295111ab5ecf80d3edfe294cb81e2bff867b44ef677c9608b9c448de33afff04e18c5d9500f29f24c4feec7193e46d9d13f385fa7ad3bbcae16eb1
6
+ metadata.gz: f9d4e71c901fccf8fcedc932e1c7c7e0086dffad4d6611dfc45343a0b62f5ce9c2f8bff764654be3e56006baccb78225fb97e03b1bb53c86b5f1bb1bc7839120
7
+ data.tar.gz: 5a54bc947866b1973a72023dcf3092850df0d9379b03eda9a3f5e4922f93418cae8be615f03d66804c9a6ea554bb110164ca59d7a57dd549b9705b1335e30b48
data/.gitignore CHANGED
@@ -6,7 +6,6 @@
6
6
  .rvmrc
7
7
  .ruby-version
8
8
  .ruby-gemset
9
- Gemfile.lock
10
9
  InstalledFiles
11
10
  _yardoc
12
11
  coverage
@@ -1,14 +1,31 @@
1
1
  # Buckaruby RuboCop configuration
2
2
 
3
+ require:
4
+ - rubocop-performance
5
+ - rubocop-rspec
6
+
3
7
  AllCops:
4
8
  TargetRubyVersion: 2.3
5
9
  DisplayCopNames: true
6
10
  DisplayStyleGuide: true
7
11
 
12
+
8
13
  # We target 2.3, but still want to support 2.0.
9
14
  Gemspec/RequiredRubyVersion:
10
15
  Enabled: false
11
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
+
12
29
  Metrics/AbcSize:
13
30
  Max: 30
14
31
 
@@ -22,9 +39,6 @@ Metrics/ClassLength:
22
39
  Metrics/CyclomaticComplexity:
23
40
  Max: 9
24
41
 
25
- Metrics/LineLength:
26
- Enabled: false
27
-
28
42
  Metrics/MethodLength:
29
43
  Enabled: false
30
44
 
@@ -34,12 +48,30 @@ Metrics/ModuleLength:
34
48
  Metrics/PerceivedComplexity:
35
49
  Max: 9
36
50
 
51
+
37
52
  Naming/AccessorMethodName:
38
53
  Enabled: false
39
54
 
40
55
  Naming/MemoizedInstanceVariableName:
41
56
  Enabled: false
42
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
+
43
75
  Style/BlockDelimiters:
44
76
  Exclude:
45
77
  - 'spec/**/*.rb'
@@ -53,6 +85,15 @@ Style/ExpandPathArguments:
53
85
  Style/GuardClause:
54
86
  Enabled: false
55
87
 
88
+ Style/HashEachMethods:
89
+ Enabled: true
90
+
91
+ Style/HashTransformKeys:
92
+ Enabled: true
93
+
94
+ Style/HashTransformValues:
95
+ Enabled: true
96
+
56
97
  Style/IfUnlessModifier:
57
98
  Enabled: false
58
99
 
@@ -3,9 +3,9 @@ sudo: false
3
3
  cache: bundler
4
4
  before_install:
5
5
  - gem update --system
6
- - gem install bundler
6
+ - gem install bundler -v '< 2'
7
7
  rvm:
8
- - 2.2.10
9
- - 2.3.8
10
- - 2.4.5
11
- - 2.5.3
8
+ - 2.4.10
9
+ - 2.5.8
10
+ - 2.6.6
11
+ - 2.7.2
@@ -1,13 +1,37 @@
1
1
  # Buckaruby changelog
2
2
 
3
+ ## 1.5.0 (2020-11-17)
4
+
5
+ - Add payment method Sofort.
6
+
7
+ ## 1.4.0 (2020-04-06)
8
+
9
+ - Add `payment_methods` to retrieve all payment methods enabled by Buckaroo and supported by this library.
10
+ - Add `specify_transaction` to get a specification for setting up a transaction.
11
+ - Fix calculating the signature for long responses and indexed fields.
12
+
13
+ ## 1.3.1 (2019-12-04)
14
+
15
+ - Update list of credit card transaction types.
16
+
17
+ ## 1.3.0 (2019-10-08)
18
+
19
+ - Add payment method American Express.
20
+
21
+ ## 1.2.0 (2019-08-06)
22
+
23
+ - Add support for sending custom & additional variables with the request.
24
+
3
25
  ## 1.1.1 (2018-11-30)
4
- - Added Handelsbanken to the list of iDEAL issuers.
26
+
27
+ - Add Handelsbanken to the list of iDEAL issuers.
5
28
 
6
29
  ## 1.1.0 (2018-06-01)
7
- - Added payment method iDEAL processing.
8
- - Added Moneyou to the list of iDEAL issuers.
9
- - Implemented refund transaction.
10
- - Implemented cancel transaction.
30
+
31
+ - Add payment method iDEAL processing.
32
+ - Add Moneyou to the list of iDEAL issuers.
33
+ - Implement refund transaction.
34
+ - Implement cancel transaction.
11
35
 
12
36
  ## 1.0.2 (2017-08-25)
13
37
 
data/Gemfile CHANGED
@@ -5,4 +5,8 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in buckaruby.gemspec
6
6
  gemspec
7
7
 
8
- gem 'rubocop', '~> 0.60.0', group: :test
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
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ buckaruby (1.5.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.6.0)
10
+ public_suffix (>= 2.0.2, < 4.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 (3.1.1)
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/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`:
@@ -170,6 +178,51 @@ response = gateway.status(transaction_id: 12345)
170
178
 
171
179
  See `Buckaruby::StatusResponse` for more details.
172
180
 
181
+ ### Merchant variables
182
+
183
+ You can send custom variables and additional variables with each request.
184
+
185
+ Use the parameter `custom` to build a hash with custom variables and `additional` for building a hash with additional variabeles.
186
+ For example:
187
+
188
+ ```ruby
189
+ options = {
190
+ amount: 10,
191
+ payment_method: Buckaruby::PaymentMethod::IDEAL,
192
+ payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first,
193
+ invoicenumber: "12345",
194
+ return_url: "http://www.return.url/",
195
+ custom: {
196
+ foo: "bar",
197
+ quux: "42"
198
+ },
199
+ additional: {
200
+ myreference: "12345"
201
+ }
202
+ }
203
+
204
+ response = gateway.setup_transaction(options)
205
+ ```
206
+
207
+ In the response, you can retrieve the custom and additional variables with the methods `custom` and `additional`:
208
+
209
+ ```ruby
210
+ puts response.custom[:foo]
211
+ puts response.additional[:myreference]
212
+ ````
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
+
173
226
  ### Error handling
174
227
 
175
228
  When missing or invalid parameters are passed to any method, an `ArgumentError` will be raised.
@@ -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"
26
- spec.add_development_dependency "rspec", "~> 3.5.0", ">= 3.5.0"
27
- spec.add_development_dependency "webmock", "~> 2.3", ">= 2.3.2"
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
28
  end
@@ -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