coins_paid_rails 1.1.2 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10ae66fd4dffda591ef4a5682a6d28401720e4ae87ee4938b6c2eccbd7075e1a
4
- data.tar.gz: 4f5da37e7b9b63fc0182814929d2b9ed567e97235363e1a0cf9ef0045dd081f4
3
+ metadata.gz: 25025c942a4c630da89e160486f2c5d1f05ed9584ce7f2c4fa27d4bf54c738f3
4
+ data.tar.gz: 5d8394faae19349b459dbd31e3277f047eda74eaaa67c9b632649100244170e7
5
5
  SHA512:
6
- metadata.gz: 8a9d0aac396d98fa0fc7963d45c2153ab3462536fc12f50dce36ce095ed51f5748333251c1e19c8663569c5d912e4514ba47fcd2d09b7e95e77f9d3614ff923f
7
- data.tar.gz: 5eeb4a643def5858eff9d3ca055a28277c3d9077816ce07117fff9f0fb8ecc644da2305b5c0642ef28447ffa7704245087c0fd00cee674c529035034ba918a4f
6
+ metadata.gz: f53a2431352a34504e6cca780e8a29b3492418ea7112ccfb647139f33e211cf98194e5964a37f837cc856a711db0f1f172bf878fbba7b5b6265ae3f4a610144a
7
+ data.tar.gz: 49ef1f19b5924e1b2ffbc1c0ae485d3c185a8fa91796e676b7fdf07429e1d472a4770d253014e5c023ad3e12681d5969e10a8a6e0b8fb1abd24bc17e92a56b6d
data/.circleci/config.yml CHANGED
@@ -35,12 +35,12 @@ jobs:
35
35
  - restore_cache:
36
36
  key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
37
37
  - restore_cache:
38
- key: v4-bundle-{{ checksum "Gemfile" }}
38
+ key: v4-bundle-{{ checksum "Gemfile.lock" }}
39
39
  - run: echo "export rvm_ignore_gemsets_flag=1" >> ~/.rvmrc
40
40
  - run: sudo apt-get update && sudo apt-get install -y libsodium-dev
41
- - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
41
+ - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
42
42
  - save_cache:
43
- key: v4-bundle-{{ checksum "Gemfile" }}
43
+ key: v4-bundle-{{ checksum "Gemfile.lock" }}
44
44
  paths:
45
45
  - ~/coins_paid/vendor/bundle
46
46
 
@@ -55,7 +55,7 @@ jobs:
55
55
  - restore_cache:
56
56
  key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
57
57
  - restore_cache:
58
- key: v4-bundle-{{ checksum "Gemfile" }}
58
+ key: v4-bundle-{{ checksum "Gemfile.lock" }}
59
59
  - attach_workspace:
60
60
  at: ~/coins_paid
61
61
  - run: sudo apt-get update && sudo apt-get install -y libsodium-dev
@@ -83,7 +83,7 @@ jobs:
83
83
  - restore_cache:
84
84
  key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
85
85
  - restore_cache:
86
- key: v4-bundle-{{ checksum "Gemfile" }}
86
+ key: v4-bundle-{{ checksum "Gemfile.lock" }}
87
87
  - run: mkdir -p ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts
88
88
  - run: sudo apt-get update && sudo apt-get install -y libsodium-dev
89
89
  - run: bundle check --path vendor/bundle
data/Gemfile CHANGED
@@ -6,4 +6,5 @@ group :test do
6
6
  gem 'simplecov', require: false
7
7
  gem 'sqlite3'
8
8
  gem 'rspec-its'
9
+ gem 'rqrcode'
9
10
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coins_paid_rails (1.0.1)
4
+ coins_paid_rails (1.1.7)
5
5
  activerecord (>= 4.2.0)
6
6
  coins_paid_api (~> 1.0)
7
7
  dry-initializer (~> 3.0)
@@ -36,6 +36,7 @@ GEM
36
36
  tzinfo (~> 1.1)
37
37
  arel (9.0.0)
38
38
  builder (3.2.4)
