ALTER TABLE order_payments
    ADD COLUMN checkout_expires_at DATETIME NULL AFTER checkout_url;

CREATE TABLE payment_webhook_events (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    provider_code VARCHAR(50) NOT NULL,
    provider_event_id VARCHAR(190) NOT NULL,
    event_type VARCHAR(120) NOT NULL,
    resource_id VARCHAR(190) NULL,
    processing_status ENUM('received', 'processed', 'ignored', 'failed') NOT NULL DEFAULT 'received',
    payload_json JSON NULL,
    failure_message TEXT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    handled_at DATETIME NULL,
    UNIQUE KEY uq_payment_webhook_events_provider_event (provider_code, provider_event_id),
    INDEX idx_payment_webhook_events_type (event_type),
    INDEX idx_payment_webhook_events_status (processing_status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
