Last active
May 6, 2020 20:57
-
-
Save joshuacronemeyer/2e37938fc2dffed16a4d41b989edfc83 to your computer and use it in GitHub Desktop.
cancel all orders for a tour with verbose confirmation for each event.
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
def cancel!(tour_id) | |
events = Tour.find(tour_id).events | |
events.each do |e| | |
orders_to_cancel = Purchase::Order.where(event_id: e.id).where(order_status: ["accepted","completed"]) | |
if orders_to_cancel.length == 0 | |
p "Skipping event with 0 orders to cancel" | |
next | |
end | |
p "Please confirm you would like to cancel #{orders_to_cancel.count} orders for event #{e.id} by typing 'CONFIRM'" | |
input = gets | |
if input == "CONFIRM\n" | |
orders_to_cancel.each do |order| | |
p "Cancelling order #{order.id}" | |
order.cancel_and_refund(reason: "Tour cancellation", admin_user: AdminUser.find_by_email("josh@applauze.com")) | |
end | |
else | |
"You didn't confirm. Goodbye." | |
break | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment