Add annual renew
This commit is contained in:
		
							parent
							
								
									ce4ae22fa5
								
							
						
					
					
						commit
						3fe83d1466
					
				
					 4 changed files with 57 additions and 15 deletions
				
			
		|  | @ -0,0 +1,33 @@ | |||
| # Generated by Django 4.2.11 on 2024-09-30 03:33 | ||||
| 
 | ||||
| from django.db import migrations, models | ||||
| 
 | ||||
| 
 | ||||
| class Migration(migrations.Migration): | ||||
| 
 | ||||
|     dependencies = [ | ||||
|         ('supporters', '0002_sustainerorder_monthly_recurring_and_more'), | ||||
|     ] | ||||
| 
 | ||||
|     operations = [ | ||||
|         migrations.RemoveField( | ||||
|             model_name='sustainerorder', | ||||
|             name='monthly_recurring', | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name='sustainerorder', | ||||
|             name='recurring', | ||||
|             field=models.CharField(default='', max_length=10), | ||||
|             preserve_default=False, | ||||
|         ), | ||||
|         migrations.AlterField( | ||||
|             model_name='sustainerorder', | ||||
|             name='acknowledge_publicly', | ||||
|             field=models.BooleanField(default=True), | ||||
|         ), | ||||
|         migrations.AlterField( | ||||
|             model_name='sustainerorder', | ||||
|             name='add_to_mailing_list', | ||||
|             field=models.BooleanField(default=True), | ||||
|         ), | ||||
|     ] | ||||
|  | @ -19,6 +19,11 @@ class Supporter(models.Model): | |||
| 
 | ||||
| 
 | ||||
| class SustainerOrder(models.Model): | ||||
|     RENEW_CHOICES = [ | ||||
|         ('', 'None'), | ||||
|         ('month', 'Monthly'), | ||||
|         ('year', 'Annual'), | ||||
|     ] | ||||
|     TSHIRT_CHOICES = [ | ||||
|         ( | ||||
|             '', | ||||
|  | @ -63,10 +68,10 @@ class SustainerOrder(models.Model): | |||
|         validators=[ | ||||
|             validators.MinValueValidator(100), | ||||
|         ]) | ||||
|     monthly_recurring = models.BooleanField(default=False) | ||||
|     recurring = models.CharField(max_length=10) | ||||
|     paid_time = models.DateTimeField(null=True, blank=True) | ||||
|     acknowledge_publicly = models.BooleanField(default=False) | ||||
|     add_to_mailing_list = models.BooleanField(default=False) | ||||
|     acknowledge_publicly = models.BooleanField(default=True) | ||||
|     add_to_mailing_list = models.BooleanField(default=True) | ||||
|     tshirt_size = models.CharField(max_length=50, choices=TSHIRT_CHOICES) | ||||
|     street = models.CharField(max_length=255, blank=True) | ||||
|     city = models.CharField(max_length=255, blank=True) | ||||
|  |  | |||
|  | @ -35,17 +35,21 @@ | |||
|       <p class="f7 black-60 mt1">To send your receipt</p> | ||||
|       </div> | ||||
|       <div class="mb2"><label> | ||||
|         <label class="mr1"><input type="radio" name="recurring" value="once" x-model="recurring"> Once</label> | ||||
|         <label><input type="radio" name="recurring" value="monthly" x-model="recurring"> Monthly</label> | ||||
|         <label class="mr1"><input type="radio" name="recurring" value="" x-model="recurring"> Once</label> | ||||
|         <label class="mr1"><input type="radio" name="recurring" value="month" x-model="recurring"> Monthly</label> | ||||
|         <label><input type="radio" name="recurring" value="year" x-model="recurring"> Annual</label> | ||||
|       </label></div> | ||||
|       <div class="mb2" x-show="recurring === 'once'"><label>Amount | ||||
|       <div class="mb2" x-show="recurring === ''"><label>Amount | ||||
|         <span class="db mt1">$ {{ form.amount }}</span> | ||||
|       </label></div> | ||||
|       <div class="mb2" x-show="recurring === 'monthly'"><label>Amount | ||||
|       <div class="mb2" x-show="recurring === 'month'"><label>Amount | ||||
|           <span class="db mt1">$ {{ form.amount_monthly }}</span> | ||||
|       </label></div> | ||||
|       <div class="mv3"><label class="lh-title"><input type="checkbox"> Acknowledge me on the public <a href="">list of sustainers</a></label></div> | ||||
|       <div class="mv3"><label class="lh-title"><input type="checkbox"> Add me to the low-traffic <a href="https://lists.sfconservancy.org/pipermail/announce/">announcements</a> email list</label></div> | ||||
|       <div class="mb2" x-show="recurring === 'year'"><label>Amount | ||||
|           <span class="db mt1">$ {{ form.amount }}</span> | ||||
|       </label></div> | ||||
|       <div class="mv3"><label class="lh-title">{{ form.acknowledge_publicly }} Acknowledge me on the public <a href="">list of sustainers</a></label></div> | ||||
|       <div class="mv3"><label class="lh-title">{{ form.add_to_mailing_list }} Add me to the low-traffic <a href="https://lists.sfconservancy.org/pipermail/announce/">announcements</a> email list</label></div> | ||||
|       <div class="mv3"> | ||||
|         <label>T-shirt: | ||||
|           <!-- Form field has an x-model attribute in forms.py. --> | ||||
|  |  | |||
|  | @ -45,7 +45,7 @@ def sponsors(request): | |||
|     return render(request, "supporters/sponsors.html", c) | ||||
| 
 | ||||
| 
 | ||||
| def create_checkout_session(reference_id, email: str, amount: int, recurring: bool, base_url: str): | ||||
| def create_checkout_session(reference_id, email: str, amount: int, recurring: str, base_url: str): | ||||
|     # https://docs.stripe.com/payments/accept-a-payment | ||||
|     YOUR_DOMAIN = base_url | ||||
|     try: | ||||
|  | @ -58,7 +58,7 @@ def create_checkout_session(reference_id, email: str, amount: int, recurring: bo | |||
|                         'product_data': {'name': 'Contribution'}, | ||||
|                         'unit_amount': amount * 100,  # in cents | ||||
|                         # https://docs.stripe.com/products-prices/pricing-models#variable-pricing | ||||
|                         'recurring': {'interval': 'month'} if recurring else None, | ||||
|                         'recurring': {'interval': recurring} if recurring else None, | ||||
|                     }, | ||||
|                     'quantity': 1, | ||||
|                 }, | ||||
|  | @ -82,12 +82,12 @@ def sustainers_stripe2(request): | |||
|         form = forms.SustainerForm(request.POST) | ||||
|         if form.is_valid(): | ||||
|             order = form.save(commit=False) | ||||
|             if form.data['recurring'] == 'monthly': | ||||
|             order.recurring = form.data['recurring'] | ||||
|             if order.recurring == 'month': | ||||
|                 order.amount = form.cleaned_data['amount_monthly'] | ||||
|                 order.monthly_recurring = True | ||||
|             order.save() | ||||
|             base_url = f'{request.scheme}://{request.get_host()}' | ||||
|             stripe_checkout_url = create_checkout_session(order.id, order.email, order.amount, order.monthly_recurring, base_url) | ||||
|             stripe_checkout_url = create_checkout_session(order.id, order.email, order.amount, order.recurring, base_url) | ||||
|             return redirect(stripe_checkout_url) | ||||
|     else: | ||||
|         form = forms.SustainerForm() | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue