aboutsummaryrefslogtreecommitdiffstats
path: root/alphabetlearning/payments/views.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-11-26 17:03:16 +0000
committerMatthew Lemon <y@yulqen.org>2024-11-26 17:03:16 +0000
commit04e490c0b0b65a21c531ac50a5ba321c79e14fa2 (patch)
tree428df0f34826b8aff22d9b37708ef286d3115015 /alphabetlearning/payments/views.py
parent78fd102b49f339af5432c2f0bebfab7ff9ac39bd (diff)
Got the basic form anbd privacy policy in place
Diffstat (limited to 'alphabetlearning/payments/views.py')
-rw-r--r--alphabetlearning/payments/views.py54
1 files changed, 41 insertions, 13 deletions
diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py
index 92751c9..e9f2ded 100644
--- a/alphabetlearning/payments/views.py
+++ b/alphabetlearning/payments/views.py
@@ -1,23 +1,20 @@
-import stripe
-from django.http import HttpResponse, HttpResponseBadRequest
-from django.core.mail import send_mail
-from django.urls import reverse_lazy
from django.conf import settings
from django.contrib.auth.decorators import login_required
-from django.shortcuts import get_object_or_404
-from django.shortcuts import redirect
-from django.shortcuts import render
+from django.core.mail import send_mail
+from django.http import HttpResponse, HttpResponseBadRequest
+from django.shortcuts import get_object_or_404, render, redirect
+from django.urls import reverse, reverse_lazy
from django.views import View
-from django.views.generic import TemplateView, DeleteView
from django.views.decorators.csrf import csrf_exempt
+from django.views.generic import TemplateView, DeleteView
+from alphabetlearning.payments.models import EmailSignup
from alphabetlearning.resources.models import Resource
from alphabetlearning.users.models import User
-from .models import CartItem
-from .models import Price
-from .models import Product
-from .models import ShoppingCart
+from .models import CartItem, Price, Product, ShoppingCart
+
+import stripe
# TODO get the cart integrated with Stripe
# Steps to convert our Cart into something that can be used with Stripe:
@@ -40,6 +37,34 @@ from .models import ShoppingCart
stripe.api_key = settings.STRIPE_SECRET_KEY
+class SuccessEmailSignupView(TemplateView):
+ template_name = "payments/success_email_signup.html"
+
+def email_signup(request):
+ if request.method == 'POST':
+ email = request.POST.get('email')
+ if email:
+ EmailSignup.objects.get_or_create(email=email)
+ # Send email to user
+ send_mail(
+ "Thank you for signing up",
+ "You have successfully signed up for our newsletter.",
+ settings.DEFAULT_FROM_EMAIL,
+ [email],
+ fail_silently=False,
+ )
+ # Send email to admin
+ admin_email = "admin@example.com" # Replace with actual admin email
+ send_mail(
+ "New Email Signup",
+ f"A new user has signed up with the email: {email}",
+ settings.DEFAULT_FROM_EMAIL,
+ [admin_email],
+ fail_silently=False,
+ )
+ return redirect(reverse('payments:success_email_signup')) # Redirect to a success page or similar
+ return render(request, 'pages/home.html') # Adjust as necessary
+
def create_line_items(resources):
price_objs = [r.price_obj.first() for r in resources]
stripe_price_ids = [p.stripe_price_id for p in price_objs]
@@ -89,7 +114,7 @@ def add_to_cart(request, resource_id):
resource = get_object_or_404(Resource, id=resource_id)
if not resource.price_obj.first():
return HttpResponseBadRequest(
- f"There is no price assigned to this resource. Please contact Alphabet Learning Support."
+ "There is no price assigned to this resource. Please contact Alphabet Learning Support."
)
cart, created = ShoppingCart.objects.get_or_create(user=request.user)
cart_item, created = CartItem.objects.get_or_create(cart=cart, resource=resource)
@@ -183,5 +208,8 @@ class DeleteCartItem(DeleteView):
request.user.shoppingcart.delete()
return redirect("resources:resource_list")
+def privacy_policy(request):
+ return render(request, 'pages/privacy_policy.html')
+