diff --git a/.ruby-version b/.ruby-version index 944880f..be94e6f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.0 +3.2.2 diff --git a/Dockerfile b/Dockerfile index bfaa914..951d566 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,80 +1,9 @@ +FROM internetee/ruby:3.2.2-bullseye -FROM ruby:3.2.0-slim-buster -SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN apt-get update > /dev/null && apt-get install -y --no-install-recommends > /dev/null \ - build-essential=* \ - curl \ - wget \ - gnupg2 \ - git \ - apt-utils \ - && apt-get dist-upgrade -yf\ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales -RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen -RUN sed -i -e 's/# et_EE.UTF-8 UTF-8/et_EE.UTF-8 UTF-8/' /etc/locale.gen && \ - dpkg-reconfigure --frontend=noninteractive locales && \ - update-locale LANG=et_EE.UTF-8 - -ENV LANG et_EE.UTF-8 -RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc -s | apt-key add - -RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list' -RUN apt-get update > /dev/null && apt-get install -y --no-install-recommends > /dev/null \ - postgresql-client-13=* \ - libpq-dev \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# add repository for Node.js in the LTS version -RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - - -RUN apt-get install -y --no-install-recommends > /dev/null \ - nodejs=* \ - qt5-default=* \ - libqt5webkit5-dev=* \ - gstreamer1.0-plugins-base=* \ - libappindicator3-1=* \ - gstreamer1.0-tools=* \ - qtdeclarative5-dev=* \ - fonts-liberation=* \ - gstreamer1.0-x=* \ - libasound2=* \ - libnspr4=* \ - libnss3=* \ - libxss1=* \ - libxtst6=* \ - xdg-utils=* \ - qtdeclarative5-dev=* \ - fonts-liberation=* \ - gstreamer1.0-x=* \ - wkhtmltopdf \ - libxslt1-dev \ - libxml2-dev \ - python-dev \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# RUN curl https://chromedriver.storage.googleapis.com/2.46/chromedriver_linux64.zip -o /chromedriver_linux64.zip -# RUN apt-get update > /dev/null \ -# && apt-get install -yf --no-install-recommends > /dev/null unzip=* \ -# && apt-get clean \ -# && rm -rf /var/lib/apt/lists/* -# RUN unzip chromedriver_linux64.zip -d /usr/local/bin -# RUN rm /chromedriver_linux64.zip - -# RUN npm install --global yarn RUN npm install -g yarn@latest -# RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb -# RUN dpkg -i /chrome.deb || apt-get update > /dev/null \ -# && apt-get install -yf --no-install-recommends > /dev/null && apt-get clean \ -# && rm -rf /var/lib/apt/lists/* -# RUN dpkg -i /chrome.deb -# RUN rm /chrome.deb -# RUN sed -i 's/SECLEVEL=2/SECLEVEL=1/' /etc/ssl/openssl.cnf +RUN sed -i 's/SECLEVEL=2/SECLEVEL=1/' /etc/ssl/openssl.cnf RUN mkdir -p /opt/webapps/app/tmp/pids WORKDIR /opt/webapps/app @@ -84,4 +13,4 @@ RUN gem install bundler && bundle install --jobs 20 --retry 5 # COPY package.json yarn.lock ./ # RUN yarn install --check-files -EXPOSE 3000 +EXPOSE 3000 \ No newline at end of file diff --git a/Gemfile b/Gemfile index 417f3f7..8cbee6d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,5 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } - -ruby '3.2.0' - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' gem 'rails', '~> 7.1.3' gem 'pg', '~> 1.1' diff --git a/Gemfile.lock b/Gemfile.lock index 37044a2..80c1f22 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,35 +37,35 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (7.1.3.2) - actionpack (= 7.1.3.2) - activesupport (= 7.1.3.2) + actioncable (7.1.4) + actionpack (= 7.1.4) + activesupport (= 7.1.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.3.2) - actionpack (= 7.1.3.2) - activejob (= 7.1.3.2) - activerecord (= 7.1.3.2) - activestorage (= 7.1.3.2) - activesupport (= 7.1.3.2) + actionmailbox (7.1.4) + actionpack (= 7.1.4) + activejob (= 7.1.4) + activerecord (= 7.1.4) + activestorage (= 7.1.4) + activesupport (= 7.1.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.1.3.2) - actionpack (= 7.1.3.2) - actionview (= 7.1.3.2) - activejob (= 7.1.3.2) - activesupport (= 7.1.3.2) + actionmailer (7.1.4) + actionpack (= 7.1.4) + actionview (= 7.1.4) + activejob (= 7.1.4) + activesupport (= 7.1.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.2) - actionpack (7.1.3.2) - actionview (= 7.1.3.2) - activesupport (= 7.1.3.2) + actionpack (7.1.4) + actionview (= 7.1.4) + activesupport (= 7.1.4) nokogiri (>= 1.8.5) racc rack (>= 2.2.4) @@ -73,35 +73,35 @@ GEM rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.3.2) - actionpack (= 7.1.3.2) - activerecord (= 7.1.3.2) - activestorage (= 7.1.3.2) - activesupport (= 7.1.3.2) + actiontext (7.1.4) + actionpack (= 7.1.4) + activerecord (= 7.1.4) + activestorage (= 7.1.4) + activesupport (= 7.1.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.3.2) - activesupport (= 7.1.3.2) + actionview (7.1.4) + activesupport (= 7.1.4) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.3.2) - activesupport (= 7.1.3.2) + activejob (7.1.4) + activesupport (= 7.1.4) globalid (>= 0.3.6) - activemodel (7.1.3.2) - activesupport (= 7.1.3.2) - activerecord (7.1.3.2) - activemodel (= 7.1.3.2) - activesupport (= 7.1.3.2) + activemodel (7.1.4) + activesupport (= 7.1.4) + activerecord (7.1.4) + activemodel (= 7.1.4) + activesupport (= 7.1.4) timeout (>= 0.4.0) - activestorage (7.1.3.2) - actionpack (= 7.1.3.2) - activejob (= 7.1.3.2) - activerecord (= 7.1.3.2) - activesupport (= 7.1.3.2) + activestorage (7.1.4) + actionpack (= 7.1.4) + activejob (= 7.1.4) + activerecord (= 7.1.4) + activesupport (= 7.1.4) marcel (~> 1.0) - activesupport (7.1.3.2) + activesupport (7.1.4) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) @@ -133,12 +133,12 @@ GEM erubi (~> 1.4) parser (>= 2.4) smart_properties - bigdecimal (3.1.7) + bigdecimal (3.1.8) bindata (2.5.0) bootsnap (1.17.0) msgpack (~> 1.2) brakeman (6.0.1) - builder (3.2.4) + builder (3.3.0) bundle-audit (0.1.0) bundler-audit bundler-audit (0.9.1) @@ -160,7 +160,7 @@ GEM capistrano-rbenv (2.2.0) capistrano (~> 3.1) sshkit (~> 1.3) - concurrent-ruby (1.2.3) + concurrent-ruby (1.3.4) connection_pool (2.4.1) countries (5.7.0) unaccent (~> 0.3) @@ -209,7 +209,7 @@ GEM dry-initializer (~> 3.0) dry-schema (>= 1.12, < 2) zeitwerk (~> 2.6) - erubi (1.12.0) + erubi (1.13.0) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) @@ -240,7 +240,7 @@ GEM turbo-rails httpi (3.0.1) rack - i18n (1.14.4) + i18n (1.14.6) concurrent-ruby (~> 1.0) i18n-tasks (1.0.13) activesupport (>= 4.0.2) @@ -257,7 +257,10 @@ GEM actionpack (>= 6.0.0) activesupport (>= 6.0.0) railties (>= 6.0.0) - irb (0.9.6) + io-console (0.7.2) + irb (1.14.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) json (2.6.3) json-jwt (1.16.6) activesupport (>= 4.2) @@ -282,15 +285,15 @@ GEM net-smtp marcel (1.0.4) mini_mime (1.1.5) - mini_portile2 (2.8.5) - minitest (5.22.3) + mini_portile2 (2.8.7) + minitest (5.25.1) money (6.16.0) i18n (>= 0.6.4, <= 2) msgpack (1.7.2) mutex_m (0.2.0) net-http (0.4.1) uri - net-imap (0.4.10) + net-imap (0.4.16) date net-protocol net-pop (0.1.2) @@ -299,14 +302,14 @@ GEM timeout net-scp (4.0.0) net-ssh (>= 2.6.5, < 8.0.0) - net-smtp (0.4.0.1) + net-smtp (0.5.0) net-protocol net-ssh (7.2.0) - nio4r (2.7.0) - nokogiri (1.16.3) + nio4r (2.7.3) + nokogiri (1.16.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.16.3-x86_64-linux) + nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) nori (2.6.0) omniauth (2.1.1) @@ -339,11 +342,13 @@ GEM pg_search (2.3.6) activerecord (>= 5.2) activesupport (>= 5.2) + psych (5.1.2) + stringio public_suffix (5.0.3) - puma (6.4.2) + puma (6.4.3) nio4r (~> 2.0) - racc (1.7.3) - rack (2.2.8.1) + racc (1.8.1) + rack (2.2.9) rack-oauth2 (2.2.0) activesupport attr_required @@ -360,20 +365,20 @@ GEM rackup (1.0.0) rack (< 3) webrick - rails (7.1.3.2) - actioncable (= 7.1.3.2) - actionmailbox (= 7.1.3.2) - actionmailer (= 7.1.3.2) - actionpack (= 7.1.3.2) - actiontext (= 7.1.3.2) - actionview (= 7.1.3.2) - activejob (= 7.1.3.2) - activemodel (= 7.1.3.2) - activerecord (= 7.1.3.2) - activestorage (= 7.1.3.2) - activesupport (= 7.1.3.2) + rails (7.1.4) + actioncable (= 7.1.4) + actionmailbox (= 7.1.4) + actionmailer (= 7.1.4) + actionpack (= 7.1.4) + actiontext (= 7.1.4) + actionview (= 7.1.4) + activejob (= 7.1.4) + activemodel (= 7.1.4) + activerecord (= 7.1.4) + activestorage (= 7.1.4) + activesupport (= 7.1.4) bundler (>= 1.15.0) - railties (= 7.1.3.2) + railties (= 7.1.4) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -384,25 +389,29 @@ GEM rails-i18n (7.0.8) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 8) - railties (7.1.3.2) - actionpack (= 7.1.3.2) - activesupport (= 7.1.3.2) + railties (7.1.4) + actionpack (= 7.1.4) + activesupport (= 7.1.4) irb rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.1.0) + rake (13.2.1) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) + rdoc (6.7.0) + psych (>= 4.0.0) redis (5.0.8) redis-client (>= 0.17.0) redis-client (0.18.0) connection_pool regexp_parser (2.8.2) - rexml (3.2.6) + reline (0.5.10) + io-console (~> 0.5) + rexml (3.3.8) rspec-core (3.12.2) rspec-support (~> 3.12.0) rspec-expectations (3.12.3) @@ -474,6 +483,7 @@ GEM net-ssh (>= 2.8.0) stimulus-rails (1.3.0) railties (>= 6.0.0) + stringio (3.1.1) strong_migrations (1.6.4) activerecord (>= 5.2) swd (2.0.2) @@ -483,7 +493,7 @@ GEM faraday-follow_redirects terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) - thor (1.3.1) + thor (1.3.2) timeout (0.4.1) turbo-rails (1.5.0) actionpack (>= 6.0.0) @@ -519,13 +529,13 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.8.1) + webrick (1.8.2) websocket (1.2.10) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) wkhtmltopdf-binary (0.12.6.6) - zeitwerk (2.6.13) + zeitwerk (2.7.0) PLATFORMS ruby @@ -587,8 +597,5 @@ DEPENDENCIES webmock wkhtmltopdf-binary -RUBY VERSION - ruby 3.2.0p0 - BUNDLED WITH 2.4.13 diff --git a/app/jobs/payment_lhv_connect_job.rb b/app/jobs/payment_lhv_connect_job.rb index 4c0eec6..4f3d47b 100644 --- a/app/jobs/payment_lhv_connect_job.rb +++ b/app/jobs/payment_lhv_connect_job.rb @@ -12,22 +12,22 @@ def perform private - def payment_process - registry_bank_account_iban = Setting.registry_bank_account_iban_lhv || 'EE177700771001155322' - + def api_lhv keystore = open_ssl_keystore - key = keystore.key - cert = keystore.certificate - api = Lhv::ConnectApi.new - api.cert = cert - api.key = key - + api.cert = keystore.certificate + api.key = keystore.key api.dev_mode = ENV['lhv_dev_mode'] == 'true' + api + end + + def registry_bank_account_iban = Setting.registry_bank_account_iban_lhv || 'EE177700771001155322' + + def payment_process incoming_transactions = [] - api.credit_debit_notification_messages.each do |message| + api_lhv.credit_debit_notification_messages.each do |message| messages_proccess(message, registry_bank_account_iban) do message.credit_transactions.each do |credit_transaction| if credit_transaction.payment_reference_number.nil? @@ -36,6 +36,8 @@ def payment_process next if credit_transaction.payment_reference_number.nil? end + next if should_skip_transaction?(credit_transaction) + incoming_transactions << credit_transaction end end @@ -97,14 +99,13 @@ def send_transactions(params:, payment_reference_number:) uri = URI.parse(url[reference.initiator.to_sym]) http = Net::HTTP.new(uri.host, uri.port) - - if Rails.env.development? || Rails.env.test? - http.use_ssl = true - http.verify_mode = OpenSSL::SSL::VERIFY_NONE # :brakemanignore: SSLVerify - else - http.use_ssl = true - http.verify_mode = OpenSSL::SSL::VERIFY_PEER - end + + http.use_ssl = true + http.verify_mode = if Rails.env.development? || Rails.env.test? + OpenSSL::SSL::VERIFY_NONE # :brakemanignore: SSLVerify + else + OpenSSL::SSL::VERIFY_PEER + end res = http.post(url[reference.initiator.to_sym], params.to_json, headers) @@ -154,4 +155,23 @@ def test_transactions payment_reference_number: '7366488', payment_description: 'description 7366488') end + + def should_skip_transaction?(transaction) + card_payment_entry?(transaction) || + auction_portal_payment?(transaction) || + account_interest_entry?(transaction) + end + + def card_payment_entry?(transaction) + transaction.payment_description.to_s.start_with?('Kaardimaksete tulu') + end + + def auction_portal_payment?(transaction) + transaction.payment_description.to_s.start_with?('billing.internet.ee/EE') || + transaction.payment_description.to_s.start_with?('www.internet.ee/EE') + end + + def account_interest_entry?(transaction) + transaction.payment_description.to_s.start_with?('Konto intress') + end end diff --git a/db/schema.rb b/db/schema.rb index d929856..ff3262d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_31_100825) do +ActiveRecord::Schema[7.1].define(version: 2023_11_30_114315) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/jobs/payment_lhv_connect_job_spec.rb b/spec/jobs/payment_lhv_connect_job_spec.rb index e870b82..f7229e6 100644 --- a/spec/jobs/payment_lhv_connect_job_spec.rb +++ b/spec/jobs/payment_lhv_connect_job_spec.rb @@ -106,5 +106,137 @@ expect_any_instance_of(PaymentLhvConnectJob).to receive(:send_transactions).with(params: [params_for_sending], payment_reference_number: ref) PaymentLhvConnectJob.perform_now end + + it 'should skip card payment entries' do + date = Time.zone.now - 4.hours + card_payment = OpenStruct.new( + amount: '20.74', + currency: 'EUR', + date: date, + payment_reference_number: nil, + payment_description: 'Kaardimaksete tulu 24.09.2024' + ) + regular_payment = OpenStruct.new( + amount: '10.0', + currency: 'EUR', + date: date, + payment_reference_number: '123', + payment_description: 'Regular payment' + ) + + Lhv::ConnectApi.class_eval do + define_method :credit_debit_notification_messages do + message = OpenStruct.new( + bank_account_iban: Setting.registry_bank_account_iban_lhv || 'EE177700771001155322', + credit_transactions: [card_payment, regular_payment] + ) + [message] + end + end + + openssl_struct = OpenStruct.new(key: 'key', certificate: 'certificate') + allow_any_instance_of(PaymentLhvConnectJob).to receive(:open_ssl_keystore).and_return(openssl_struct) + + expect_any_instance_of(PaymentLhvConnectJob).to receive(:send_transactions).with( + params: [regular_payment], + payment_reference_number: '123' + ) + PaymentLhvConnectJob.perform_now + end + + it 'should skip card payment entries and auction portal payments' do + date = Time.zone.now - 4.hours + card_payment = OpenStruct.new( + amount: '20.74', + currency: 'EUR', + date: date, + payment_reference_number: nil, + payment_description: 'Kaardimaksete tulu 24.09.2024' + ) + auction_payment = OpenStruct.new( + amount: '123.0', + currency: 'EUR', + date: date, + payment_reference_number: nil, + payment_description: 'billing.internet.ee/EE, st994341, Ref:11111, 140001, 140002' + ) + regular_payment = OpenStruct.new( + amount: '10.0', + currency: 'EUR', + date: date, + payment_reference_number: '123', + payment_description: 'Regular payment' + ) + + Lhv::ConnectApi.class_eval do + define_method :credit_debit_notification_messages do + message = OpenStruct.new( + bank_account_iban: Setting.registry_bank_account_iban_lhv || 'EE177700771001155322', + credit_transactions: [card_payment, auction_payment, regular_payment] + ) + [message] + end + end + + openssl_struct = OpenStruct.new(key: 'key', certificate: 'certificate') + allow_any_instance_of(PaymentLhvConnectJob).to receive(:open_ssl_keystore).and_return(openssl_struct) + + expect_any_instance_of(PaymentLhvConnectJob).to receive(:send_transactions).with( + params: [regular_payment], + payment_reference_number: '123' + ) + PaymentLhvConnectJob.perform_now + end + + it 'should skip card payment entries, auction portal payments, and account interest entries' do + date = Time.zone.now - 4.hours + card_payment = OpenStruct.new( + amount: '20.74', + currency: 'EUR', + date: date, + payment_reference_number: nil, + payment_description: 'Kaardimaksete tulu 24.09.2024' + ) + auction_payment = OpenStruct.new( + amount: '123.0', + currency: 'EUR', + date: date, + payment_reference_number: nil, + payment_description: 'billing.internet.ee/EE, st994341, Ref:11111, 140001, 140002' + ) + account_interest = OpenStruct.new( + amount: '1.0', + currency: 'EUR', + date: date, + payment_reference_number: nil, + payment_description: 'Konto intress EE557700771000598731, 01.09.2024 - 30.09.2024, intressimäär 1.00%.' + ) + regular_payment = OpenStruct.new( + amount: '10.0', + currency: 'EUR', + date: date, + payment_reference_number: '123', + payment_description: 'Regular payment' + ) + + Lhv::ConnectApi.class_eval do + define_method :credit_debit_notification_messages do + message = OpenStruct.new( + bank_account_iban: Setting.registry_bank_account_iban_lhv || 'EE177700771001155322', + credit_transactions: [card_payment, auction_payment, account_interest, regular_payment] + ) + [message] + end + end + + openssl_struct = OpenStruct.new(key: 'key', certificate: 'certificate') + allow_any_instance_of(PaymentLhvConnectJob).to receive(:open_ssl_keystore).and_return(openssl_struct) + + expect_any_instance_of(PaymentLhvConnectJob).to receive(:send_transactions).with( + params: [regular_payment], + payment_reference_number: '123' + ) + PaymentLhvConnectJob.perform_now + end end end