cloud_payments 0.0.2 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +12 -6
- data/Gemfile +2 -2
- data/README.md +88 -5
- data/Rakefile +1 -0
- data/cloud_payments.gemspec +8 -8
- data/config.ru +1 -0
- data/lib/cloud_payments.rb +6 -1
- data/lib/cloud_payments/client.rb +3 -2
- data/lib/cloud_payments/client/errors.rb +1 -0
- data/lib/cloud_payments/client/gateway_errors.rb +3 -1
- data/lib/cloud_payments/client/response.rb +2 -1
- data/lib/cloud_payments/client/serializer.rb +1 -0
- data/lib/cloud_payments/client/serializer/base.rb +9 -1
- data/lib/cloud_payments/client/serializer/multi_json.rb +1 -0
- data/lib/cloud_payments/config.rb +4 -0
- data/lib/cloud_payments/models.rb +8 -0
- data/lib/cloud_payments/models/like_subscription.rb +30 -0
- data/lib/cloud_payments/models/model.rb +9 -0
- data/lib/cloud_payments/models/on_fail.rb +31 -0
- data/lib/cloud_payments/models/on_kassa_receipt.rb +23 -0
- data/lib/cloud_payments/models/on_pay.rb +37 -0
- data/lib/cloud_payments/models/on_recurrent.rb +22 -0
- data/lib/cloud_payments/models/order.rb +14 -0
- data/lib/cloud_payments/models/secure3d.rb +1 -0
- data/lib/cloud_payments/models/subscription.rb +9 -32
- data/lib/cloud_payments/models/transaction.rb +13 -4
- data/lib/cloud_payments/namespaces.rb +12 -1
- data/lib/cloud_payments/namespaces/base.rb +2 -1
- data/lib/cloud_payments/namespaces/cards.rb +6 -0
- data/lib/cloud_payments/namespaces/kassa.rb +22 -0
- data/lib/cloud_payments/namespaces/orders.rb +15 -0
- data/lib/cloud_payments/namespaces/payments.rb +11 -0
- data/lib/cloud_payments/namespaces/subscriptions.rb +6 -0
- data/lib/cloud_payments/namespaces/tokens.rb +1 -0
- data/lib/cloud_payments/version.rb +2 -1
- data/lib/cloud_payments/webhooks.rb +42 -0
- data/spec/cloud_payments/client/response_spec.rb +3 -1
- data/spec/cloud_payments/client/serializer/multi_json_spec.rb +1 -0
- data/spec/cloud_payments/models/order_spec.rb +62 -0
- data/spec/cloud_payments/models/secure3d_spec.rb +1 -0
- data/spec/cloud_payments/models/subscription_spec.rb +1 -1
- data/spec/cloud_payments/models/transaction_spec.rb +25 -1
- data/spec/cloud_payments/namespaces/base_spec.rb +10 -3
- data/spec/cloud_payments/namespaces/cards_spec.rb +42 -2
- data/spec/cloud_payments/namespaces/kassa_spec.rb +43 -0
- data/spec/cloud_payments/namespaces/orders_spec.rb +57 -0
- data/spec/cloud_payments/namespaces/payments_spec.rb +119 -0
- data/spec/cloud_payments/namespaces/subscriptions_spec.rb +21 -1
- data/spec/cloud_payments/namespaces/tokens_spec.rb +1 -0
- data/spec/cloud_payments/namespaces_spec.rb +2 -1
- data/spec/cloud_payments/webhooks_spec.rb +272 -0
- data/spec/cloud_payments_spec.rb +27 -4
- data/spec/fixtures/apis/cards/post3ds/failed.yml +45 -0
- data/spec/fixtures/apis/cards/post3ds/successful.yml +48 -0
- data/spec/fixtures/apis/orders/cancel/failed.yml +6 -0
- data/spec/fixtures/apis/orders/cancel/successful.yml +6 -0
- data/spec/fixtures/apis/orders/create/successful.yml +20 -0
- data/spec/fixtures/apis/payments/find/failed.yml +45 -0
- data/spec/fixtures/apis/payments/find/failed_with_message.yml +6 -0
- data/spec/fixtures/apis/payments/find/successful.yml +48 -0
- data/spec/fixtures/apis/payments/get/failed.yml +46 -0
- data/spec/fixtures/apis/payments/get/failed_with_message.yml +6 -0
- data/spec/fixtures/apis/payments/get/refunded.yml +49 -0
- data/spec/fixtures/apis/payments/get/successful.yml +49 -0
- data/spec/fixtures/apis/subscriptions/find/successful.yml +4 -4
- data/spec/fixtures/apis/subscriptions/get/successful.yml +31 -0
- data/spec/spec_helper.rb +13 -24
- data/spec/support/examples.rb +1 -0
- data/spec/support/helpers.rb +3 -2
- metadata +62 -34
- data/spec/cloud_payments/client_spec.rb +0 -5
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe CloudPayments::Subscription do
|
@@ -53,7 +54,6 @@ describe CloudPayments::Subscription do
|
|
53
54
|
|
54
55
|
it_behaves_like :raise_without_attribute, :id
|
55
56
|
it_behaves_like :raise_without_attribute, :account_id
|
56
|
-
it_behaves_like :raise_without_attribute, :description
|
57
57
|
it_behaves_like :raise_without_attribute, :email
|
58
58
|
it_behaves_like :raise_without_attribute, :amount
|
59
59
|
it_behaves_like :raise_without_attribute, :currency_code
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe CloudPayments::Transaction do
|
@@ -33,11 +34,13 @@ describe CloudPayments::Transaction do
|
|
33
34
|
card_type: 'Visa',
|
34
35
|
card_type_code: 0,
|
35
36
|
card_exp_date: '10/17',
|
37
|
+
issuer: 'Sberbank of Russia',
|
36
38
|
issuer_bank_country: 'RU',
|
37
39
|
status: 'Completed',
|
38
40
|
status_code: 3,
|
39
41
|
reason: 'Approved',
|
40
42
|
reason_code: 0,
|
43
|
+
refunded: false,
|
41
44
|
card_holder_message: 'Payment successful',
|
42
45
|
name: 'CARDHOLDER NAME',
|
43
46
|
token: 'a4e67841-abb0-42de-a364-d1d8f9f4b3c0'
|
@@ -71,12 +74,14 @@ describe CloudPayments::Transaction do
|
|
71
74
|
specify{ expect(subject.card_type).to eq('Visa') }
|
72
75
|
specify{ expect(subject.card_type_code).to eq(0) }
|
73
76
|
specify{ expect(subject.card_exp_date).to eq('10/17') }
|
77
|
+
specify{ expect(subject.issuer).to eq('Sberbank of Russia') }
|
74
78
|
specify{ expect(subject.issuer_bank_country).to eq('RU') }
|
75
79
|
specify{ expect(subject.reason).to eq('Approved') }
|
76
80
|
specify{ expect(subject.reason_code).to eq(0) }
|
77
81
|
specify{ expect(subject.card_holder_message).to eq('Payment successful') }
|
78
82
|
specify{ expect(subject.name).to eq('CARDHOLDER NAME') }
|
79
83
|
specify{ expect(subject.token).to eq('a4e67841-abb0-42de-a364-d1d8f9f4b3c0') }
|
84
|
+
specify{ expect(subject.refunded).to eq(false) }
|
80
85
|
|
81
86
|
context 'without any attributes' do
|
82
87
|
let(:attributes){ {} }
|
@@ -110,9 +115,11 @@ describe CloudPayments::Transaction do
|
|
110
115
|
it_behaves_like :not_raise_without_attribute, :ip_longitude, :ip_lng
|
111
116
|
it_behaves_like :not_raise_without_attribute, :card_type_code
|
112
117
|
it_behaves_like :not_raise_without_attribute, :card_exp_date
|
118
|
+
it_behaves_like :not_raise_without_attribute, :issuer
|
113
119
|
it_behaves_like :not_raise_without_attribute, :issuer_bank_country
|
114
120
|
it_behaves_like :not_raise_without_attribute, :reason
|
115
121
|
it_behaves_like :not_raise_without_attribute, :reason_code
|
122
|
+
it_behaves_like :not_raise_without_attribute, :refunded
|
116
123
|
it_behaves_like :not_raise_without_attribute, :card_holder_message
|
117
124
|
it_behaves_like :not_raise_without_attribute, :name
|
118
125
|
it_behaves_like :not_raise_without_attribute, :token
|
@@ -205,7 +212,7 @@ describe CloudPayments::Transaction do
|
|
205
212
|
subject{ CloudPayments::Transaction.new(default_attributes.merge(attributes)) }
|
206
213
|
|
207
214
|
describe '#subscription' do
|
208
|
-
before{ stub_api_request('subscriptions/
|
215
|
+
before{ stub_api_request('subscriptions/get/successful').perform }
|
209
216
|
|
210
217
|
context 'with subscription_id' do
|
211
218
|
let(:attributes){ { subscription_id: 'sc_8cf8a9338fb' } }
|
@@ -250,5 +257,22 @@ describe CloudPayments::Transaction do
|
|
250
257
|
specify{ expect(subject.ip_location).to be_nil }
|
251
258
|
end
|
252
259
|
end
|
260
|
+
|
261
|
+
describe '#refunded?' do
|
262
|
+
context do
|
263
|
+
let(:attributes) { { refunded: false } }
|
264
|
+
specify { expect(subject.refunded?).to be_falsey }
|
265
|
+
end
|
266
|
+
|
267
|
+
context do
|
268
|
+
let(:attributes) { { refunded: true } }
|
269
|
+
specify { expect(subject.refunded?).to be_truthy }
|
270
|
+
end
|
271
|
+
|
272
|
+
context do
|
273
|
+
let(:attributes) { { refunded: nil } }
|
274
|
+
specify { expect(subject.refunded?).to be_falsey }
|
275
|
+
end
|
276
|
+
end
|
253
277
|
end
|
254
278
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
class TestNamespace < CloudPayments::Namespaces::Base
|
@@ -14,8 +15,8 @@ describe CloudPayments::Namespaces::Base do
|
|
14
15
|
subject{ TestNamespace.new(CloudPayments.client) }
|
15
16
|
|
16
17
|
def stub_api(path, body = '')
|
17
|
-
url = "http://
|
18
|
-
stub_request(:post, url).with(body: body, headers: headers)
|
18
|
+
url = "http://localhost:9292#{path}"
|
19
|
+
stub_request(:post, url).with(body: body, headers: headers, basic_auth: ['user', 'pass'])
|
19
20
|
end
|
20
21
|
|
21
22
|
describe '#request' do
|
@@ -63,7 +64,13 @@ describe CloudPayments::Namespaces::Base do
|
|
63
64
|
|
64
65
|
context 'config.raise_banking_errors = true' do
|
65
66
|
before { CloudPayments.config.raise_banking_errors = true }
|
66
|
-
specify
|
67
|
+
specify do
|
68
|
+
begin
|
69
|
+
subject.request(:path, request_params)
|
70
|
+
rescue CloudPayments::Client::GatewayErrors::LostCard => err
|
71
|
+
expect(err).to be_a CloudPayments::Client::ReasonedGatewayError
|
72
|
+
end
|
73
|
+
end
|
67
74
|
end
|
68
75
|
|
69
76
|
context 'config.raise_banking_errors = false' do
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe CloudPayments::Namespaces::Cards do
|
@@ -13,11 +14,11 @@ describe CloudPayments::Namespaces::Cards do
|
|
13
14
|
card_cryptogram_packet: '01492500008719030128SM'
|
14
15
|
} }
|
15
16
|
|
16
|
-
|
17
|
+
describe '#charge' do
|
17
18
|
context 'config.raise_banking_errors = false' do
|
18
19
|
before { CloudPayments.config.raise_banking_errors = false }
|
19
20
|
|
20
|
-
|
21
|
+
context do
|
21
22
|
before{ stub_api_request('cards/charge/successful').perform }
|
22
23
|
specify{ expect(subject.charge(attributes)).to be_instance_of(CloudPayments::Transaction) }
|
23
24
|
specify{ expect(subject.charge(attributes)).not_to be_required_secure3d }
|
@@ -116,4 +117,43 @@ describe CloudPayments::Namespaces::Cards do
|
|
116
117
|
end
|
117
118
|
end
|
118
119
|
end
|
120
|
+
|
121
|
+
describe '#post3ds' do
|
122
|
+
let(:attributes){ { transaction_id: 12345, pa_res: 'AQ==' } }
|
123
|
+
|
124
|
+
context 'config.raise_banking_errors = false' do
|
125
|
+
before { CloudPayments.config.raise_banking_errors = false }
|
126
|
+
|
127
|
+
context do
|
128
|
+
before{ stub_api_request('cards/post3ds/successful').perform }
|
129
|
+
specify{ expect(subject.post3ds(attributes)).to be_instance_of(CloudPayments::Transaction) }
|
130
|
+
specify{ expect(subject.post3ds(attributes)).not_to be_required_secure3d }
|
131
|
+
specify{ expect(subject.post3ds(attributes)).to be_completed }
|
132
|
+
specify{ expect(subject.post3ds(attributes).id).to eq(12345) }
|
133
|
+
end
|
134
|
+
|
135
|
+
context do
|
136
|
+
before{ stub_api_request('cards/post3ds/failed').perform }
|
137
|
+
specify{ expect(subject.post3ds(attributes)).to be_instance_of(CloudPayments::Transaction) }
|
138
|
+
specify{ expect(subject.post3ds(attributes)).not_to be_required_secure3d }
|
139
|
+
specify{ expect(subject.post3ds(attributes)).to be_declined }
|
140
|
+
specify{ expect(subject.post3ds(attributes).id).to eq(12345) }
|
141
|
+
specify{ expect(subject.post3ds(attributes).reason).to eq('InsufficientFunds') }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'config.raise_banking_errors = true' do
|
146
|
+
before { CloudPayments.config.raise_banking_errors = true }
|
147
|
+
|
148
|
+
context do
|
149
|
+
before{ stub_api_request('cards/post3ds/successful').perform }
|
150
|
+
specify{ expect{ subject.post3ds(attributes) }.not_to raise_error }
|
151
|
+
end
|
152
|
+
|
153
|
+
context do
|
154
|
+
before{ stub_api_request('cards/post3ds/failed').perform }
|
155
|
+
specify{ expect{ subject.post3ds(attributes) }.to raise_error(CloudPayments::Client::GatewayErrors::InsufficientFunds) }
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
119
159
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe CloudPayments::Namespaces::Kassa do
|
7
|
+
subject{ described_class.new(CloudPayments.client) }
|
8
|
+
|
9
|
+
describe '#receipt' do
|
10
|
+
let(:attributes) do
|
11
|
+
{
|
12
|
+
inn: '7708806666',
|
13
|
+
type: 'Income',
|
14
|
+
customer_receipt: {
|
15
|
+
items: [
|
16
|
+
{
|
17
|
+
amount: '13350.00',
|
18
|
+
label: 'Good Description',
|
19
|
+
price: '13350.00',
|
20
|
+
quantity: 1.0,
|
21
|
+
vat: 0
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
context do
|
29
|
+
before{ attributes.delete(:inn) }
|
30
|
+
specify{ expect{subject.receipt(attributes)}.to raise_error(described_class::InnNotProvided) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context do
|
34
|
+
before{ attributes.delete(:type) }
|
35
|
+
specify{ expect{subject.receipt(attributes)}.to raise_error(described_class::TypeNotProvided) }
|
36
|
+
end
|
37
|
+
|
38
|
+
context do
|
39
|
+
before{ attributes.delete(:customer_receipt) }
|
40
|
+
specify{ expect{subject.receipt(attributes)}.to raise_error(described_class::CustomerReceiptNotProvided) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe CloudPayments::Namespaces::Orders do
|
7
|
+
subject{ described_class.new(CloudPayments.client) }
|
8
|
+
|
9
|
+
describe '#create' do
|
10
|
+
let(:attributes) do
|
11
|
+
{
|
12
|
+
amount: 10.0,
|
13
|
+
currency: 'RUB',
|
14
|
+
description: 'Оплата на сайте example.com',
|
15
|
+
email: 'client@test.local',
|
16
|
+
require_confirmation: true,
|
17
|
+
send_email: false,
|
18
|
+
invoice_id: 'invoice_100',
|
19
|
+
account_id: 'account_200',
|
20
|
+
phone: '+7(495)765-4321',
|
21
|
+
send_sms: false,
|
22
|
+
send_whats_app: false
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
context do
|
27
|
+
before{ stub_api_request('orders/create/successful').perform }
|
28
|
+
|
29
|
+
specify{ expect(subject.create(attributes)).to be_instance_of(CloudPayments::Order) }
|
30
|
+
|
31
|
+
context do
|
32
|
+
let(:sub){ subject.create(attributes) }
|
33
|
+
|
34
|
+
specify{ expect(sub.id).to eq('f2K8LV6reGE9WBFn') }
|
35
|
+
specify{ expect(sub.amount).to eq(10.0) }
|
36
|
+
specify{ expect(sub.currency).to eq('RUB') }
|
37
|
+
specify{ expect(sub.currency_code).to eq(0) }
|
38
|
+
specify{ expect(sub.email).to eq('client@test.local') }
|
39
|
+
specify{ expect(sub.description).to eq('Оплата на сайте example.com') }
|
40
|
+
specify{ expect(sub.require_confirmation).to eq(true) }
|
41
|
+
specify{ expect(sub.url).to eq('https://orders.cloudpayments.ru/d/f2K8LV6reGE9WBFn') }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#cancel' do
|
47
|
+
context do
|
48
|
+
before{ stub_api_request('orders/cancel/successful').perform }
|
49
|
+
specify{ expect(subject.cancel('12345')).to be_truthy }
|
50
|
+
end
|
51
|
+
|
52
|
+
context do
|
53
|
+
before{ stub_api_request('orders/cancel/failed').perform }
|
54
|
+
specify{ expect{ subject.cancel('12345') }.to raise_error(CloudPayments::Client::GatewayError, 'Error message') }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe CloudPayments::Namespaces::Payments do
|
@@ -93,4 +94,122 @@ describe CloudPayments::Namespaces::Payments do
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
end
|
97
|
+
|
98
|
+
describe '#get' do
|
99
|
+
let(:transaction_id) { 12345 }
|
100
|
+
|
101
|
+
context 'config.raise_banking_errors = false' do
|
102
|
+
before { CloudPayments.config.raise_banking_errors = false }
|
103
|
+
|
104
|
+
context 'transaction not found' do
|
105
|
+
before{ stub_api_request('payments/get/failed_with_message').perform }
|
106
|
+
specify{ expect{subject.get(transaction_id)}.to raise_error(CloudPayments::Client::GatewayError, 'Not found') }
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'transaction is failed' do
|
110
|
+
before{ stub_api_request('payments/get/failed').perform }
|
111
|
+
specify{ expect(subject.get(transaction_id)).to be_instance_of(CloudPayments::Transaction) }
|
112
|
+
specify{ expect(subject.get(transaction_id)).not_to be_required_secure3d }
|
113
|
+
specify{ expect(subject.get(transaction_id)).to be_declined }
|
114
|
+
specify{ expect(subject.get(transaction_id).id).to eq(transaction_id) }
|
115
|
+
specify{ expect(subject.get(transaction_id).reason).to eq('InsufficientFunds') }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'transaction is successful' do
|
119
|
+
before{ stub_api_request('payments/get/successful').perform }
|
120
|
+
specify{ expect(subject.get(transaction_id)).to be_instance_of(CloudPayments::Transaction) }
|
121
|
+
specify{ expect(subject.get(transaction_id)).not_to be_required_secure3d }
|
122
|
+
specify{ expect(subject.get(transaction_id)).to be_completed }
|
123
|
+
specify{ expect(subject.get(transaction_id).id).to eq(transaction_id) }
|
124
|
+
specify{ expect(subject.get(transaction_id).reason).to eq('Approved') }
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'transaction is refunded' do
|
128
|
+
before{ stub_api_request('payments/get/refunded').perform }
|
129
|
+
specify{ expect(subject.get(transaction_id)).to be_completed }
|
130
|
+
specify{ expect(subject.get(transaction_id)).to be_refunded }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'config.raise_banking_errors = true' do
|
135
|
+
before { CloudPayments.config.raise_banking_errors = true}
|
136
|
+
|
137
|
+
context 'transaction not found' do
|
138
|
+
before{ stub_api_request('payments/get/failed_with_message').perform }
|
139
|
+
specify{ expect{subject.get(transaction_id)}.to raise_error(CloudPayments::Client::GatewayError, 'Not found') }
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'transaction is failed' do
|
143
|
+
before{ stub_api_request('payments/get/failed').perform }
|
144
|
+
specify{ expect{subject.get(transaction_id)}.to raise_error(CloudPayments::Client::GatewayErrors::InsufficientFunds) }
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'transaction is successful' do
|
148
|
+
before{ stub_api_request('payments/get/successful').perform }
|
149
|
+
specify{ expect{subject.get(transaction_id)}.to_not raise_error }
|
150
|
+
specify{ expect(subject.get(transaction_id)).to be_instance_of(CloudPayments::Transaction) }
|
151
|
+
specify{ expect(subject.get(transaction_id)).not_to be_required_secure3d }
|
152
|
+
specify{ expect(subject.get(transaction_id)).to be_completed }
|
153
|
+
specify{ expect(subject.get(transaction_id).id).to eq(transaction_id) }
|
154
|
+
specify{ expect(subject.get(transaction_id).reason).to eq('Approved') }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe '#find' do
|
160
|
+
let(:invoice_id) { '1234567' }
|
161
|
+
|
162
|
+
context 'config.raise_banking_errors = false' do
|
163
|
+
before { CloudPayments.config.raise_banking_errors = false }
|
164
|
+
|
165
|
+
context 'payment is not found' do
|
166
|
+
before{ stub_api_request('payments/find/failed_with_message').perform }
|
167
|
+
specify{ expect{subject.find(invoice_id)}.to raise_error(CloudPayments::Client::GatewayError, 'Not found') }
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'payment is failed' do
|
171
|
+
before{ stub_api_request('payments/find/failed').perform }
|
172
|
+
specify{ expect(subject.find(invoice_id)).to be_instance_of(CloudPayments::Transaction) }
|
173
|
+
specify{ expect(subject.find(invoice_id)).not_to be_required_secure3d }
|
174
|
+
specify{ expect(subject.find(invoice_id)).to be_declined }
|
175
|
+
specify{ expect(subject.find(invoice_id).id).to eq(12345) }
|
176
|
+
specify{ expect(subject.find(invoice_id).invoice_id).to eq(invoice_id) }
|
177
|
+
specify{ expect(subject.find(invoice_id).reason).to eq('InsufficientFunds') }
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'transaction is successful' do
|
181
|
+
before{ stub_api_request('payments/find/successful').perform }
|
182
|
+
specify{ expect(subject.find(invoice_id)).to be_instance_of(CloudPayments::Transaction) }
|
183
|
+
specify{ expect(subject.find(invoice_id)).not_to be_required_secure3d }
|
184
|
+
specify{ expect(subject.find(invoice_id)).to be_completed }
|
185
|
+
specify{ expect(subject.find(invoice_id).id).to eq(12345) }
|
186
|
+
specify{ expect(subject.find(invoice_id).invoice_id).to eq(invoice_id) }
|
187
|
+
specify{ expect(subject.find(invoice_id).reason).to eq('Approved') }
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'config.raise_banking_errors = true' do
|
192
|
+
before { CloudPayments.config.raise_banking_errors = true}
|
193
|
+
|
194
|
+
context 'payment is not found' do
|
195
|
+
before{ stub_api_request('payments/find/failed_with_message').perform }
|
196
|
+
specify{ expect{subject.find(invoice_id)}.to raise_error(CloudPayments::Client::GatewayError, 'Not found') }
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'payment is failed' do
|
200
|
+
before{ stub_api_request('payments/find/failed').perform }
|
201
|
+
specify{ expect{subject.find(invoice_id)}.to raise_error(CloudPayments::Client::GatewayErrors::InsufficientFunds) }
|
202
|
+
end
|
203
|
+
|
204
|
+
context 'transaction is successful' do
|
205
|
+
before{ stub_api_request('payments/find/successful').perform }
|
206
|
+
specify{ expect(subject.find(invoice_id)).to be_instance_of(CloudPayments::Transaction) }
|
207
|
+
specify{ expect(subject.find(invoice_id)).not_to be_required_secure3d }
|
208
|
+
specify{ expect(subject.find(invoice_id)).to be_completed }
|
209
|
+
specify{ expect(subject.find(invoice_id).id).to eq(12345) }
|
210
|
+
specify{ expect(subject.find(invoice_id).invoice_id).to eq(invoice_id) }
|
211
|
+
specify{ expect(subject.find(invoice_id).reason).to eq('Approved') }
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
96
215
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe CloudPayments::Namespaces::Subscriptions do
|
@@ -5,7 +6,7 @@ describe CloudPayments::Namespaces::Subscriptions do
|
|
5
6
|
|
6
7
|
describe '#find' do
|
7
8
|
context do
|
8
|
-
before{ stub_api_request('subscriptions/
|
9
|
+
before{ stub_api_request('subscriptions/get/successful').perform }
|
9
10
|
|
10
11
|
specify{ expect(subject.find('sc_8cf8a9338fb')).to be_instance_of(CloudPayments::Subscription) }
|
11
12
|
|
@@ -21,6 +22,25 @@ describe CloudPayments::Namespaces::Subscriptions do
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
25
|
+
describe '#find_all' do
|
26
|
+
context do
|
27
|
+
before{ stub_api_request('subscriptions/find/successful').perform }
|
28
|
+
|
29
|
+
specify{ expect(subject.find_all("user@example.com")).to be_instance_of(Array) }
|
30
|
+
specify{ expect(subject.find_all("user@example.com").first).to be_instance_of(CloudPayments::Subscription) }
|
31
|
+
|
32
|
+
context do
|
33
|
+
let(:sub){ subject.find_all("user@example.com").first }
|
34
|
+
|
35
|
+
specify{ expect(sub.id).to eq('sc_8cf8a9338fb') }
|
36
|
+
specify{ expect(sub.account_id).to eq('user@example.com') }
|
37
|
+
specify{ expect(sub.description).to eq('Monthly subscription') }
|
38
|
+
specify{ expect(sub.started_at).to eq(DateTime.parse('2014-08-09T11:49:41')) }
|
39
|
+
specify{ expect(sub).to be_active }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
24
44
|
describe '#create' do
|
25
45
|
let(:attributes){ {
|
26
46
|
token: '477BBA133C182267F',
|