Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for multiple payments on account when comparing payment amount to CyberSource paid amount. #111

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading