From d71977ba27d875c33e0a2b7ef306b81e5b011d0d Mon Sep 17 00:00:00 2001
From: Ben Sturmfels
Date: Wed, 18 Sep 2024 15:34:59 +1000
Subject: [PATCH] Add prototype monthly recurring payment via Stripe
---
conservancy/supporters/forms.py | 4 ++
...stainerorder_monthly_recurring_and_more.py | 71 +++++++++++++++++++
conservancy/supporters/models.py | 2 +-
.../supporters/sustainers_stripe.html | 5 +-
.../supporters/sustainers_stripe2.html | 20 +++++-
conservancy/supporters/views.py | 17 +++--
6 files changed, 110 insertions(+), 9 deletions(-)
create mode 100644 conservancy/supporters/migrations/0002_sustainerorder_monthly_recurring_and_more.py
diff --git a/conservancy/supporters/forms.py b/conservancy/supporters/forms.py
index f5dd93ef..8e92368c 100644
--- a/conservancy/supporters/forms.py
+++ b/conservancy/supporters/forms.py
@@ -3,6 +3,8 @@ from django import forms
from .models import SustainerOrder
class SustainerForm(forms.ModelForm):
+ amount_monthly = forms.IntegerField(initial=12, required=False)
+
class Meta:
model = SustainerOrder
fields = [
@@ -22,4 +24,6 @@ class SustainerForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['amount'].widget.attrs['style'] = 'width: 5rem'
+ self.fields['amount'].initial = 128
+ self.fields['amount_monthly'].widget.attrs['style'] = 'width: 5rem'
self.fields['tshirt_size'].widget.attrs['x-model'] = 'tshirt_size'
diff --git a/conservancy/supporters/migrations/0002_sustainerorder_monthly_recurring_and_more.py b/conservancy/supporters/migrations/0002_sustainerorder_monthly_recurring_and_more.py
new file mode 100644
index 00000000..b13196a2
--- /dev/null
+++ b/conservancy/supporters/migrations/0002_sustainerorder_monthly_recurring_and_more.py
@@ -0,0 +1,71 @@
+# Generated by Django 4.2.16 on 2024-09-18 01:27
+
+import django.core.validators
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('supporters', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='sustainerorder',
+ name='monthly_recurring',
+ field=models.BooleanField(default=False),
+ ),
+ migrations.AlterField(
+ model_name='sustainerorder',
+ name='amount',
+ field=models.IntegerField(
+ validators=[django.core.validators.MinValueValidator(100)]
+ ),
+ ),
+ migrations.AlterField(
+ model_name='sustainerorder',
+ name='paid_time',
+ field=models.DateTimeField(blank=True, null=True),
+ ),
+ migrations.AlterField(
+ model_name='sustainerorder',
+ name='tshirt_size',
+ field=models.CharField(
+ choices=[
+ ('', (('None', 'None'),)),
+ (
+ "Men's",
+ (
+ ("Men's S", "Men's S"),
+ ("Men's M", "Men's M"),
+ ("Men's L", "Men's L"),
+ ("Men's XL", "Men's XL"),
+ ("Men's 2XL", "Men's 2XL"),
+ ),
+ ),
+ (
+ "Standard women's",
+ (
+ ("Standard women's S", "Standard women's S"),
+ ("Standard women's M", "Standard women's M"),
+ ("Standard women's L", "Standard women's L"),
+ ("Standard women's XL", "Standard women's XL"),
+ ("Standard women's 2XL", "Standard women's 2XL"),
+ ),
+ ),
+ (
+ "Fitted women's",
+ (
+ ("Fitted women's S", "Fitted women's S"),
+ ("Fitted women's M", "Fitted women's M"),
+ ("Fitted women's L", "Fitted women's L"),
+ ("Fitted women's XL", "Fitted women's XL"),
+ ("Fitted women's 2XL", "Fitted women's 2XL"),
+ ),
+ ),
+ ],
+ max_length=50,
+ ),
+ ),
+ ]
diff --git a/conservancy/supporters/models.py b/conservancy/supporters/models.py
index 1aa9c54d..5d306313 100644
--- a/conservancy/supporters/models.py
+++ b/conservancy/supporters/models.py
@@ -60,10 +60,10 @@ class SustainerOrder(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField()
amount = models.IntegerField(
- default=128,
validators=[
validators.MinValueValidator(100),
])
+ monthly_recurring = models.BooleanField(default=False)
paid_time = models.DateTimeField(null=True, blank=True)
acknowledge_publicly = models.BooleanField(default=False)
add_to_mailing_list = models.BooleanField(default=False)
diff --git a/conservancy/supporters/templates/supporters/sustainers_stripe.html b/conservancy/supporters/templates/supporters/sustainers_stripe.html
index 8715e1ce..37456eb4 100644
--- a/conservancy/supporters/templates/supporters/sustainers_stripe.html
+++ b/conservancy/supporters/templates/supporters/sustainers_stripe.html
@@ -27,6 +27,9 @@
progress::-webkit-progress-value {
background: #224c57;
}
+ .btn:active {
+ transform: scale(1.05);
+ }
{% endblock %}
@@ -275,7 +278,7 @@ reach for reproducibility.
diff --git a/conservancy/supporters/templates/supporters/sustainers_stripe2.html b/conservancy/supporters/templates/supporters/sustainers_stripe2.html
index 6a2dd06b..e741a25b 100644
--- a/conservancy/supporters/templates/supporters/sustainers_stripe2.html
+++ b/conservancy/supporters/templates/supporters/sustainers_stripe2.html
@@ -6,6 +6,11 @@
{% block head %}
{{ block.super }}
+
{% endblock %}
{% block content %}
@@ -17,8 +22,10 @@
x-data="{
tshirt_size: 'None',
tshirt_required: function () { return this.tshirt_size !== 'None' },
+ recurring: 'once',
}">
{% csrf_token %}
+ {{ form.errors }}
@@ -27,9 +34,16 @@
To send your receipt
-