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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca0648f0a6575163b3684b909a613114b6f7634d
4
- data.tar.gz: 58d4b4baf6dbf494a39839352c24c522a415ea87
3
+ metadata.gz: 4bf463fefe2e48b81e3802d81e8141a535a4f586
4
+ data.tar.gz: b2192a33d06fd0c4c9cba9e9eb7969cd12fdc061
5
5
  SHA512:
6
- metadata.gz: dfc7886aaa82c537c786ed16543abd0934d28529e1c40a76709699c6f4d9f3ee49b7caca09aac5c79de733b88397cfac1a29209a3f2df6960df2fb1227c5519f
7
- data.tar.gz: dacded44324296a0af0c05063047d87f6764bd613ab438091995caf7abcb6d80b25a1d06235b6283da0a1701940c7f061a11ce7cd4d3395be72d10c5302ff418
6
+ metadata.gz: 636784a521333470080bfaf8603bb5049e6129d94f2cd01cf20cae672c6ff84827f8a9ddb6221e3eb5b0a7bc2f484fe5788e21d5580c8303a7df5bcaa0ffcd1c
7
+ data.tar.gz: 88a2da8cf30a4791535456fe99b3b06a845d42cbfcf52799558b09e0b41fa3186667f954a05633a4de401f130894a1b5c56fdcd449030c052a7cea66464df827
data/.rubocop.yml CHANGED
@@ -42,8 +42,5 @@ Style/IfUnlessModifier:
42
42
  Style/MutableConstant:
43
43
  Enabled: false
44
44
 
45
- Style/RedundantReturn:
46
- Enabled: false
47
-
48
45
  Style/StringLiterals:
49
46
  Enabled: false
data/.travis.yml CHANGED
@@ -2,5 +2,6 @@ language: ruby
2
2
  sudo: false
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.2.5
6
- - 2.3.1
5
+ - 2.2.6
6
+ - 2.3.3
7
+ - 2.4.0
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 = "http://www.buckaroo.nl/"
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")
@@ -27,7 +27,7 @@ module Buckaruby
27
27
  raise ArgumentError, "Invalid payment method, only #{PaymentMethod::IDEAL} is supported."
28
28
  end
29
29
 
30
- return Ideal::ISSUERS
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
- request = build_request(:setup_transaction)
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
- request = build_request(:recurrent_transaction)
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
- request = build_request(:status)
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
- return CallbackResponse.new(response, @options)
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
@@ -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
- return country_code + verification_number + account_identification
22
+ country_code + verification_number + account_identification
23
23
  end
24
24
  end
25
25
  end
@@ -24,7 +24,7 @@ module Buckaruby
24
24
 
25
25
  @logger.debug("[execute] response: #{response.inspect}")
26
26
 
27
- return response
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
- return params
62
+ params
63
63
  end
64
64
 
65
65
  def post_data(params)
66
- return params.map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
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
- return query
72
+ query
73
73
  end
74
74
 
75
75
  def test?
76
- return @options[:mode] == :test
76
+ @options[:mode] == :test
77
77
  end
78
78
 
79
79
  def api_url
80
- return test? ? Urls::TEST_URL : Urls::PRODUCTION_URL
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
- return params
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
- return params
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
- return params
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
- return params
185
+ params
191
186
  end
192
187
  end
193
188
  end
@@ -30,72 +30,72 @@ module Buckaruby
30
30
  def account_bic
31
31
  case payment_method
32
32
  when PaymentMethod::IDEAL
33
- return params[:brq_service_ideal_consumerbic]
33
+ params[:brq_service_ideal_consumerbic]
34
34
  when PaymentMethod::SEPA_DIRECT_DEBIT
35
- return params[:brq_service_sepadirectdebit_customerbic]
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
- return params[:brq_service_ideal_consumeriban]
42
+ params[:brq_service_ideal_consumeriban]
43
43
  when PaymentMethod::SEPA_DIRECT_DEBIT
44
- return params[:brq_service_sepadirectdebit_customeriban]
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
- return params[:brq_service_ideal_consumername] || params[:brq_customer_name]
51
+ params[:brq_service_ideal_consumername] || params[:brq_customer_name]
52
52
  when PaymentMethod::SEPA_DIRECT_DEBIT
53
- return params[:brq_service_sepadirectdebit_customername] || params[:brq_customer_name]
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
- return parse_date(params[:brq_service_sepadirectdebit_collectdate])
59
+ parse_date(params[:brq_service_sepadirectdebit_collectdate])
60
60
  end
61
61
  end
62
62
 
63
63
  def invoicenumber
