Private
Public Access
1
0

Merge branch 'feature/betterpayments' into develop

This commit is contained in:
Sander Roosendaal
2018-12-31 17:23:36 +01:00
16 changed files with 98 additions and 47 deletions

View File

@@ -115,6 +115,7 @@ def update_subscription(rower,data,method='up'):
amount = data['amount']
amount = '{amount:.2f}'.format(amount=amount)
gatewaydata = {
"price": amount,
"plan_id": plan.external_id,
@@ -124,16 +125,19 @@ def update_subscription(rower,data,method='up'):
},
}
if plan.paymenttype == 'single':
gatewaydata['number_of_billing_cycles'] = 1
else:
gatewaydata['never_expires'] = True
result = gateway.subscription.update(
rower.subscription_id,
gatewaydata
)
try:
result = gateway.subscription.update(
rower.subscription_id,
gatewaydata
)
except:
return False
if result.is_success:
rower.paidplan = plan
@@ -164,13 +168,13 @@ def update_subscription(rower,data,method='up'):
handle_send_email_subscription_update,
name, rower.user.email,
plan.name,
plan.paymenttype == 'recurring',
plan.paymenttype,
plan.price,
amount,
result.subscription.billing_period_end_date.strftime('%Y-%m-%d'),
method)
return True
return True,amount
else:
errors = result.errors.for_object("subscription")
codes = [str(e.code) for e in errors]
@@ -183,9 +187,9 @@ def update_subscription(rower,data,method='up'):
if create_new:
return create_subscription(rower,data)
return False
return False,0
return False
return False,0
def create_subscription(rower,data):
@@ -203,7 +207,7 @@ def create_subscription(rower,data):
if result.is_success:
payment_method_token = result.payment_method.token
else:
return False
return False,0
result = gateway.subscription.create({
"payment_method_token": payment_method_token,
@@ -225,7 +229,7 @@ def create_subscription(rower,data):
)
recurring = plan.paymenttype == 'recurring',
recurring = plan.paymenttype
job = myqueue(
queuehigh,
@@ -237,12 +241,12 @@ def create_subscription(rower,data):
plan.price,
result.subscription.billing_period_end_date.strftime('%Y-%m-%d')
)
return True
return True,plan.price
else:
return False
return False,0
return False
return False,0
def cancel_subscription(rower,id):
themessages = []
@@ -268,6 +272,7 @@ def cancel_subscription(rower,id):
rower.planexpires = timezone.now()
rower.clubsize = 0
rower.rowerplan = 'basic'
rower.subscription_id = None
rower.save()
themessages.append("Your plan was reset to basic")
@@ -309,7 +314,8 @@ def find_subscriptions(rower):
'plan_id': subscription.plan_id,
'price': subscription.price,
'id': subscription.id,
'plan': plan.name
'plan': plan.name,
'never_expires': subscription.never_expires
}
result.append(thedict)

View File

