Last active
September 28, 2020 21:54
-
-
Save zarazan/2a7fa22c2c3b4cd052e1fdd689d7ed75 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
ActiveRecord::Base.transaction do | |
puts "message,created_at,id,key,one_cent_board,processed,transport_type,facility_id,store_number,customer,account_number,amount_approved,employee,payment_action" | |
kyle = User.find_by(email: "[email protected]"); | |
emv_transactions = EmvTransaction.where(processed: false, created_at: DateTime.parse('2020-09-24')..DateTime.parse('2020-09-25 10:00')) | |
emv_transactions.each do |emv_transaction| | |
facility = emv_transaction.facility | |
provider_response = emv_transaction.saved_provider_response&.dig('result') | |
payment_detail = provider_response&.dig('payment_details', 'payment_detail') | |
output = [ | |
facility.in_time_zone { emv_transaction.created_at }, | |
emv_transaction.id, | |
emv_transaction.key, | |
emv_transaction.one_cent_boarding, | |
emv_transaction.processed, | |
emv_transaction.transport_type, | |
facility.id, | |
facility.store_number, | |
payment_detail&.dig('customer'), | |
payment_detail&.dig('account_number'), | |
provider_response&.dig('total_amount_approved'), | |
emv_transaction.user&.full_name, | |
emv_transaction.payment_action | |
] | |
output_csv = output.join(',') | |
ledger_id = emv_transaction.form_serialized.dig('successful_payment_event', 'payment_amounts_attributes', '0', 'ledger_id') | |
ledger = Ledger.find_by_id(ledger_id) | |
if !ledger | |
puts "Ledger Not Found," + output_csv | |
next | |
end | |
if !ledger.moved_in_at? | |
puts "Not Moved In," + output_csv | |
next | |
end | |
if !emv_transaction.payment_action.include?('move_in') | |
puts "Not A Move In Skipping," + output_csv | |
next | |
end | |
emv_transaction.form_serialized['successful_payment_event']['tenant_id'] = ledger.tenant_id | |
service = EmvPaymentReconciliationService.new(emv_transaction, kyle); | |
def service.supported_payment?; return true; end; | |
success = false | |
Timecop.travel(ledger.moved_in_at) do | |
success = service.process | |
end | |
if !success | |
puts "Failed to apply payment," + output_csv | |
next | |
end | |
end_date = ledger.gllis.pluck(:effective_on).sort.last.to_date | |
AbacusGlCorrectorService.process(ledger: ledger, start_date: ledger.moved_in_at, end_date: end_date) | |
puts "Success," + output_csv | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment