buckaruby 1.3.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +23 -0
- data/.rubocop.yml +22 -5
- data/CHANGELOG.md +25 -7
- data/Gemfile +3 -3
- data/Gemfile.lock +30 -28
- data/README.md +21 -1
- data/buckaruby.gemspec +1 -1
- data/lib/buckaruby.rb +1 -2
- data/lib/buckaruby/field_mapper.rb +52 -0
- data/lib/buckaruby/gateway.rb +30 -4
- data/lib/buckaruby/iban.rb +4 -2
- data/lib/buckaruby/ideal.rb +4 -3
- data/lib/buckaruby/operation.rb +1 -0
- data/lib/buckaruby/payment_method.rb +2 -0
- data/lib/buckaruby/request.rb +24 -0
- data/lib/buckaruby/response.rb +20 -84
- data/lib/buckaruby/signature.rb +22 -4
- data/lib/buckaruby/transaction_status.rb +19 -0
- data/lib/buckaruby/transaction_type.rb +81 -0
- data/lib/buckaruby/version.rb +1 -1
- data/spec/buckaruby/field_mapper_spec.rb +69 -0
- data/spec/buckaruby/gateway_spec.rb +90 -2
- data/spec/buckaruby/signature_spec.rb +6 -0
- data/spec/fixtures/responses/callback_payment_giropay.txt +1 -0
- data/spec/fixtures/responses/callback_payment_sofort.txt +1 -0
- data/spec/fixtures/responses/specify_transaction_success.txt +1 -0
- metadata +18 -9
- data/.travis.yml +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbc9889fbec21efa16afde817a492b839b2c69ae3c2d442ed5a4d0f8631d27ca
|
4
|
+
data.tar.gz: 3e09c5226383463a8364a16dcd21f70ace68632cede58ba48bc6c9d00e67470f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f89515b95016c1f954b9862de10c98c8a9d82027a6276307c60ae73a68075c880d36ceb560a5858acc9eafc404737cabc096c16572f09f645f8324b95194d74
|
7
|
+
data.tar.gz: 38a8749448b840d033f60c2698f050594f4feef63ace780122801c6fe5a2739cc3ab4a67c364358a66132b59a1233c177fa89fb28ae206c8f98b180b1fa45eae
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- 1.x
|
7
|
+
pull_request:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0']
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby-version }}
|
21
|
+
bundler-cache: true
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -5,7 +5,7 @@ require:
|
|
5
5
|
- rubocop-rspec
|
6
6
|
|
7
7
|
AllCops:
|
8
|
-
TargetRubyVersion: 2.
|
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:
|
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/CHANGELOG.md
CHANGED
@@ -1,27 +1,45 @@
|
|
1
1
|
# Buckaruby changelog
|
2
2
|
|
3
|
+
## 1.7.0 (2021-07-16)
|
4
|
+
|
5
|
+
- Add payment method Giropay.
|
6
|
+
|
7
|
+
## 1.6.0 (2021-04-15)
|
8
|
+
|
9
|
+
- Add Revolut to the list of iDEAL issuers.
|
10
|
+
|
11
|
+
## 1.5.0 (2020-11-17)
|
12
|
+
|
13
|
+
- Add payment method Sofort.
|
14
|
+
|
15
|
+
## 1.4.0 (2020-04-06)
|
16
|
+
|
17
|
+
- Add `payment_methods` to retrieve all payment methods enabled by Buckaroo and supported by this library.
|
18
|
+
- Add `specify_transaction` to get a specification for setting up a transaction.
|
19
|
+
- Fix calculating the signature for long responses and indexed fields.
|
20
|
+
|
3
21
|
## 1.3.1 (2019-12-04)
|
4
22
|
|
5
23
|
- Update list of credit card transaction types.
|
6
24
|
|
7
25
|
## 1.3.0 (2019-10-08)
|
8
26
|
|
9
|
-
-
|
27
|
+
- Add payment method American Express.
|
10
28
|
|
11
29
|
## 1.2.0 (2019-08-06)
|
12
30
|
|
13
|
-
-
|
31
|
+
- Add support for sending custom & additional variables with the request.
|
14
32
|
|
15
33
|
## 1.1.1 (2018-11-30)
|
16
34
|
|
17
|
-
-
|
35
|
+
- Add Handelsbanken to the list of iDEAL issuers.
|
18
36
|
|
19
37
|
## 1.1.0 (2018-06-01)
|
20
38
|
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
39
|
+
- Add payment method iDEAL processing.
|
40
|
+
- Add Moneyou to the list of iDEAL issuers.
|
41
|
+
- Implement refund transaction.
|
42
|
+
- Implement cancel transaction.
|
25
43
|
|
26
44
|
## 1.0.2 (2017-08-25)
|
27
45
|
|
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.
|
10
|
-
gem 'rubocop-performance', '~> 1.5.
|
11
|
-
gem 'rubocop-rspec', '~> 1.
|
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,52 +1,54 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
buckaruby (1.
|
4
|
+
buckaruby (1.7.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
addressable (2.
|
10
|
-
public_suffix (>= 2.0.2, <
|
9
|
+
addressable (2.8.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
11
|
ast (2.4.0)
|
12
12
|
crack (0.4.3)
|
13
13
|
safe_yaml (~> 1.0.0)
|
14
|
-
diff-lcs (1.
|
14
|
+
diff-lcs (1.4.4)
|
15
15
|
hashdiff (1.0.0)
|
16
16
|
jaro_winkler (1.5.4)
|
17
17
|
parallel (1.19.1)
|
18
|
-
parser (2.
|
18
|
+
parser (2.7.0.5)
|
19
19
|
ast (~> 2.4.0)
|
20
|
-
public_suffix (
|
20
|
+
public_suffix (4.0.6)
|
21
21
|
rainbow (3.0.0)
|
22
|
-
rake (
|
23
|
-
|
24
|
-
|
25
|
-
rspec-
|
26
|
-
rspec-
|
27
|
-
|
28
|
-
|
29
|
-
|
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.
|
32
|
-
rspec-mocks (3.
|
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.
|
35
|
-
rspec-support (3.
|
36
|
-
rubocop (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.
|
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, <
|
43
|
-
rubocop-performance (1.5.
|
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.
|
47
|
+
rubocop-rspec (1.38.1)
|
46
48
|
rubocop (>= 0.68.1)
|
47
49
|
ruby-progressbar (1.10.1)
|
48
50
|
safe_yaml (1.0.5)
|
49
|
-
unicode-display_width (1.
|
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 (~>
|
63
|
+
rake (~> 12.3)
|
62
64
|
rspec (~> 3.0)
|
63
|
-
rubocop (~> 0.
|
64
|
-
rubocop-performance (~> 1.5.
|
65
|
-
rubocop-rspec (~> 1.
|
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
@@ -1,7 +1,7 @@
|
|
1
1
|
# Buckaruby
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/buckaruby.svg)](https://badge.fury.io/rb/buckaruby)
|
4
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/KentaaNL/buckaruby/actions/workflows/test.yml/badge.svg)](https://github.com/KentaaNL/buckaruby/actions)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/KentaaNL/buckaruby/badges/gpa.svg)](https://codeclimate.com/github/KentaaNL/buckaruby)
|
6
6
|
|
7
7
|
The Buckaruby gem provides a Ruby library for communicating with the Buckaroo Payment Engine 3.0.
|
@@ -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", "~>
|
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
|
data/lib/buckaruby/gateway.rb
CHANGED
@@ -17,7 +17,21 @@ module Buckaruby
|
|
17
17
|
@logger = config.logger
|
18
18
|
end
|
19
19
|
|
20
|
-
#
|
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,
|
154
|
-
PaymentMethod::
|
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, PaymentMethod::GIROPAY
|
155
177
|
]
|
156
178
|
validate_payment_method!(options, valid_payment_methods)
|
157
179
|
|
@@ -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
|