Email COnfigs & setup
This commit is contained in:
@@ -786,6 +786,13 @@ def _process_subscription_payment(account, plan_id: str, capture_result: dict) -
|
||||
f"plan={plan.name}"
|
||||
)
|
||||
|
||||
# Send subscription activated email
|
||||
try:
|
||||
from igny8_core.business.billing.services.email_service import BillingEmailService
|
||||
BillingEmailService.send_subscription_activated_email(account, subscription)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send subscription activated email: {e}")
|
||||
|
||||
return {
|
||||
'subscription_id': subscription.id,
|
||||
'plan_name': plan.name,
|
||||
@@ -915,6 +922,14 @@ def _handle_subscription_activated(resource: dict):
|
||||
if update_fields != ['updated_at']:
|
||||
account.save(update_fields=update_fields)
|
||||
|
||||
# Send subscription activated email
|
||||
try:
|
||||
subscription = Subscription.objects.get(account=account, external_payment_id=subscription_id)
|
||||
from igny8_core.business.billing.services.email_service import BillingEmailService
|
||||
BillingEmailService.send_subscription_activated_email(account, subscription)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send subscription activated email: {e}")
|
||||
|
||||
except Account.DoesNotExist:
|
||||
logger.error(f"Account {custom_id} not found for PayPal subscription activation")
|
||||
|
||||
@@ -973,7 +988,16 @@ def _handle_subscription_payment_failed(resource: dict):
|
||||
subscription.status = 'past_due'
|
||||
subscription.save(update_fields=['status', 'updated_at'])
|
||||
|
||||
# TODO: Send payment failure notification email
|
||||
# Send payment failure notification email
|
||||
try:
|
||||
from igny8_core.business.billing.services.email_service import BillingEmailService
|
||||
BillingEmailService.send_payment_failed_notification(
|
||||
account=subscription.account,
|
||||
subscription=subscription,
|
||||
failure_reason='PayPal payment could not be processed'
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send payment failed email: {e}")
|
||||
|
||||
except Subscription.DoesNotExist:
|
||||
pass
|
||||
|
||||
@@ -28,6 +28,7 @@ from ..services.stripe_service import StripeService, StripeConfigurationError
|
||||
from ..services.payment_service import PaymentService
|
||||
from ..services.invoice_service import InvoiceService
|
||||
from ..services.credit_service import CreditService
|
||||
from ..services.email_service import BillingEmailService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -608,6 +609,12 @@ def _activate_subscription(account, stripe_subscription_id: str, plan_id: str, s
|
||||
f"plan={plan.name}, credits={plan.included_credits}"
|
||||
)
|
||||
|
||||
# Send subscription activated email
|
||||
try:
|
||||
BillingEmailService.send_subscription_activated_email(account, subscription)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send subscription activated email: {e}")
|
||||
|
||||
|
||||
def _add_purchased_credits(account, credit_package_id: str, credit_amount: str, session: dict):
|
||||
"""
|
||||
@@ -736,7 +743,7 @@ def _handle_payment_failed(invoice: dict):
|
||||
"""
|
||||
Handle failed payment.
|
||||
|
||||
Updates subscription status to past_due.
|
||||
Updates subscription status to past_due and sends notification email.
|
||||
"""
|
||||
subscription_id = invoice.get('subscription')
|
||||
if not subscription_id:
|
||||
@@ -749,7 +756,17 @@ def _handle_payment_failed(invoice: dict):
|
||||
|
||||
logger.info(f"Subscription {subscription_id} marked as past_due due to payment failure")
|
||||
|
||||
# TODO: Send payment failure notification email
|
||||
# Send payment failure notification email
|
||||
try:
|
||||
from igny8_core.business.billing.services.email_service import BillingEmailService
|
||||
failure_reason = invoice.get('last_finalization_error', {}).get('message', 'Payment could not be processed')
|
||||
BillingEmailService.send_payment_failed_notification(
|
||||
account=subscription.account,
|
||||
subscription=subscription,
|
||||
failure_reason=failure_reason
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send payment failed email: {e}")
|
||||
|
||||
except Subscription.DoesNotExist:
|
||||
logger.warning(f"Subscription not found for payment failure: {subscription_id}")
|
||||
|
||||
Reference in New Issue
Block a user