cloud_payments 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +4 -8
- data/Gemfile +2 -2
- data/lib/cloud_payments/client/gateway_errors.rb +2 -1
- data/lib/cloud_payments/client/serializer/base.rb +8 -1
- data/lib/cloud_payments/namespaces/subscriptions.rb +5 -0
- data/lib/cloud_payments/version.rb +1 -1
- data/spec/cloud_payments/models/transaction_spec.rb +1 -1
- data/spec/cloud_payments/namespaces/base_spec.rb +9 -3
- data/spec/cloud_payments/namespaces/subscriptions_spec.rb +20 -1
- 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 +3 -10
- data/spec/support/helpers.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87ad4228e46b088bd3c828392f883daed80b30a9
|
4
|
+
data.tar.gz: e557846dcc4fce01747d2d852d717560d4d36068
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d77521d6995902f1f6692c4f39faa2ac84c0daffe44d3c57c80e2209b6d37426ab2791158a536d8023706c15170769af00d1f7dbb8d9eac71b89e486266b51
|
7
|
+
data.tar.gz: d6c183255aa997ec093fe8ff4b745ed5079e5f85926c350c9e17876689589d29bfb9938da0c3bb8b024017cd03306771a019bc48c25540020fbf49c2c50e5499
|
data/.travis.yml
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
cache: bundler
|
3
|
+
script: bundle exec rspec
|
4
|
+
before_install: gem install bundler
|
5
5
|
env:
|
6
6
|
- CODECLIMATE_REPO_TOKEN=8e9b89269d9aafc2dec2706a43825201de496b743505d7a7666068f7b22b07d
|
7
7
|
rvm:
|
8
|
-
- '1.9.3'
|
9
|
-
- '2.0'
|
10
|
-
- '2.1'
|
11
8
|
- '2.2'
|
12
|
-
- '2.3
|
13
|
-
- rbx-2
|
9
|
+
- '2.3'
|
14
10
|
- ruby-head
|
15
11
|
matrix:
|
16
12
|
allow_failures:
|
data/Gemfile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module CloudPayments
|
2
2
|
class Client
|
3
|
+
class ReasonedGatewayError < StandardError; end
|
3
4
|
module GatewayErrors; end
|
4
5
|
|
5
6
|
REASON_CODES = {
|
@@ -29,7 +30,7 @@ module CloudPayments
|
|
29
30
|
|
30
31
|
GATEWAY_ERRORS = REASON_CODES.inject({}) do |result, error|
|
31
32
|
status, name = error
|
32
|
-
result[status] = GatewayErrors.const_set(name, Class.new(
|
33
|
+
result[status] = GatewayErrors.const_set(name, Class.new(ReasonedGatewayError))
|
33
34
|
result
|
34
35
|
end
|
35
36
|
end
|
@@ -20,7 +20,14 @@ module CloudPayments
|
|
20
20
|
|
21
21
|
def convert_keys_from_api(attributes)
|
22
22
|
attributes.each_with_object({}) do |(key, value), result|
|
23
|
-
value =
|
23
|
+
value = case value
|
24
|
+
when Hash
|
25
|
+
convert_keys_from_api(value)
|
26
|
+
when Array
|
27
|
+
value.map { |item| convert_keys_from_api(item) }
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
24
31
|
|
25
32
|
key = key.to_s.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
26
33
|
key.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
@@ -6,6 +6,11 @@ module CloudPayments
|
|
6
6
|
Subscription.new(response[:model])
|
7
7
|
end
|
8
8
|
|
9
|
+
def find_all(account_id)
|
10
|
+
response = request(:find, account_id: account_id)
|
11
|
+
Array(response[:model]).map { |item| Subscription.new(item) }
|
12
|
+
end
|
13
|
+
|
9
14
|
def create(attributes)
|
10
15
|
response = request(:create, attributes)
|
11
16
|
Subscription.new(response[:model])
|
@@ -205,7 +205,7 @@ describe CloudPayments::Transaction do
|
|
205
205
|
subject{ CloudPayments::Transaction.new(default_attributes.merge(attributes)) }
|
206
206
|
|
207
207
|
describe '#subscription' do
|
208
|
-
before{ stub_api_request('subscriptions/
|
208
|
+
before{ stub_api_request('subscriptions/get/successful').perform }
|
209
209
|
|
210
210
|
context 'with subscription_id' do
|
211
211
|
let(:attributes){ { subscription_id: 'sc_8cf8a9338fb' } }
|
@@ -14,8 +14,8 @@ describe CloudPayments::Namespaces::Base do
|
|
14
14
|
subject{ TestNamespace.new(CloudPayments.client) }
|
15
15
|
|
16
16
|
def stub_api(path, body = '')
|
17
|
-
url = "http://
|
18
|
-
stub_request(:post, url).with(body: body, headers: headers)
|
17
|
+
url = "http://localhost:9292#{path}"
|
18
|
+
stub_request(:post, url).with(body: body, headers: headers, basic_auth: ['user', 'pass'])
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#request' do
|
@@ -63,7 +63,13 @@ describe CloudPayments::Namespaces::Base do
|
|
63
63
|
|
64
64
|
context 'config.raise_banking_errors = true' do
|
65
65
|
before { CloudPayments.config.raise_banking_errors = true }
|
66
|
-
specify
|
66
|
+
specify do
|
67
|
+
begin
|
68
|
+
subject.request(:path, request_params)
|
69
|
+
rescue CloudPayments::Client::GatewayErrors::LostCard => err
|
70
|
+
expect(err).to be_a CloudPayments::Client::ReasonedGatewayError
|
71
|
+
end
|
72
|
+
end
|
67
73
|
end
|
68
74
|
|
69
75
|
context 'config.raise_banking_errors = false' do
|
@@ -5,7 +5,7 @@ describe CloudPayments::Namespaces::Subscriptions do
|
|
5
5
|
|
6
6
|
describe '#find' do
|
7
7
|
context do
|
8
|
-
before{ stub_api_request('subscriptions/
|
8
|
+
before{ stub_api_request('subscriptions/get/successful').perform }
|
9
9
|
|
10
10
|
specify{ expect(subject.find('sc_8cf8a9338fb')).to be_instance_of(CloudPayments::Subscription) }
|
11
11
|
|
@@ -21,6 +21,25 @@ describe CloudPayments::Namespaces::Subscriptions do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
describe '#find_all' do
|
25
|
+
context do
|
26
|
+
before{ stub_api_request('subscriptions/find/successful').perform }
|
27
|
+
|
28
|
+
specify{ expect(subject.find_all("user@example.com")).to be_instance_of(Array) }
|
29
|
+
specify{ expect(subject.find_all("user@example.com").first).to be_instance_of(CloudPayments::Subscription) }
|
30
|
+
|
31
|
+
context do
|
32
|
+
let(:sub){ subject.find_all("user@example.com").first }
|
33
|
+
|
34
|
+
specify{ expect(sub.id).to eq('sc_8cf8a9338fb') }
|
35
|
+
specify{ expect(sub.account_id).to eq('user@example.com') }
|
36
|
+
specify{ expect(sub.description).to eq('Monthly subscription') }
|
37
|
+
specify{ expect(sub.started_at).to eq(DateTime.parse('2014-08-09T11:49:41')) }
|
38
|
+
specify{ expect(sub).to be_active }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
24
43
|
describe '#create' do
|
25
44
|
let(:attributes){ {
|
26
45
|
token: '477BBA133C182267F',
|
@@ -1,11 +1,11 @@
|
|
1
1
|
---
|
2
2
|
:request:
|
3
|
-
:url: '/subscriptions/
|
4
|
-
:body: '{"
|
3
|
+
:url: '/subscriptions/find'
|
4
|
+
:body: '{"AccountId":"user@example.com"}'
|
5
5
|
:response:
|
6
6
|
:body: >
|
7
7
|
{
|
8
|
-
"Model":{
|
8
|
+
"Model":[{
|
9
9
|
"Id":"sc_8cf8a9338fb",
|
10
10
|
"AccountId":"user@example.com",
|
11
11
|
"Description":"Monthly subscription",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"FailedTransactionsNumber":0,
|
26
26
|
"LastTransactionDateIso":"2014-08-09T11:49:41",
|
27
27
|
"NextTransactionDateIso":"2014-08-09T11:49:41"
|
28
|
-
},
|
28
|
+
}],
|
29
29
|
"Success":true,
|
30
30
|
"Message": null
|
31
31
|
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
:request:
|
3
|
+
:url: '/subscriptions/get'
|
4
|
+
:body: '{"Id":"sc_8cf8a9338fb"}'
|
5
|
+
:response:
|
6
|
+
:body: >
|
7
|
+
{
|
8
|
+
"Model":{
|
9
|
+
"Id":"sc_8cf8a9338fb",
|
10
|
+
"AccountId":"user@example.com",
|
11
|
+
"Description":"Monthly subscription",
|
12
|
+
"Email":"user@example.com",
|
13
|
+
"Amount":1.02,
|
14
|
+
"CurrencyCode":0,
|
15
|
+
"Currency":"RUB",
|
16
|
+
"RequireConfirmation":false,
|
17
|
+
"StartDateIso":"2014-08-09T11:49:41",
|
18
|
+
"IntervalCode":1,
|
19
|
+
"Interval":"Month",
|
20
|
+
"Period":1,
|
21
|
+
"MaxPeriods":12,
|
22
|
+
"StatusCode":0,
|
23
|
+
"Status":"Active",
|
24
|
+
"SuccessfulTransactionsNumber":0,
|
25
|
+
"FailedTransactionsNumber":0,
|
26
|
+
"LastTransactionDateIso":"2014-08-09T11:49:41",
|
27
|
+
"NextTransactionDateIso":"2014-08-09T11:49:41"
|
28
|
+
},
|
29
|
+
"Success":true,
|
30
|
+
"Message": null
|
31
|
+
}
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,9 @@ end
|
|
8
8
|
require 'bundler'
|
9
9
|
Bundler.require(:default, :test)
|
10
10
|
|
11
|
+
require 'webmock/rspec'
|
12
|
+
|
13
|
+
WebMock.enable!
|
11
14
|
WebMock.disable_net_connect!
|
12
15
|
|
13
16
|
Dir["./spec/support/**/*.rb"].each { |f| require f }
|
@@ -25,14 +28,4 @@ RSpec.configure do |config|
|
|
25
28
|
config.include CloudPayments::RSpec::Helpers
|
26
29
|
|
27
30
|
config.after(:suite){ WebMock.allow_net_connect! }
|
28
|
-
|
29
|
-
# config.around :each, time_freeze: ->(v){ v.is_a?(Date) || v.is_a?(Time) || v.is_a?(String) } do |example|
|
30
|
-
# datetime = if example.metadata[:time_freeze].is_a?(String)
|
31
|
-
# DateTime.parse(example.metadata[:time_freeze])
|
32
|
-
# else
|
33
|
-
# example.metadata[:time_freeze]
|
34
|
-
# end
|
35
|
-
|
36
|
-
# Timecop.freeze(datetime){ example.run }
|
37
|
-
# end
|
38
31
|
end
|
data/spec/support/helpers.rb
CHANGED
@@ -44,13 +44,13 @@ module CloudPayments
|
|
44
44
|
@webmock_stub ||= begin
|
45
45
|
if fixture
|
46
46
|
WebMock::StubRegistry.instance.register_request_stub(WebMock::RequestStub.new(:post, url)).
|
47
|
-
with(body: request[:body] || '', headers: request_headers)
|
47
|
+
with(body: request[:body] || '', headers: request_headers, basic_auth: ['user', 'pass'])
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def url
|
53
|
-
"http://
|
53
|
+
"http://localhost:9292#{request[:url]}"
|
54
54
|
end
|
55
55
|
|
56
56
|
def request_headers
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_payments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- undr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- spec/fixtures/apis/subscriptions/cancel/successful.yml
|
164
164
|
- spec/fixtures/apis/subscriptions/create/successful.yml
|
165
165
|
- spec/fixtures/apis/subscriptions/find/successful.yml
|
166
|
+
- spec/fixtures/apis/subscriptions/get/successful.yml
|
166
167
|
- spec/fixtures/apis/subscriptions/update/successful.yml
|
167
168
|
- spec/fixtures/apis/tokens/auth/failed.yml
|
168
169
|
- spec/fixtures/apis/tokens/auth/successful.yml
|
@@ -235,6 +236,7 @@ test_files:
|
|
235
236
|
- spec/fixtures/apis/subscriptions/cancel/successful.yml
|
236
237
|
- spec/fixtures/apis/subscriptions/create/successful.yml
|
237
238
|
- spec/fixtures/apis/subscriptions/find/successful.yml
|
239
|
+
- spec/fixtures/apis/subscriptions/get/successful.yml
|
238
240
|
- spec/fixtures/apis/subscriptions/update/successful.yml
|
239
241
|
- spec/fixtures/apis/tokens/auth/failed.yml
|
240
242
|
- spec/fixtures/apis/tokens/auth/successful.yml
|