diff --git a/Gemfile.lock b/Gemfile.lock index f7bd8b0b53..045d2706e8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,49 +11,49 @@ GEM specs: aasm (5.0.8) concurrent-ruby (~> 1.0) - actioncable (5.2.4.5) - actionpack (= 5.2.4.5) + actioncable (5.2.4.6) + actionpack (= 5.2.4.6) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4.5) - actionpack (= 5.2.4.5) - actionview (= 5.2.4.5) - activejob (= 5.2.4.5) + actionmailer (5.2.4.6) + actionpack (= 5.2.4.6) + actionview (= 5.2.4.6) + activejob (= 5.2.4.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.5) - actionview (= 5.2.4.5) - activesupport (= 5.2.4.5) + actionpack (5.2.4.6) + actionview (= 5.2.4.6) + activesupport (= 5.2.4.6) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.5) - activesupport (= 5.2.4.5) + actionview (5.2.4.6) + activesupport (= 5.2.4.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.4.5) - activesupport (= 5.2.4.5) + activejob (5.2.4.6) + activesupport (= 5.2.4.6) globalid (>= 0.3.6) - activemodel (5.2.4.5) - activesupport (= 5.2.4.5) - activerecord (5.2.4.5) - activemodel (= 5.2.4.5) - activesupport (= 5.2.4.5) + activemodel (5.2.4.6) + activesupport (= 5.2.4.6) + activerecord (5.2.4.6) + activemodel (= 5.2.4.6) + activesupport (= 5.2.4.6) arel (>= 9.0) - activestorage (5.2.4.5) - actionpack (= 5.2.4.5) - activerecord (= 5.2.4.5) + activestorage (5.2.4.6) + actionpack (= 5.2.4.6) + activerecord (= 5.2.4.6) marcel (~> 0.3.1) - activesupport (5.2.4.5) + activesupport (5.2.4.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) amq-protocol (2.3.2) amqp (1.8.0) amq-protocol (>= 2.2.0) @@ -68,15 +68,15 @@ GEM arel-to-sql (1.0.0) arel (>= 6.0) ast (2.4.2) - aws-eventstream (1.1.1) - aws-sigv4 (1.2.3) + aws-eventstream (1.2.0) + aws-sigv4 (1.5.2) aws-eventstream (~> 1, >= 1.0.2) base58 (0.2.3) better-faraday (1.0.8) activesupport (>= 4.0, < 6.0) faraday (~> 0.12) - bootsnap (1.7.3) - msgpack (~> 1.0) + bootsnap (1.16.0) + msgpack (~> 1.2) builder (3.2.4) bullet (5.9.0) activesupport (>= 3.0.0) @@ -92,26 +92,27 @@ GEM coderay (1.1.3) composite_primary_keys (11.3.1) activerecord (~> 5.2.4) - concurrent-ruby (1.1.8) - connection_pool (2.2.5) + concurrent-ruby (1.2.0) + connection_pool (2.3.0) cookiejar (0.3.3) crack (0.4.5) rexml crass (1.0.6) - daemons (1.3.1) + daemons (1.4.1) database_cleaner (1.99.0) - diff-lcs (1.4.4) + date (3.3.3) + diff-lcs (1.5.0) digest-sha3 (1.1.0) - dry-configurable (0.12.1) + dry-configurable (0.13.0) concurrent-ruby (~> 1.0) - dry-core (~> 0.5, >= 0.5.0) - dry-container (0.7.2) + dry-core (~> 0.6) + dry-container (0.9.0) concurrent-ruby (~> 1.0) - dry-configurable (~> 0.1, >= 0.1.3) - dry-core (0.5.0) + dry-configurable (~> 0.13, >= 0.13.0) + dry-core (0.7.1) concurrent-ruby (~> 1.0) - dry-inflector (0.2.0) - dry-logic (1.1.0) + dry-inflector (0.2.1) + dry-logic (1.2.0) concurrent-ruby (~> 1.0) dry-core (~> 0.5, >= 0.5) dry-types (1.5.1) @@ -130,16 +131,16 @@ GEM eventmachine (>= 1.0.0.beta.4) em-synchrony (1.0.6) eventmachine (>= 1.0.0.beta.1) - em-websocket (0.5.2) + em-websocket (0.5.3) eventmachine (>= 0.12.9) - http_parser.rb (~> 0.6.0) + http_parser.rb (~> 0) email_validator (1.6.0) activemodel enumerize (2.2.2) activesupport (>= 3.2) env-tweaks (1.0.1) activesupport (>= 3.0, < 7.0) - erubi (1.10.0) + erubi (1.12.0) eventmachine (1.2.7) factory_bot (5.2.0) activesupport (>= 4.2.0) @@ -148,7 +149,7 @@ GEM railties (>= 4.2.0) faker (1.9.6) i18n (>= 0.7) - faraday (0.17.4) + faraday (0.17.6) multipart-post (>= 1.2, < 3) faraday_middleware (0.13.1) faraday (>= 0.7.4, < 1.0) @@ -160,14 +161,14 @@ GEM multi_json (>= 1.0.0) rack (>= 1.0.0) websocket-driver (>= 0.5.1) - faye-websocket (0.11.0) + faye-websocket (0.11.1) eventmachine (>= 0.12.0) websocket-driver (>= 0.5.1) - ffi (1.15.0) + ffi (1.15.5) figaro (1.1.1) thor (~> 0.14) - globalid (0.4.2) - activesupport (>= 4.2.0) + globalid (1.1.0) + activesupport (>= 5.0) god (0.13.7) grape (1.3.3) activesupport @@ -194,13 +195,13 @@ GEM hashdiff (1.0.1) hashie (3.6.0) hiredis (0.6.3) - http_parser.rb (0.6.0) - i18n (1.8.10) + http_parser.rb (0.8.0) + i18n (1.12.0) concurrent-ruby (~> 1.0) influxdb (0.7.0) - io-console (0.5.9) - irb (1.3.4) - reline (>= 0.1.5) + io-console (0.6.0) + irb (1.6.2) + reline (>= 0.3.0) irix (2.6.0) em-synchrony (~> 1.0) em-websocket @@ -208,34 +209,37 @@ GEM faraday_middleware (~> 0.13.1) faye (~> 1.2) peatio (>= 2.4.2) - jwt (2.2.2) + jwt (2.2.3) jwt-multisig (1.0.5) activesupport (>= 4.0) jwt (~> 2.2) jwt-rack (0.1.1) jwt (~> 2.2) rack - kaminari (1.2.1) + kaminari (1.2.2) activesupport (>= 4.1.0) - kaminari-actionview (= 1.2.1) - kaminari-activerecord (= 1.2.1) - kaminari-core (= 1.2.1) - kaminari-actionview (1.2.1) + kaminari-actionview (= 1.2.2) + kaminari-activerecord (= 1.2.2) + kaminari-core (= 1.2.2) + kaminari-actionview (1.2.2) actionview - kaminari-core (= 1.2.1) - kaminari-activerecord (1.2.1) + kaminari-core (= 1.2.2) + kaminari-activerecord (1.2.2) activerecord - kaminari-core (= 1.2.1) - kaminari-core (1.2.1) + kaminari-core (= 1.2.2) + kaminari-core (1.2.2) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.9.0) + loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.1) + mail (2.8.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp marcel (0.3.3) mimemagic (~> 0.3.2) memoist (0.16.2) @@ -244,28 +248,37 @@ GEM mimemagic (0.3.10) nokogiri (~> 1) rake - mini_mime (1.0.3) - mini_portile2 (2.5.0) - minitest (5.14.4) - mocha (1.12.0) - msgpack (1.4.2) + mini_mime (1.1.2) + mini_portile2 (2.8.1) + minitest (5.17.0) + mocha (1.16.1) + msgpack (1.6.0) multi_json (1.15.0) - multipart-post (2.1.1) - mustermann (1.1.1) + multipart-post (2.3.0) + mustermann (3.0.0) ruby2_keywords (~> 0.0.1) - mustermann-grape (1.0.1) + mustermann-grape (1.0.2) mustermann (>= 1.0.0) - mysql2 (0.5.3) + mysql2 (0.5.5) net-http-persistent (3.0.1) connection_pool (~> 2.2) - nio4r (2.5.7) - nokogiri (1.11.2) - mini_portile2 (~> 2.5.0) + net-imap (0.3.4) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.5.8) + nokogiri (1.13.10) + mini_portile2 (~> 2.8.0) racc (~> 1.4) - parallel (1.20.1) - parser (3.0.0.0) + parallel (1.22.1) + parser (3.2.1.0) ast (~> 2.4.1) - peatio (2.6.3) + peatio (2.6.5) activemodel (> 5.2, <= 6.0.0) amqp bunny @@ -287,7 +300,7 @@ GEM memoist (~> 0.16.0) net-http-persistent (~> 3.0.1) peatio (>= 0.6.3) - peatio-bitgo (2.6.6) + peatio-bitgo (2.6.8) activesupport (~> 5.2.3) better-faraday (~> 1.0.5) faraday (~> 0.17) @@ -301,7 +314,7 @@ GEM memoist (~> 0.16.0) net-http-persistent (~> 3.0.1) peatio (>= 0.6.3) - peatio-electrum (2.6.2) + peatio-electrum (2.6.3) activesupport (~> 5.2.3) faraday (~> 0.17) net-http-persistent (~> 3.0.1) @@ -320,66 +333,66 @@ GEM memoist (~> 0.16.0) net-http-persistent (~> 3.0.1) peatio (>= 0.6.3) - pg (1.2.3) + pg (1.4.5) polyamorous (2.3.2) activerecord (>= 5.2.1) - prometheus-client (2.1.0) + prometheus-client (4.0.0) pry (0.13.1) coderay (~> 1.1) method_source (~> 1.0) pry-byebug (3.9.0) byebug (~> 11.0) pry (~> 0.13.0) - public_suffix (4.0.6) + public_suffix (5.0.1) puma (3.12.6) - racc (1.5.2) - rack (2.2.3) + racc (1.6.2) + rack (2.2.6.2) rack-accept (0.4.5) rack (>= 0.4) rack-attack (5.4.2) rack (>= 1.0, < 3) rack-cors (1.0.6) rack (>= 1.6.0) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.4.5) - actioncable (= 5.2.4.5) - actionmailer (= 5.2.4.5) - actionpack (= 5.2.4.5) - actionview (= 5.2.4.5) - activejob (= 5.2.4.5) - activemodel (= 5.2.4.5) - activerecord (= 5.2.4.5) - activestorage (= 5.2.4.5) - activesupport (= 5.2.4.5) + rack-test (2.0.2) + rack (>= 1.3) + rails (5.2.4.6) + actioncable (= 5.2.4.6) + actionmailer (= 5.2.4.6) + actionpack (= 5.2.4.6) + actionview (= 5.2.4.6) + activejob (= 5.2.4.6) + activemodel (= 5.2.4.6) + activerecord (= 5.2.4.6) + activestorage (= 5.2.4.6) + activesupport (= 5.2.4.6) bundler (>= 1.3.0) - railties (= 5.2.4.5) + railties (= 5.2.4.6) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) - loofah (~> 2.3) - railties (5.2.4.5) - actionpack (= 5.2.4.5) - activesupport (= 5.2.4.5) + rails-html-sanitizer (1.5.0) + loofah (~> 2.19, >= 2.19.1) + railties (5.2.4.6) + actionpack (= 5.2.4.6) + activesupport (= 5.2.4.6) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) - rainbow (3.0.0) - rake (13.0.3) + rainbow (3.1.1) + rake (13.0.6) ransack (2.3.2) activerecord (>= 5.2.1) activesupport (>= 5.2.1) i18n polyamorous (= 2.3.2) - rb-fsevent (0.10.4) + rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - rbtree (0.4.4) + rbtree (0.4.6) redis (4.1.4) - regexp_parser (2.1.1) - reline (0.2.4) + regexp_parser (2.7.0) + reline (0.3.2) io-console (~> 0.5) rexml (3.2.4) rspec-core (3.9.0) @@ -410,50 +423,51 @@ GEM rubocop-ast (>= 0.6.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.4.1) - parser (>= 2.7.1.5) + rubocop-ast (1.26.0) + parser (>= 3.2.1.0) rubocop-rspec (1.44.1) rubocop (~> 0.87) rubocop-ast (>= 0.7.1) ruby-prof (0.17.0) ruby-progressbar (1.11.0) - ruby2_keywords (0.0.4) + ruby2_keywords (0.0.5) ruby_dep (1.5.0) safe_yaml (1.0.5) scout_apm (2.6.10) parser sentry-raven (2.9.0) faraday (>= 0.7.6, < 1.0) - sprockets (4.0.2) + sprockets (4.2.0) concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) - thin (1.8.0) + thin (1.8.1) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) thor (0.20.3) thread_safe (0.3.6) - timecop (0.9.4) - tzinfo (1.2.9) + timecop (0.9.6) + timeout (0.3.2) + tzinfo (1.2.11) thread_safe (~> 0.1) - unicode-display_width (1.7.0) - uniform_notifier (1.14.2) - validate_url (1.0.13) + unicode-display_width (1.8.0) + uniform_notifier (1.16.0) + validate_url (1.0.15) activemodel (>= 3.0.0) public_suffix validates_lengths_from_database (0.7.0) activerecord (>= 3) - vault (0.16.0) + vault (0.17.0) aws-sigv4 - webmock (3.12.2) - addressable (>= 2.3.6) + webmock (3.18.1) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - websocket-driver (0.7.3) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -539,7 +553,7 @@ DEPENDENCIES webmock (~> 3.5) RUBY VERSION - ruby 2.6.6p146 + ruby 2.6.10p210 BUNDLED WITH - 2.1.4 + 1.17.3 diff --git a/app/api/v2/management/withdraws.rb b/app/api/v2/management/withdraws.rb index a1e99dcdc6..fe34c0f3d1 100644 --- a/app/api/v2/management/withdraws.rb +++ b/app/api/v2/management/withdraws.rb @@ -86,9 +86,11 @@ def perform_action(withdraw, action) requires :currency, type: String, values: -> { Currency.codes(bothcase: true) }, desc: 'The currency code.' requires :amount, type: BigDecimal, desc: 'The amount to withdraw.' optional :note, type: String, desc: 'The note for withdraw.' + optional :additional_fee, type: { value: Boolean, message: 'management.withdraw.non_boolean_additional_fee' }, + default: false, desc: 'Additional fee charge for withdraw.' optional :action, type: String, values: %w[process], desc: 'The action to perform.' optional :transfer_type, type: String, - values: { value: -> { Withdraw::TRANSFER_TYPES.keys }, message: 'account.withdraw.transfer_type_not_in_list' }, + values: { value: -> { Withdraw::TRANSFER_TYPES.keys }, message: 'management.withdraw.transfer_type_not_in_list' }, desc: -> { API::V2::Admin::Entities::Withdraw.documentation[:transfer_type][:desc] } exactly_one_of :rid, :beneficiary_id @@ -112,8 +114,9 @@ def perform_action(withdraw, action) error!({ errors: ['TID already exist'] }, 422) if Withdraw.where(tid: params[:tid]).present? end + amount = params[:additional_fee] ? params[:amount] + currency.withdraw_fee : params[:amount] declared_params = declared(params, include_missing: false).slice(:tid, :rid, :note, :transfer_type).merge( - sum: params[:amount], + sum: amount, member: member, currency: currency, tid: params[:tid] diff --git a/spec/api/v2/management/withdraws_spec.rb b/spec/api/v2/management/withdraws_spec.rb index c9f3abb997..eb44252928 100644 --- a/spec/api/v2/management/withdraws_spec.rb +++ b/spec/api/v2/management/withdraws_spec.rb @@ -120,9 +120,10 @@ def request context 'withdrawal with beneficiary' do let(:beneficiary) { create(:beneficiary, state: :active, currency: currency) } let(:data) do - { uid: member.uid, - currency: currency.code, - amount: amount.to_s, + { uid: member.uid, + currency: currency.code, + amount: amount.to_s, + additional_fee: true, beneficiary_id: beneficiary.id } end @@ -130,12 +131,13 @@ def request request expect(response).to have_http_status(201) record = Withdraw.find_by_tid!(JSON.parse(response.body).fetch('tid')) - expect(record.sum).to eq 0.1575 + new_amount = currency.withdraw_fee + data[:amount].to_d + expect(record.sum).to eq new_amount expect(record.aasm_state).to eq 'accepted' expect(record.rid).to eq beneficiary.rid expect(record.account).to eq account - expect(record.account.balance).to eq (1.2 - amount) - expect(record.account.locked).to eq amount + expect(record.account.balance).to eq (1.2 - new_amount) + expect(record.account.locked).to eq new_amount end context 'pending beneficiary' do