buckaruby 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +20 -4
- data/.travis.yml +7 -3
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -1
- data/README.md +58 -4
- data/Rakefile +2 -0
- data/buckaruby.gemspec +1 -1
- data/lib/buckaruby.rb +3 -1
- data/lib/buckaruby/action.rb +3 -0
- data/lib/buckaruby/configuration.rb +73 -0
- data/lib/buckaruby/currency.rb +4 -0
- data/lib/buckaruby/exception.rb +26 -0
- data/lib/buckaruby/gateway.rb +99 -45
- data/lib/buckaruby/iban.rb +2 -0
- data/lib/buckaruby/ideal.rb +5 -2
- data/lib/buckaruby/language.rb +2 -0
- data/lib/buckaruby/operation.rb +4 -0
- data/lib/buckaruby/payment_method.rb +5 -1
- data/lib/buckaruby/request.rb +70 -27
- data/lib/buckaruby/response.rb +106 -37
- data/lib/buckaruby/signature.rb +8 -9
- data/lib/buckaruby/support/case_insensitive_hash.rb +2 -0
- data/lib/buckaruby/transaction_status.rb +2 -0
- data/lib/buckaruby/transaction_type.rb +2 -0
- data/lib/buckaruby/version.rb +3 -1
- data/spec/buckaruby/configuration_spec.rb +113 -0
- data/spec/buckaruby/gateway_spec.rb +165 -83
- data/spec/buckaruby/iban_spec.rb +2 -0
- data/spec/buckaruby/signature_spec.rb +38 -17
- data/spec/buckaruby/support/case_insensitive_hash_spec.rb +2 -0
- data/spec/fixtures/responses/callback_invalid_signature.txt +1 -0
- data/spec/fixtures/responses/callback_payment_cancelled.txt +1 -0
- data/spec/fixtures/responses/callback_payment_empty_transaction_type.txt +1 -0
- data/spec/fixtures/responses/callback_payment_failed.txt +1 -0
- data/spec/fixtures/responses/callback_payment_pending.txt +1 -0
- data/spec/fixtures/responses/callback_payment_rejected.txt +1 -0
- data/spec/fixtures/responses/callback_payment_sepa.txt +1 -0
- data/spec/fixtures/responses/callback_payment_success.txt +1 -0
- data/spec/fixtures/responses/callback_recurrent_sepa.txt +1 -0
- data/spec/fixtures/responses/callback_recurrent_visa.txt +1 -0
- data/spec/fixtures/responses/callback_refund_ideal.txt +1 -0
- data/spec/fixtures/responses/callback_refund_paypal.txt +1 -0
- data/spec/fixtures/responses/callback_reversal_paypal.txt +1 -0
- data/spec/fixtures/responses/callback_reversal_sepa.txt +1 -0
- data/spec/fixtures/responses/callback_valid_signature.txt +1 -0
- data/spec/fixtures/responses/cancel_success.txt +1 -0
- data/spec/fixtures/responses/recurrent_transaction_success.txt +1 -0
- data/spec/fixtures/responses/refund_info_error.txt +1 -0
- data/spec/fixtures/responses/refund_info_success.txt +1 -0
- data/spec/fixtures/responses/refund_transaction_success.txt +1 -0
- data/spec/fixtures/responses/setup_transaction_success.txt +1 -0
- data/spec/fixtures/responses/status_cancellable.txt +1 -0
- data/spec/fixtures/responses/status_noncancellable.txt +1 -0
- data/spec/fixtures/responses/status_success.txt +1 -0
- data/spec/spec_helper.rb +2 -0
- metadata +54 -4
- data/lib/buckaruby/urls.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c5c39e48aa11568771e7f89251560e47ac6a9ce8f151a05e146a8281ab58483
|
4
|
+
data.tar.gz: 450e2c0daa5a9bb0c12a119f6dd6b3aa0bf616ba35ba2403c6d47b214246e7ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0ab66f241e872cde63993bca6d996b3a773be5336850cd2495677cc39caf1e1c3286ff681c789d49362278b4d1afdfddecf4fb366bbabb75de384b4ffa2efc5
|
7
|
+
data.tar.gz: 41712687c28b2a086cedb478938b79985b50d0bd6b4aedfba21a0143f3a60a3b92fade5de73782f3a8f481184a9ec08510842a7887db045cbaad569af0a00efe
|
data/.rubocop.yml
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# Buckaruby RuboCop configuration
|
2
2
|
|
3
3
|
AllCops:
|
4
|
-
TargetRubyVersion: 2.
|
4
|
+
TargetRubyVersion: 2.3
|
5
5
|
DisplayCopNames: true
|
6
6
|
DisplayStyleGuide: true
|
7
7
|
|
8
|
+
# We target 2.3, but still want to support 2.0.
|
9
|
+
Gemspec/RequiredRubyVersion:
|
10
|
+
Enabled: false
|
11
|
+
|
8
12
|
Metrics/AbcSize:
|
9
13
|
Max: 30
|
10
14
|
|
@@ -24,10 +28,16 @@ Metrics/LineLength:
|
|
24
28
|
Metrics/MethodLength:
|
25
29
|
Enabled: false
|
26
30
|
|
31
|
+
Metrics/ModuleLength:
|
32
|
+
Enabled: false
|
33
|
+
|
27
34
|
Metrics/PerceivedComplexity:
|
28
35
|
Max: 9
|
29
36
|
|
30
|
-
|
37
|
+
Naming/AccessorMethodName:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Naming/MemoizedInstanceVariableName:
|
31
41
|
Enabled: false
|
32
42
|
|
33
43
|
Style/BlockDelimiters:
|
@@ -37,14 +47,20 @@ Style/BlockDelimiters:
|
|
37
47
|
Style/ConditionalAssignment:
|
38
48
|
Enabled: false
|
39
49
|
|
50
|
+
Style/ExpandPathArguments:
|
51
|
+
Enabled: false
|
52
|
+
|
40
53
|
Style/GuardClause:
|
41
54
|
Enabled: false
|
42
55
|
|
43
56
|
Style/IfUnlessModifier:
|
44
57
|
Enabled: false
|
45
58
|
|
46
|
-
Style/
|
59
|
+
Style/StringLiterals:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/SafeNavigation:
|
47
63
|
Enabled: false
|
48
64
|
|
49
|
-
Style/
|
65
|
+
Style/SymbolArray:
|
50
66
|
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Buckaruby changelog
|
2
2
|
|
3
|
+
## 1.1.0 (2018-06-01)
|
4
|
+
- Added payment method iDEAL processing.
|
5
|
+
- Added Moneyou to the list of iDEAL issuers.
|
6
|
+
- Implemented refund transaction.
|
7
|
+
- Implemented cancel transaction.
|
8
|
+
|
3
9
|
## 1.0.2 (2017-08-25)
|
4
10
|
|
5
11
|
- Recognize credit card transactions via Atos.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -49,6 +49,8 @@ gateway = Buckaruby::Gateway.new(
|
|
49
49
|
)
|
50
50
|
```
|
51
51
|
|
52
|
+
You can override the default mode with the parameter `mode`.
|
53
|
+
|
52
54
|
### Start transaction
|
53
55
|
|
54
56
|
To start a new transaction, use the method `setup_transaction`:
|
@@ -65,7 +67,9 @@ options = {
|
|
65
67
|
response = gateway.setup_transaction(options)
|
66
68
|
```
|
67
69
|
|
68
|
-
|
70
|
+
The response includes a `status` to check if the transaction was successful and a `redirect_url` which you can use to redirect the user to when present.
|
71
|
+
|
72
|
+
See `Buckaruby::SetupTransactionResponse` for more details.
|
69
73
|
|
70
74
|
### Recurrent transaction
|
71
75
|
|
@@ -83,6 +87,8 @@ options = {
|
|
83
87
|
}
|
84
88
|
|
85
89
|
response = gateway.setup_transaction(options)
|
90
|
+
|
91
|
+
transaction = response.transaction_id # use this for the recurrent transaction
|
86
92
|
```
|
87
93
|
|
88
94
|
The response will include a `transaction_id` which you must use to make a recurrent transaction:
|
@@ -98,7 +104,51 @@ options = {
|
|
98
104
|
response = gateway.recurrent_transaction(options)
|
99
105
|
```
|
100
106
|
|
101
|
-
|
107
|
+
The response includes a `status` to check if the transaction was successful.
|
108
|
+
|
109
|
+
See `Buckaruby::RecurrentTransactionResponse` for more details.
|
110
|
+
|
111
|
+
### Refund transaction
|
112
|
+
|
113
|
+
For some transactions it's possible to do a refund: Buckaroo creates a new "reverse" transaction based on the original transaction.
|
114
|
+
|
115
|
+
First check if the transaction is refundable, with the parameter `transaction_id` set to the original transaction ID:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
response = gateway.refundable?(transaction_id: "abcdefg")
|
119
|
+
```
|
120
|
+
|
121
|
+
If the reponse is positive then you can refund the transaction with:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
response = gateway.refund_transaction(transaction_id: "abcdefg")
|
125
|
+
```
|
126
|
+
|
127
|
+
The response includes a `status` to check if the refund was successful.
|
128
|
+
|
129
|
+
If you try to refund a transaction that's not refundable, then a `Buckaruby::NonRefundableTransactionException` will be raised.
|
130
|
+
|
131
|
+
See `Buckaruby::RefundTransactionResponse` for more details.
|
132
|
+
|
133
|
+
### Cancel transaction
|
134
|
+
|
135
|
+
Sometimes a transaction can be cancelled, for example a SEPA Direct Debit transaction before it has been offered to the bank.
|
136
|
+
|
137
|
+
You can check if the transaction is cancellable, by using the method `cancellable?` with the parameter `transaction_id`:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
response = gateway.cancellable?(transaction_id: "abcdefg")
|
141
|
+
```
|
142
|
+
|
143
|
+
If the response is positive then you can cancel the transaction with:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
response = gateway.cancel_transaction(transaction_id: "abcdefg")
|
147
|
+
```
|
148
|
+
|
149
|
+
If this does not result in an exception, then the cancel was successful.
|
150
|
+
|
151
|
+
If you try to cancel a transaction that's not cancellable, then a `Buckaruby::NonCancellableTransactionException` will be raised.
|
102
152
|
|
103
153
|
### Push response
|
104
154
|
|
@@ -108,7 +158,7 @@ Buckaroo can be configured to send push notifications for transactions. You can
|
|
108
158
|
response = gateway.callback(params)
|
109
159
|
```
|
110
160
|
|
111
|
-
|
161
|
+
See `Buckaruby::CallbackResponse` for more details.
|
112
162
|
|
113
163
|
### Get status
|
114
164
|
|
@@ -118,7 +168,7 @@ To query the status of any transaction, use the method `status` with either the
|
|
118
168
|
response = gateway.status(transaction_id: 12345)
|
119
169
|
```
|
120
170
|
|
121
|
-
|
171
|
+
See `Buckaruby::StatusResponse` for more details.
|
122
172
|
|
123
173
|
### Error handling
|
124
174
|
|
@@ -134,6 +184,10 @@ When the signature could not be verified, a `Buckaruby::SignatureException` will
|
|
134
184
|
|
135
185
|
All Buckaruby exceptions listed here inherit from the class `Buckaruby::BuckarooException`.
|
136
186
|
|
187
|
+
## Example
|
188
|
+
|
189
|
+
For a complete and working example project check out [Buckaruby PoC](https://github.com/KentaaNL/buckaruby-poc).
|
190
|
+
|
137
191
|
## Contributing
|
138
192
|
|
139
193
|
Bug reports and pull requests are welcome on GitHub at https://github.com/KentaaNL/buckaruby.
|
data/Rakefile
CHANGED
data/buckaruby.gemspec
CHANGED
data/lib/buckaruby.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'buckaruby/support/case_insensitive_hash'
|
2
4
|
|
3
5
|
require_relative 'buckaruby/action'
|
@@ -8,8 +10,8 @@ require_relative 'buckaruby/operation'
|
|
8
10
|
require_relative 'buckaruby/payment_method'
|
9
11
|
require_relative 'buckaruby/transaction_status'
|
10
12
|
require_relative 'buckaruby/transaction_type'
|
11
|
-
require_relative 'buckaruby/urls'
|
12
13
|
|
14
|
+
require_relative 'buckaruby/configuration'
|
13
15
|
require_relative 'buckaruby/exception'
|
14
16
|
require_relative 'buckaruby/gateway'
|
15
17
|
require_relative 'buckaruby/iban'
|
data/lib/buckaruby/action.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Buckaruby
|
6
|
+
# Configuration settings for the Buckaruby Gateway.
|
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
|
12
|
+
|
13
|
+
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)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test?
|
22
|
+
@mode == :test
|
23
|
+
end
|
24
|
+
|
25
|
+
def production?
|
26
|
+
@mode == :production
|
27
|
+
end
|
28
|
+
|
29
|
+
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?
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_secret(options)
|
42
|
+
@secret = options[:secret]
|
43
|
+
|
44
|
+
raise ArgumentError, "Missing required parameter: secret" if @secret.to_s.empty?
|
45
|
+
end
|
46
|
+
|
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
|
51
|
+
|
52
|
+
if @mode != :test && @mode != :production
|
53
|
+
raise ArgumentError, "Invalid Buckaroo mode provided: #{@mode} (expected :test or :production)"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
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
|
60
|
+
|
61
|
+
unless [:sha1, :sha256, :sha512].include?(@hash_method)
|
62
|
+
raise ArgumentError, "Invalid hash method provided: #{@hash_method} (expected :sha1, :sha256 or :sha512)"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
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)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/buckaruby/currency.rb
CHANGED
data/lib/buckaruby/exception.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Buckaruby
|
2
4
|
# Base class for exceptions.
|
3
5
|
class BuckarooException < StandardError
|
@@ -66,4 +68,28 @@ module Buckaruby
|
|
66
68
|
super(message)
|
67
69
|
end
|
68
70
|
end
|
71
|
+
|
72
|
+
# Exception raised when trying to refund a non refundable transaction.
|
73
|
+
class NonRefundableTransactionException < BuckarooException
|
74
|
+
attr_reader :transaction_id
|
75
|
+
|
76
|
+
def initialize(transaction_id)
|
77
|
+
@transaction_id = transaction_id
|
78
|
+
|
79
|
+
message = "Not a refundable transaction: #{transaction_id}"
|
80
|
+
super(message)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Exception raised when trying to cancel a non cancellable transaction.
|
85
|
+
class NonCancellableTransactionException < BuckarooException
|
86
|
+
attr_reader :transaction_id
|
87
|
+
|
88
|
+
def initialize(transaction_id)
|
89
|
+
@transaction_id = transaction_id
|
90
|
+
|
91
|
+
message = "Not a cancellable transaction: #{transaction_id}"
|
92
|
+
super(message)
|
93
|
+
end
|
94
|
+
end
|
69
95
|
end
|
data/lib/buckaruby/gateway.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bigdecimal'
|
2
|
-
require 'logger'
|
3
4
|
|
4
5
|
module Buckaruby
|
5
6
|
# Implementation of the BPE 3.0 NVP Gateway.
|
@@ -9,22 +10,17 @@ module Buckaruby
|
|
9
10
|
attr_accessor :mode
|
10
11
|
end
|
11
12
|
|
12
|
-
attr_reader :
|
13
|
+
attr_reader :config
|
13
14
|
|
14
15
|
def initialize(options = {})
|
15
|
-
|
16
|
-
|
17
|
-
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
18
|
-
@options = options
|
19
|
-
|
20
|
-
set_buckaroo_mode!(@options)
|
21
|
-
set_hash_method!(@options)
|
16
|
+
@config = Configuration.new(options)
|
17
|
+
@logger = config.logger
|
22
18
|
end
|
23
19
|
|
24
20
|
# Get a list with payment issuers.
|
25
21
|
def issuers(payment_method)
|
26
|
-
if payment_method != PaymentMethod::IDEAL
|
27
|
-
raise ArgumentError, "Invalid payment method, only
|
22
|
+
if payment_method != PaymentMethod::IDEAL && payment_method != PaymentMethod::IDEAL_PROCESSING
|
23
|
+
raise ArgumentError, "Invalid payment method, only iDEAL is supported."
|
28
24
|
end
|
29
25
|
|
30
26
|
Ideal::ISSUERS
|
@@ -50,6 +46,40 @@ module Buckaruby
|
|
50
46
|
execute_request(:recurrent_transaction, options)
|
51
47
|
end
|
52
48
|
|
49
|
+
# Checks if a transaction is refundable.
|
50
|
+
def refundable?(options = {})
|
51
|
+
@logger.debug("[refundable?] options=#{options.inspect}")
|
52
|
+
|
53
|
+
validate_required_params!(options, :transaction_id)
|
54
|
+
|
55
|
+
response = execute_request(:refund_info, options)
|
56
|
+
response.refundable?
|
57
|
+
end
|
58
|
+
|
59
|
+
# Refund a transaction.
|
60
|
+
def refund_transaction(options = {})
|
61
|
+
@logger.debug("[refund_transaction] options=#{options.inspect}")
|
62
|
+
|
63
|
+
validate_refund_transaction_params!(options)
|
64
|
+
|
65
|
+
response = execute_request(:refund_info, options)
|
66
|
+
unless response.refundable?
|
67
|
+
raise NonRefundableTransactionException, options[:transaction_id]
|
68
|
+
end
|
69
|
+
|
70
|
+
# Pick maximum refundable amount if amount is not supplied.
|
71
|
+
options[:amount] = response.maximum_amount unless options[:amount]
|
72
|
+
|
73
|
+
# Fill required parameters with data from refund info request.
|
74
|
+
options.merge!(
|
75
|
+
payment_method: response.payment_method,
|
76
|
+
invoicenumber: response.invoicenumber,
|
77
|
+
currency: response.currency
|
78
|
+
)
|
79
|
+
|
80
|
+
execute_request(:refund_transaction, options)
|
81
|
+
end
|
82
|
+
|
53
83
|
# Get transaction status.
|
54
84
|
def status(options = {})
|
55
85
|
@logger.debug("[status] options=#{options.inspect}")
|
@@ -59,13 +89,37 @@ module Buckaruby
|
|
59
89
|
execute_request(:status, options)
|
60
90
|
end
|
61
91
|
|
92
|
+
# Checks if a transaction is cancellable.
|
93
|
+
def cancellable?(options = {})
|
94
|
+
@logger.debug("[cancellable?] options=#{options.inspect}")
|
95
|
+
|
96
|
+
validate_required_params!(options, :transaction_id)
|
97
|
+
|
98
|
+
response = execute_request(:status, options)
|
99
|
+
response.cancellable?
|
100
|
+
end
|
101
|
+
|
102
|
+
# Cancel a transaction.
|
103
|
+
def cancel_transaction(options = {})
|
104
|
+
@logger.debug("[cancel_transaction] options=#{options.inspect}")
|
105
|
+
|
106
|
+
validate_required_params!(options, :transaction_id)
|
107
|
+
|
108
|
+
response = execute_request(:status, options)
|
109
|
+
unless response.cancellable?
|
110
|
+
raise NonCancellableTransactionException, options[:transaction_id]
|
111
|
+
end
|
112
|
+
|
113
|
+
execute_request(:cancel, options)
|
114
|
+
end
|
115
|
+
|
62
116
|
# Verify the response / callback.
|
63
117
|
def callback(response = {})
|
64
118
|
if response.empty?
|
65
119
|
raise ArgumentError, "No callback parameters found"
|
66
120
|
end
|
67
121
|
|
68
|
-
CallbackResponse.new(response,
|
122
|
+
CallbackResponse.new(response, config)
|
69
123
|
end
|
70
124
|
|
71
125
|
private
|
@@ -85,7 +139,7 @@ module Buckaruby
|
|
85
139
|
required_params << :return_url if options[:payment_method] != PaymentMethod::SEPA_DIRECT_DEBIT
|
86
140
|
|
87
141
|
case options[:payment_method]
|
88
|
-
when PaymentMethod::IDEAL
|
142
|
+
when PaymentMethod::IDEAL, PaymentMethod::IDEAL_PROCESSING
|
89
143
|
required_params << :payment_issuer
|
90
144
|
when PaymentMethod::SEPA_DIRECT_DEBIT
|
91
145
|
required_params << [:account_iban, :account_name]
|
@@ -96,7 +150,7 @@ module Buckaruby
|
|
96
150
|
validate_amount!(options)
|
97
151
|
|
98
152
|
valid_payment_methods = [
|
99
|
-
PaymentMethod::IDEAL, PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO,
|
153
|
+
PaymentMethod::IDEAL, PaymentMethod::IDEAL_PROCESSING, PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO,
|
100
154
|
PaymentMethod::SEPA_DIRECT_DEBIT, PaymentMethod::PAYPAL, PaymentMethod::BANCONTACT_MISTER_CASH
|
101
155
|
]
|
102
156
|
validate_payment_method!(options, valid_payment_methods)
|
@@ -106,7 +160,7 @@ module Buckaruby
|
|
106
160
|
|
107
161
|
# Validate amount of money, must be greater than 0.
|
108
162
|
def validate_amount!(options)
|
109
|
-
money = BigDecimal
|
163
|
+
money = BigDecimal(options[:amount].to_s)
|
110
164
|
if money <= 0
|
111
165
|
raise ArgumentError, "Invalid amount: #{options[:amount]} (must be greater than 0)"
|
112
166
|
end
|
@@ -121,7 +175,7 @@ module Buckaruby
|
|
121
175
|
|
122
176
|
# Validate the payment issuer when iDEAL is selected as payment method.
|
123
177
|
def validate_payment_issuer!(options)
|
124
|
-
if options[:payment_method] == PaymentMethod::IDEAL
|
178
|
+
if options[:payment_method] == PaymentMethod::IDEAL || options[:payment_method] == PaymentMethod::IDEAL_PROCESSING
|
125
179
|
unless Ideal::ISSUERS.include?(options[:payment_issuer])
|
126
180
|
raise ArgumentError, "Invalid payment issuer: #{options[:payment_issuer]}"
|
127
181
|
end
|
@@ -143,6 +197,17 @@ module Buckaruby
|
|
143
197
|
validate_payment_method!(options, valid_payment_methods)
|
144
198
|
end
|
145
199
|
|
200
|
+
# Validate params for refund transaction.
|
201
|
+
def validate_refund_transaction_params!(options)
|
202
|
+
unless options[:transaction_id]
|
203
|
+
raise ArgumentError, "Missing required parameter: transaction_id"
|
204
|
+
end
|
205
|
+
|
206
|
+
if options[:amount]
|
207
|
+
validate_amount!(options)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
146
211
|
# Validate params for transaction status.
|
147
212
|
def validate_status_params!(options)
|
148
213
|
if !options[:transaction_id] && !options[:payment_id]
|
@@ -157,29 +222,6 @@ module Buckaruby
|
|
157
222
|
options[:account_iban] = iban
|
158
223
|
end
|
159
224
|
|
160
|
-
# Set Buckaroo mode from options, class setting or the default (test).
|
161
|
-
def set_buckaroo_mode!(options)
|
162
|
-
mode = options.key?(:mode) ? options[:mode] : Gateway.mode
|
163
|
-
mode ||= :test
|
164
|
-
|
165
|
-
if mode != :test && mode != :production
|
166
|
-
raise ArgumentError, "Invalid Buckaroo mode provided: #{mode} (expected :test or :production)"
|
167
|
-
end
|
168
|
-
|
169
|
-
options[:mode] = mode
|
170
|
-
end
|
171
|
-
|
172
|
-
# Set the hash method from options or default (SHA-1).
|
173
|
-
def set_hash_method!(options)
|
174
|
-
hash_method = (options[:hash_method] || "SHA1").downcase.to_sym
|
175
|
-
|
176
|
-
unless [:sha1, :sha256, :sha512].include?(hash_method)
|
177
|
-
raise ArgumentError, "Invalid hash method provided: #{options[:hash_method]} (expected :sha1, :sha256 or :sha512)"
|
178
|
-
end
|
179
|
-
|
180
|
-
options[:hash_method] = hash_method
|
181
|
-
end
|
182
|
-
|
183
225
|
# Build and execute a request.
|
184
226
|
def execute_request(request_type, options)
|
185
227
|
request = build_request(request_type)
|
@@ -187,11 +229,17 @@ module Buckaruby
|
|
187
229
|
|
188
230
|
case request_type
|
189
231
|
when :setup_transaction
|
190
|
-
SetupTransactionResponse.new(response,
|
232
|
+
SetupTransactionResponse.new(response, config)
|
191
233
|
when :recurrent_transaction
|
192
|
-
RecurrentTransactionResponse.new(response,
|
234
|
+
RecurrentTransactionResponse.new(response, config)
|
235
|
+
when :refund_transaction
|
236
|
+
RefundTransactionResponse.new(response, config)
|
237
|
+
when :refund_info
|
238
|
+
RefundInfoResponse.new(response, config)
|
193
239
|
when :status
|
194
|
-
StatusResponse.new(response,
|
240
|
+
StatusResponse.new(response, config)
|
241
|
+
when :cancel
|
242
|
+
CancelResponse.new(response, config)
|
195
243
|
end
|
196
244
|
end
|
197
245
|
|
@@ -199,11 +247,17 @@ module Buckaruby
|
|
199
247
|
def build_request(request_type)
|
200
248
|
case request_type
|
201
249
|
when :setup_transaction
|
202
|
-
SetupTransactionRequest.new(
|
250
|
+
SetupTransactionRequest.new(config)
|
203
251
|
when :recurrent_transaction
|
204
|
-
RecurrentTransactionRequest.new(
|
252
|
+
RecurrentTransactionRequest.new(config)
|
253
|
+
when :refund_transaction
|
254
|
+
RefundTransactionRequest.new(config)
|
255
|
+
when :refund_info
|
256
|
+
RefundInfoRequest.new(config)
|
205
257
|
when :status
|
206
|
-
StatusRequest.new(
|
258
|
+
StatusRequest.new(config)
|
259
|
+
when :cancel
|
260
|
+
CancelRequest.new(config)
|
207
261
|
end
|
208
262
|
end
|
209
263
|
end
|