fix fix fi x fix
This commit is contained in:
@@ -1055,6 +1055,125 @@ Current Balance: {current_credits} credits
|
||||
To avoid service interruption, please top up your credits:
|
||||
{context['topup_url']}
|
||||
|
||||
Thank you,
|
||||
The IGNY8 Team
|
||||
""".strip(),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def send_invoice_email(invoice, is_reminder=False):
|
||||
"""
|
||||
Send invoice email to the account owner.
|
||||
Used for manual payment methods (bank transfer, local wallet, manual).
|
||||
|
||||
Args:
|
||||
invoice: Invoice model instance
|
||||
is_reminder: If True, sends as a reminder email
|
||||
"""
|
||||
service = get_email_service()
|
||||
frontend_url = BillingEmailService._get_frontend_url()
|
||||
|
||||
account = invoice.account
|
||||
|
||||
subject_prefix = 'Reminder: ' if is_reminder else ''
|
||||
|
||||
context = {
|
||||
'account_name': account.name,
|
||||
'invoice_number': invoice.invoice_number or f'INV-{invoice.id}',
|
||||
'invoice_date': invoice.created_at.strftime('%Y-%m-%d'),
|
||||
'due_date': invoice.due_date.strftime('%Y-%m-%d') if invoice.due_date else 'N/A',
|
||||
'total_amount': invoice.total_amount,
|
||||
'currency': invoice.currency or 'USD',
|
||||
'items': invoice.items or [],
|
||||
'payment_instructions': invoice.metadata.get('payment_instructions', ''),
|
||||
'is_reminder': is_reminder,
|
||||
'frontend_url': frontend_url,
|
||||
'invoice_url': f'{frontend_url}/billing/invoices/{invoice.id}',
|
||||
}
|
||||
|
||||
subject = f'{subject_prefix}Invoice #{context["invoice_number"]} - Payment Required'
|
||||
|
||||
try:
|
||||
result = service.send_transactional(
|
||||
to=account.billing_email or account.owner.email,
|
||||
subject=subject,
|
||||
template='emails/invoice.html',
|
||||
context=context,
|
||||
tags=['billing', 'invoice', 'reminder' if is_reminder else 'new'],
|
||||
)
|
||||
logger.info(f'Invoice email sent for Invoice {invoice.id} (reminder={is_reminder})')
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to send invoice email: {str(e)}')
|
||||
reminder_text = 'This is a reminder that your ' if is_reminder else ''
|
||||
return service.send_transactional(
|
||||
to=account.billing_email or account.owner.email,
|
||||
subject=subject,
|
||||
text=f"""
|
||||
Hi {account.name},
|
||||
|
||||
{reminder_text}Invoice #{context['invoice_number']} requires your attention.
|
||||
|
||||
Invoice Details:
|
||||
- Invoice Number: {context['invoice_number']}
|
||||
- Date: {context['invoice_date']}
|
||||
- Due Date: {context['due_date']}
|
||||
- Amount: {context['currency']} {context['total_amount']}
|
||||
|
||||
To view and pay your invoice:
|
||||
{context['invoice_url']}
|
||||
|
||||
{context['payment_instructions']}
|
||||
|
||||
If you have any questions, please contact our support team.
|
||||
|
||||
Thank you,
|
||||
The IGNY8 Team
|
||||
""".strip(),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def send_subscription_expired_email(account, subscription):
|
||||
"""
|
||||
Send email when subscription expires due to non-payment.
|
||||
"""
|
||||
service = get_email_service()
|
||||
frontend_url = BillingEmailService._get_frontend_url()
|
||||
|
||||
context = {
|
||||
'account_name': account.name,
|
||||
'plan_name': subscription.plan.name if subscription.plan else 'N/A',
|
||||
'frontend_url': frontend_url,
|
||||
'billing_url': f'{frontend_url}/account/plans',
|
||||
}
|
||||
|
||||
try:
|
||||
result = service.send_transactional(
|
||||
to=account.billing_email or account.owner.email,
|
||||
subject='Subscription Expired - Action Required',
|
||||
template='emails/subscription_expired.html',
|
||||
context=context,
|
||||
tags=['billing', 'subscription-expired'],
|
||||
)
|
||||
logger.info(f'Subscription expired email sent for account {account.id}')
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to send subscription expired email: {str(e)}')
|
||||
return service.send_transactional(
|
||||
to=account.billing_email or account.owner.email,
|
||||
subject='Subscription Expired - Action Required',
|
||||
text=f"""
|
||||
Hi {account.name},
|
||||
|
||||
Your subscription to the {context['plan_name']} plan has expired due to non-payment.
|
||||
|
||||
Your account access may be limited until you renew your subscription.
|
||||
|
||||
To reactivate your subscription:
|
||||
{context['billing_url']}
|
||||
|
||||
If you have any questions or need assistance, please contact our support team.
|
||||
|
||||
Thank you,
|
||||
The IGNY8 Team
|
||||
""".strip(),
|
||||
|
||||
Reference in New Issue
Block a user