buckaruby 1.7.0 → 2.0.1

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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -54
  3. data/README.md +54 -18
  4. data/lib/buckaruby/action.rb +4 -4
  5. data/lib/buckaruby/amount.rb +25 -0
  6. data/lib/buckaruby/configuration.rb +35 -40
  7. data/lib/buckaruby/currency.rb +3 -3
  8. data/lib/buckaruby/exception.rb +9 -8
  9. data/lib/buckaruby/gateway.rb +64 -72
  10. data/lib/buckaruby/operation.rb +5 -5
  11. data/lib/buckaruby/payment_method.rb +20 -12
  12. data/lib/buckaruby/request.rb +62 -68
  13. data/lib/buckaruby/response.rb +69 -67
  14. data/lib/buckaruby/signature.rb +26 -7
  15. data/lib/buckaruby/transaction_type.rb +24 -21
  16. data/lib/buckaruby/version.rb +1 -1
  17. data/lib/buckaruby.rb +1 -2
  18. metadata +16 -97
  19. data/.github/workflows/test.yml +0 -23
  20. data/.gitignore +0 -19
  21. data/.rubocop.yml +0 -107
  22. data/Gemfile +0 -12
  23. data/Gemfile.lock +0 -71
  24. data/Rakefile +0 -10
  25. data/buckaruby.gemspec +0 -28
  26. data/lib/buckaruby/iban.rb +0 -29
  27. data/lib/buckaruby/ideal.rb +0 -21
  28. data/spec/buckaruby/configuration_spec.rb +0 -113
  29. data/spec/buckaruby/field_mapper_spec.rb +0 -69
  30. data/spec/buckaruby/gateway_spec.rb +0 -803
  31. data/spec/buckaruby/iban_spec.rb +0 -75
  32. data/spec/buckaruby/signature_spec.rb +0 -89
  33. data/spec/buckaruby/support/case_insensitive_hash_spec.rb +0 -74
  34. data/spec/fixtures/responses/callback_invalid_signature.txt +0 -1
  35. data/spec/fixtures/responses/callback_payment_amex.txt +0 -1
  36. data/spec/fixtures/responses/callback_payment_cancelled.txt +0 -1
  37. data/spec/fixtures/responses/callback_payment_empty_transaction_type.txt +0 -1
  38. data/spec/fixtures/responses/callback_payment_failed.txt +0 -1
  39. data/spec/fixtures/responses/callback_payment_giropay.txt +0 -1
  40. data/spec/fixtures/responses/callback_payment_pending.txt +0 -1
  41. data/spec/fixtures/responses/callback_payment_rejected.txt +0 -1
  42. data/spec/fixtures/responses/callback_payment_sepa.txt +0 -1
  43. data/spec/fixtures/responses/callback_payment_sofort.txt +0 -1
  44. data/spec/fixtures/responses/callback_payment_success.txt +0 -1
  45. data/spec/fixtures/responses/callback_payment_visa.txt +0 -1
  46. data/spec/fixtures/responses/callback_recurrent_sepa.txt +0 -1
  47. data/spec/fixtures/responses/callback_recurrent_visa.txt +0 -1
  48. data/spec/fixtures/responses/callback_refund_amex.txt +0 -1
  49. data/spec/fixtures/responses/callback_refund_ideal.txt +0 -1
  50. data/spec/fixtures/responses/callback_refund_paypal.txt +0 -1
  51. data/spec/fixtures/responses/callback_reversal_paypal.txt +0 -1
  52. data/spec/fixtures/responses/callback_reversal_sepa.txt +0 -1
  53. data/spec/fixtures/responses/callback_valid_signature.txt +0 -1
  54. data/spec/fixtures/responses/cancel_success.txt +0 -1
  55. data/spec/fixtures/responses/recurrent_transaction_success.txt +0 -1
  56. data/spec/fixtures/responses/refund_info_error.txt +0 -1
  57. data/spec/fixtures/responses/refund_info_success.txt +0 -1
  58. data/spec/fixtures/responses/refund_transaction_success.txt +0 -1
  59. data/spec/fixtures/responses/setup_transaction_success.txt +0 -1
  60. data/spec/fixtures/responses/specify_transaction_success.txt +0 -1
  61. data/spec/fixtures/responses/status_cancellable.txt +0 -1
  62. data/spec/fixtures/responses/status_noncancellable.txt +0 -1
  63. data/spec/fixtures/responses/status_success.txt +0 -1
  64. data/spec/spec_helper.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbc9889fbec21efa16afde817a492b839b2c69ae3c2d442ed5a4d0f8631d27ca
