Private
Public Access
1
0

simple upgrade/billing address form

This commit is contained in:
Sander Roosendaal
2018-12-19 10:33:43 +01:00
parent 0b79b0de98
commit fa61957be7
8 changed files with 126 additions and 7 deletions

View File

@@ -2,7 +2,8 @@ from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple from django.contrib.admin.widgets import FilteredSelectMultiple
from rowers.models import ( from rowers.models import (
Workout,Rower,Team,PlannedSession,GeoCourse, Workout,Rower,Team,PlannedSession,GeoCourse,
VirtualRace,VirtualRaceResult,IndoorVirtualRaceResult VirtualRace,VirtualRaceResult,IndoorVirtualRaceResult,
PaidPlan
) )
from rowers.rows import validate_file_extension,must_be_csv,validate_image_extension,validate_kml from rowers.rows import validate_file_extension,must_be_csv,validate_image_extension,validate_kml
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.forms import UserCreationForm
@@ -712,6 +713,18 @@ class StatsOptionsForm(forms.Form):
for type in mytypes.checktypes: for type in mytypes.checktypes:
self.fields[type] = forms.BooleanField(initial=True,required=False) self.fields[type] = forms.BooleanField(initial=True,required=False)
class PlanSelectForm(forms.Form):
plan = forms.ModelChoiceField(queryset=PaidPlan.objects.all(),
widget=forms.RadioSelect,required=True)
def __init__(self, *args, **kwargs):
paymentprocessor = kwargs.pop('paymentprocessor',None)
super(PlanSelectForm, self).__init__(*args, **kwargs)
self.fields['plan'].empty_label = None
if paymentprocessor:
self.fields['plan'].queryset = PaidPlan.objects.filter(
paymentprocessor=paymentprocessor
).exclude(shortname="basic").order_by("price","clubsize","shortname")
class CourseSelectForm(forms.Form): class CourseSelectForm(forms.Form):
course = forms.ModelChoiceField(queryset=GeoCourse.objects.all()) course = forms.ModelChoiceField(queryset=GeoCourse.objects.all())

View File

@@ -571,7 +571,7 @@ class PaidPlan(models.Model):
clubsize = models.IntegerField(default=0) clubsize = models.IntegerField(default=0)
def __unicode__(self): def __unicode__(self):
return '{name} - {shortname} at {price} EURO ({paymenttype} payment) / {paymentprocessor}'.format( return '{name} - {shortname} at {price} EURO ({paymenttype} payment)'.format(
name = self.name, name = self.name,
shortname = self.shortname, shortname = self.shortname,
price = self.price, price = self.price,
@@ -3002,6 +3002,20 @@ class RowerImportExportForm(ModelForm):
'trainingpeaks_auto_export', 'trainingpeaks_auto_export',
] ]
# Form to collect rower's Billing Info
class RowerBillingAddressForm(ModelForm):
class Meta:
model = Rower
fields = [
'street_address',
'city',
'postal_code',
'country'
]
def __init__(self, *args, **kwargs):
super(RowerBillingAddressForm, self).__init__(*args, **kwargs)
self.fields['country'].required = True
# Form to set rower's Email and Weight category # Form to set rower's Email and Weight category

View File

@@ -27,4 +27,9 @@ def setrowerplans():
else: else:
print 'Could not set plan for ',r print 'Could not set plan for ',r
def is_existing_customer(rower):
if rower.country is not None and rower.customer_id is not None and r.country != '':
return True
return False

View File

@@ -0,0 +1,36 @@
{% extends "newbase.html" %}
{% block title %}Rowsandall Paid Membership{% endblock title %}
{% load rowerfilters %}
{% block main %}
<h1>Upgrade</h1>
<form action="" method="post">
<ul class="main-content">
<li class="grid_4">
<h2>Fill in Billing Details</h2>
<p>For tax reasons, we need your country of residence</p>
<table>
{{ billingaddressform.as_table }}
</table>
</li>
<li class="grid_4">
<h2>Choose your Plan</h2>
<table width="100%">
{{ planselectform.as_table }}
</table>
</li>
<li class="grid_4">
{% csrf_token %}
<input type="submit" value="Proceed">
You will be able to review your order before purchase.
</li>
</ul>
</form>
{% endblock %}
{% block sidebar %}
{% include 'menu_help.html' %}
{% endblock %}

View File

@@ -211,14 +211,22 @@
{% elif rower and rower.rowerplan == 'basic' %} {% elif rower and rower.rowerplan == 'basic' %}
<td colspan="3"> <td colspan="3">
<button style="width:100%"> <button style="width:100%">
{% if user|existing_customer %}
<a href="/rowers/upgrade">UPGRADE NOW</a> <a href="/rowers/upgrade">UPGRADE NOW</a>
{% else %}
<a href="/rowers/billing">BUY NOW</a>
{% endif %}
</button> </button>
</td> </td>
{% elif rower and rower.rowerplan == 'pro' %} {% elif rower and rower.rowerplan == 'pro' %}
<td>&nbsp;</td> <td>&nbsp;</td>
<td colspan="2"> <td colspan="2">
<button style="width:100%"> <button style="width:100%">
{% if user|existing_customer %}
<a href="/rowers/upgrade">UPGRADE NOW</a> <a href="/rowers/upgrade">UPGRADE NOW</a>
{% else %}
<a href="/rowers/billing">BUY NOW</a>
{% endif %}
</button> </button>
</td> </td>
{% elif rower and rower.rowerplan == 'plan' %} {% elif rower and rower.rowerplan == 'plan' %}
@@ -226,7 +234,11 @@
<td>&nbsp;</td> <td>&nbsp;</td>
<td> <td>
<button style="width:100%"> <button style="width:100%">
{% if user|existing_customer %}
<a href="/rowers/upgrade">UPGRADE NOW</a> <a href="/rowers/upgrade">UPGRADE NOW</a>
{% else %}
<a href="/rowers/billing">BUY NOW</a>
{% endif %}
</button> </button>
</td> </td>
{% else %} {% else %}