64
- return params[:brq_invoicenumber]
64
+ params[:brq_invoicenumber]
65
65
  end
66
66
 
67
67
  def mandate_reference
68
68
  if payment_method == PaymentMethod::SEPA_DIRECT_DEBIT
69
- return params[:brq_service_sepadirectdebit_mandatereference]
69
+ params[:brq_service_sepadirectdebit_mandatereference]
70
70
  end
71
71
  end
72
72
 
73
73
  def payment_id
74
- return params[:brq_payment]
74
+ params[:brq_payment]
75
75
  end
76
76
 
77
77
  def payment_method
78
- return parse_payment_method(params[:brq_payment_method] || params[:brq_transaction_method])
78
+ parse_payment_method(params[:brq_payment_method] || params[:brq_transaction_method])
79
79
  end
80
80
 
81
81
  def redirect_url
82
- return params[:brq_redirecturl]
82
+ params[:brq_redirecturl]
83
83
  end
84
84
 
85
85
  def refund_transaction_id
86
- return params[:brq_relatedtransaction_refund]
86
+ params[:brq_relatedtransaction_refund]
87
87
  end
88
88
 
89
89
  def reversal_transaction_id
90
- return params[:brq_relatedtransaction_reversal]
90
+ params[:brq_relatedtransaction_reversal]
91
91
  end
92
92
 
93
93
  def timestamp
94
- return parse_time(params[:brq_timestamp])
94
+ parse_time(params[:brq_timestamp])
95
95
  end
96
96
 
97
97
  def transaction_id
98
- return params[:brq_transactions]
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
- return TransactionType::PAYMENT
106
+ TransactionType::PAYMENT
107
107
  when 'C005', 'V014', 'V031', 'V032', 'V034', 'V043', 'V044', 'V046', 'V094'
108
- return TransactionType::PAYMENT_RECURRENT
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
- return TransactionType::REFUND
110
+ TransactionType::REFUND
111
111
  when 'C501', 'C502', 'C562', 'V111', 'V131', 'V132', 'V134', 'V143', 'V144', 'V146'
112
- return TransactionType::REVERSAL
112
+ TransactionType::REVERSAL
113
113
  end
114
114
  else
115
115
  # Fallback when transaction type is not known (cancelling credit card)
116
- return TransactionType::PAYMENT
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
- return TransactionStatus::SUCCESS
124
+ TransactionStatus::SUCCESS
125
125
  when '490', '491', '492'
126
- return TransactionStatus::FAILED
126
+ TransactionStatus::FAILED
127
127
  when '690'
128
- return TransactionStatus::REJECTED
129
- when '790', '791'
130
- return TransactionStatus::PENDING
128
+ TransactionStatus::REJECTED
129
+ when '790', '791', '792', '793'
130
+ TransactionStatus::PENDING
131
131
  when '890', '891'
132
- return TransactionStatus::CANCELLED
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
- return hash
154
+ hash
155
155
  end
156
156
 
157
157
  private
158
158
 
159
159
  def parse_date(date)
160
- return date ? Date.strptime(date, '%Y-%m-%d') : nil
160
+ date ? Date.strptime(date, '%Y-%m-%d') : nil
161
161
  end
162
162
 
163
163
  def parse_time(time)
164
- return time ? Time.strptime(time, '%Y-%m-%d %H:%M:%S') : nil
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
- return method ? method.downcase : nil
168
+ method ? method.downcase : nil
169
169
  end
170
170
  end
171
171
 
@@ -10,11 +10,11 @@ module Buckaruby
10
10
 
11
11
  case hash_method
12
12
  when :sha1
13
- return Digest::SHA1.hexdigest(generate_signature_string(params, secret))
13
+ Digest::SHA1.hexdigest(generate_signature_string(params, secret))
14
14
  when :sha256
15
- return Digest::SHA256.hexdigest(generate_signature_string(params, secret))
15
+ Digest::SHA256.hexdigest(generate_signature_string(params, secret))
16
16
  when :sha512
17
- return Digest::SHA512.hexdigest(generate_signature_string(params, secret))
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
- return string
27
+ string
28
28
  end
29
29
  end
30
30
  end
@@ -28,7 +28,7 @@ module Buckaruby
28
28
 
29
29
  def convert_key(key)
30
30
  string = key.is_a?(Symbol) ? key.to_s : key
31
- return string.downcase
31
+ string.downcase
32
32
  end
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module Buckaruby
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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.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: 2016-11-24 00:00:00.000000000 Z
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: http://www.buckaroo.nl/
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.4.8
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.