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
data/lib/buckaruby/signature.rb
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'digest'
|
2
4
|
|
3
5
|
module Buckaruby
|
4
6
|
# Calculate a signature based on the parameters of the payment request or response.
|
5
7
|
# -> see BPE 3.0 Gateway NVP, chapter 4 'Digital Signature'
|
6
8
|
class Signature
|
7
|
-
def self.generate_signature(params,
|
8
|
-
|
9
|
-
hash_method = options[:hash_method]
|
10
|
-
|
11
|
-
case hash_method
|
9
|
+
def self.generate_signature(params, config)
|
10
|
+
case config.hash_method
|
12
11
|
when :sha1
|
13
|
-
Digest::SHA1.hexdigest(generate_signature_string(params, secret))
|
12
|
+
Digest::SHA1.hexdigest(generate_signature_string(params, config.secret))
|
14
13
|
when :sha256
|
15
|
-
Digest::SHA256.hexdigest(generate_signature_string(params, secret))
|
14
|
+
Digest::SHA256.hexdigest(generate_signature_string(params, config.secret))
|
16
15
|
when :sha512
|
17
|
-
Digest::SHA512.hexdigest(generate_signature_string(params, secret))
|
16
|
+
Digest::SHA512.hexdigest(generate_signature_string(params, config.secret))
|
18
17
|
else
|
19
|
-
raise ArgumentError, "Invalid hash method provided: #{hash_method}"
|
18
|
+
raise ArgumentError, "Invalid hash method provided: #{config.hash_method}"
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
data/lib/buckaruby/version.rb
CHANGED
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Buckaruby::Configuration do
|
6
|
+
describe '#website' do
|
7
|
+
it 'sets the website from options' do
|
8
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D")
|
9
|
+
expect(config.website).to eq("12345678")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'raises an exception when website is missing' do
|
13
|
+
expect {
|
14
|
+
Buckaruby::Configuration.new(secret: "7C222FB2927D828AF22F592134E8932480637C0D")
|
15
|
+
}.to raise_error(ArgumentError)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#secret' do
|
20
|
+
it 'sets the secret from options' do
|
21
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D")
|
22
|
+
expect(config.secret).to eq("7C222FB2927D828AF22F592134E8932480637C0D")
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'raises an exception when secret is missing' do
|
26
|
+
expect {
|
27
|
+
Buckaruby::Configuration.new(website: "12345678")
|
28
|
+
}.to raise_error(ArgumentError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#mode' do
|
33
|
+
it 'returns test when no mode is passed' do
|
34
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D")
|
35
|
+
expect(config.mode).to eq(:test)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns test when mode test is passed' do
|
39
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :test)
|
40
|
+
expect(config.mode).to eq(:test)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns production when mode production is passed' do
|
44
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :production)
|
45
|
+
expect(config.mode).to eq(:production)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'raises an exception when an invalid mode is passed' do
|
49
|
+
expect {
|
50
|
+
Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :invalid)
|
51
|
+
}.to raise_error(ArgumentError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#hash_method' do
|
56
|
+
it 'raises an exception when an invalid hash method is passed' do
|
57
|
+
expect {
|
58
|
+
Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: :invalid)
|
59
|
+
}.to raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'accepts SHA-1 as hash method' do
|
63
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: 'SHA1')
|
64
|
+
expect(config.hash_method).to eq(:sha1)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'accepts SHA-256 as hash method' do
|
68
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: :SHA256)
|
69
|
+
expect(config.hash_method).to eq(:sha256)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'accepts SHA-512 as hash method' do
|
73
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: :sha512)
|
74
|
+
expect(config.hash_method).to eq(:sha512)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#test?' do
|
79
|
+
it 'returns true when mode is test' do
|
80
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :test)
|
81
|
+
expect(config.test?).to be true
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns false when mode is production' do
|
85
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :production)
|
86
|
+
expect(config.test?).to be false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#production?' do
|
91
|
+
it 'returns false when mode is test' do
|
92
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :test)
|
93
|
+
expect(config.production?).to be false
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns true when mode is production' do
|
97
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :production)
|
98
|
+
expect(config.production?).to be true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#api_url' do
|
103
|
+
it 'returns the test URL when mode is test' do
|
104
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :test)
|
105
|
+
expect(config.api_url).to eq("https://testcheckout.buckaroo.nl/nvp/")
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'returns the production URL when mode is production' do
|
109
|
+
config = Buckaruby::Configuration.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :production)
|
110
|
+
expect(config.api_url).to eq("https://checkout.buckaroo.nl/nvp/")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Buckaruby::Gateway do
|
@@ -21,59 +23,13 @@ describe Buckaruby::Gateway do
|
|
21
23
|
}.to raise_error(ArgumentError)
|
22
24
|
end
|
23
25
|
end
|
24
|
-
|
25
|
-
describe 'set mode' do
|
26
|
-
it 'should be test when no mode is passed' do
|
27
|
-
gateway = Buckaruby::Gateway.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D")
|
28
|
-
expect(gateway.options[:mode]).to eq(:test)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should be test when mode test is passed' do
|
32
|
-
gateway = Buckaruby::Gateway.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :test)
|
33
|
-
expect(gateway.options[:mode]).to eq(:test)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should be production when mode production is passed' do
|
37
|
-
gateway = Buckaruby::Gateway.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :production)
|
38
|
-
expect(gateway.options[:mode]).to eq(:production)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should raise an exception when an invalid mode is passed' do
|
42
|
-
expect {
|
43
|
-
Buckaruby::Gateway.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", mode: :invalid)
|
44
|
-
}.to raise_error(ArgumentError)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'set hash method' do
|
49
|
-
it 'should raise an exception when an invalid hash method is passed' do
|
50
|
-
expect {
|
51
|
-
Buckaruby::Gateway.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: :invalid)
|
52
|
-
}.to raise_error(ArgumentError)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should accept SHA-1 as hash method' do
|
56
|
-
gateway = Buckaruby::Gateway.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: 'SHA1')
|
57
|
-
expect(gateway.options[:hash_method]).to eq(:sha1)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should accept SHA-256 as hash method' do
|
61
|
-
gateway = Buckaruby::Gateway.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: :SHA256)
|
62
|
-
expect(gateway.options[:hash_method]).to eq(:sha256)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should accept SHA-512 as hash method' do
|
66
|
-
gateway = Buckaruby::Gateway.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D", hash_method: :sha512)
|
67
|
-
expect(gateway.options[:hash_method]).to eq(:sha512)
|
68
|
-
end
|
69
|
-
end
|
70
26
|
end
|
71
27
|
|
72
28
|
subject { Buckaruby::Gateway.new(website: "12345678", secret: "7C222FB2927D828AF22F592134E8932480637C0D") }
|
73
29
|
|
74
30
|
it { expect(subject).to be_an_instance_of(Buckaruby::Gateway) }
|
75
31
|
|
76
|
-
describe '
|
32
|
+
describe '#issuers' do
|
77
33
|
context 'when no or false parameters are passed' do
|
78
34
|
it 'should raise an ArgumentError' do
|
79
35
|
expect { subject.issuers }.to raise_error(ArgumentError)
|
@@ -87,20 +43,27 @@ describe Buckaruby::Gateway do
|
|
87
43
|
it { expect(issuers).to include("INGBNL2A" => "ING") }
|
88
44
|
end
|
89
45
|
|
90
|
-
context 'when
|
46
|
+
context 'when ideal processing is passed' do
|
47
|
+
let(:issuers) { subject.issuers(Buckaruby::PaymentMethod::IDEAL_PROCESSING) }
|
48
|
+
it { expect(issuers.length).to be > 0 }
|
49
|
+
it { expect(issuers).to include("RABONL2U" => "Rabobank") }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when visa, mastercard, maestro, bankcontact, sepa direct debit or paypal is passed' do
|
91
53
|
it 'should raise an ArgumentError' do
|
92
54
|
expect { subject.issuers(Buckaruby::PaymentMethod::VISA) }.to raise_error(ArgumentError)
|
93
55
|
expect { subject.issuers(Buckaruby::PaymentMethod::MASTER_CARD) }.to raise_error(ArgumentError)
|
56
|
+
expect { subject.issuers(Buckaruby::PaymentMethod::MAESTRO) }.to raise_error(ArgumentError)
|
94
57
|
expect { subject.issuers(Buckaruby::PaymentMethod::SEPA_DIRECT_DEBIT) }.to raise_error(ArgumentError)
|
58
|
+
expect { subject.issuers(Buckaruby::PaymentMethod::BANCONTACT_MISTER_CASH) }.to raise_error(ArgumentError)
|
95
59
|
expect { subject.issuers(Buckaruby::PaymentMethod::PAYPAL) }.to raise_error(ArgumentError)
|
96
60
|
end
|
97
61
|
end
|
98
62
|
end
|
99
63
|
|
100
|
-
describe '
|
64
|
+
describe '#setup_transaction' do
|
101
65
|
before(:each) do
|
102
|
-
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest")
|
103
|
-
.to_return(body: "BRQ_ACTIONREQUIRED=redirect&BRQ_AMOUNT=10.00&BRQ_APIRESULT=ActionRequired&BRQ_CURRENCY=EUR&BRQ_DESCRIPTION=Test&BRQ_INVOICENUMBER=12345&BRQ_PAYMENT=12345&BRQ_PAYMENT_METHOD=ideal&BRQ_REDIRECTURL=https%3A%2F%2Ftestcheckout.buckaroo.nl%2Fhtml%2Fredirect.ashx%3Fr%3D41C48B55FA9164E123CC73B1157459E840BE5D24&BRQ_SERVICE_IDEAL_CONSUMERISSUER=Rabobank&BRQ_STATUSCODE=791&BRQ_STATUSCODE_DETAIL=S002&BRQ_STATUSMESSAGE=An+additional+action+is+required%3A+RedirectToIdeal&BRQ_TEST=true&BRQ_TIMESTAMP=2014-11-05+13%3A10%3A40&BRQ_TRANSACTIONS=41C48B55FA9164E123CC73B1157459E840BE5D24&BRQ_WEBSITEKEY=12345678&BRQ_SIGNATURE=3d6ef7e249d9509d120c7b84f27f081adf06074b")
|
66
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(body: File.read("spec/fixtures/responses/setup_transaction_success.txt"))
|
104
67
|
end
|
105
68
|
|
106
69
|
it 'should raise an exception when initiating a transaction with missing parameters' do
|
@@ -144,8 +107,7 @@ describe Buckaruby::Gateway do
|
|
144
107
|
end
|
145
108
|
|
146
109
|
it 'should raise a ConnectionException when connection the Buckaroo fails' do
|
147
|
-
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest")
|
148
|
-
.to_raise(Errno::ECONNREFUSED)
|
110
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_raise(Errno::ECONNREFUSED)
|
149
111
|
|
150
112
|
expect {
|
151
113
|
subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first, invoicenumber: "12345", return_url: "http://www.return.url/")
|
@@ -153,8 +115,7 @@ describe Buckaruby::Gateway do
|
|
153
115
|
end
|
154
116
|
|
155
117
|
it 'should raise an InvalidResponseException when Buckaroo returns an invalid response' do
|
156
|
-
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest")
|
157
|
-
.to_return(status: 500)
|
118
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(status: 500)
|
158
119
|
|
159
120
|
expect {
|
160
121
|
subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first, invoicenumber: "12345", return_url: "http://www.return.url/")
|
@@ -162,8 +123,7 @@ describe Buckaruby::Gateway do
|
|
162
123
|
end
|
163
124
|
|
164
125
|
it 'should raise an ApiException when API result Fail is returned' do
|
165
|
-
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest")
|
166
|
-
.to_return(body: "BRQ_APIRESULT=Fail&BRQ_APIERRORMESSAGE=Invalid+request")
|
126
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(body: "BRQ_APIRESULT=Fail&BRQ_APIERRORMESSAGE=Invalid+request")
|
167
127
|
|
168
128
|
expect {
|
169
129
|
subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first, invoicenumber: "12345", return_url: "http://www.return.url/")
|
@@ -243,11 +203,9 @@ describe Buckaruby::Gateway do
|
|
243
203
|
end
|
244
204
|
end
|
245
205
|
|
246
|
-
describe '
|
206
|
+
describe '#recurrent_transaction' do
|
247
207
|
before(:each) do
|
248
|
-
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest")
|
249
|
-
.to_return(body:
|
250
|
-
"BRQ_AMOUNT=10.00&BRQ_APIRESULT=Success&BRQ_CURRENCY=EUR&BRQ_CUSTOMER_NAME=Test&BRQ_DESCRIPTION=Test&BRQ_INVOICENUMBER=12345&BRQ_ISSUING_COUNTRY=IE&BRQ_PAYMENT=8EE820309AA9455C91350DD5D3160362&BRQ_PAYMENT_METHOD=visa&BRQ_RECURRING=True&BRQ_SERVICE_VISA_CARDEXPIRATIONDATE=2016-01&BRQ_SERVICE_VISA_CARDNUMBERENDING=0969&BRQ_SERVICE_VISA_MASKEDCARDNUMBER=491611%2A%2A%2A%2A%2A%2A0969&BRQ_STATUSCODE=190&BRQ_STATUSCODE_DETAIL=S001&BRQ_STATUSMESSAGE=Transaction+successfully+processed&BRQ_TEST=true&BRQ_TIMESTAMP=2016-01-19+15%3A13%3A44&BRQ_TRANSACTIONS=41C48B55FA9164E123CC73B1157459E840BE5D24&BRQ_WEBSITEKEY=12345678&BRQ_SIGNATURE=b6a5a54c7e0d731f211c2080519e7aabc9775f47")
|
208
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(body: File.read("spec/fixtures/responses/recurrent_transaction_success.txt"))
|
251
209
|
end
|
252
210
|
|
253
211
|
it 'should raise an exception when initiating a recurrent transaction with missing parameters' do
|
@@ -282,14 +240,66 @@ describe Buckaruby::Gateway do
|
|
282
240
|
end
|
283
241
|
end
|
284
242
|
|
285
|
-
describe '
|
243
|
+
describe '#refundable?' do
|
244
|
+
it 'should raise an exception when required parameters are missing' do
|
245
|
+
expect {
|
246
|
+
subject.refundable?
|
247
|
+
}.to raise_error(ArgumentError)
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'should return true when the transaction is refundable' do
|
251
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=RefundInfo").to_return(body: File.read("spec/fixtures/responses/refund_info_success.txt"))
|
252
|
+
|
253
|
+
response = subject.refundable?(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
|
254
|
+
expect(response).to be true
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'should return false when the transaction was not found' do
|
258
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=RefundInfo").to_return(body: File.read("spec/fixtures/responses/refund_info_error.txt"))
|
259
|
+
|
260
|
+
response = subject.refundable?(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
|
261
|
+
expect(response).to be false
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe '#refund_transaction' do
|
266
|
+
it 'should raise an exception when required parameters are missing' do
|
267
|
+
expect {
|
268
|
+
subject.refund_transaction
|
269
|
+
}.to raise_error(ArgumentError)
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'should raise an exception when the transaction is not refundable' do
|
273
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=RefundInfo").to_return(body: File.read("spec/fixtures/responses/refund_info_error.txt"))
|
274
|
+
|
275
|
+
expect {
|
276
|
+
subject.refund_transaction(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
|
277
|
+
}.to raise_error(Buckaruby::NonRefundableTransactionException)
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should refund the transaction' do
|
281
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=RefundInfo").to_return(body: File.read("spec/fixtures/responses/refund_info_success.txt"))
|
282
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(body: File.read("spec/fixtures/responses/refund_transaction_success.txt"))
|
283
|
+
|
284
|
+
response = subject.refund_transaction(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
|
285
|
+
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
|
286
|
+
expect(response.transaction_type).to eq(Buckaruby::TransactionType::PAYMENT)
|
287
|
+
expect(response.payment_method).to eq(Buckaruby::PaymentMethod::IDEAL)
|
288
|
+
expect(response.transaction_id).to eq("8CCE4BB06339F28A506E1A328025D7DF13CCAD59")
|
289
|
+
expect(response.payment_id).to eq("E86256B2787EE7FF0C33D0D4C6159CD922227B79")
|
290
|
+
expect(response.refund_transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
|
291
|
+
expect(response.invoicenumber).to eq("12345")
|
292
|
+
expect(response.timestamp).to be_an_instance_of(Time)
|
293
|
+
expect(response.to_h).to be_an_instance_of(Hash)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe '#status' do
|
286
298
|
before(:each) do
|
287
|
-
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus")
|
288
|
-
.to_return(body:
|
289
|
-
"BRQ_AMOUNT=10.00&BRQ_APIRESULT=Success&BRQ_CURRENCY=EUR&BRQ_CUSTOMER_NAME=J.+de+Tester&BRQ_DESCRIPTION=Test&BRQ_INVOICENUMBER=12345&BRQ_MUTATIONTYPE=Collecting&BRQ_PAYER_HASH=e02377112efcd30bb7420bb1b9855a3778864572&BRQ_PAYMENT=E86256B2787EE7FF0C33D0D4C6159CD922227B79&BRQ_SERVICE_IDEAL_CONSUMERBIC=RABONL2U&BRQ_SERVICE_IDEAL_CONSUMERIBAN=NL44RABO0123456789&BRQ_SERVICE_IDEAL_CONSUMERISSUER=ING&BRQ_SERVICE_IDEAL_CONSUMERNAME=J.+de+Tester&BRQ_STATUSCODE=190&BRQ_STATUSCODE_DETAIL=S001&BRQ_STATUSMESSAGE=Transaction+successfully+processed&BRQ_TEST=true&BRQ_TIMESTAMP=2015-02-16+13%3A25%3A58&BRQ_TRANSACTION_CANCELABLE=False&BRQ_TRANSACTION_METHOD=ideal&BRQ_TRANSACTION_TYPE=C021&BRQ_TRANSACTIONS=41C48B55FA9164E123CC73B1157459E840BE5D24&BRQ_WEBSITEKEY=12345678&BRQ_SIGNATURE=b92de342cc863acd0c46ed3c8cb6add87668e22f")
|
299
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_success.txt"))
|
290
300
|
end
|
291
301
|
|
292
|
-
it 'should raise an exception when
|
302
|
+
it 'should raise an exception when required parameters are missing' do
|
293
303
|
expect {
|
294
304
|
subject.status
|
295
305
|
}.to raise_error(ArgumentError)
|
@@ -317,15 +327,73 @@ describe Buckaruby::Gateway do
|
|
317
327
|
end
|
318
328
|
end
|
319
329
|
|
320
|
-
describe '
|
321
|
-
it 'should raise an exception when parameters are
|
330
|
+
describe '#cancellable?' do
|
331
|
+
it 'should raise an exception when required parameters are missing' do
|
332
|
+
expect {
|
333
|
+
subject.cancellable?
|
334
|
+
}.to raise_error(ArgumentError)
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'should return true when the transaction is cancellable' do
|
338
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_cancellable.txt"))
|
339
|
+
|
340
|
+
response = subject.cancellable?(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
|
341
|
+
expect(response).to be true
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'should return false when the transaction is not cancellable' do
|
345
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_noncancellable.txt"))
|
346
|
+
|
347
|
+
response = subject.cancellable?(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
|
348
|
+
expect(response).to be false
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
describe '#cancel_transaction' do
|
353
|
+
it 'should raise an exception when required parameters are missing' do
|
354
|
+
expect {
|
355
|
+
subject.cancel_transaction
|
356
|
+
}.to raise_error(ArgumentError)
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'should raise an exception when the transaction is not cancellable' do
|
360
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_noncancellable.txt"))
|
361
|
+
|
362
|
+
expect {
|
363
|
+
subject.cancel_transaction(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
|
364
|
+
}.to raise_error(Buckaruby::NonCancellableTransactionException)
|
365
|
+
end
|
366
|
+
|
367
|
+
it 'should cancel the transaction' do
|
368
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_cancellable.txt"))
|
369
|
+
stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=CancelTransaction").to_return(body: File.read("spec/fixtures/responses/cancel_success.txt"))
|
370
|
+
|
371
|
+
response = subject.cancel_transaction(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
|
372
|
+
expect(response).to be_an_instance_of(Buckaruby::CancelResponse)
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
describe '#callback' do
|
377
|
+
it 'should raise an exception when parameters are missing' do
|
322
378
|
expect {
|
323
379
|
subject.callback
|
324
380
|
}.to raise_error(ArgumentError)
|
325
381
|
end
|
326
382
|
|
383
|
+
it 'should raise an exception when parameter is an empty Hash' do
|
384
|
+
expect {
|
385
|
+
subject.callback({})
|
386
|
+
}.to raise_error(ArgumentError)
|
387
|
+
end
|
388
|
+
|
389
|
+
it 'should raise an exception when parameter is an empty String' do
|
390
|
+
expect {
|
391
|
+
subject.callback("")
|
392
|
+
}.to raise_error(ArgumentError)
|
393
|
+
end
|
394
|
+
|
327
395
|
it 'should raise a SignatureException when the signature is invalid' do
|
328
|
-
params =
|
396
|
+
params = File.read("spec/fixtures/responses/callback_invalid_signature.txt")
|
329
397
|
|
330
398
|
expect {
|
331
399
|
subject.callback(params)
|
@@ -333,6 +401,20 @@ describe Buckaruby::Gateway do
|
|
333
401
|
end
|
334
402
|
|
335
403
|
it 'should return the status when the signature is valid' do
|
404
|
+
params = File.read("spec/fixtures/responses/callback_valid_signature.txt")
|
405
|
+
|
406
|
+
response = subject.callback(params)
|
407
|
+
expect(response).to be_an_instance_of(Buckaruby::CallbackResponse)
|
408
|
+
expect(response.transaction_status).to be
|
409
|
+
expect(response.transaction_type).to be
|
410
|
+
expect(response.payment_method).to be
|
411
|
+
expect(response.payment_id).to be
|
412
|
+
expect(response.invoicenumber).to be
|
413
|
+
expect(response.timestamp).to be_an_instance_of(Time)
|
414
|
+
expect(response.to_h).to be_an_instance_of(Hash)
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'should accept a Hash as parameters' do
|
336
418
|
params = { "brq_amount" => "10.00", "brq_currency" => "EUR", "brq_customer_name" => "J. de Tester", "brq_description" => "Test", "brq_invoicenumber" => "12345", "brq_mutationtype" => "Collecting", "brq_payer_hash" => "e02377112efcd30bb7420bb1b9855a3778864572", "brq_payment" => "E86256B2787EE7FF0C33D0D4C6159CD922227B79", "brq_service_ideal_consumerbic" => "RABONL2U", "brq_service_ideal_consumeriban" => "NL44RABO0123456789", "brq_service_ideal_consumerissuer" => "Rabobank", "brq_service_ideal_consumername" => "J. de Tester", "brq_statuscode" => "190", "brq_statuscode_detail" => "S001", "brq_statusmessage" => "Transaction successfully processed", "brq_test" => "true", "brq_timestamp" => "2014-11-05 13:10:42", "brq_transaction_method" => "ideal", "brq_transaction_type" => "C021", "brq_transactions" => "41C48B55FA9164E123CC73B1157459E840BE5D24", "brq_websitekey" => "12345678", "brq_signature" => "0a74bba15fccd8094f33678c001b44851643876d" }
|
337
419
|
|
338
420
|
response = subject.callback(params)
|
@@ -348,7 +430,7 @@ describe Buckaruby::Gateway do
|
|
348
430
|
|
349
431
|
context 'payment response' do
|
350
432
|
it 'should set the success status when payment status is success' do
|
351
|
-
params =
|
433
|
+
params = File.read("spec/fixtures/responses/callback_payment_success.txt")
|
352
434
|
|
353
435
|
response = subject.callback(params)
|
354
436
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
|
@@ -362,7 +444,7 @@ describe Buckaruby::Gateway do
|
|
362
444
|
end
|
363
445
|
|
364
446
|
it 'should set the failed status when payment status is failed' do
|
365
|
-
params =
|
447
|
+
params = File.read("spec/fixtures/responses/callback_payment_failed.txt")
|
366
448
|
|
367
449
|
response = subject.callback(params)
|
368
450
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::FAILED)
|
@@ -376,7 +458,7 @@ describe Buckaruby::Gateway do
|
|
376
458
|
end
|
377
459
|
|
378
460
|
it 'should set the rejected status when payment status is rejected' do
|
379
|
-
params =
|
461
|
+
params = File.read("spec/fixtures/responses/callback_payment_rejected.txt")
|
380
462
|
|
381
463
|
response = subject.callback(params)
|
382
464
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::REJECTED)
|
@@ -390,7 +472,7 @@ describe Buckaruby::Gateway do
|
|
390
472
|
end
|
391
473
|
|
392
474
|
it 'should set the cancelled status when payment status is cancelled' do
|
393
|
-
params =
|
475
|
+
params = File.read("spec/fixtures/responses/callback_payment_cancelled.txt")
|
394
476
|
|
395
477
|
response = subject.callback(params)
|
396
478
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::CANCELLED)
|
@@ -404,7 +486,7 @@ describe Buckaruby::Gateway do
|
|
404
486
|
end
|
405
487
|
|
406
488
|
it 'should set the pending status when payment status is pending' do
|
407
|
-
params =
|
489
|
+
params = File.read("spec/fixtures/responses/callback_payment_pending.txt")
|
408
490
|
|
409
491
|
response = subject.callback(params)
|
410
492
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::PENDING)
|
@@ -418,7 +500,7 @@ describe Buckaruby::Gateway do
|
|
418
500
|
end
|
419
501
|
|
420
502
|
it 'should include account iban, bic and name for an ideal response' do
|
421
|
-
params =
|
503
|
+
params = File.read("spec/fixtures/responses/callback_payment_success.txt")
|
422
504
|
|
423
505
|
response = subject.callback(params)
|
424
506
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
|
@@ -432,7 +514,7 @@ describe Buckaruby::Gateway do
|
|
432
514
|
end
|
433
515
|
|
434
516
|
it 'should include account iban, name, mandate reference and collect date for a sepa direct debit response' do
|
435
|
-
params =
|
517
|
+
params = File.read("spec/fixtures/responses/callback_payment_sepa.txt")
|
436
518
|
|
437
519
|
response = subject.callback(params)
|
438
520
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::PENDING)
|
@@ -450,7 +532,7 @@ describe Buckaruby::Gateway do
|
|
450
532
|
end
|
451
533
|
|
452
534
|
it 'should return transaction type payment when cancelling a visa or mastercard transaction (empty transaction type)' do
|
453
|
-
params =
|
535
|
+
params = File.read("spec/fixtures/responses/callback_payment_empty_transaction_type.txt")
|
454
536
|
|
455
537
|
response = subject.callback(params)
|
456
538
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::CANCELLED)
|
@@ -464,7 +546,7 @@ describe Buckaruby::Gateway do
|
|
464
546
|
|
465
547
|
context 'payment recurrent response' do
|
466
548
|
it 'should recognize a visa payment recurrent response' do
|
467
|
-
params =
|
549
|
+
params = File.read("spec/fixtures/responses/callback_recurrent_visa.txt")
|
468
550
|
|
469
551
|
response = subject.callback(params)
|
470
552
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
|
@@ -478,7 +560,7 @@ describe Buckaruby::Gateway do
|
|
478
560
|
end
|
479
561
|
|
480
562
|
it 'should recognize a sepa direct debit payment recurrent response' do
|
481
|
-
params =
|
563
|
+
params = File.read("spec/fixtures/responses/callback_recurrent_sepa.txt")
|
482
564
|
|
483
565
|
response = subject.callback(params)
|
484
566
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
|
@@ -494,7 +576,7 @@ describe Buckaruby::Gateway do
|
|
494
576
|
|
495
577
|
context 'refund response' do
|
496
578
|
it 'should recognize an ideal refund response' do
|
497
|
-
params =
|
579
|
+
params = File.read("spec/fixtures/responses/callback_refund_ideal.txt")
|
498
580
|
|
499
581
|
response = subject.callback(params)
|
500
582
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
|
@@ -509,7 +591,7 @@ describe Buckaruby::Gateway do
|
|
509
591
|
end
|
510
592
|
|
511
593
|
it 'should recognize a paypal refund response' do
|
512
|
-
params =
|
594
|
+
params = File.read("spec/fixtures/responses/callback_refund_paypal.txt")
|
513
595
|
|
514
596
|
response = subject.callback(params)
|
515
597
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
|
@@ -526,7 +608,7 @@ describe Buckaruby::Gateway do
|
|
526
608
|
|
527
609
|
context 'reversal response' do
|
528
610
|
it 'should recognize a sepa direct debit reversal response' do
|
529
|
-
params =
|
611
|
+
params = File.read("spec/fixtures/responses/callback_reversal_sepa.txt")
|
530
612
|
|
531
613
|
response = subject.callback(params)
|
532
614
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
|
@@ -541,7 +623,7 @@ describe Buckaruby::Gateway do
|
|
541
623
|
end
|
542
624
|
|
543
625
|
it 'should recognize a paypal reversal response' do
|
544
|
-
params =
|
626
|
+
params = File.read("spec/fixtures/responses/callback_reversal_paypal.txt")
|
545
627
|
|
546
628
|
response = subject.callback(params)
|
547
629
|
expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
|