
-- KINET MikroTik Admin Module - Update v22 Voucher Online Midtrans Snap Otomatis
ALTER TABLE voucher_online_orders ADD COLUMN IF NOT EXISTS payment_provider VARCHAR(40) NOT NULL DEFAULT 'manual' AFTER payment_method;
ALTER TABLE voucher_online_orders ADD COLUMN IF NOT EXISTS midtrans_order_id VARCHAR(80) NULL AFTER payment_url;
ALTER TABLE voucher_online_orders ADD COLUMN IF NOT EXISTS midtrans_snap_token VARCHAR(160) NULL AFTER midtrans_order_id;
ALTER TABLE voucher_online_orders ADD COLUMN IF NOT EXISTS midtrans_redirect_url TEXT NULL AFTER midtrans_snap_token;
ALTER TABLE voucher_online_orders ADD INDEX IF NOT EXISTS idx_voucher_online_provider (payment_provider);
ALTER TABLE voucher_online_orders ADD INDEX IF NOT EXISTS idx_voucher_online_midtrans_order (midtrans_order_id);
INSERT INTO settings (setting_key, setting_value) VALUES
('payment_midtrans_snap_expiry_minutes', '60'),
('voucher_online_payment_mode', 'midtrans_snap_on_paid'),
('voucher_online_wait_gateway_note', 'Voucher online memakai Midtrans Snap. Order hanya pending saat checkout; voucher baru digenerate setelah webhook Midtrans settlement/capture valid.')
ON DUPLICATE KEY UPDATE setting_key = setting_key;