4
- data.tar.gz: 3e09c5226383463a8364a16dcd21f70ace68632cede58ba48bc6c9d00e67470f
3
+ metadata.gz: eaefc0e467387241658fea872018f395d2e0cebdd467ea855f8754972f1d22b3
4
+ data.tar.gz: 7fa06dbb6978cbbd359a3ebcb7d2908e6d4394cc5b35f397ad25d39b1aff2775
5
5
  SHA512:
6
- metadata.gz: 3f89515b95016c1f954b9862de10c98c8a9d82027a6276307c60ae73a68075c880d36ceb560a5858acc9eafc404737cabc096c16572f09f645f8324b95194d74
7
- data.tar.gz: 38a8749448b840d033f60c2698f050594f4feef63ace780122801c6fe5a2739cc3ab4a67c364358a66132b59a1233c177fa89fb28ae206c8f98b180b1fa45eae
6
+ metadata.gz: c77704f6cf7b7b405191800d1d78001ab43f4c51f6ef3f881272db39308315256a92bc9dcb7cd7e5ae755123dc13d0008b77a6eca35590625a7190268564839d
7
+ data.tar.gz: 9b5c9573fea56fd98b3be526eabeee80d883d2dbd25886a0ee568e919e6af34e64a34d938f3a4440032fb996ff6e4a96eea2136e6f48809a2d02288442a10ad5
data/CHANGELOG.md CHANGED
@@ -1,57 +1,5 @@
1
1
  # Buckaruby changelog
2
2
 
