buckaruby 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -3
- data/.travis.yml +3 -2
- data/CHANGELOG.md +10 -0
- data/README.md +2 -0
- data/buckaruby.gemspec +1 -1
- data/lib/buckaruby/gateway.rb +20 -14
- data/lib/buckaruby/iban.rb +1 -1
- data/lib/buckaruby/request.rb +15 -20
- data/lib/buckaruby/response.rb +31 -31
- data/lib/buckaruby/signature.rb +4 -4
- data/lib/buckaruby/support/case_insensitive_hash.rb +1 -1
- data/lib/buckaruby/version.rb +1 -1
- data/spec/buckaruby/gateway_spec.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bf463fefe2e48b81e3802d81e8141a535a4f586
|
4
|
+
data.tar.gz: b2192a33d06fd0c4c9cba9e9eb7969cd12fdc061
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 636784a521333470080bfaf8603bb5049e6129d94f2cd01cf20cae672c6ff84827f8a9ddb6221e3eb5b0a7bc2f484fe5788e21d5580c8303a7df5bcaa0ffcd1c
|
7
|
+
data.tar.gz: 88a2da8cf30a4791535456fe99b3b06a845d42cbfcf52799558b09e0b41fa3186667f954a05633a4de401f130894a1b5c56fdcd449030c052a7cea66464df827
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Buckaruby changelog
|
2
|
+
|
3
|
+
## 1.0.1 (2017-01-05)
|
4
|
+
|
5
|
+
- Recognize status codes 792 & 793 as a pending transaction.
|
6
|
+
- For SEPA Direct Debit, make the collect date configurable and let Buckaroo determine the default.
|
7
|
+
|
8
|
+
## 1.0.0 (2016-11-24)
|
9
|
+
|
10
|
+
- First public release.
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Buckaruby
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/buckaruby.svg)](https://badge.fury.io/rb/buckaruby)
|
3
4
|
[![Build Status](https://travis-ci.org/KentaaNL/buckaruby.svg?branch=master)](https://travis-ci.org/KentaaNL/buckaruby)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/KentaaNL/buckaruby/badges/gpa.svg)](https://codeclimate.com/github/KentaaNL/buckaruby)
|
4
6
|
|
5
7
|
The Buckaruby gem provides a Ruby library for communicating with the Buckaroo Payment Engine 3.0.
|
6
8
|
|
data/buckaruby.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["support@kentaa.nl"]
|
11
11
|
spec.summary = "Ruby library for communicating with the Buckaroo Payment Engine 3.0."
|
12
12
|
spec.description = "The Buckaruby gem provides a Ruby library for communicating with the Buckaroo Payment Engine 3.0."
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://github.com/KentaaNL/buckaruby"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
data/lib/buckaruby/gateway.rb
CHANGED
@@ -27,7 +27,7 @@ module Buckaruby
|
|
27
27
|
raise ArgumentError, "Invalid payment method, only #{PaymentMethod::IDEAL} is supported."
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
Ideal::ISSUERS
|
31
31
|
end
|
32
32
|
|
33
33
|
# Setup a new transaction.
|
@@ -38,10 +38,7 @@ module Buckaruby
|
|
38
38
|
|
39
39
|
normalize_account_iban!(options) if options[:payment_method] == PaymentMethod::SEPA_DIRECT_DEBIT
|
40
40
|
|
41
|
-
|
42
|
-
response = request.execute(options)
|
43
|
-
|
44
|
-
return SetupTransactionResponse.new(response, @options)
|
41
|
+
execute_request(:setup_transaction, options)
|
45
42
|
end
|
46
43
|
|
47
44
|
# Setup a recurrent transaction.
|
@@ -50,10 +47,7 @@ module Buckaruby
|
|
50
47
|
|
51
48
|
validate_recurrent_transaction_params!(options)
|
52
49
|
|
53
|
-
|
54
|
-
response = request.execute(options)
|
55
|
-
|
56
|
-
return RecurrentTransactionResponse.new(response, @options)
|
50
|
+
execute_request(:recurrent_transaction, options)
|
57
51
|
end
|
58
52
|
|
59
53
|
# Get transaction status.
|
@@ -62,10 +56,7 @@ module Buckaruby
|
|
62
56
|
|
63
57
|
validate_status_params!(options)
|
64
58
|
|
65
|
-
|
66
|
-
response = request.execute(options)
|
67
|
-
|
68
|
-
return StatusResponse.new(response, @options)
|
59
|
+
execute_request(:status, options)
|
69
60
|
end
|
70
61
|
|
71
62
|
# Verify the response / callback.
|
@@ -74,7 +65,7 @@ module Buckaruby
|
|
74
65
|
raise ArgumentError, "No callback parameters found"
|
75
66
|
end
|
76
67
|
|
77
|
-
|
68
|
+
CallbackResponse.new(response, @options)
|
78
69
|
end
|
79
70
|
|
80
71
|
private
|
@@ -189,6 +180,21 @@ module Buckaruby
|
|
189
180
|
options[:hash_method] = hash_method
|
190
181
|
end
|
191
182
|
|
183
|
+
# Build and execute a request.
|
184
|
+
def execute_request(request_type, options)
|
185
|
+
request = build_request(request_type)
|
186
|
+
response = request.execute(options)
|
187
|
+
|
188
|
+
case request_type
|
189
|
+
when :setup_transaction
|
190
|
+
SetupTransactionResponse.new(response, @options)
|
191
|
+
when :recurrent_transaction
|
192
|
+
RecurrentTransactionResponse.new(response, @options)
|
193
|
+
when :status
|
194
|
+
StatusResponse.new(response, @options)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
192
198
|
# Factory method for constructing a request.
|
193
199
|
def build_request(request_type)
|
194
200
|
case request_type
|
data/lib/buckaruby/iban.rb
CHANGED
@@ -19,7 +19,7 @@ module Buckaruby
|
|
19
19
|
all_numbers = country_code_added.gsub(/[A-Z]/) { |p| (p.respond_to?(:ord) ? p.ord : p[0]) - 55 } + '00'
|
20
20
|
verification_number = (98 - (all_numbers.to_i % 97)).to_s.rjust(2, '0')
|
21
21
|
|
22
|
-
|
22
|
+
country_code + verification_number + account_identification
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/buckaruby/request.rb
CHANGED
@@ -24,7 +24,7 @@ module Buckaruby
|
|
24
24
|
|
25
25
|
@logger.debug("[execute] response: #{response.inspect}")
|
26
26
|
|
27
|
-
|
27
|
+
response
|
28
28
|
end
|
29
29
|
|
30
30
|
def build_request_params(_options)
|
@@ -59,25 +59,25 @@ module Buckaruby
|
|
59
59
|
# Sign the data with our secret key.
|
60
60
|
params[:brq_signature] = Signature.generate_signature(params, @options)
|
61
61
|
|
62
|
-
|
62
|
+
params
|
63
63
|
end
|
64
64
|
|
65
65
|
def post_data(params)
|
66
|
-
|
66
|
+
params.map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
|
67
67
|
end
|
68
68
|
|
69
69
|
def parse_response(body)
|
70
70
|
query = CGI.parse(body)
|
71
71
|
query.each { |key, value| query[key] = value.first }
|
72
|
-
|
72
|
+
query
|
73
73
|
end
|
74
74
|
|
75
75
|
def test?
|
76
|
-
|
76
|
+
@options[:mode] == :test
|
77
77
|
end
|
78
78
|
|
79
79
|
def api_url
|
80
|
-
|
80
|
+
test? ? Urls::TEST_URL : Urls::PRODUCTION_URL
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -102,7 +102,7 @@ module Buckaruby
|
|
102
102
|
params[:brq_description] = options[:description] if options[:description]
|
103
103
|
params[:brq_return] = options[:return_url] if options[:return_url]
|
104
104
|
|
105
|
-
|
105
|
+
params
|
106
106
|
end
|
107
107
|
|
108
108
|
def build_transaction_request_params(_options)
|
@@ -112,10 +112,6 @@ module Buckaruby
|
|
112
112
|
|
113
113
|
# Request for a creating a new transaction.
|
114
114
|
class SetupTransactionRequest < TransactionRequest
|
115
|
-
def execute(options)
|
116
|
-
super(options.merge(action: Action::PAY))
|
117
|
-
end
|
118
|
-
|
119
115
|
def build_transaction_request_params(options)
|
120
116
|
params = {}
|
121
117
|
|
@@ -130,14 +126,17 @@ module Buckaruby
|
|
130
126
|
params.merge!(
|
131
127
|
brq_service_sepadirectdebit_action: Action::PAY,
|
132
128
|
brq_service_sepadirectdebit_customeriban: options[:account_iban],
|
133
|
-
brq_service_sepadirectdebit_customeraccountname: options[:account_name]
|
134
|
-
brq_service_sepadirectdebit_collectdate: (Date.today + 5).strftime("%Y-%m-%d")
|
129
|
+
brq_service_sepadirectdebit_customeraccountname: options[:account_name]
|
135
130
|
)
|
136
131
|
|
137
132
|
if options[:account_bic]
|
138
133
|
params[:brq_service_sepadirectdebit_customerbic] = options[:account_bic]
|
139
134
|
end
|
140
135
|
|
136
|
+
if options[:collect_date]
|
137
|
+
params[:brq_service_sepadirectdebit_collectdate] = options[:collect_date].strftime("%Y-%m-%d")
|
138
|
+
end
|
139
|
+
|
141
140
|
if options[:mandate_reference]
|
142
141
|
params.merge!(
|
143
142
|
brq_service_sepadirectdebit_action: [Action::PAY, Action::EXTRA_INFO].join(","),
|
@@ -149,16 +148,12 @@ module Buckaruby
|
|
149
148
|
|
150
149
|
params[:brq_startrecurrent] = options[:recurring] if options[:recurring]
|
151
150
|
|
152
|
-
|
151
|
+
params
|
153
152
|
end
|
154
153
|
end
|
155
154
|
|
156
155
|
# Request for a creating a recurrent transaction.
|
157
156
|
class RecurrentTransactionRequest < TransactionRequest
|
158
|
-
def execute(options)
|
159
|
-
super(options.merge(action: Action::PAY_RECURRENT))
|
160
|
-
end
|
161
|
-
|
162
157
|
def build_transaction_request_params(options)
|
163
158
|
params = {}
|
164
159
|
|
@@ -171,7 +166,7 @@ module Buckaruby
|
|
171
166
|
|
172
167
|
params[:brq_originaltransaction] = options[:transaction_id]
|
173
168
|
|
174
|
-
|
169
|
+
params
|
175
170
|
end
|
176
171
|
end
|
177
172
|
|
@@ -187,7 +182,7 @@ module Buckaruby
|
|
187
182
|
params[:brq_transaction] = options[:transaction_id] if options[:transaction_id]
|
188
183
|
params[:brq_payment] = options[:payment_id] if options[:payment_id]
|
189
184
|
|
190
|
-
|
185
|
+
params
|
191
186
|
end
|
192
187
|
end
|
193
188
|
end
|
data/lib/buckaruby/response.rb
CHANGED
@@ -30,72 +30,72 @@ module Buckaruby
|
|
30
30
|
def account_bic
|
31
31
|
case payment_method
|
32
32
|
when PaymentMethod::IDEAL
|
33
|
-
|
33
|
+
params[:brq_service_ideal_consumerbic]
|
34
34
|
when PaymentMethod::SEPA_DIRECT_DEBIT
|
35
|
-
|
35
|
+
params[:brq_service_sepadirectdebit_customerbic]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
def account_iban
|
40
40
|
case payment_method
|
41
41
|
when PaymentMethod::IDEAL
|
42
|
-
|
42
|
+
params[:brq_service_ideal_consumeriban]
|
43
43
|
when PaymentMethod::SEPA_DIRECT_DEBIT
|
44
|
-
|
44
|
+
params[:brq_service_sepadirectdebit_customeriban]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def account_name
|
49
49
|
case payment_method
|
50
50
|
when PaymentMethod::IDEAL
|
51
|
-
|
51
|
+
params[:brq_service_ideal_consumername] || params[:brq_customer_name]
|
52
52
|
when PaymentMethod::SEPA_DIRECT_DEBIT
|
53
|
-
|
53
|
+
params[:brq_service_sepadirectdebit_customername] || params[:brq_customer_name]
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def collect_date
|
58
58
|
if payment_method == PaymentMethod::SEPA_DIRECT_DEBIT
|
59
|
-
|
59
|
+
parse_date(params[:brq_service_sepadirectdebit_collectdate])
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
def invoicenumber
|
64
|
-
|
64
|
+
params[:brq_invoicenumber]
|
65
65
|
end
|
66
66
|
|
67
67
|
def mandate_reference
|
68
68
|
if payment_method == PaymentMethod::SEPA_DIRECT_DEBIT
|
69
|
-
|
69
|
+
params[:brq_service_sepadirectdebit_mandatereference]
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
def payment_id
|
74
|
-
|
74
|
+
params[:brq_payment]
|
75
75
|
end
|
76
76
|
|
77
77
|
def payment_method
|
78
|
-
|
78
|
+
parse_payment_method(params[:brq_payment_method] || params[:brq_transaction_method])
|
79
79
|
end
|
80
80
|
|
81
81
|
def redirect_url
|
82
|
-
|
82
|
+
params[:brq_redirecturl]
|
83
83
|
end
|
84
84
|
|
85
85
|
def refund_transaction_id
|
86
|
-
|
86
|
+
params[:brq_relatedtransaction_refund]
|
87
87
|
end
|
88
88
|
|
89
89
|
def reversal_transaction_id
|
90
|
-
|
90
|
+
params[:brq_relatedtransaction_reversal]
|
91
91
|
end
|
92
92
|
|
93
93
|
def timestamp
|
94
|
-
|
94
|
+
parse_time(params[:brq_timestamp])
|
95
95
|
end
|
96
96
|
|
97
97
|
def transaction_id
|
98
|
-
|
98
|
+
params[:brq_transactions]
|
99
99
|
end
|
100
100
|
|
101
101
|
def transaction_type
|
@@ -103,17 +103,17 @@ module Buckaruby
|
|
103
103
|
# See http://support.buckaroo.nl/index.php/Transactietypes
|
104
104
|
case params[:brq_transaction_type]
|
105
105
|
when 'C001', 'C002', 'C004', 'C021', 'C043', 'C044', 'C046', 'C090', 'V001', 'V002', 'V010', 'V021', 'V090'
|
106
|
-
|
106
|
+
TransactionType::PAYMENT
|
107
107
|
when 'C005', 'V014', 'V031', 'V032', 'V034', 'V043', 'V044', 'V046', 'V094'
|
108
|
-
|
108
|
+
TransactionType::PAYMENT_RECURRENT
|
109
109
|
when 'C079', 'C080', 'C082', 'C092', 'C101', 'C102', 'C121', 'C500', 'V067', 'V068', 'V070', 'V079', 'V080', 'V082', 'V092', 'V101', 'V102', 'V110'
|
110
|
-
|
110
|
+
TransactionType::REFUND
|
111
111
|
when 'C501', 'C502', 'C562', 'V111', 'V131', 'V132', 'V134', 'V143', 'V144', 'V146'
|
112
|
-
|
112
|
+
TransactionType::REVERSAL
|
113
113
|
end
|
114
114
|
else
|
115
115
|
# Fallback when transaction type is not known (cancelling credit card)
|
116
|
-
|
116
|
+
TransactionType::PAYMENT
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -121,15 +121,15 @@ module Buckaruby
|
|
121
121
|
# See http://support.buckaroo.nl/index.php/Statuscodes
|
122
122
|
case params[:brq_statuscode]
|
123
123
|
when '190'
|
124
|
-
|
124
|
+
TransactionStatus::SUCCESS
|
125
125
|
when '490', '491', '492'
|
126
|
-
|
126
|
+
TransactionStatus::FAILED
|
127
127
|
when '690'
|
128
|
-
|
129
|
-
when '790', '791'
|
130
|
-
|
128
|
+
TransactionStatus::REJECTED
|
129
|
+
when '790', '791', '792', '793'
|
130
|
+
TransactionStatus::PENDING
|
131
131
|
when '890', '891'
|
132
|
-
|
132
|
+
TransactionStatus::CANCELLED
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
@@ -151,21 +151,21 @@ module Buckaruby
|
|
151
151
|
transaction_status: transaction_status
|
152
152
|
}.reject { |_key, value| value.nil? }
|
153
153
|
|
154
|
-
|
154
|
+
hash
|
155
155
|
end
|
156
156
|
|
157
157
|
private
|
158
158
|
|
159
159
|
def parse_date(date)
|
160
|
-
|
160
|
+
date ? Date.strptime(date, '%Y-%m-%d') : nil
|
161
161
|
end
|
162
162
|
|
163
163
|
def parse_time(time)
|
164
|
-
|
164
|
+
time ? Time.strptime(time, '%Y-%m-%d %H:%M:%S') : nil
|
165
165
|
end
|
166
166
|
|
167
167
|
def parse_payment_method(method)
|
168
|
-
|
168
|
+
method ? method.downcase : nil
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
data/lib/buckaruby/signature.rb
CHANGED
@@ -10,11 +10,11 @@ module Buckaruby
|
|
10
10
|
|
11
11
|
case hash_method
|
12
12
|
when :sha1
|
13
|
-
|
13
|
+
Digest::SHA1.hexdigest(generate_signature_string(params, secret))
|
14
14
|
when :sha256
|
15
|
-
|
15
|
+
Digest::SHA256.hexdigest(generate_signature_string(params, secret))
|
16
16
|
when :sha512
|
17
|
-
|
17
|
+
Digest::SHA512.hexdigest(generate_signature_string(params, secret))
|
18
18
|
else
|
19
19
|
raise ArgumentError, "Invalid hash method provided: #{hash_method}"
|
20
20
|
end
|
@@ -24,7 +24,7 @@ module Buckaruby
|
|
24
24
|
sign_params = params.select { |key, _value| key.to_s.upcase.start_with?("BRQ_", "ADD_", "CUST_") && key.to_s.casecmp("BRQ_SIGNATURE").nonzero? }
|
25
25
|
string = sign_params.sort_by { |p| p.first.downcase }.map { |param| "#{param[0]}=#{param[1]}" }.join
|
26
26
|
string << secret
|
27
|
-
|
27
|
+
string
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/lib/buckaruby/version.rb
CHANGED
@@ -208,7 +208,7 @@ describe Buckaruby::Gateway do
|
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'should initiate a transaction for payment method sepa direct debit' do
|
211
|
-
response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::SEPA_DIRECT_DEBIT, invoicenumber: "12345", return_url: "http://www.return.url/", account_iban: "NL13TEST0123456789", account_name: "J. Tester", mandate_reference: "00P12345")
|
211
|
+
response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::SEPA_DIRECT_DEBIT, invoicenumber: "12345", return_url: "http://www.return.url/", account_iban: "NL13TEST0123456789", account_name: "J. Tester", mandate_reference: "00P12345", collect_date: Date.new(2016, 1, 1))
|
212
212
|
expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse)
|
213
213
|
expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
|
214
214
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::PENDING)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buckaruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kentaa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- ".gitignore"
|
70
70
|
- ".rubocop.yml"
|
71
71
|
- ".travis.yml"
|
72
|
+
- CHANGELOG.md
|
72
73
|
- Gemfile
|
73
74
|
- LICENSE.txt
|
74
75
|
- README.md
|
@@ -97,7 +98,7 @@ files:
|
|
97
98
|
- spec/buckaruby/signature_spec.rb
|
98
99
|
- spec/buckaruby/support/case_insensitive_hash_spec.rb
|
99
100
|
- spec/spec_helper.rb
|
100
|
-
homepage:
|
101
|
+
homepage: https://github.com/KentaaNL/buckaruby
|
101
102
|
licenses:
|
102
103
|
- MIT
|
103
104
|
metadata: {}
|
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
120
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.6.8
|
121
122
|
signing_key:
|
122
123
|
specification_version: 4
|
123
124
|
summary: Ruby library for communicating with the Buckaroo Payment Engine 3.0.
|