From ae9bc97c743ea4d31a3f392db72a948d87d3b2ab Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sat, 19 Oct 2024 14:41:08 +0100 Subject: Test email in the console --- alphabetlearning/payments/views.py | 15 +++++++++++++-- config/settings/production.py | 5 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py index dfbf8f1..73a14c2 100644 --- a/alphabetlearning/payments/views.py +++ b/alphabetlearning/payments/views.py @@ -1,5 +1,6 @@ import stripe from django.http import HttpResponse +from django.core.mail import send_mail from django.conf import settings from django.contrib.auth.decorators import login_required from django.shortcuts import get_object_or_404 @@ -20,7 +21,10 @@ from .models import ShoppingCart # TODO get the cart integrated with Stripe # Steps to convert our Cart into something that can be used with Stripe: # -# - Sort out the webhook +# - X Sort out the webhook +# - Associate the purchases with the users profile page +# - We need a profile page! +# - Fix the email and make it nice # - Associate each of our resources with a Product item # - this should be done in the create resource page # - or we can do it manually for the time being @@ -132,6 +136,13 @@ def stripe_webhook(request): payment_intent = session["payment_intent"] # TODO send an email to the customer - print("Here we send an email to the customer") + send_mail( + "Thank you for your purchase", + "You have bought something nice - enjoy it", + settings.DEFAULT_FROM_EMAIL, + [customer_email], + fail_silently=False, + ) + return HttpResponse(status=200) diff --git a/config/settings/production.py b/config/settings/production.py index 4fab057..f8e48ac 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -105,14 +105,14 @@ STORAGES = { # https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email DEFAULT_FROM_EMAIL = env( "DJANGO_DEFAULT_FROM_EMAIL", - default="pyblackbird-cc ", + default="alphabetlearning.online ", ) # https://docs.djangoproject.com/en/dev/ref/settings/#server-email SERVER_EMAIL = env("DJANGO_SERVER_EMAIL", default=DEFAULT_FROM_EMAIL) # https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix EMAIL_SUBJECT_PREFIX = env( "DJANGO_EMAIL_SUBJECT_PREFIX", - default="[pyblackbird-cc] ", + default="Alphabet Learning Online -", ) # ADMIN @@ -134,6 +134,7 @@ ADMIN_URL = env("DJANGO_ADMIN_URL") # "MAILGUN_API_URL": env("MAILGUN_API_URL", default="https://api.mailgun.net/v3"), # } +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" # LOGGING # ------------------------------------------------------------------------------ -- cgit v1.2.3