@@ -852,6 +852,7 @@ def handle_send_email_subscription_create(
from_email = 'Rowsandall <admin@rowsandall.com>'
d = {
'name': username,
'siteurl': siteurl,

View File

@@ -16,7 +16,13 @@
</li>
<li class="grid_4">
<h2>Choose your Plan</h2>
<table width="100%">
<p>Unless specified otherwise, the payments on the
recurring payment plans are annual. The prices are specified
as a price per year.
</p>
<table width="100%">
{{ planselectform.as_table }}
</table>
</li>

View File

@@ -7,7 +7,7 @@
<p>
Thank you for changing to {{ user.rower.paidplan.name }}. You're all settled.
membership.
You will receive an email confirming the transaction.
</p>
<p>

View File

@@ -78,7 +78,11 @@
</li>
<li class="grid_4">
<p>
Your downgrade will be effective immediately. You will not be charged.
Your downgrade will be effective immediately.
We need your payment method to process the downgrade.
If the selected
new plan has a lower price than your current plan, your payment method
will not be charged.
</p>
</li>
</ul>

View File

@@ -39,13 +39,6 @@
<td>&#10004;</td>
<td>&#10004;</td>
</tr>
<tr>
<td>Automatic Synchronization with other fitness sites</td>
<td>&nbsp;</td>
<td>&#10004;</td>
<td>&#10004;</td>
<td>&#10004;</td>
</tr>
<tr>
<td>Heart rate and power zones</td>
<td>&#10004;</td>
@@ -60,6 +53,13 @@
<td>&#10004;</td>
<td>&#10004;</td>
</tr>
<tr>
<td>Automatic Synchronization with other fitness sites</td>
<td>&nbsp;</td>
<td>&#10004;</td>
<td>&#10004;</td>
<td>&#10004;</td>
</tr>
<tr>
<td>Advanced Analysis (Critical Power, Stats, Box Chart, Trend Flex)</td>
<td>&nbsp;</td>
@@ -125,9 +125,16 @@
<td nowrap="nowrap">From 65&euro;/year</td>
<td nowrap="nowrap">From 90&euro;/year</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
{% if rower %}
<tr>
<td>Your current plan</td>
<td><h3>Your current plan</h3></td>
<td>
{% if rower.rowerplan == 'basic' %}
<h3>BASIC</h3>
@@ -137,21 +144,21 @@
</td>
<td>
{% if rower.rowerplan == 'pro' %}
PRO
<h3>PRO ({{ rower.paymenttype }})</h3>
{% else %}
&nbsp;
{% endif %}
</td>
<td>
{% if rower.rowerplan == 'plan' %}
SELF-COACH
<h3>SELF-COACH ({{ rower.paymenttype }})</h3>
{% else %}
&nbsp;
{% endif %}
</td>
<td>
{% if rower.rowerplan == 'coach' %}
COACH
<h3>COACH ({{ rower.paymenttype }})</h3>
{% else %}
&nbsp;
{% endif %}
@@ -265,9 +272,6 @@
<h2>Coach and Self-Coach Membership</h2>
<p>The Coach plan functionality listed is available to the coach only. Individual athletes
can purchase upgrades to "Pro" and "Self-Coach" plans.
</p>
<p>Rowsandall.com's Training Planning functionality
is part of the paid "Self-Coach" and "Coach" plans.</p>
@@ -279,6 +283,11 @@
athletes.
</p>
<p>The Coach plan functionality listed is available to the coach only.
Individual athletes
can purchase upgrades to "Pro" and "Self-Coach" plans.
</p>
<p>If you would like to find a coach who helps you plan your training
through rowsandall.com, contact me throught the contact form.</p>

View File

@@ -7,7 +7,8 @@
<p>
Thank you for registering to {{ user.rower.paidplan.name }}. You have paid for 12 months
membership.
membership. You were charged {{ amount }} &euro; You will receive an email
confirming the payment
</p>
<p>

View File

@@ -8,7 +8,7 @@
subscription to the Rowsandall paid plan "{{ planname }}".
</p>
{% if recurring %}
{% if recurring=='recurring' %}
<p>
Your next charge is due on {{ end_of_billing_period }}. We will charge your {{ paymentmethod }}
on that date.

View File

@@ -7,7 +7,7 @@
New plan: "{{ planname }}".
</p>
{% if recurring %}
{% if recurring=='recurring'%}
<p>
The subscription cost is &euro;{{ price }} per year.
The next charge is due on {{ end_of_billing_period }}.

View File

@@ -7,7 +7,7 @@
Thank you. You have successfully changed your plan to "{{ planname }}".
</p>
{% if recurring %}
{% if recurring=='recurring' %}
<p>
The subscription cost is &euro;{{ price }} per year.
Your next charge is due on {{ end_of_billing_period }}. We will charge you automatically

View File

@@ -7,7 +7,7 @@
New plan: "{{ planname }}".
</p>
{% if recurring %}
{% if recurring=='recurring' %}
<p>
The subscription cost is &euro;{{ price }} per year.
The next charge is due on {{ end_of_billing_period }}.

View File

@@ -9,7 +9,7 @@
You are now on the Rowsandall paid plan "{{ planname }}".
</p>
{% if recurring %}
{% if recurring=='recurring' %}
<p>
The subscription cost is &euro;{{ price }} per year.
Your next charge is due on {{ end_of_billing_period }}. We will charge you automatically

View File

@@ -7,7 +7,7 @@
New plan: "{{ planname }}".
</p>
{% if recurring %}
{% if recurring=='recurring' %}
<p>
The subscription cost is &euro;{{ price }} per year.
The next charge is due on {{ end_of_billing_period }}.

View File

@@ -12,7 +12,8 @@
<table class="plantable shortpadded" width="80%">
<thead>
<tr>
<th>Subscription</th><th>Next Billing Date</th><th>Price</th><th>&nbsp;</th>
<th>Subscription</th><th>Paid Until</th><th>Price</th>
<th>Subscription type</th><th>&nbsp;</th>
</tr>
</thead>
<tbody>
@@ -27,6 +28,13 @@
<td>
{{ subscription|lookup:"price" }} &euro;
</td>
<td>
{% if subscription|lookup:"never_expires" %}
Recurring
{% else %}
Not recurring
{% endif %}
</td>
<td>
<a href="/rowers/me/cancelsubscription/{{ subscription|lookup:'id' }}">Stop this plan</a>
</td>
@@ -37,7 +45,9 @@
<p>
<p>
By clicking on the link to stop the plan, you will downgrade to the Basic plan.
Future payments will be stopped.
Future payments will be stopped. Warning: You will not receive a refund.
If you wanted to downgrade (and receive a credit for the price
difference), click here: <a href="/rowers/downgrade">Downgrade</a>.
</p>
{% else %}
<p>
@@ -45,7 +55,7 @@
from the site.
</p>
<p>
If you have paid through PayPal, log in to your PayPal account and cancel the recurring payment
If you have paid through PayPal, log in to your PayPal account and cancel any recurring payment
there. We will manually downgrade your subscription.
</p>
<p>

View File

@@ -17,6 +17,12 @@
</li>
<li class="grid_3">
<h2>Choose your Plan</h2>
<p>Unless specified otherwise, the payments on the
recurring payment plans are annual. The prices are specified
as a price per year.
</p>
<table width="100%">
{{ planselectform.as_table }}
</table>

View File

@@ -1376,10 +1376,12 @@ def checkouts_view(request):
form = BillingForm(request.POST)
if form.is_valid():
data = form.cleaned_data
success = braintreestuff.create_subscription(r,data)
success,amount = braintreestuff.create_subscription(r,data)
if success:
messages.info(request,"Your payment has succeeded and your plan has been updated")
url = reverse(payment_completed_view)
url = "{baseurl}?amount={amount:.2f}".format(
baseurl = reverse(payment_completed_view),
amount = amount)
return HttpResponseRedirect(url)
else:
messages.error(request,"There was a problem with your payment")
@@ -1410,10 +1412,12 @@ def upgrade_checkouts_view(request):
form = BillingForm(request.POST)
if form.is_valid():
data = form.cleaned_data
success = braintreestuff.update_subscription(r,data)
success,amount = braintreestuff.update_subscription(r,data)
if success:
messages.info(request,"Your payment has succeeded and your plan has been updated")
url = reverse(payment_completed_view)
url = "{baseurl}?amount={amount:.2f}".format(
baseurl = reverse(payment_completed_view),
amount = amount)
return HttpResponseRedirect(url)
else:
messages.error(request,"There was a problem with your payment")
@@ -1468,13 +1472,17 @@ def payment_completed_view(request):
if not PAYMENT_PROCESSING_ON:
url = reverse('promembership')
return HttpResponseRedirect(url)
amount = request.GET.get('amount',0)
r = getrequestrower(request)
return render(request,
"payment_completed.html",
{
'rower':r
'rower':r,
'amount':amount,
})
@login_required()