Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Redeem Voucher in Marketplace Manually

Purpose

Use this script for manual voucher redemption in exceptional operational cases. It marks specified ticket codes as redeemed and records redemption metadata.

Prerequisites

  • Rails console access with write permission
  • Verified ticket codes list

How to run

rails c --production
# paste and run script

Script

codes = %w[
  VC-894A884405
  VC-7A1B918EA4
  VC-6585A2F822
  VC-CC148A686C
  VC-943FC43866
  VC-648E93A198
  VC-9FA0FF0751
  VC-72C27F3652
  VC-B027782008
  VC-0250C59C83
  VC-0E82AAB0553
  VC-F4633B7364
  VC-EC1CDFABEB
  VC-CF32E65991
  VC-29FE6D2BDB
  VC-DE40FDC2BD
  VC-F5CE933E07
  VC-0E82AAB053
  VC-6860B057D0
  VC-F31DBAED3C
  VC-6F5DE67037
].uniq

invalid = []
errors = []

codes.each do |code|
  ticket = Ticket.find_by(ticket_code: code)
  if ticket.blank?
    invalid << code
    next
  end

  next if ticket.redeemed_at.present?

  begin
    # Use restaurant timezone for redemption timestamp consistency.
    ticket.name = 'Redeemed by admin'
    ticket.phone = ''
    ticket.redeemed_at = Time.now_in_tz(ticket.ticket_transaction.restaurant.time_zone)
    ticket.save!
  rescue StandardError => e
    errors << { code: code, error: e.message }
  end
end

puts "Invalid codes: #{invalid.join(', ')}"
puts "Errors: #{errors}"

Verification

For each processed code:

  1. Ticket.find_by(ticket_code: code).redeemed_at should be present.
  2. Confirm status in admin marketplace/ticket detail page.