coins_paid_rails 1.1.1 → 1.1.6

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: accffa021325022ed6042edf69cb52cb0802efa27dcd010ef0231f56450d18f0
4
- data.tar.gz: f4af0fa8eb061e4a5d9761d5f7c98e1f7a08c970c1fa84413c2ffaae1284ee11
3
+ metadata.gz: df7e3a2b5d34d191761e465f1c8a82d4b7711d93b39bc03eebe9bfadccb339ec
4
+ data.tar.gz: 8dbf452034f18709317f11f0318b37e71cc32d8f3fcf7b936b1d0c0a754a34ae
5
5
  SHA512:
6
- metadata.gz: 7c5a79288917f9447a1e87d0d929630079ee4fa8d0c43f9193a4f81742c02bde4d610a75580f822d19c50ef0c0da8bd1299a51ff386d9166cf4f4b7a1cbc0085
7
- data.tar.gz: 0120a87cb1537bdea850921f5a0dfdfaa7ac3bc57b1484b6d35428a3b8959519c5311629baee6ffd324524ff3966a175d681093b41c678b5d118918bfebe8286
6
+ metadata.gz: 86fb4482d7847a7b2acdcc22a2d17857dc290e0a271095ba932489bff59f05466ac12568a364ccf6fdc02081e9e0e21d787f4b0829e36f58560f4d883b365543
7
+ data.tar.gz: 2d4ccb6c6cb43dc7d6392e34908b8349fa274fd6aef8ba8d92ec514eebe541f274fd6e52f40ba9d831e02d06a3e3ac0b053c41bef291eda513b2247aa316bf2e
data/.circleci/config.yml CHANGED
@@ -11,7 +11,7 @@ jobs:
11
11
  - checkout
12
12
  - run: mkdir log
13
13
  - save_cache:
14
- key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
14
+ key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
15
15
  paths:
16
16
  - ~/coins_paid
17
17
 
@@ -33,14 +33,14 @@ jobs:
33
33
  <<: *defaults
34
34
  steps:
35
35
  - restore_cache:
36
- key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
36
+ key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
37
37
  - restore_cache:
38
- key: v1-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: v1-bundle-{{ checksum "Gemfile" }}
43
+ key: v4-bundle-{{ checksum "Gemfile.lock" }}
44
44
  paths:
45
45
  - ~/coins_paid/vendor/bundle
46
46
 
@@ -53,9 +53,9 @@ jobs:
53
53
  CIRCLE_ARTIFACTS: "./tmp"
54
54
  steps:
55
55
  - restore_cache:
56
- key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
56
+ key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
57
57
  - restore_cache:
58
- key: v1-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
@@ -81,9 +81,9 @@ jobs:
81
81
  <<: *defaults
82
82
  steps:
83
83
  - restore_cache:
84
- key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
84
+ key: v4-repo-{{ .Environment.CIRCLE_SHA1 }}
85
85
  - restore_cache:
