/**
* Migration: Add payment failure email templates
* @ai-summary Adds email templates for payment failures during grace period
* @ai-context Three templates: immediate, 7-day warning, 1-day warning
*/
-- Extend template_key CHECK constraint to include payment failure templates
ALTER TABLE email_templates
DROP CONSTRAINT IF EXISTS email_templates_template_key_check;
ALTER TABLE email_templates
ADD CONSTRAINT email_templates_template_key_check
CHECK (template_key IN (
'maintenance_due_soon', 'maintenance_overdue',
'document_expiring', 'document_expired',
'payment_failed_immediate', 'payment_failed_7day', 'payment_failed_1day'
));
-- Insert payment failure email templates
INSERT INTO email_templates (template_key, name, description, subject, body, variables, html_body) VALUES
(
'payment_failed_immediate',
'Payment Failed - Immediate Notice',
'Sent immediately when a subscription payment fails',
'MotoVaultPro: Payment Failed - Action Required',
'Hi {{userName}},
We were unable to process your payment for your {{tier}} subscription.
Your subscription will remain active for 30 days while we attempt to collect payment. After 30 days, your subscription will be downgraded to the free tier.
Please update your payment method to avoid interruption of service.
Amount Due: ${{amount}}
Next Retry: {{retryDate}}
Best regards,
MotoVaultPro Team',
'["userName", "tier", "amount", "retryDate"]',
'
Payment Failed
Payment Failed
|
|
Hi {{userName}},
We were unable to process your payment for your {{tier}} subscription.
Your subscription will remain active for 30 days while we attempt to collect payment. After 30 days, your subscription will be downgraded to the free tier.
Please update your payment method to avoid interruption of service.
|
Amount Due: ${{amount}}
Next Retry: {{retryDate}}
|
|
|
Best regards, MotoVaultPro Team
|
|
'
),
(
'payment_failed_7day',
'Payment Failed - 7 Days Left',
'Sent 7 days before grace period ends',
'MotoVaultPro: Urgent - 7 Days Until Downgrade',
'Hi {{userName}},
This is an urgent reminder that your {{tier}} subscription payment is still outstanding.
Your subscription will be downgraded to the free tier in 7 days if payment is not received.
Amount Due: ${{amount}}
Grace Period Ends: {{gracePeriodEnd}}
Please update your payment method immediately to avoid losing access to premium features.
Best regards,
MotoVaultPro Team',
'["userName", "tier", "amount", "gracePeriodEnd"]',
'
Payment Reminder - 7 Days Left
Urgent: 7 Days Until Downgrade
|
|
Hi {{userName}},
This is an urgent reminder that your {{tier}} subscription payment is still outstanding.
Your subscription will be downgraded in 7 days
If payment is not received by {{gracePeriodEnd}}, you will lose access to premium features.
|
Amount Due: ${{amount}}
Grace Period Ends: {{gracePeriodEnd}}
|
|
|
Best regards, MotoVaultPro Team
|
|
'
),
(
'payment_failed_1day',
'Payment Failed - Final Notice',
'Sent 1 day before grace period ends',
'MotoVaultPro: FINAL NOTICE - Downgrade Tomorrow',
'Hi {{userName}},
FINAL NOTICE: Your {{tier}} subscription will be downgraded to the free tier tomorrow if payment is not received.
Amount Due: ${{amount}}
Grace Period Ends: {{gracePeriodEnd}}
This is your last chance to update your payment method and keep your premium features.
After downgrade:
- Access to premium features will be lost
- Data remains safe but with reduced vehicle limits
- You can resubscribe at any time
Please update your payment method now to avoid interruption.
Best regards,
MotoVaultPro Team',
'["userName", "tier", "amount", "gracePeriodEnd"]',
'
Final Notice - Downgrade Tomorrow
FINAL NOTICE
Downgrade Tomorrow
|
|
Hi {{userName}},
FINAL NOTICE
Your {{tier}} subscription will be downgraded to the free tier tomorrow if payment is not received.
|
Amount Due: ${{amount}}
Grace Period Ends: {{gracePeriodEnd}}
|
This is your last chance to update your payment method and keep your premium features.
After downgrade:
- Access to premium features will be lost
- Data remains safe but with reduced vehicle limits
- You can resubscribe at any time
|
|
Best regards, MotoVaultPro Team
|
|
'
);