coingate 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +11 -9
- data/README.md +9 -9
- data/lib/coingate.rb +8 -16
- data/lib/coingate/api_error.rb +5 -2
- data/lib/coingate/error_handler.rb +4 -2
- data/lib/coingate/merchant/order.rb +1 -1
- data/lib/coingate/version.rb +1 -1
- data/spec/merchant/order_spec.rb +18 -27
- data/spec/shared.rb +1 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20d0f614e7f63f731fcf8be425e7996815f2821a
|
4
|
+
data.tar.gz: e881bbb6daa9a65d4c3aecfa42b180a0ecf2eba9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f482452dadb80bdd536b96a133ed4b2c5892cb97a54fc57930935439b97bc07407022dfdf1acbc5f590d24becb0db993fddfee5cffc77d11b6893d1e1a7708d1
|
7
|
+
data.tar.gz: 8b36ae10c932f22763edd06395d8fb21a9325be0e185d9203e5dc57b4ad7cab90ce763ba9aae8659ec82ef13360db798e76b8fd2385e34075b5a9a7491cee306
|
data/Gemfile.lock
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
coingate (
|
4
|
+
coingate (2.0.0)
|
5
5
|
rest-client
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.2.5)
|
11
|
-
domain_name (0.5.
|
11
|
+
domain_name (0.5.20180417)
|
12
12
|
unf (>= 0.0.5, < 1.0.0)
|
13
|
-
http-cookie (1.0.
|
13
|
+
http-cookie (1.0.3)
|
14
14
|
domain_name (~> 0.5)
|
15
|
-
mime-types (
|
15
|
+
mime-types (3.1)
|
16
|
+
mime-types-data (~> 3.2015)
|
17
|
+
mime-types-data (3.2016.0521)
|
16
18
|
netrc (0.11.0)
|
17
19
|
rake (10.5.0)
|
18
|
-
rest-client (
|
20
|
+
rest-client (2.0.2)
|
19
21
|
http-cookie (>= 1.0.2, < 2.0)
|
20
|
-
mime-types (>= 1.16, <
|
21
|
-
netrc (~> 0.
|
22
|
+
mime-types (>= 1.16, < 4.0)
|
23
|
+
netrc (~> 0.8)
|
22
24
|
rspec (3.4.0)
|
23
25
|
rspec-core (~> 3.4.0)
|
24
26
|
rspec-expectations (~> 3.4.0)
|
@@ -34,7 +36,7 @@ GEM
|
|
34
36
|
rspec-support (3.4.1)
|
35
37
|
unf (0.1.4)
|
36
38
|
unf_ext
|
37
|
-
unf_ext (0.0.7.
|
39
|
+
unf_ext (0.0.7.5)
|
38
40
|
|
39
41
|
PLATFORMS
|
40
42
|
ruby
|
@@ -46,4 +48,4 @@ DEPENDENCIES
|
|
46
48
|
rspec
|
47
49
|
|
48
50
|
BUNDLED WITH
|
49
|
-
1.
|
51
|
+
1.16.0
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ And then execute:
|
|
21
21
|
Or install it yourself by executing:
|
22
22
|
|
23
23
|
$ gem install coingate
|
24
|
-
|
24
|
+
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
### Create API credentials
|
@@ -34,17 +34,17 @@ You can set default configuration like this:
|
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
CoinGate.config do |config|
|
37
|
-
config.
|
38
|
-
config.api_key = 'get_your_key_at_coingatecom'
|
39
|
-
config.api_secret = 'get_your_key_at_coingatecom'
|
37
|
+
config.auth_token = 'get_your_auth_token_at_coingatecom'
|
40
38
|
config.environment = 'live' # live or sandbox. Default: live
|
41
39
|
end
|
40
|
+
|
41
|
+
order = CoinGate::Merchant::Order.find(1)
|
42
42
|
```
|
43
43
|
|
44
44
|
Or you can pass authentication params individually, for example:
|
45
45
|
|
46
46
|
```ruby
|
47
|
-
CoinGate::Merchant::Order.find(1, {
|
47
|
+
order = CoinGate::Merchant::Order.find(1, {auth_token: 'coingate', environment: 'sandbox'})
|
48
48
|
```
|
49
49
|
|
50
50
|
### Create Order
|
@@ -54,8 +54,8 @@ CoinGate::Merchant::Order.find(1, {app_id: 1, api_key: 'coingate', api_secret: '
|
|
54
54
|
```ruby
|
55
55
|
post_params = {
|
56
56
|
order_id: 'ORDER-1412759367',
|
57
|
-
|
58
|
-
|
57
|
+
price_amount: 1050.99,
|
58
|
+
price_currency: 'USD',
|
59
59
|
receive_currency: 'EUR',
|
60
60
|
callback_url: 'https://example.com/payments/callback?token=6tCENGUYI62ojkuzDPX7Jg',
|
61
61
|
cancel_url: 'https://example.com/cart',
|
@@ -77,8 +77,8 @@ end
|
|
77
77
|
```ruby
|
78
78
|
post_params = {
|
79
79
|
order_id: 'ORDER-1412759367',
|
80
|
-
|
81
|
-
|
80
|
+
price_amount: 1050.99,
|
81
|
+
price_currency: 'USD',
|
82
82
|
receive_currency: 'EUR',
|
83
83
|
callback_url: 'https://example.com/payments/callback?token=6tCENGUYI62ojkuzDPX7Jg',
|
84
84
|
cancel_url: 'https://example.com/cart',
|
data/lib/coingate.rb
CHANGED
@@ -12,21 +12,19 @@ require 'json'
|
|
12
12
|
|
13
13
|
module CoinGate
|
14
14
|
class << self
|
15
|
-
attr_accessor :
|
15
|
+
attr_accessor :auth_token, :environment
|
16
16
|
|
17
17
|
def config
|
18
18
|
yield self
|
19
19
|
end
|
20
20
|
|
21
21
|
def api_request(url, request_method = :post, params = {}, authentication = {})
|
22
|
-
|
23
|
-
api_key = authentication[:api_key] || self.api_key
|
24
|
-
api_secret = authentication[:api_secret] || self.api_secret
|
22
|
+
auth_token = authentication[:auth_token] || self.auth_token
|
25
23
|
environment = authentication[:environment] || self.environment || 'live'
|
26
24
|
|
27
|
-
# Check if
|
28
|
-
if
|
29
|
-
CoinGate.raise_error(400, {'reason' => '
|
25
|
+
# Check if auth_token was passed
|
26
|
+
if auth_token.nil?
|
27
|
+
CoinGate.raise_error(400, {'reason' => 'AuthTokenMissing'})
|
30
28
|
end
|
31
29
|
|
32
30
|
# Check if right environment passed
|
@@ -39,19 +37,13 @@ module CoinGate
|
|
39
37
|
url = (
|
40
38
|
case environment
|
41
39
|
when 'sandbox'
|
42
|
-
'https://api-sandbox.coingate.com/
|
40
|
+
'https://api-sandbox.coingate.com/v2'
|
43
41
|
else
|
44
|
-
'https://api.coingate.com/
|
42
|
+
'https://api.coingate.com/v2'
|
45
43
|
end) + url
|
46
44
|
|
47
|
-
nonce = (Time.now.to_f * 1e6).to_i
|
48
|
-
message = nonce.to_s + app_id.to_s + api_key
|
49
|
-
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), api_secret, message)
|
50
|
-
|
51
45
|
headers = {
|
52
|
-
|
53
|
-
'Access-Key' => api_key,
|
54
|
-
'Access-Signature' => signature
|
46
|
+
Authorization: "Token #{auth_token}"
|
55
47
|
}
|
56
48
|
|
57
49
|
begin
|
data/lib/coingate/api_error.rb
CHANGED
@@ -3,12 +3,12 @@ module CoinGate
|
|
3
3
|
|
4
4
|
# HTTP Status 400
|
5
5
|
class BadRequest < APIError; end
|
6
|
-
class
|
6
|
+
class AuthTokenMissing < BadRequest; end
|
7
7
|
class BadEnvironment < BadRequest; end
|
8
8
|
|
9
9
|
# HTTP Status 401
|
10
10
|
class Unauthorized < APIError; end
|
11
|
-
class
|
11
|
+
class BadAuthToken < Unauthorized; end
|
12
12
|
|
13
13
|
# HTTP Status 404
|
14
14
|
class NotFound < APIError; end
|
@@ -19,6 +19,9 @@ module CoinGate
|
|
19
19
|
# HTTP Status 422
|
20
20
|
class UnprocessableEntity < APIError; end
|
21
21
|
class OrderIsNotValid < UnprocessableEntity; end
|
22
|
+
|
23
|
+
# HTTP Status 429
|
24
|
+
class RateLimitException < UnprocessableEntity; end
|
22
25
|
|
23
26
|
# HTTP Status 500
|
24
27
|
class InternalServerError < APIError; end
|
@@ -9,14 +9,14 @@ module CoinGate
|
|
9
9
|
raise (case http_code
|
10
10
|
when 400
|
11
11
|
case reason
|
12
|
-
when '
|
12
|
+
when 'AuthTokenMissing' then AuthTokenMissing
|
13
13
|
when 'BadEnvironment' then BadEnvironment
|
14
14
|
else BadRequest
|
15
15
|
end
|
16
16
|
|
17
17
|
when 401 then
|
18
18
|
case reason
|
19
|
-
when '
|
19
|
+
when 'BadAuthToken' then BadAuthToken
|
20
20
|
else Unauthorized
|
21
21
|
end
|
22
22
|
|
@@ -34,6 +34,8 @@ module CoinGate
|
|
34
34
|
when 'OrderIsNotValid' then OrderIsNotValid
|
35
35
|
else UnprocessableEntity
|
36
36
|
end
|
37
|
+
|
38
|
+
when 429 then RateLimitException
|
37
39
|
|
38
40
|
when 500 then InternalServerError
|
39
41
|
|
data/lib/coingate/version.rb
CHANGED
data/spec/merchant/order_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe CoinGate::Merchant::Order do
|
|
6
6
|
let(:valid_order_params) do
|
7
7
|
{
|
8
8
|
order_id: 'ORDER-1412759367',
|
9
|
-
|
10
|
-
|
9
|
+
price_amount: 1050.99,
|
10
|
+
price_currency: 'USD',
|
11
11
|
receive_currency: 'EUR',
|
12
12
|
callback_url: 'https://example.com/payments/callback?token=6tCENGUYI62ojkuzDPX7Jg',
|
13
13
|
cancel_url: 'https://example.com/cart',
|
@@ -18,9 +18,7 @@ describe CoinGate::Merchant::Order do
|
|
18
18
|
|
19
19
|
before do
|
20
20
|
CoinGate.config do |config|
|
21
|
-
config.
|
22
|
-
config.api_key = @authentication[:api_key]
|
23
|
-
config.api_secret = @authentication[:api_secret]
|
21
|
+
config.auth_token = @authentication[:auth_token]
|
24
22
|
config.environment = @authentication[:environment]
|
25
23
|
end
|
26
24
|
end
|
@@ -32,8 +30,8 @@ describe CoinGate::Merchant::Order do
|
|
32
30
|
end
|
33
31
|
|
34
32
|
context 'valid' do
|
35
|
-
it { expect(CoinGate::Merchant::Order.create(valid_order_params).
|
36
|
-
it { expect(CoinGate::Merchant::Order.create!(valid_order_params).
|
33
|
+
it { expect(CoinGate::Merchant::Order.create(valid_order_params).new?).to be true }
|
34
|
+
it { expect(CoinGate::Merchant::Order.create!(valid_order_params).new?).to be true }
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
@@ -42,8 +40,8 @@ describe CoinGate::Merchant::Order do
|
|
42
40
|
it do
|
43
41
|
order = CoinGate::Merchant::Order.create(valid_order_params)
|
44
42
|
|
45
|
-
expect(CoinGate::Merchant::Order.find(order.id).
|
46
|
-
expect(CoinGate::Merchant::Order.find!(order.id).
|
43
|
+
expect(CoinGate::Merchant::Order.find(order.id).new?).to be true
|
44
|
+
expect(CoinGate::Merchant::Order.find!(order.id).new?).to be true
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
@@ -56,28 +54,23 @@ describe CoinGate::Merchant::Order do
|
|
56
54
|
describe 'passing auth params through arguments' do
|
57
55
|
before do
|
58
56
|
CoinGate.config do |config|
|
59
|
-
config.
|
60
|
-
config.api_key = nil
|
61
|
-
config.api_secret = nil
|
62
|
-
config.environment = nil
|
57
|
+
config.auth_token = nil
|
63
58
|
end
|
64
59
|
end
|
65
60
|
|
66
61
|
describe 'create order' do
|
67
62
|
context 'params not passed' do
|
68
|
-
it { expect { CoinGate::Merchant::Order.create({}) }.to raise_error CoinGate::
|
69
|
-
it { expect { CoinGate::Merchant::Order.create!({}) }.to raise_error CoinGate::
|
63
|
+
it { expect { CoinGate::Merchant::Order.create({}) }.to raise_error CoinGate::AuthTokenMissing }
|
64
|
+
it { expect { CoinGate::Merchant::Order.create!({}) }.to raise_error CoinGate::AuthTokenMissing }
|
70
65
|
end
|
71
66
|
|
72
67
|
context 'invalid params passed' do
|
73
68
|
authentication = {
|
74
|
-
|
75
|
-
api_key: 'a',
|
76
|
-
api_secret: 'a'
|
69
|
+
auth_token: 'a'
|
77
70
|
}
|
78
71
|
|
79
|
-
it { expect { CoinGate::Merchant::Order.create({}, authentication) }.to raise_error CoinGate::
|
80
|
-
it { expect { CoinGate::Merchant::Order.create!({}, authentication) }.to raise_error CoinGate::
|
72
|
+
it { expect { CoinGate::Merchant::Order.create({}, authentication) }.to raise_error CoinGate::BadAuthToken }
|
73
|
+
it { expect { CoinGate::Merchant::Order.create!({}, authentication) }.to raise_error CoinGate::BadAuthToken }
|
81
74
|
end
|
82
75
|
|
83
76
|
context 'valid params passed' do
|
@@ -88,19 +81,17 @@ describe CoinGate::Merchant::Order do
|
|
88
81
|
|
89
82
|
describe 'find order' do
|
90
83
|
context 'params not passed' do
|
91
|
-
it { expect { CoinGate::Merchant::Order.find(0) }.to raise_error CoinGate::
|
92
|
-
it { expect { CoinGate::Merchant::Order.find!(0) }.to raise_error CoinGate::
|
84
|
+
it { expect { CoinGate::Merchant::Order.find(0) }.to raise_error CoinGate::AuthTokenMissing }
|
85
|
+
it { expect { CoinGate::Merchant::Order.find!(0) }.to raise_error CoinGate::AuthTokenMissing }
|
93
86
|
end
|
94
87
|
|
95
88
|
context 'invalid params passed' do
|
96
89
|
authentication = {
|
97
|
-
|
98
|
-
api_key: 'a',
|
99
|
-
api_secret: 'a'
|
90
|
+
auth_token: 'a',
|
100
91
|
}
|
101
92
|
|
102
|
-
it { expect { CoinGate::Merchant::Order.find(0, authentication) }.to raise_error CoinGate::
|
103
|
-
it { expect { CoinGate::Merchant::Order.find!(0, authentication) }.to raise_error CoinGate::
|
93
|
+
it { expect { CoinGate::Merchant::Order.find(0, authentication) }.to raise_error CoinGate::BadAuthToken }
|
94
|
+
it { expect { CoinGate::Merchant::Order.find!(0, authentication) }.to raise_error CoinGate::BadAuthToken }
|
104
95
|
end
|
105
96
|
|
106
97
|
context 'valid params passed' do
|
data/spec/shared.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
RSpec.shared_context 'shared' do
|
2
2
|
before(:all) do
|
3
3
|
@authentication = {
|
4
|
-
|
5
|
-
api_key: 'iob0ctFgeHLajvfxzYnIPB',
|
6
|
-
api_secret: 'ytaqXRWZ17ONlpshPTQuF50rIVLwBbmi',
|
4
|
+
auth_token: 'gYEWru1zBeUU2p4FVHTfVYmxZ7jzTxxBPphgHjET',
|
7
5
|
environment: 'sandbox'
|
8
6
|
}
|
9
7
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coingate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Achmedovas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.6.10
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Library for CoinGate
|