Skip to content

Instantly share code, notes, and snippets.

@detomastah
Created October 15, 2012 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save detomastah/3892576 to your computer and use it in GitHub Desktop.
Save detomastah/3892576 to your computer and use it in GitHub Desktop.
Updated timestamps for invoices
$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