aboutsummaryrefslogtreecommitdiffstats
path: root/alphabetlearning/payments
diff options
context:
space:
mode:
Diffstat (limited to 'alphabetlearning/payments')
-rw-r--r--alphabetlearning/payments/admin.py5
-rw-r--r--alphabetlearning/payments/migrations/0009_emailsignup_alter_price_resource.py28
-rw-r--r--alphabetlearning/payments/models.py7
-rw-r--r--alphabetlearning/payments/urls.py4
-rw-r--r--alphabetlearning/payments/views.py54
5 files changed, 85 insertions, 13 deletions
diff --git a/alphabetlearning/payments/admin.py b/alphabetlearning/payments/admin.py
index 685af63..e9b70db 100644
--- a/alphabetlearning/payments/admin.py
+++ b/alphabetlearning/payments/admin.py
@@ -6,6 +6,7 @@ from .models import Product
from .models import ShoppingCart
from .models import Subscription
from .models import SubscriptionPlan
+from .models import EmailSignup
from alphabetlearning.resources.models import Resource
@@ -16,6 +17,9 @@ from alphabetlearning.resources.models import Resource
# inlines = [PriceInlineAdmin]
+class SuccessEmailSignupAdmin(admin.ModelAdmin):
+ list_display = ("email", "date_added")
+
class SubscriptionPlanAdmin(admin.ModelAdmin):
list_display = ("name", "price", "description", "allowed_downloads")
@@ -42,3 +46,4 @@ admin.site.register(Price)
admin.site.register(ShoppingCart, ShoppingCartAdmin)
admin.site.register(CartItem)
admin.site.register(Subscription, SubscriptionAdmin)
+admin.site.register(EmailSignup, SuccessEmailSignupAdmin) \ No newline at end of file
diff --git a/alphabetlearning/payments/migrations/0009_emailsignup_alter_price_resource.py b/alphabetlearning/payments/migrations/0009_emailsignup_alter_price_resource.py
new file mode 100644
index 0000000..4be05a2
--- /dev/null
+++ b/alphabetlearning/payments/migrations/0009_emailsignup_alter_price_resource.py
@@ -0,0 +1,28 @@
+# Generated by Django 5.0.4 on 2024-11-25 11:32
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('payments', '0008_remove_price_product_price_resource'),
+ ('resources', '0020_remove_resource_price_resource_stripe_product_id'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='EmailSignup',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('email', models.EmailField(max_length=254, unique=True)),
+ ('date_added', models.DateTimeField(auto_now_add=True)),
+ ],
+ ),
+ migrations.AlterField(
+ model_name='price',
+ name='resource',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='price_obj', to='resources.resource'),
+ ),
+ ]
diff --git a/alphabetlearning/payments/models.py b/alphabetlearning/payments/models.py
index 7bf4164..7a8c7bb 100644
--- a/alphabetlearning/payments/models.py
+++ b/alphabetlearning/payments/models.py
@@ -5,6 +5,13 @@ from django.db import models
from alphabetlearning.resources.models import Resource
+class EmailSignup(models.Model):
+ email = models.EmailField(unique=True)
+ date_added = models.DateTimeField(auto_now_add=True)
+
+ def __str__(self):
+ return self.email
+
class Product(models.Model):
name = models.CharField(max_length=255)
stripe_product_id = models.CharField(max_length=100)
diff --git a/alphabetlearning/payments/urls.py b/alphabetlearning/payments/urls.py
index 9bedaf7..12f445d 100644
--- a/alphabetlearning/payments/urls.py
+++ b/alphabetlearning/payments/urls.py
@@ -3,6 +3,7 @@ from django.urls import path
from . import views
from .views import CancelView
from .views import SuccessView
+from .views import privacy_policy # Import the new view
app_name = "payments"
@@ -20,4 +21,7 @@ urlpatterns = [
path("landing/", views.ProductLandingPageView.as_view(), name="landing"),
path("delete-cart-item/<int:pk>", views. DeleteCartItem.as_view(), name="delete_cart_item"),
path("webhooks/stripe/", views.stripe_webhook, name="stripe-webhook"),
+ path("email_signup/", views.email_signup, name="email_signup"),
+ path("success_email_signup/", views.SuccessEmailSignupView.as_view(), name="success_email_signup"),
+ path('privacy-policy/', privacy_policy, name='privacy_policy'), # Add this line
]
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')
+