86
- key: v1-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/.gitignore CHANGED
@@ -1,3 +1,2 @@
1
1
  /*.gem
2
- /Gemfile.lock
3
2
  **/test.db
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
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 ADDED
@@ -0,0 +1,153 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ coins_paid_rails (1.1.6)
5
+ activerecord (>= 4.2.0)
6
+ coins_paid_api (~> 1.0)
7
+ dry-initializer (~> 3.0)
8
+ dry-struct (~> 1.0)
9
+
10
+ GEM
11
+ remote: http://www.rubygems.org/
12
+ specs:
13
+ actionpack (5.2.4.4)
14
+ actionview (= 5.2.4.4)
15
+ activesupport (= 5.2.4.4)
16
+ rack (~> 2.0, >= 2.0.8)
17
+ rack-test (>= 0.6.3)
18
+ rails-dom-testing (~> 2.0)
19
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
20
+ actionview (5.2.4.4)
21
+ activesupport (= 5.2.4.4)
22
+ builder (~> 3.1)
23
+ erubi (~> 1.4)
24
+ rails-dom-testing (~> 2.0)
25
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
26
+ activemodel (5.2.4.4)
27
+ activesupport (= 5.2.4.4)
28
+ activerecord (5.2.4.4)
29
+ activemodel (= 5.2.4.4)
30
+ activesupport (= 5.2.4.4)
31
+ arel (>= 9.0)
32
+ activesupport (5.2.4.4)
33
+ concurrent-ruby (~> 1.0, >= 1.0.2)
34
+ i18n (>= 0.7, < 2)
35
+ minitest (~> 5.1)
36
+ tzinfo (~> 1.1)
37
+ arel (9.0.0)
38
+ builder (3.2.4)
39
+ chunky_png (1.4.0)
40
+ coins_paid_api (1.0.5)
41
+ dry-struct (~> 1.0)
42
+ faraday (~> 0.12)
43
+ faraday_middleware (~> 0.11)
44
+ concurrent-ruby (1.1.7)
45
+ crass (1.0.6)
46
+ diff-lcs (1.4.4)
47
+ docile (1.1.5)
48
+ dry-configurable (0.12.1)
49
+ concurrent-ruby (~> 1.0)
50
+ dry-core (~> 0.5, >= 0.5.0)
51
+ dry-container (0.7.2)
52
+ concurrent-ruby (~> 1.0)
53
+ dry-configurable (~> 0.1, >= 0.1.3)
54
+ dry-core (0.6.0)
55
+ concurrent-ruby (~> 1.0)
56
+ dry-inflector (0.2.0)
57
+ dry-initializer (3.0.4)
58
+ dry-logic (1.2.0)
59
+ concurrent-ruby (~> 1.0)
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)
64
+ ice_nine (~> 0.11)
65
+ dry-types (1.5.1)
66
+ concurrent-ruby (~> 1.0)
67
+ dry-container (~> 0.3)
68
+ dry-core (~> 0.5, >= 0.5)
69
+ dry-inflector (~> 0.1, >= 0.1.2)
70
+ dry-logic (~> 1.0, >= 1.0.2)
71
+ erubi (1.10.0)
72
+ faraday (0.17.4)
73
+ multipart-post (>= 1.2, < 3)
74
+ faraday_middleware (0.14.0)
75
+ faraday (>= 0.7.4, < 1.0)
76
+ i18n (1.8.5)
77
+ concurrent-ruby (~> 1.0)
78
+ ice_nine (0.11.2)
79
+ json (2.3.0)
80
+ loofah (2.8.0)
81
+ crass (~> 1.0.2)
82
+ nokogiri (>= 1.5.9)
83
+ method_source (1.0.0)
84
+ mini_portile2 (2.5.0)
85
+ minitest (5.14.2)
86
+ multipart-post (2.1.1)
87
+ nokogiri (1.11.1)
88
+ mini_portile2 (~> 2.5.0)
89
+ racc (~> 1.4)
90
+ racc (1.5.2)
91
+ rack (2.2.3)
92
+ rack-test (1.1.0)
93
+ rack (>= 1.0, < 3)
94
+ rails-dom-testing (2.0.3)
95
+ activesupport (>= 4.2.0)
96
+ nokogiri (>= 1.6)
97
+ rails-html-sanitizer (1.3.0)
98
+ loofah (~> 2.3)
99
+ railties (5.2.4.4)
100
+ actionpack (= 5.2.4.4)
101
+ activesupport (= 5.2.4.4)
102
+ method_source
103
+ rake (>= 0.8.7)
104
+ thor (>= 0.19.0, < 2.0)
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)
110
+ rspec-core (3.10.0)
111
+ rspec-support (~> 3.10.0)
112
+ rspec-expectations (3.10.0)
113
+ diff-lcs (>= 1.2.0, < 2.0)
114
+ rspec-support (~> 3.10.0)
115
+ rspec-its (1.3.0)
116
+ rspec-core (>= 3.0.0)
117
+ rspec-expectations (>= 3.0.0)
118
+ rspec-mocks (3.10.0)
119
+ diff-lcs (>= 1.2.0, < 2.0)
120
+ rspec-support (~> 3.10.0)
121
+ rspec-rails (4.0.1)
122
+ actionpack (>= 4.2)
123
+ activesupport (>= 4.2)
124
+ railties (>= 4.2)
125
+ rspec-core (~> 3.9)
126
+ rspec-expectations (~> 3.9)
127
+ rspec-mocks (~> 3.9)
128
+ rspec-support (~> 3.9)
129
+ rspec-support (3.10.0)
130
+ simplecov (0.13.0)
131
+ docile (~> 1.1.0)
132
+ json (>= 1.8, < 3)
133
+ simplecov-html (~> 0.10.0)
134
+ simplecov-html (0.10.2)
135
+ sqlite3 (1.4.2)
136
+ thor (1.0.1)
137
+ thread_safe (0.3.6)
138
+ tzinfo (1.2.8)
139
+ thread_safe (~> 0.1)
140
+
141
+ PLATFORMS
142
+ ruby
143
+
144
+ DEPENDENCIES
145
+ coins_paid_rails!
146
+ rqrcode
147
+ rspec-its
148
+ rspec-rails
149
+ simplecov
150
+ sqlite3
151
+
152
+ BUNDLED WITH
153
+ 1.17.1
@@ -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.1'
4
+ s.version = '1.1.6'
5
5
  s.files = `git ls-files`.split("\n")