3
- ## 1.7.0 (2021-07-16)
3
+ We use [GitHub releases](https://github.com/KentaaNL/buckaruby/releases) for the CHANGELOG since version 2.0 of this gem.
4
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
-
21
- ## 1.3.1 (2019-12-04)
22
-
23
- - Update list of credit card transaction types.
24
-
25
- ## 1.3.0 (2019-10-08)
26
-
27
- - Add payment method American Express.
28
-
29
- ## 1.2.0 (2019-08-06)
30
-
31
- - Add support for sending custom & additional variables with the request.
32
-
33
- ## 1.1.1 (2018-11-30)
34
-
35
- - Add Handelsbanken to the list of iDEAL issuers.
36
-
37
- ## 1.1.0 (2018-06-01)
38
-
39
- - Add payment method iDEAL processing.
40
- - Add Moneyou to the list of iDEAL issuers.
41
- - Implement refund transaction.
42
- - Implement cancel transaction.
43
-
44
- ## 1.0.2 (2017-08-25)
45
-
46
- - Recognize credit card transactions via Atos.
47
- - Fix detection of recurrent payments.
48
- - Minor improvements to exception handling.
49
-
50
- ## 1.0.1 (2017-01-05)
51
-
52
- - Recognize status codes 792 & 793 as a pending transaction.
53
- - For SEPA Direct Debit, make the collect date configurable and let Buckaroo determine the default.
54
-
55
- ## 1.0.0 (2016-11-24)
56
-
57
- - First public release.
5
+ Check the 1.x branch for previous changes: https://github.com/KentaaNL/buckaruby/blob/1.x/CHANGELOG.md
data/README.md CHANGED
@@ -6,6 +6,26 @@
6
6
 
7
7
  The Buckaruby gem provides a Ruby library for communicating with the Buckaroo Payment Engine 3.0.
8
8
 
9
+ ## Table of Contents
10
+
11
+ - [Installation](#installation)
12
+ - [Usage](#usage)
13
+ - [Payment methods](#payment-methods)
14
+ - [Get issuers](#get-issuers)
15
+ - [Start transaction](#start-transaction)
16
+ - [Recurrent transaction](#recurrent-transaction)
17
+ - [Refund transaction](#refund-transaction)
18
+ - [Cancel transaction](#cancel-transaction)
19
+ - [Push response](#push-response)
20
+ - [Get status](#get-status)
21
+ - [Merchant variables](#merchant-variables)
22
+ - [Transaction request specification](#transaction-request-specification)
23
+ - [Error handling](#error-handling)
24
+ - [Example](#example)
25
+ - [Development](#development)
26
+ - [Contributing](#contributing)
27
+ - [License](#license)
28
+
9
29
  ## Installation
10
30
 
11
31
  Add this line to your application's Gemfile:
@@ -22,14 +42,6 @@ Or install it yourself as:
22
42
 
23
43
  ## Usage
24
44
 
25
- Configure Buckaruby to use it in test or production (live) mode:
26
-
27
- ```ruby
28
- Buckaruby::Gateway.mode = :production # defaults to :test
29
- ```
30
-
31
- ### Initialization
32
-
33
45
  Create the gateway and configure it using your Buckaroo website key and secret key:
34
46
 
35
47
  ```ruby
@@ -49,7 +61,15 @@ gateway = Buckaruby::Gateway.new(
49
61
  )
50
62
  ```
51
63
 
52
- You can override the default mode with the parameter `mode`.
64
+ The gateway is created for the live environment by default. If you want to use the testing environment, then add `test: true`:
65
+
66
+ ```ruby
67
+ gateway = Buckaruby::Gateway.new(
68
+ website: "123456789",
69
+ secret: "abcdef1234567890",
70
+ test: true # use the testing environment; default is false
71
+ )
72
+ ```
53
73
 
54
74
  ### Payment methods
55
75
 
@@ -59,6 +79,14 @@ To retrieve the payment methods enabled in Buckaroo and supported by this librar
59
79
  payment_methods = gateway.payment_methods
60
80
  ```
61
81
 
82
+ ### Get issuers
83
+
84
+ When using iDEAL as payment method, it is mandatory to send the `issuer` parameter in the start transaction request. You can retrieve the list of available issuers with the method `issuers`. This will return a hash with the ID of the issuer (hash key) and the issuer name (hash value).
85
+
86
+ ```ruby
87
+ issuers = gateway.issuers(Buckaruby::PaymentMethod::IDEAL)
88
+ ```
89
+
62
90
  ### Start transaction
63
91
 
64
92
  To start a new transaction, use the method `setup_transaction`:
@@ -67,7 +95,7 @@ To start a new transaction, use the method `setup_transaction`:
67
95
  options = {
68
96
  amount: 10,
69
97
  payment_method: Buckaruby::PaymentMethod::IDEAL,
70
- payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first,
98
+ issuer: "INGBNL2A",
71
99
  invoicenumber: "12345",
72
100
  return_url: "http://www.return.url/"
73
101
  }
@@ -123,7 +151,7 @@ For some transactions it's possible to do a refund: Buckaroo creates a new "reve
123
151
  First check if the transaction is refundable, with the parameter `transaction_id` set to the original transaction ID:
124
152
 
125
153
  ```ruby
126
- response = gateway.refundable?(transaction_id: "abcdefg")
154
+ response = gateway.refundable_transaction?(transaction_id: "abcdefg")
127
155
  ```
128
156
 
129
157
  If the reponse is positive then you can refund the transaction with:
@@ -142,10 +170,10 @@ See `Buckaruby::RefundTransactionResponse` for more details.
142
170
 
143
171
  Sometimes a transaction can be cancelled, for example a SEPA Direct Debit transaction before it has been offered to the bank.
144
172
 
145
- You can check if the transaction is cancellable, by using the method `cancellable?` with the parameter `transaction_id`:
173
+ You can check if the transaction is cancellable, by using the method `cancellable_transaction?` with the parameter `transaction_id`:
146
174
 
147
175
  ```ruby
148
- response = gateway.cancellable?(transaction_id: "abcdefg")
176
+ response = gateway.cancellable_transaction?(transaction_id: "abcdefg")
149
177
  ```
150
178
 
151
179
  If the response is positive then you can cancel the transaction with:
@@ -160,13 +188,15 @@ If you try to cancel a transaction that's not cancellable, then a `Buckaruby::No
160
188
 
161
189
  ### Push response
162
190
 
163
- Buckaroo can be configured to send push notifications for transactions. You can use the method `callback` to verify and parse the push response:
191
+ Buckaroo can be configured to send push notifications for transactions. You can use the method `parse_push` to verify and parse the push response:
164
192
 
165
193
  ```ruby
166
- response = gateway.callback(params)
194
+ response = gateway.parse_push(params)
167
195
  ```
168
196
 
169
- See `Buckaruby::CallbackResponse` for more details.
197
+ This method can also be used to parse the post data on the return page.
198
+
199
+ See `Buckaruby::PushResponse` for more details.
170
200
 
171
201
  ### Get status
172
202
 
@@ -189,7 +219,7 @@ For example:
189
219
  options = {
190
220
  amount: 10,
191
221
  payment_method: Buckaruby::PaymentMethod::IDEAL,
192
- payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first,
222
+ issuer: "INGBNL2A",
193
223
  invoicenumber: "12345",
194
224
  return_url: "http://www.return.url/",
195
225
  custom: {
@@ -209,7 +239,7 @@ In the response, you can retrieve the custom and additional variables with the m
209
239
  ```ruby
210
240
  puts response.custom[:foo]
211
241
  puts response.additional[:myreference]
212
- ````
242
+ ```
213
243
 
214
244
  ### Transaction request specification
215
245
 
@@ -241,6 +271,12 @@ All Buckaruby exceptions listed here inherit from the class `Buckaruby::Buckaroo
241
271
 
242
272
  For a complete and working example project check out [Buckaruby PoC](https://github.com/KentaaNL/buckaruby-poc).
243
273
 
274
+ ## Development
275
+
276
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
277
+
278
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
279
+
244
280
  ## Contributing
245
281
 
246
282
  Bug reports and pull requests are welcome on GitHub at https://github.com/KentaaNL/buckaruby.
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Buckaruby
4
4
  module Action
5
- PAY = "Pay"
6
- PAY_RECURRENT = "PayRecurrent"
7
- REFUND = "Refund"
8
- EXTRA_INFO = "ExtraInfo"
5
+ PAY = 'Pay'
6
+ PAY_RECURRENT = 'PayRecurrent'
7
+ REFUND = 'Refund'
8
+ EXTRA_INFO = 'ExtraInfo'
9
9
  end
10
10
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bigdecimal'
4
+
5
+ module Buckaruby
6
+ # Helper for converting/formatting amounts.
7
+ class Amount
8
+ def initialize(amount)
9
+ @amount = BigDecimal(amount.to_s)
10
+ end
11
+
12
+ def positive?
13
+ @amount.positive?
14
+ end
15
+
16
+ def to_d
17
+ @amount
18
+ end
19
+
20
+ # Convert the amount to a String with 2 decimals.
21
+ def to_s
22
+ format('%.2f', @amount)
23
+ end
24
+ end
25
+ end
@@ -5,69 +5,64 @@ require 'logger'
5
5
  module Buckaruby
6
6
  # Configuration settings for the Buckaruby Gateway.
7
7
  class Configuration
8
- TEST_URL = "https://testcheckout.buckaroo.nl/nvp/"
9
- PRODUCTION_URL = "https://checkout.buckaroo.nl/nvp/"
10
-
11
- attr_reader :website, :secret, :mode, :hash_method, :logger
8
+ TEST_URL = 'https://testcheckout.buckaroo.nl/nvp/'
9
+ LIVE_URL = 'https://checkout.buckaroo.nl/nvp/'
12
10
 
13
11
  def initialize(options)
14
- set_website(options)
15
- set_secret(options)
16
- set_buckaroo_mode(options)
17
- set_hash_method(options)
18
- set_logger(options)
12
+ @options = options
19
13
  end
20
14
 
21
15
  def test?
22
- @mode == :test
16
+ @options.fetch(:test, false)
23
17
  end
24
18
 
25
- def production?
26
- @mode == :production
19
+ def live?
20
+ !test?
27
21
  end
28
22
 
29
23
  def api_url
30
- test? ? TEST_URL : PRODUCTION_URL
31
- end
32
-
33
- private
34
-
35
- def set_website(options)
36
- @website = options[:website]
37
-
38
- raise ArgumentError, "Missing required parameter: website" if @website.to_s.empty?
24
+ live? ? LIVE_URL : TEST_URL
39
25
  end
40
26
 
41
- def set_secret(options)
42
- @secret = options[:secret]
27
+ def website
28
+ @website ||= begin
29
+ website = @options[:website]
30
+ raise ArgumentError, 'Missing required parameter: website' if website.to_s.empty?
43
31
 
44
- raise ArgumentError, "Missing required parameter: secret" if @secret.to_s.empty?
32
+ website
33
+ end
45
34
  end
46
35
 
47
- # Set Buckaroo mode from options, class setting or the default (test).
48
- def set_buckaroo_mode(options)
49
- @mode = options.key?(:mode) ? options[:mode] : Gateway.mode
50
- @mode ||= :test
36
+ def secret
37
+ @secret ||= begin
38
+ secret = @options[:secret]
39
+ raise ArgumentError, 'Missing required parameter: secret' if secret.to_s.empty?
51
40
 
52
- if @mode != :test && @mode != :production
53
- raise ArgumentError, "Invalid Buckaroo mode provided: #{@mode} (expected :test or :production)"
41
+ secret
54
42
  end
55
43
  end
56
44
 
57
- # Set the hash method from options or default (SHA-1).
58
- def set_hash_method(options)
59
- @hash_method = (options[:hash_method] || "SHA1").downcase.to_sym
45
+ # Use the hash method from options or default (SHA-1).
46
+ def hash_method
47
+ @hash_method ||= begin
48
+ hash_method = (@options[:hash_method] || 'SHA1').downcase.to_sym
60
49
 
61
- unless [:sha1, :sha256, :sha512].include?(@hash_method)
62
- raise ArgumentError, "Invalid hash method provided: #{@hash_method} (expected :sha1, :sha256 or :sha512)"
50
+ unless [:sha1, :sha256, :sha512].include?(hash_method)
51
+ raise ArgumentError, "Invalid hash method provided: #{hash_method} (expected :sha1, :sha256 or :sha512)"
52
+ end
53
+
54
+ hash_method
63
55
  end
64
56
  end
65
57
 
66
- # Set the logger from options, to Rails or to stdout.
67
- def set_logger(options)
68
- @logger = options[:logger]
69
- @logger ||= Rails.logger if defined?(Rails)
70
- @logger ||= Logger.new(STDOUT)
58
+ # Use the logger from options, to Rails or to stdout.
59
+ def logger
60
+ @logger ||= begin
61
+ logger = @options[:logger]
62
+ logger ||= Rails.logger if defined?(Rails)
63
+ logger ||= Logger.new($stdout)
64
+ logger
65
+ end
71
66
  end
72
67
  end
73
68
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Buckaruby
4
4
  module Currency
5
- EURO = "EUR"
6
- BRITISH_POUND = "GBP"
7
- US_DOLLAR = "USD"
5
+ EURO = 'EUR'
6
+ BRITISH_POUND = 'GBP'
7
+ US_DOLLAR = 'USD'
8
8
  end
9
9
  end
@@ -12,13 +12,14 @@ module Buckaruby
12
12
  def initialize(params = {})
13
13
  @params = params
14
14
 
15
- if status_message && status_code
16
- message = "API request failed: #{status_message} (#{status_code})"
17
- elsif error_message
18
- message = "API request failed: #{error_message}"
19
- else
20
- message = "API request failed"
21
- end
15
+ message =
16
+ if status_message && status_code
17
+ "API request failed: #{status_message} (#{status_code})"
18
+ elsif error_message
19
+ "API request failed: #{error_message}"
20
+ else
21
+ 'API request failed'
22
+ end
22
23
 
23
24
  super(message)
24
25
  end
@@ -60,7 +61,7 @@ module Buckaruby
60
61
  class SignatureException < BuckarooException
61
62
  attr_reader :sent_signature, :generated_signature
62
63
 
63
- def initialize(sent_signature = "", generated_signature = "")
64
+ def initialize(sent_signature, generated_signature)
64
65
  @sent_signature = sent_signature
65
66
  @generated_signature = generated_signature
66
67