View File

@@ -24,6 +24,8 @@ from rowers.models import checkaccessuser
from rowers.mytypes import otwtypes from rowers.mytypes import otwtypes
from rowers.utils import NoTokenError from rowers.utils import NoTokenError
import rowers.payments as payments
def strfdelta(tdelta): def strfdelta(tdelta):
minutes,seconds = divmod(tdelta.seconds,60) minutes,seconds = divmod(tdelta.seconds,60)
tenths = int(tdelta.microseconds/1e5) tenths = int(tdelta.microseconds/1e5)
@@ -59,6 +61,13 @@ def secondstotimestring(tdelta):
return res return res
@register.filter
def existing_customer(user):
if user.is_anonymous():
return False
else:
return payments.is_existing_customer(user.rower)
@register.filter @register.filter
def aantalcomments(workout): def aantalcomments(workout):
try: try:

View File

@@ -438,6 +438,7 @@ urlpatterns = [
url(r'^analysis/$', views.analysis_view,name='analysis'), url(r'^analysis/$', views.analysis_view,name='analysis'),
url(r'^laboratory/$', views.laboratory_view,name='laboratory'), url(r'^laboratory/$', views.laboratory_view,name='laboratory'),
url(r'^promembership', TemplateView.as_view(template_name='promembership.html'),name='promembership'), url(r'^promembership', TemplateView.as_view(template_name='promembership.html'),name='promembership'),
url(r'^billing',views.billing_view,name='billing'),
url(r'^paidplans',views.paidplans_view,name='paidplans'), url(r'^paidplans',views.paidplans_view,name='paidplans'),
url(r'^checkouts',views.checkouts_view,name='checkouts'), url(r'^checkouts',views.checkouts_view,name='checkouts'),
url(r'^payments',views.payments_view,name='payments'), url(r'^payments',views.payments_view,name='payments'),

View File

@@ -28,7 +28,7 @@ import isodate
import re import re
import cgi import cgi
from icalendar import Calendar, Event from icalendar import Calendar, Event
import braintree import rowers.braintreestuff as braintreestuff
from django.shortcuts import render from django.shortcuts import render
from django.template.loader import render_to_string from django.template.loader import render_to_string
@@ -51,7 +51,7 @@ from rowers.forms import (
RaceResultFilterForm,PowerIntervalUpdateForm,FlexAxesForm, RaceResultFilterForm,PowerIntervalUpdateForm,FlexAxesForm,
FlexOptionsForm,DataFrameColumnsForm,OteWorkoutTypeForm, FlexOptionsForm,DataFrameColumnsForm,OteWorkoutTypeForm,
MetricsForm,DisqualificationForm,disqualificationreasons, MetricsForm,DisqualificationForm,disqualificationreasons,
disqualifiers,SearchForm,BillingForm disqualifiers,SearchForm,BillingForm,PlanSelectForm
) )
from django.core.urlresolvers import reverse, reverse_lazy from django.core.urlresolvers import reverse, reverse_lazy
@@ -84,7 +84,7 @@ from rowers.models import (
createmicrofillers, createmesofillers, createmicrofillers, createmesofillers,
microcyclecheckdates,mesocyclecheckdates,macrocyclecheckdates, microcyclecheckdates,mesocyclecheckdates,macrocyclecheckdates,
TrainingMesoCycleForm, TrainingMicroCycleForm, TrainingMesoCycleForm, TrainingMicroCycleForm,
RaceLogo, RaceLogo,RowerBillingAddressForm,
) )
from rowers.models import ( from rowers.models import (
RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm, RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm,
@@ -1036,10 +1036,39 @@ def paidplans_view(request):
r = None r = None
return render(request, return render(request,
'paidplans.html', 'paidplans.html',
{'rower':r}) {'rower':r})
@login_required()
def billing_view(request):
r = getrequestrower(request)
if request.method == 'POST':
billingaddressform = RowerBillingAddressForm(request.POST)
planselectform = PlanSelectForm(request.POST,paymentprocessor='braintree')
if billingaddressform.is_valid():
cd = billingaddressform.cleaned_data
for attr, value in cd.items():
setattr(r, attr, value)
r.save()
if planselectform.is_valid():
plan = planselectform.cleaned_data['plan']
else:
billingaddressform = RowerBillingAddressForm(instance=r)
planselectform = PlanSelectForm(paymentprocessor='braintree')
return render(request,
'billing.html',
{'rower':r,
'billingaddressform':billingaddressform,
'planselectform':planselectform,
})
# Experimental - Payments # Experimental - Payments
@login_required() @login_required()
def payments_view(request): def payments_view(request):