diff --git a/.gitignore b/.gitignore index fae062e..3703714 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ -/config/settings/dev.yml -/config/settings/prod.yml -/log/* *.csv secret.yaml diff --git a/cyber_source/download_payment_batch_detail_report.rb b/cyber_source/download_payment_batch_detail_report.rb index 7c6cd0f..15123de 100644 --- a/cyber_source/download_payment_batch_detail_report.rb +++ b/cyber_source/download_payment_batch_detail_report.rb @@ -18,7 +18,7 @@ class DownloadPaymentBatchDetailReport enableLog: true, merchantKeyId: ENV.fetch('MERCHANT_KEY_ID', nil), merchantsecretKey: ENV.fetch('MERCHANT_SECRET_KEY', nil), - logDirectory: 'harvestlog', + logDirectory: 'log', logFilename: 'cybs' }.freeze @@ -64,30 +64,40 @@ def main end if accounts && (accounts['totalRecords']).positive? + payments = [] + + accounts['accounts'].each do |a| + next unless is_a_payment?(a, paydate) + + payments << a['amount'].to_f + end + accounts['accounts'].each do |account| - account_date = Date.parse(account['metadata']['createdDate']) - payment_date = Date.parse(paydate) + next unless is_a_payment?(account, paydate) - unless (account_date == payment_date) && (account['amount'].to_f == paid.to_f) && (account['paymentStatus']['name'] == 'Paid fully') - next - end + puts user_id + puts "TOTAL PAYMENTS: #{payments.sum}" + puts "PAID in CYB:#{paid.to_f}" + + if (payments.sum == paid.to_f) - payload = { - paydate: paydate, - user_id: user_id, - folio_payment_id: account['id'], - library: account['feeFineOwner'], - reason: account['feeFineType'], - paid: paid - } + payload = { + paydate: Date.parse(paydate), + user_id: user_id, + folio_payment_id: account['id'], + library: account['feeFineOwner'], + reason: account['feeFineType'], + paid: account['amount'].to_f + } - credits.push(payload) + credits.push(payload) + end end end end end puts credits - sleep(ENV.fetch('SLEEP', 2)&.to_i) + sleep(ENV. fetch('SLEEP', 2)&.to_i) end credits.any? && CSV.open('files/credits.csv', 'w+') do |csv| csv << credits.first.keys @@ -100,6 +110,22 @@ def main puts e.backtrace end + def is_a_payment?(account, paydate) + payment_date = Date.parse(paydate) + + (created_date(account) == payment_date || updated_date(account) == payment_date) && + (account['paymentStatus']['name'] == 'Paid fully') + end + + def created_date(account) + Date.parse(account['metadata']['createdDate']) + end + + def updated_date(account) + Date.parse(account['metadata']['updatedDate']) + end + + def download_report(report_date) CyberSource::ReportDownloadsApi.new( CyberSource::ApiClient.new, CONFIGURATION_DICTIONARY.transform_keys(&:to_s)