39
+ chunky_png (1.4.0)
39
40
  coins_paid_api (1.0.5)
40
41
  dry-struct (~> 1.0)
41
42
  faraday (~> 0.12)
@@ -44,36 +45,31 @@ GEM
44
45
  crass (1.0.6)
45
46
  diff-lcs (1.4.4)
46
47
  docile (1.1.5)
47
- dry-configurable (0.11.6)
48
+ dry-configurable (0.12.1)
48
49
  concurrent-ruby (~> 1.0)
49
- dry-core (~> 0.4, >= 0.4.7)
50
- dry-equalizer (~> 0.2)
50
+ dry-core (~> 0.5, >= 0.5.0)
51
51
  dry-container (0.7.2)
52
52
  concurrent-ruby (~> 1.0)
53
53
  dry-configurable (~> 0.1, >= 0.1.3)
54
- dry-core (0.5.0)
54
+ dry-core (0.6.0)
55
55
  concurrent-ruby (~> 1.0)
56
- dry-equalizer (0.3.0)
57
56
  dry-inflector (0.2.0)
58
57
  dry-initializer (3.0.4)
59
- dry-logic (1.0.8)
58
+ dry-logic (1.2.0)
60
59
  concurrent-ruby (~> 1.0)
61
- dry-core (~> 0.2)
62
- dry-equalizer (~> 0.2)
63
- dry-struct (1.3.0)
64
- dry-core (~> 0.4, >= 0.4.4)
65
- dry-equalizer (~> 0.3)
66
- dry-types (~> 1.3)
60
+ dry-core (~> 0.5, >= 0.5)
61
+ dry-struct (1.4.0)
62
+ dry-core (~> 0.5, >= 0.5)
63
+ dry-types (~> 1.5)
67
64
  ice_nine (~> 0.11)
68
- dry-types (1.4.0)
65
+ dry-types (1.5.1)
69
66
  concurrent-ruby (~> 1.0)
70
67
  dry-container (~> 0.3)
71
- dry-core (~> 0.4, >= 0.4.4)
72
- dry-equalizer (~> 0.3)
68
+ dry-core (~> 0.5, >= 0.5)
73
69
  dry-inflector (~> 0.1, >= 0.1.2)
74
70
  dry-logic (~> 1.0, >= 1.0.2)
75
71
  erubi (1.10.0)
76
- faraday (0.17.3)
72
+ faraday (0.17.4)
77
73
  multipart-post (>= 1.2, < 3)
78
74
  faraday_middleware (0.14.0)
79
75
  faraday (>= 0.7.4, < 1.0)
@@ -85,11 +81,13 @@ GEM
85
81
  crass (~> 1.0.2)
86
82
  nokogiri (>= 1.5.9)
87
83
  method_source (1.0.0)
88
- mini_portile2 (2.4.0)
84
+ mini_portile2 (2.5.0)
89
85
  minitest (5.14.2)
90
86
  multipart-post (2.1.1)
91
- nokogiri (1.10.10)
92
- mini_portile2 (~> 2.4.0)
87
+ nokogiri (1.11.1)
88
+ mini_portile2 (~> 2.5.0)
89
+ racc (~> 1.4)
90
+ racc (1.5.2)
93
91
  rack (2.2.3)
94
92
  rack-test (1.1.0)
95
93
  rack (>= 1.0, < 3)
@@ -105,6 +103,10 @@ GEM
105
103
  rake (>= 0.8.7)
106
104
  thor (>= 0.19.0, < 2.0)
107
105
  rake (13.0.1)
106
+ rqrcode (2.1.0)
107
+ chunky_png (~> 1.0)
108
+ rqrcode_core (~> 1.0)
109
+ rqrcode_core (1.2.0)
108
110
  rspec-core (3.10.0)
109
111
  rspec-support (~> 3.10.0)
110
112
  rspec-expectations (3.10.0)
@@ -141,6 +143,7 @@ PLATFORMS
141
143
 
142
144
  DEPENDENCIES
