Skip to content

Commit

Permalink
Merge pull request #111 from sul-dlss/jgreben-patch
Browse files Browse the repository at this point in the history
Check for multiple payments on account when comparing payment amount to CyberSource paid amount.
  • Loading branch information
jgreben authored Feb 2, 2024
2 parents 9cbb50c + 8ce0c3a commit 9289867
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
/config/settings/dev.yml
/config/settings/prod.yml
/log/*
*.csv
secret.yaml
58 changes: 42 additions & 16 deletions cyber_source/download_payment_batch_detail_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 9289867

Please sign in to comment.