cloud_payments 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +4 -0
  4. data/.travis.yml +8 -0
  5. data/Gemfile +10 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +106 -0
  8. data/Rakefile +7 -0
  9. data/cloud_payments.gemspec +28 -0
  10. data/config.ru +58 -0
  11. data/lib/cloud_payments.rb +34 -0
  12. data/lib/cloud_payments/client.rb +50 -0
  13. data/lib/cloud_payments/client/errors.rb +68 -0
  14. data/lib/cloud_payments/client/gateway_errors.rb +36 -0
  15. data/lib/cloud_payments/client/response.rb +22 -0
  16. data/lib/cloud_payments/client/serializer.rb +9 -0
  17. data/lib/cloud_payments/client/serializer/base.rb +46 -0
  18. data/lib/cloud_payments/client/serializer/multi_json.rb +17 -0
  19. data/lib/cloud_payments/config.rb +44 -0
  20. data/lib/cloud_payments/models.rb +4 -0
  21. data/lib/cloud_payments/models/model.rb +5 -0
  22. data/lib/cloud_payments/models/secure3d.rb +15 -0
  23. data/lib/cloud_payments/models/subscription.rb +49 -0
  24. data/lib/cloud_payments/models/transaction.rb +82 -0
  25. data/lib/cloud_payments/namespaces.rb +23 -0
  26. data/lib/cloud_payments/namespaces/base.rb +50 -0
  27. data/lib/cloud_payments/namespaces/cards.rb +25 -0
  28. data/lib/cloud_payments/namespaces/payments.rb +32 -0
  29. data/lib/cloud_payments/namespaces/subscriptions.rb +24 -0
  30. data/lib/cloud_payments/namespaces/tokens.rb +15 -0
  31. data/lib/cloud_payments/version.rb +3 -0
  32. data/spec/cloud_payments/client/response_spec.rb +35 -0
  33. data/spec/cloud_payments/client/serializer/multi_json_spec.rb +16 -0
  34. data/spec/cloud_payments/client_spec.rb +5 -0
  35. data/spec/cloud_payments/models/secure3d_spec.rb +37 -0
  36. data/spec/cloud_payments/models/subscription_spec.rb +141 -0
  37. data/spec/cloud_payments/models/transaction_spec.rb +254 -0
  38. data/spec/cloud_payments/namespaces/base_spec.rb +75 -0
  39. data/spec/cloud_payments/namespaces/cards_spec.rb +119 -0
  40. data/spec/cloud_payments/namespaces/payments_spec.rb +96 -0
  41. data/spec/cloud_payments/namespaces/subscriptions_spec.rb +82 -0
  42. data/spec/cloud_payments/namespaces/tokens_spec.rb +90 -0
  43. data/spec/cloud_payments/namespaces_spec.rb +45 -0
  44. data/spec/cloud_payments_spec.rb +14 -0
  45. data/spec/fixtures/apis/cards/auth/failed.yml +45 -0
  46. data/spec/fixtures/apis/cards/auth/secure3d.yml +15 -0
  47. data/spec/fixtures/apis/cards/auth/successful.yml +48 -0
  48. data/spec/fixtures/apis/cards/charge/failed.yml +45 -0
  49. data/spec/fixtures/apis/cards/charge/secure3d.yml +15 -0
  50. data/spec/fixtures/apis/cards/charge/successful.yml +48 -0
  51. data/spec/fixtures/apis/payments/confirm/failed.yml +6 -0
  52. data/spec/fixtures/apis/payments/confirm/failed_with_message.yml +6 -0
  53. data/spec/fixtures/apis/payments/confirm/successful.yml +6 -0
  54. data/spec/fixtures/apis/payments/post3ds/failed.yml +45 -0
  55. data/spec/fixtures/apis/payments/post3ds/successful.yml +48 -0
  56. data/spec/fixtures/apis/payments/refund/failed.yml +6 -0
  57. data/spec/fixtures/apis/payments/refund/failed_with_message.yml +6 -0
  58. data/spec/fixtures/apis/payments/refund/successful.yml +6 -0
  59. data/spec/fixtures/apis/payments/void/failed.yml +6 -0
  60. data/spec/fixtures/apis/payments/void/failed_with_message.yml +6 -0
  61. data/spec/fixtures/apis/payments/void/successful.yml +6 -0
  62. data/spec/fixtures/apis/ping/failed.yml +5 -0
  63. data/spec/fixtures/apis/ping/successful.yml +5 -0
  64. data/spec/fixtures/apis/subscriptions/cancel/successful.yml +6 -0
  65. data/spec/fixtures/apis/subscriptions/create/successful.yml +31 -0
  66. data/spec/fixtures/apis/subscriptions/find/successful.yml +31 -0
  67. data/spec/fixtures/apis/subscriptions/update/successful.yml +31 -0
  68. data/spec/fixtures/apis/tokens/auth/failed.yml +45 -0
  69. data/spec/fixtures/apis/tokens/auth/successful.yml +48 -0
  70. data/spec/fixtures/apis/tokens/charge/failed.yml +45 -0
  71. data/spec/fixtures/apis/tokens/charge/successful.yml +48 -0
  72. data/spec/spec_helper.rb +38 -0
  73. data/spec/support/examples.rb +27 -0
  74. data/spec/support/helpers.rb +89 -0
  75. metadata +244 -0
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ class TestNamespace < CloudPayments::Namespaces::Base
4
+ end
5
+
6
+ describe CloudPayments::Namespaces::Base do
7
+ let(:headers){ { 'Content-Type' => 'application/json' } }
8
+ let(:successful_body){ '{"Model":{},"Success":true}' }
9
+ let(:failed_body){ '{"Success":false,"Message":"Error message"}' }
10
+ let(:failed_transaction_body){ '{"Model":{"ReasonCode":5041,"CardHolderMessage":"Contact your bank"},"Success":false}' }
11
+ let(:request_body){ '{"Amount":120,"CurrencyCode":"RUB"}' }
12
+ let(:request_params){ { amount: 120, currency_code: 'RUB' } }
13
+
14
+ subject{ TestNamespace.new(CloudPayments.client) }
15
+
16
+ def stub_api(path, body = '')
17
+ url = "http://user:pass@localhost:9292#{path}"
18
+ stub_request(:post, url).with(body: body, headers: headers)
19
+ end
20
+
21
+ describe '#request' do
22
+ context do
23
+ before{ stub_api('/testnamespace', request_body).to_return(body: successful_body, headers: headers) }
24
+ specify{ expect(subject.request(nil, request_params)) }
25
+ end
26
+
27
+ context 'with path' do
28
+ before{ stub_api('/testnamespace/path', request_body).to_return(body: successful_body, headers: headers) }
29
+
30
+ specify{ expect(subject.request(:path, request_params)) }
31
+ end
32
+
33
+ context 'with path and parent path' do
34
+ subject{ TestNamespace.new(CloudPayments.client, 'parent') }
35
+
36
+ before{ stub_api('/parent/testnamespace/path', request_body).to_return(body: successful_body, headers: headers) }
37
+
38
+ specify{ expect(subject.request(:path, request_params)) }
39
+ end
40
+
41
+ context 'when status is greater than 300' do
42
+ before{ stub_api('/testnamespace/path', request_body).to_return(status: 404, headers: headers) }
43
+
44
+ specify{ expect{ subject.request(:path, request_params) }.to raise_error(CloudPayments::Client::Errors::NotFound) }
45
+ end
46
+
47
+ context 'when failed request' do
48
+ before{ stub_api('/testnamespace/path', request_body).to_return(body: failed_body, headers: headers) }
49
+
50
+ context 'config.raise_banking_errors = true' do
51
+ before { CloudPayments.config.raise_banking_errors = true }
52
+ specify{ expect{ subject.request(:path, request_params) }.to raise_error(CloudPayments::Client::GatewayError, 'Error message') }
53
+ end
54
+
55
+ context 'config.raise_banking_errors = false' do
56
+ before { CloudPayments.config.raise_banking_errors = false }
57
+ specify{ expect{ subject.request(:path, request_params) }.to raise_error(CloudPayments::Client::GatewayError, 'Error message') }
58
+ end
59
+ end
60
+
61
+ context 'when failed transaction' do
62
+ before{ stub_api('/testnamespace/path', request_body).to_return(body: failed_transaction_body, headers: headers) }
63
+
64
+ context 'config.raise_banking_errors = true' do
65
+ before { CloudPayments.config.raise_banking_errors = true }
66
+ specify{ expect{ subject.request(:path, request_params) }.to raise_error(CloudPayments::Client::GatewayErrors::LostCard) }
67
+ end
68
+
69
+ context 'config.raise_banking_errors = false' do
70
+ before { CloudPayments.config.raise_banking_errors = false }
71
+ specify{ expect{ subject.request(:path, request_params) }.not_to raise_error }
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe CloudPayments::Namespaces::Cards do
4
+ subject{ CloudPayments::Namespaces::Cards.new(CloudPayments.client, '/payments') }
5
+
6
+ let(:attributes){ {
7
+ amount: 10,
8
+ currency: 'RUB',
9
+ invoice_id: '1234567',
10
+ description: 'Payment for goods on example.com',
11
+ account_id: 'user_x',
12
+ name: 'CARDHOLDER NAME',
13
+ card_cryptogram_packet: '01492500008719030128SM'
14
+ } }
15
+
16
+ context do
17
+ context 'config.raise_banking_errors = false' do
18
+ before { CloudPayments.config.raise_banking_errors = false }
19
+
20
+ describe '#charge' do
21
+ before{ stub_api_request('cards/charge/successful').perform }
22
+ specify{ expect(subject.charge(attributes)).to be_instance_of(CloudPayments::Transaction) }
23
+ specify{ expect(subject.charge(attributes)).not_to be_required_secure3d }
24
+ specify{ expect(subject.charge(attributes)).to be_completed }
25
+ specify{ expect(subject.charge(attributes).id).to eq(12345) }
26
+ end
27
+
28
+ context do
29
+ before{ stub_api_request('cards/charge/secure3d').perform }
30
+ specify{ expect(subject.charge(attributes)).to be_instance_of(CloudPayments::Secure3D) }
31
+ specify{ expect(subject.charge(attributes)).to be_required_secure3d }
32
+ specify{ expect(subject.charge(attributes).id).to eq(12345) }
33
+ specify{ expect(subject.charge(attributes).transaction_id).to eq(12345) }
34
+ specify{ expect(subject.charge(attributes).pa_req).to eq('eJxVUdtugkAQ') }
35
+ specify{ expect(subject.charge(attributes).acs_url).to eq('https://test.paymentgate.ru/acs/auth/start.do') }
36
+ end
37
+
38
+ context do
39
+ before{ stub_api_request('cards/charge/failed').perform }
40
+ specify{ expect(subject.charge(attributes)).to be_instance_of(CloudPayments::Transaction) }
41
+ specify{ expect(subject.charge(attributes)).not_to be_required_secure3d }
42
+ specify{ expect(subject.charge(attributes)).to be_declined }
43
+ specify{ expect(subject.charge(attributes).id).to eq(12345) }
44
+ specify{ expect(subject.charge(attributes).reason).to eq('InsufficientFunds') }
45
+ end
46
+ end
47
+
48
+ context 'config.raise_banking_errors = true' do
49
+ before { CloudPayments.config.raise_banking_errors = true }
50
+
51
+ context do
52
+ before{ stub_api_request('cards/charge/successful').perform }
53
+ specify{ expect{ subject.charge(attributes) }.not_to raise_error }
54
+ end
55
+
56
+ context do
57
+ before{ stub_api_request('cards/charge/secure3d').perform }
58
+ specify{ expect{ subject.charge(attributes) }.not_to raise_error }
59
+ end
60
+
61
+ context do
62
+ before{ stub_api_request('cards/charge/failed').perform }
63
+ specify{ expect{ subject.charge(attributes) }.to raise_error(CloudPayments::Client::GatewayErrors::InsufficientFunds) }
64
+ end
65
+ end
66
+ end
67
+
68
+ describe '#auth' do
69
+ context 'config.raise_banking_errors = false' do
70
+ before { CloudPayments.config.raise_banking_errors = false }
71
+
72
+ context do
73
+ before{ stub_api_request('cards/auth/successful').perform }
74
+ specify{ expect(subject.auth(attributes)).to be_instance_of(CloudPayments::Transaction) }
75
+ specify{ expect(subject.auth(attributes)).not_to be_required_secure3d }
76
+ specify{ expect(subject.auth(attributes)).to be_authorized }
77
+ specify{ expect(subject.auth(attributes).id).to eq(12345) }
78
+ end
79
+
80
+ context do
81
+ before{ stub_api_request('cards/auth/secure3d').perform }
82
+ specify{ expect(subject.auth(attributes)).to be_instance_of(CloudPayments::Secure3D) }
83
+ specify{ expect(subject.auth(attributes)).to be_required_secure3d }
84
+ specify{ expect(subject.auth(attributes).id).to eq(12345) }
85
+ specify{ expect(subject.auth(attributes).transaction_id).to eq(12345) }
86
+ specify{ expect(subject.auth(attributes).pa_req).to eq('eJxVUdtugkAQ') }
87
+ specify{ expect(subject.auth(attributes).acs_url).to eq('https://test.paymentgate.ru/acs/auth/start.do') }
88
+ end
89
+
90
+ context do
91
+ before{ stub_api_request('cards/auth/failed').perform }
92
+ specify{ expect(subject.auth(attributes)).to be_instance_of(CloudPayments::Transaction) }
93
+ specify{ expect(subject.auth(attributes)).not_to be_required_secure3d }
94
+ specify{ expect(subject.auth(attributes)).to be_declined }
95
+ specify{ expect(subject.auth(attributes).id).to eq(12345) }
96
+ specify{ expect(subject.auth(attributes).reason).to eq('InsufficientFunds') }
97
+ end
98
+ end
99
+
100
+ context 'config.raise_banking_errors = true' do
101
+ before { CloudPayments.config.raise_banking_errors = true }
102
+
103
+ context do
104
+ before{ stub_api_request('cards/auth/successful').perform }
105
+ specify{ expect{ subject.auth(attributes) }.not_to raise_error }
106
+ end
107
+
108
+ context do
109
+ before{ stub_api_request('cards/auth/secure3d').perform }
110
+ specify{ expect{ subject.auth(attributes) }.not_to raise_error }
111
+ end
112
+
113
+ context do
114
+ before{ stub_api_request('cards/auth/failed').perform }
115
+ specify{ expect{ subject.auth(attributes) }.to raise_error(CloudPayments::Client::GatewayErrors::InsufficientFunds) }
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe CloudPayments::Namespaces::Payments do
4
+ subject{ CloudPayments::Namespaces::Payments.new(CloudPayments.client) }
5
+
6
+ describe '#cards' do
7
+ specify{ expect(subject.cards).to be_instance_of(CloudPayments::Namespaces::Cards) }
8
+ specify{ expect(subject.cards.parent_path).to eq('payments') }
9
+ end
10
+
11
+ describe '#tokens' do
12
+ specify{ expect(subject.tokens).to be_instance_of(CloudPayments::Namespaces::Tokens) }
13
+ specify{ expect(subject.tokens.parent_path).to eq('payments') }
14
+ end
15
+
16
+ describe '#confirm' do
17
+ context do
18
+ before{ stub_api_request('payments/confirm/successful').perform }
19
+ specify{ expect(subject.confirm(12345, 120)).to be_truthy }
20
+ end
21
+
22
+ context do
23
+ before{ stub_api_request('payments/confirm/failed').perform }
24
+ specify{ expect(subject.confirm(12345, 120)).to be_falsy }
25
+ end
26
+
27
+ context do
28
+ before{ stub_api_request('payments/confirm/failed_with_message').perform }
29
+ specify{ expect{ subject.confirm(12345, 120) }.to raise_error(CloudPayments::Client::GatewayError, 'Error message') }
30
+ end
31
+ end
32
+
33
+ describe '#void' do
34
+ context do
35
+ before{ stub_api_request('payments/void/successful').perform }
36
+ specify{ expect(subject.void(12345)).to be_truthy }
37
+ end
38
+
39
+ context do
40
+ before{ stub_api_request('payments/void/failed').perform }
41
+ specify{ expect(subject.void(12345)).to be_falsy }
42
+ end
43
+
44
+ context do
45
+ before{ stub_api_request('payments/void/failed_with_message').perform }
46
+ specify{ expect{ subject.void(12345) }.to raise_error(CloudPayments::Client::GatewayError, 'Error message') }
47
+ end
48
+ end
49
+
50
+ describe '#refund' do
51
+ context do
52
+ before{ stub_api_request('payments/refund/successful').perform }
53
+ specify{ expect(subject.refund(12345, 120)).to be_truthy }
54
+ end
55
+
56
+ context do
57
+ before{ stub_api_request('payments/refund/failed').perform }
58
+ specify{ expect(subject.refund(12345, 120)).to be_falsy }
59
+ end
60
+
61
+ context do
62
+ before{ stub_api_request('payments/refund/failed_with_message').perform }
63
+ specify{ expect{ subject.refund(12345, 120) }.to raise_error(CloudPayments::Client::GatewayError, 'Error message') }
64
+ end
65
+ end
66
+
67
+ describe '#post3ds' do
68
+ context 'config.raise_banking_errors = false' do
69
+ before { CloudPayments.config.raise_banking_errors = false }
70
+
71
+ context do
72
+ before{ stub_api_request('payments/post3ds/successful').perform }
73
+ specify{ expect(subject.post3ds(12345, 'eJxVUdtugkAQ')).to be_instance_of(CloudPayments::Transaction) }
74
+ end
75
+
76
+ context do
77
+ before{ stub_api_request('payments/post3ds/failed').perform }
78
+ specify{ expect{ subject.post3ds(12345, 'eJxVUdtugkAQ') }.not_to raise_error }
79
+ end
80
+ end
81
+
82
+ context 'config.raise_banking_errors = true' do
83
+ before { CloudPayments.config.raise_banking_errors = true }
84
+
85
+ context do
86
+ before{ stub_api_request('payments/post3ds/successful').perform }
87
+ specify{ expect{ subject.post3ds(12345, 'eJxVUdtugkAQ') }.not_to raise_error }
88
+ end
89
+
90
+ context do
91
+ before{ stub_api_request('payments/post3ds/failed').perform }
92
+ specify{ expect{ subject.post3ds(12345, 'eJxVUdtugkAQ') }.to raise_error(CloudPayments::Client::GatewayErrors::InsufficientFunds) }
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe CloudPayments::Namespaces::Subscriptions do
4
+ subject{ CloudPayments::Namespaces::Subscriptions.new(CloudPayments.client) }
5
+
6
+ describe '#find' do
7
+ context do
8
+ before{ stub_api_request('subscriptions/find/successful').perform }
9
+
10
+ specify{ expect(subject.find('sc_8cf8a9338fb')).to be_instance_of(CloudPayments::Subscription) }
11
+
12
+ context do
13
+ let(:sub){ subject.find('sc_8cf8a9338fb') }
14
+
15
+ specify{ expect(sub.id).to eq('sc_8cf8a9338fb') }
16
+ specify{ expect(sub.account_id).to eq('user@example.com') }
17
+ specify{ expect(sub.description).to eq('Monthly subscription') }
18
+ specify{ expect(sub.started_at).to eq(DateTime.parse('2014-08-09T11:49:41')) }
19
+ specify{ expect(sub).to be_active }
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '#create' do
25
+ let(:attributes){ {
26
+ token: '477BBA133C182267F',
27
+ account_id: 'user@example.com',
28
+ description: 'Monthly subscription',
29
+ email: 'user@example.com',
30
+ amount: 1.02,
31
+ currency: 'RUB',
32
+ require_confirmation: false,
33
+ start_date: '2014-08-09T11:49:41',
34
+ interval: 'Month',
35
+ period: 1,
36
+ max_periods: 12
37
+ } }
38
+
39
+ context do
40
+ before{ stub_api_request('subscriptions/create/successful').perform }
41
+
42
+ specify{ expect(subject.create(attributes)).to be_instance_of(CloudPayments::Subscription) }
43
+
44
+ context do
45
+ let(:sub){ subject.create(attributes) }
46
+
47
+ specify{ expect(sub.id).to eq('sc_8cf8a9338fb') }
48
+ specify{ expect(sub.account_id).to eq('user@example.com') }
49
+ specify{ expect(sub.description).to eq('Monthly subscription') }
50
+ specify{ expect(sub.started_at).to eq(DateTime.parse('2014-08-09T11:49:41')) }
51
+ specify{ expect(sub).to be_active }
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#update' do
57
+ let(:attributes){ { account_id: 'user2@example.com', email: 'user2@example.com', max_periods: 6 } }
58
+
59
+ context do
60
+ before{ stub_api_request('subscriptions/update/successful').perform }
61
+
62
+ specify{ expect(subject.update('sc_8cf8a9338fb', attributes)).to be_instance_of(CloudPayments::Subscription) }
63
+
64
+ context do
65
+ let(:sub){ subject.update('sc_8cf8a9338fb', attributes) }
66
+
67
+ specify{ expect(sub.id).to eq('sc_8cf8a9338fb') }
68
+ specify{ expect(sub.account_id).to eq('user2@example.com') }
69
+ specify{ expect(sub.max_periods).to eq(6) }
70
+ specify{ expect(sub).to be_active }
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#cancel' do
76
+ context do
77
+ before{ stub_api_request('subscriptions/cancel/successful').perform }
78
+
79
+ specify{ expect(subject.cancel('sc_8cf8a9338fb')).to be_truthy }
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe CloudPayments::Namespaces::Tokens do
4
+ subject{ CloudPayments::Namespaces::Tokens.new(CloudPayments.client, '/payments') }
5
+
6
+ let(:attributes){ {
7
+ amount: 10,
8
+ currency: 'RUB',
9
+ invoice_id: '1234567',
10
+ description: 'Payment for goods on example.com',
11
+ account_id: 'user_x',
12
+ name: 'CARDHOLDER NAME',
13
+ token: 'a4e67841-abb0-42de-a364-d1d8f9f4b3c0'
14
+ } }
15
+
16
+ describe '#charge' do
17
+ context 'config.raise_banking_errors = true' do
18
+ before { CloudPayments.config.raise_banking_errors = true }
19
+ after { CloudPayments.config.raise_banking_errors = false }
20
+
21
+ context do
22
+ before { stub_api_request('tokens/charge/successful').perform }
23
+ specify{ expect{ subject.charge(attributes) }.not_to raise_error }
24
+ end
25
+
26
+ context do
27
+ before { stub_api_request('tokens/charge/failed').perform }
28
+ specify{ expect{ subject.charge(attributes) }.to raise_error(CloudPayments::Client::GatewayErrors::InsufficientFunds) }
29
+ end
30
+ end
31
+
32
+ context 'config.raise_banking_errors = false' do
33
+ before { CloudPayments.config.raise_banking_errors = false }
34
+
35
+ context do
36
+ before{ stub_api_request('tokens/charge/successful').perform }
37
+ specify{ expect(subject.charge(attributes)).to be_instance_of(CloudPayments::Transaction) }
38
+ specify{ expect(subject.charge(attributes)).not_to be_required_secure3d }
39
+ specify{ expect(subject.charge(attributes)).to be_completed }
40
+ specify{ expect(subject.charge(attributes).id).to eq(12345) }
41
+ end
42
+
43
+ context do
44
+ before{ stub_api_request('tokens/charge/failed').perform }
45
+ specify{ expect(subject.charge(attributes)).to be_instance_of(CloudPayments::Transaction) }
46
+ specify{ expect(subject.charge(attributes)).not_to be_required_secure3d }
47
+ specify{ expect(subject.charge(attributes)).to be_declined }
48
+ specify{ expect(subject.charge(attributes).id).to eq(12345) }
49
+ specify{ expect(subject.charge(attributes).reason).to eq('InsufficientFunds') }
50
+ end
51
+ end
52
+ end
53
+
54
+ describe '#auth' do
55
+ context 'config.raise_banking_errors = true' do
56
+ before { CloudPayments.config.raise_banking_errors = true }
57
+
58
+ context do
59
+ before { stub_api_request('tokens/auth/successful').perform }
60
+ specify{ expect{ subject.auth(attributes) }.not_to raise_error }
61
+ end
62
+
63
+ context do
64
+ before { stub_api_request('tokens/auth/failed').perform }
65
+ specify{ expect{ subject.auth(attributes) }.to raise_error(CloudPayments::Client::GatewayErrors::InsufficientFunds) }
66
+ end
67
+ end
68
+
69
+ context 'config.raise_banking_errors = false' do
70
+ before { CloudPayments.config.raise_banking_errors = false }
71
+
72
+ context do
73
+ before{ stub_api_request('tokens/auth/successful').perform }
74
+ specify{ expect(subject.auth(attributes)).to be_instance_of(CloudPayments::Transaction) }
75
+ specify{ expect(subject.auth(attributes)).not_to be_required_secure3d }
76
+ specify{ expect(subject.auth(attributes)).to be_authorized }
77
+ specify{ expect(subject.auth(attributes).id).to eq(12345) }
78
+ end
79
+
80
+ context do
81
+ before{ stub_api_request('tokens/auth/failed').perform }
82
+ specify{ expect(subject.auth(attributes)).to be_instance_of(CloudPayments::Transaction) }
83
+ specify{ expect(subject.auth(attributes)).not_to be_required_secure3d }
84
+ specify{ expect(subject.auth(attributes)).to be_declined }
85
+ specify{ expect(subject.auth(attributes).id).to eq(12345) }
86
+ specify{ expect(subject.auth(attributes).reason).to eq('InsufficientFunds') }
87
+ end
88
+ end
89
+ end
90
+ end