6
6
  s.summary = 'CoinsPaid Rails Integration'
7
7
  s.license = 'MIT'
@@ -10,5 +10,5 @@ Gem::Specification.new do |s|
10
10
  s.add_runtime_dependency 'activerecord', '>= 4.2.0'
11
11
  s.add_runtime_dependency 'dry-initializer', '~> 3.0'
12
12
  s.add_runtime_dependency 'dry-struct', '~> 1.0'
13
- s.add_development_dependency 'rspec-rails', '~> 3.0'
13
+ s.add_development_dependency 'rspec-rails'
14
14
  end
@@ -17,9 +17,11 @@ module CoinsPaid
17
17
  end
18
18
 
19
19
  def call
20
- CoinsPaidAddress.find_or_create_by!(request_data.attributes.slice(:foreign_id, :currency)) do |address|
21
- response = CoinsPaid::API.take_address(request_data.attributes)
22
- address.assign_attributes(response.attributes)
20
+ ActiveRecord::Base.transaction do
21
+ CoinsPaidAddress.lock.find_or_create_by!(request_data.attributes.slice(:foreign_id, :currency)) do |address|
22
+ response = CoinsPaid::API.take_address(request_data.attributes)
23
+ address.assign_attributes(response.attributes)
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -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:)
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.1
4
+ version: 1.1.6
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-10-30 00:00:00.000000000 Z
12
+ date: 2021-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coins_paid_api
@@ -71,18 +71,18 @@ dependencies:
71
71
  name: rspec-rails
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '3.0'
76
+ version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '3.0'
84
- description:
85
- email:
83
+ version: '0'
84
+ description:
85
+ email:
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -90,7 +90,9 @@ files:
90
90
  - ".circleci/config.yml"
91
91
  - ".gitignore"
92
92
  - ".rspec"
93
+ - ".ruby-version"
93
94
  - Gemfile
95
+ - Gemfile.lock
94
96
  - coins_paid_rails.gemspec
95
97
  - lib/coins_paid.rb
96
98
  - lib/coins_paid/address.rb
@@ -105,11 +107,11 @@ files:
105
107
  - spec/qr_code_spec.rb
106
108
  - spec/spec_helper.rb
107
109
  - spec/support/database/create_table.rb
108
- homepage:
110
+ homepage:
109
111
  licenses:
110
112
  - MIT
111
113
  metadata: {}
112
- post_install_message:
114
+ post_install_message:
113
115
  rdoc_options: []
114
116
  require_paths:
115
117
  - lib
@@ -124,9 +126,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
126
  - !ruby/object:Gem::Version
125
127
  version: '0'
126
128
  requirements: []
127
- rubyforge_project:
129
+ rubyforge_project:
128
130
  rubygems_version: 2.7.6
129
- signing_key:
131
+ signing_key:
130
132
  specification_version: 4
131
133
  summary: CoinsPaid Rails Integration
132
134
  test_files: []