Created
October 15, 2012 13:55
-
-
Save detomastah/3892576 to your computer and use it in GitHub Desktop.
Updated timestamps for invoices
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
$affected = [] | |
$not_updated = [] | |
def update_timestamp(invoice, created_at) | |
if created_at.blank? | |
$not_updated << invoice | |
else | |
created_at = created_at.in_time_zone - 30.minutes | |
puts "#{invoice.id} #{invoice.created_at} -> #{created_at}" | |
invoice.created_at = created_at | |
invoice.save! | |
$affected << invoice | |
end | |
end | |
Order.where(:payment_status => "capture_success").joins(:invoice).each do |order| | |
payment_attributes = order.payment_attributes | |
invoice = order.invoice | |
if invoice && payment_attributes && payment_attributes['message_capture_success_key'] | |
if [TelecashStrategy.payment_method, PaypalStrategy.payment_method].include?(order.payment_method.to_sym) | |
created_at = payment_attributes. | |
fetch('message_capture_success_key')['received_at'] | |
update_timestamp(order.invoice, created_at) | |
end | |
end | |
end;nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment