Last active
August 9, 2022 19:47
-
-
Save john-diaz/db7761d295de01533bd552cd9f603c11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./lib/helpers" | |
events = []; | |
w.file_uploads.each do |f| | |
puts "NEXT FILE\n\n\n" | |
content = f.download | |
CSV.parse(content, headers: true) do |row| | |
d = row["AccountingDate"] || row["Accepted Date"] || row["Issued Date"] | |
payment_date = Date.strptime(d, "%m/%d/%Y %I:%M:%S %p") | |
description = row["Description"] | |
currency = row["Currency"] || "CAD" | |
total_amount = row["SubtotalAmount"].to_f + row["TipAmount"].to_f + row["TaxAmount"].to_f | |
puts [total_amount, currency] | |
amount_in_cents = if currency == "USD" | |
(total_amount * 100).to_i | |
else | |
(convert_currency_to_usd( | |
total_amount, | |
currency, | |
payment_date | |
) * 100).to_i | |
end | |
event = IntegrationEvent.create!( | |
integrator_id: integrator.id, | |
event: "event.payments.charge", | |
identifiers: {"vendor": {}, "transaction": {"description": description}}, | |
modifiers: { | |
"payment_method": { | |
"third_party_id": SecureRandom::uuid() | |
}, | |
"amount_in_cents": amount_in_cents | |
}, | |
metadata: {klick_csv:true}, | |
source_description: "csv", | |
event_timestamp: payment_date | |
) | |
puts event.id | |
end | |
end | |
puts "DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment