buckaruby 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -46
- data/README.md +55 -19
- data/lib/buckaruby/action.rb +4 -4
- data/lib/buckaruby/amount.rb +25 -0
- data/lib/buckaruby/configuration.rb +35 -40
- data/lib/buckaruby/currency.rb +3 -3
- data/lib/buckaruby/exception.rb +9 -8
- data/lib/buckaruby/gateway.rb +64 -72
- data/lib/buckaruby/operation.rb +5 -5
- data/lib/buckaruby/payment_method.rb +20 -11
- data/lib/buckaruby/request.rb +62 -68
- data/lib/buckaruby/response.rb +69 -67
- data/lib/buckaruby/signature.rb +26 -7
- data/lib/buckaruby/transaction_type.rb +5 -3
- data/lib/buckaruby/version.rb +1 -1
- data/lib/buckaruby.rb +1 -2
- metadata +16 -95
- data/.gitignore +0 -19
- data/.rubocop.yml +0 -107
- data/.travis.yml +0 -11
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -71
- data/Rakefile +0 -10
- data/buckaruby.gemspec +0 -28
- data/lib/buckaruby/iban.rb +0 -29
- data/lib/buckaruby/ideal.rb +0 -20
- data/spec/buckaruby/configuration_spec.rb +0 -113
- data/spec/buckaruby/field_mapper_spec.rb +0 -69
- data/spec/buckaruby/gateway_spec.rb +0 -780
- data/spec/buckaruby/iban_spec.rb +0 -75
- data/spec/buckaruby/signature_spec.rb +0 -89
- data/spec/buckaruby/support/case_insensitive_hash_spec.rb +0 -74
- data/spec/fixtures/responses/callback_invalid_signature.txt +0 -1
- data/spec/fixtures/responses/callback_payment_amex.txt +0 -1
- data/spec/fixtures/responses/callback_payment_cancelled.txt +0 -1
- data/spec/fixtures/responses/callback_payment_empty_transaction_type.txt +0 -1
- data/spec/fixtures/responses/callback_payment_failed.txt +0 -1
- data/spec/fixtures/responses/callback_payment_pending.txt +0 -1
- data/spec/fixtures/responses/callback_payment_rejected.txt +0 -1
- data/spec/fixtures/responses/callback_payment_sepa.txt +0 -1
- data/spec/fixtures/responses/callback_payment_sofort.txt +0 -1
- data/spec/fixtures/responses/callback_payment_success.txt +0 -1
- data/spec/fixtures/responses/callback_payment_visa.txt +0 -1
- data/spec/fixtures/responses/callback_recurrent_sepa.txt +0 -1
- data/spec/fixtures/responses/callback_recurrent_visa.txt +0 -1
- data/spec/fixtures/responses/callback_refund_amex.txt +0 -1
- data/spec/fixtures/responses/callback_refund_ideal.txt +0 -1
- data/spec/fixtures/responses/callback_refund_paypal.txt +0 -1
- data/spec/fixtures/responses/callback_reversal_paypal.txt +0 -1
- data/spec/fixtures/responses/callback_reversal_sepa.txt +0 -1
- data/spec/fixtures/responses/callback_valid_signature.txt +0 -1
- data/spec/fixtures/responses/cancel_success.txt +0 -1
- data/spec/fixtures/responses/recurrent_transaction_success.txt +0 -1
- data/spec/fixtures/responses/refund_info_error.txt +0 -1
- data/spec/fixtures/responses/refund_info_success.txt +0 -1
- data/spec/fixtures/responses/refund_transaction_success.txt +0 -1
- data/spec/fixtures/responses/setup_transaction_success.txt +0 -1
- data/spec/fixtures/responses/specify_transaction_success.txt +0 -1
- data/spec/fixtures/responses/status_cancellable.txt +0 -1
- data/spec/fixtures/responses/status_noncancellable.txt +0 -1
- data/spec/fixtures/responses/status_success.txt +0 -1
- data/spec/spec_helper.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db83b2eaca78370d9d3e5278c32040e54693b4ea6f6a75ca941a33ee41c14649
|
4
|
+
data.tar.gz: ea11aa90e58c1b21ce23160f598b1c79b23ea508afc900bf9c62080bc7cc6303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36710b69d25282ff9beecb8e143ddeb44f441fa84e687179833349fe301b631967b0c279f18924687613703c08450ad90c574c010d33ff6becc6ed065d3cf23b
|
7
|
+
data.tar.gz: 21010d0bf8ecaa35d019992433944da1a0c94e1516752db8308102dc88a7d54f90388a774f93c96000c39d12b355308a94476afb19bfc04ba83359137b4936c0
|
data/CHANGELOG.md
CHANGED
@@ -1,49 +1,5 @@
|
|
1
1
|
# Buckaruby changelog
|
2
2
|
|
3
|
-
|
3
|
+
We use [GitHub releases](https://github.com/KentaaNL/buckaruby/releases) for the CHANGELOG since version 2.0 of this gem.
|
4
4
|
|
5
|
-
|
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
|
-
|
25
|
-
## 1.1.1 (2018-11-30)
|
26
|
-
|
27
|
-
- Add Handelsbanken to the list of iDEAL issuers.
|
28
|
-
|
29
|
-
## 1.1.0 (2018-06-01)
|
30
|
-
|
31
|
-
- Add payment method iDEAL processing.
|
32
|
-
- Add Moneyou to the list of iDEAL issuers.
|
33
|
-
- Implement refund transaction.
|
34
|
-
- Implement cancel transaction.
|
35
|
-
|
36
|
-
## 1.0.2 (2017-08-25)
|
37
|
-
|
38
|
-
- Recognize credit card transactions via Atos.
|
39
|
-
- Fix detection of recurrent payments.
|
40
|
-
- Minor improvements to exception handling.
|
41
|
-
|
42
|
-
## 1.0.1 (2017-01-05)
|
43
|
-
|
44
|
-
- Recognize status codes 792 & 793 as a pending transaction.
|
45
|
-
- For SEPA Direct Debit, make the collect date configurable and let Buckaroo determine the default.
|
46
|
-
|
47
|
-
## 1.0.0 (2016-11-24)
|
48
|
-
|
49
|
-
- 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
@@ -1,11 +1,31 @@
|
|
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.
|
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
|
-
|
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
|
-
|
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.
|
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 `
|
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.
|
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 `
|
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.
|
194
|
+
response = gateway.parse_push(params)
|
167
195
|
```
|
168
196
|
|
169
|
-
|
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
|
-
|
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.
|
data/lib/buckaruby/action.rb
CHANGED
@@ -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 =
|
9
|
-
|
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
|
-
|
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
|
-
@
|
16
|
+
@options.fetch(:test, false)
|
23
17
|
end
|
24
18
|
|
25
|
-
def
|
26
|
-
|
19
|
+
def live?
|
20
|
+
!test?
|
27
21
|
end
|
28
22
|
|
29
23
|
def api_url
|
30
|
-
|
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
|
42
|
-
@
|
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
|
-
|
32
|
+
website
|
33
|
+
end
|
45
34
|
end
|
46
35
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
raise ArgumentError, "Invalid Buckaroo mode provided: #{@mode} (expected :test or :production)"
|
41
|
+
secret
|
54
42
|
end
|
55
43
|
end
|
56
44
|
|
57
|
-
#
|
58
|
-
def
|
59
|
-
@hash_method
|
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
|
-
|
62
|
-
|
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
|
-
#
|
67
|
-
def
|
68
|
-
@logger
|
69
|
-
|
70
|
-
|
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
|
data/lib/buckaruby/currency.rb
CHANGED
data/lib/buckaruby/exception.rb
CHANGED
@@ -12,13 +12,14 @@ module Buckaruby
|
|
12
12
|
def initialize(params = {})
|
13
13
|
@params = params
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
64
|
+
def initialize(sent_signature, generated_signature)
|
64
65
|
@sent_signature = sent_signature
|
65
66
|
@generated_signature = generated_signature
|
66
67
|
|