143
145
  coins_paid_rails!
146
+ rqrcode
144
147
  rspec-its
145
148
  rspec-rails
146
149
  simplecov
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'coins_paid_rails'
3
3
  s.authors = ['Artem Biserov(artembiserov)', 'Oleg Ivanov(morhekil)']
4
- s.version = '1.1.2'
4
+ s.version = '1.1.7'
5
5
  s.files = `git ls-files`.split("\n")
6
6
  s.summary = 'CoinsPaid Rails Integration'
7
7
  s.license = 'MIT'
@@ -10,15 +10,15 @@ module CoinsPaid
10
10
  end
11
11
 
12
12
  def url
13
- "#{token_type}:#{address}?label=#{encode(label)}&message=#{encode(message)}"
13
+ known_url? ? "#{token_type}:#{address.address}?label=#{encode(label)}&message=#{encode(message)}" : nil
14
14
  end
15
15
 
16
16
  def address
17
- @address ||= CoinsPaid.address(player_id, currency: currency).address
17
+ @address ||= CoinsPaid.address(player_id, currency: currency)
18
18
  end
19
19
 
20
20
  def svg
21
- RQRCode::QRCode.new(url).as_svg(
21
+ RQRCode::QRCode.new(url || address.address).as_svg(
22
22
  offset: 0,
23
23
  color: '000',
24
24
  shape_rendering: 'crispEdges',
@@ -30,11 +30,15 @@ module CoinsPaid
30
30
  private
31
31
 
32
32
  def token_type
33
- ADDRESS_PREFIXES.fetch(currency)
33
+ ADDRESS_PREFIXES[currency]
34
34
  end
35
35
 
36
36
  def encode(string)
37
37
  URI.encode_www_form_component(string)
38
38
  end
39
+
40
+ def known_url?
41
+ token_type.present?
42
+ end
39
43
  end
40
44
  end
data/lib/coins_paid.rb CHANGED
@@ -15,11 +15,14 @@ module CoinsPaid
15
15
  ADDRESS_PREFIXES = {
16
16
  'BTC' => 'bitcoin',
17
17
  'BCH' => 'bitcoincash',
18
+ 'DOGE' => 'doge',
18
19
  'ETH' => 'ethereum',
19
20
  'EURTE' => 'ethereum',
20
21
  'LTC' => 'litecoin',
21
22
  'USDT' => 'bitcoin',
22
- 'USDTE' => 'ethereum'
23
+ 'USDTE' => 'ethereum',
24
+ 'TRX' => 'tron',
25
+ 'USDTT' => 'tron'
23
26
  }.freeze
24
27
 
25
28
  def address(foreign_id, currency:)
@@ -33,4 +36,8 @@ module CoinsPaid
33
36
  def currency(name)
34
37
  CoinsPaid::API.currencies_list.find { |item| item.currency == name } || raise(UnknownCurrency, name)
35
38
  end
39
+
40
+ def issued_addresses(foreign_id)
41
+ CoinsPaidAddress.where(foreign_id: foreign_id).order(:currency)
42
+ end
36
43
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe CoinsPaid, '.issued_addresses' do
4
+ let(:foreign_id) { 123 }
5
+
6
+ it 'returns addresses with requested foreign_id ordered by currency' do
7
+ attrs = {
8
+ foreign_id: foreign_id,
9
+ currency: 'BTC',
10
+ address: 'addr',
11
+ external_id: 1
12
+ }
13
+
14
+ addr1 = CoinsPaid::CoinsPaidAddress.create!(attrs)
15
+ addr2 = CoinsPaid::CoinsPaidAddress.create!(attrs.merge(currency: 'ETH'))
16
+ CoinsPaid::CoinsPaidAddress.create!(attrs.merge(foreign_id: 555))
17
+
18
+ expect(CoinsPaid.issued_addresses(foreign_id)).to eq [addr1, addr2]
19
+ end
20
+ end
data/spec/qr_code_spec.rb CHANGED
@@ -2,25 +2,58 @@
2
2
 
3
3
  describe CoinsPaid, '.qr_code' do
4
4
  let(:foreign_id) { 123 }
5
+ let(:currency) { 'BTC' }
6
+ let(:address) { 'abc123' }
5
7
  let(:coins_paid_address) do
6
8
  instance_double CoinsPaid::CoinsPaidAddress,
7
- currency: 'BTC',
8
- address: 'abc123'
9
+ currency: currency,
10
+ address: address
9
11
  end
10
12
  subject(:qr_code) do
11
13
  described_class.qr_code(
12
14
  foreign_id,
13
- currency: 'BTC',
15
+ currency: currency,
14
16
  label: 'RedStar deposit',
15
17
  message: 'Make a deposit to RedStar'
16
18
  )
17
19
  end
18
20
 
19
21
  before do
20
- allow(CoinsPaid).to receive(:address).with(foreign_id, currency: 'BTC').and_return(coins_paid_address)
22
+ allow(CoinsPaid).to receive(:address).with(foreign_id, currency: currency).and_return(coins_paid_address)
21
23
  end
22
24
 
23
- describe '#payment_url' do
24
- its(:url) { is_expected.to eq 'bitcoin:abc123?label=RedStar+deposit&message=Make+a+deposit+to+RedStar' }
25
+ context 'it is known how to build payment url for the currency' do
26
+ let(:currency) { 'BTC' }
27
+ let(:url) { "bitcoin:#{address}?label=RedStar+deposit&message=Make+a+deposit+to+RedStar" }
28
+
29
+ describe '#url' do
30
+ its(:url) { is_expected.to eq url }
31
+ end
32
+
33
+ describe '#svg' do
34
+ it 'encodes payment url' do
35
+ expect(RQRCode::QRCode).to receive(:new).with(url).and_call_original
36
+ qr_code.svg
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'it is not known how to build payment url for the currency' do
42
+ let(:currency) { 'BNB' }
43
+
44
+ describe '#url' do
45
+ its(:url) { is_expected.to be_nil }
46
+ end
47
+
48
+ describe '#svg' do
49
+ it 'encodes payment address' do
50
+ expect(RQRCode::QRCode).to receive(:new).with(address).and_call_original
51
+ qr_code.svg
52
+ end
53
+ end
54
+ end
55
+
56
+ context '#address' do
57
+ its(:address) { is_expected.to eq coins_paid_address }
25
58
  end
26
59
  end
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,7 @@ require 'active_record'
9
9
  require "active_record/railtie"
10
10
  require 'rspec/rails'
11
11
  require 'rspec/its'
12
+ require 'rqrcode'
12
13
 
13
14
  require 'coins_paid_rails'
14
15
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coins_paid_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Biserov(artembiserov)
8
8
  - Oleg Ivanov(morhekil)
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-16 00:00:00.000000000 Z
12
+ date: 2021-09-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coins_paid_api
@@ -81,8 +81,8 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
- description:
85
- email:
84
+ description:
85
+ email:
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -104,14 +104,15 @@ files:
104
104
  - lib/generators/coins_paid/templates/migration.rb
105
105
  - spec/address_spec.rb
106
106
  - spec/currency_spec.rb
107
+ - spec/issued_addresses_spec.rb
107
108
  - spec/qr_code_spec.rb
108
109
  - spec/spec_helper.rb
109
110
  - spec/support/database/create_table.rb
110
- homepage:
111
+ homepage:
111
112
  licenses:
112
113
  - MIT
113
114
  metadata: {}
114
- post_install_message:
115
+ post_install_message:
115
116
  rdoc_options: []
116
117
  require_paths:
117
118
  - lib
@@ -126,9 +127,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  - !ruby/object:Gem::Version
127
128
  version: '0'
128
129
  requirements: []
129
- rubyforge_project:
130
+ rubyforge_project:
130
131
  rubygems_version: 2.7.6
131
- signing_key:
132
+ signing_key:
132
133
  specification_version: 4
133
134
  summary: CoinsPaid Rails Integration
134
135
  test_files: []