Skip to content

Instantly share code, notes, and snippets.

@bryanmtl
Last active December 21, 2015 01:58
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 bryanmtl/6231471 to your computer and use it in GitHub Desktop.
Save bryanmtl/6231471 to your computer and use it in GitHub Desktop.
A quick rake task to identify possible Spree orders that contain invalid payments that might actually have been successfully processed
# Rake task
desc 'Generate a list of potential orders with falsely flagged invalid payments'
task list_orders_with_complete_and_invalid_payments: :environment do
Spree::Order.complete.where(legacy: false).each do |order|
if order && order.has_mulitple_payments? && order.has_an_invalid_and_complete_payment?
puts " -> Order #{order.number} has a potentially problematic payment"
end
end
end
# to add to order model
def has_mulitple_payments?
payments.count > 1
end
def has_an_invalid_and_complete_payment?
payment_states & %w(completed invalid) == payment_states.uniq
end
def payment_states
payments.map(&:state)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment