upgrade done
This commit is contained in:
@@ -85,6 +85,49 @@ def make_payment(rower,data):
|
||||
else:
|
||||
return 0,''
|
||||
|
||||
def update_subscription(rower,data):
|
||||
planid = data['plan']
|
||||
plan = PaidPlan.objects.get(id=planid)
|
||||
nonce_from_the_client = data['payment_method_nonce']
|
||||
amount = data['amount']
|
||||
amount = '{amount:.2f}'.format(amount=amount)
|
||||
print amount,'aap'
|
||||
|
||||
gatewaydata = {
|
||||
"price": amount,
|
||||
"plan_id": plan.external_id,
|
||||
"payment_method_nonce": nonce_from_the_client,
|
||||
"options": {
|
||||
"prorate_charges":True,
|
||||
},
|
||||
}
|
||||
|
||||
if plan.paymenttype == 'single':
|
||||
gatewaydata['number_of_billing_cycles'] = 1
|
||||
else:
|
||||
gatewaydata['never_expires'] = True
|
||||
|
||||
result = gateway.subscription.update(
|
||||
rower.subscription_id,
|
||||
gatewaydata
|
||||
)
|
||||
|
||||
if result.is_success:
|
||||
rower.paidplan = plan
|
||||
rower.planexpires = result.subscription.billing_period_end_date
|
||||
rower.teamplanexpires = result.subscription.billing_period_end_date
|
||||
rower.clubsize = plan.clubsize
|
||||
rower.paymenttype = plan.paymenttype
|
||||
rower.rowerplan = plan.shortname
|
||||
rower.subscription_id = result.subscription.id
|
||||
rower.save()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def create_subscription(rower,data):
|
||||
planid = data['plan']
|
||||
plan = PaidPlan.objects.get(id=planid)
|
||||
|
||||
@@ -720,12 +720,26 @@ class PlanSelectForm(forms.Form):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
paymentprocessor = kwargs.pop('paymentprocessor',None)
|
||||
rower = kwargs.pop('rower',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")
|
||||
).exclude(
|
||||
shortname="basic"
|
||||
).order_by(
|
||||
"price","clubsize","shortname"
|
||||
)
|
||||
if rower:
|
||||
amount = rower.paidplan.price
|
||||
self.fields['plan'].queryset = PaidPlan.objects.filter(
|
||||
paymentprocessor=rower.paymentprocessor
|
||||
).exclude(
|
||||
price__lte=amount
|
||||
).order_by(
|
||||
"price","clubsize","shortname"
|
||||
)
|
||||
|
||||
class CourseSelectForm(forms.Form):
|
||||
course = forms.ModelChoiceField(queryset=GeoCourse.objects.all())
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<th>City</th><td>{{ user.rower.city }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Posstal Code</th><td>{{ user.rower.postal_code }}</td>
|
||||
<th>Postal Code</th><td>{{ user.rower.postal_code }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Country</th><td>{{ user.rower.country }}
|
||||
|
||||
49
rowers/templates/upgrade.html
Normal file
49
rowers/templates/upgrade.html
Normal file
@@ -0,0 +1,49 @@
|
||||
{% 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_3">
|
||||
<h2>Billing Details</h2>
|
||||
<p>For tax reasons, we need your country of residence. You should
|
||||
update this when it is incorrect.</p>
|
||||
<table>
|
||||
{{ billingaddressform.as_table }}
|
||||
</table>
|
||||
</li>
|
||||
<li class="grid_3">
|
||||
<h2>Choose your Plan</h2>
|
||||
<table width="100%">
|
||||
{{ planselectform.as_table }}
|
||||
</table>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
Your upgrade will be effective immediately. For the current billing
|
||||
cycle, you will be charged for a prorated amount. For example, when
|
||||
you upgrade from a 15€ plan to a 65€ plan (a difference of
|
||||
50€) in the 6th month of the 12 month billing cycle, you
|
||||
will be charged 35€.
|
||||
</p>
|
||||
<p>
|
||||
Looking for the <a href="/rowers/downgrade">downgrade</a> option?
|
||||
</p>
|
||||
</li>
|
||||
<li class="grid_3">
|
||||
{% 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_profile.html' %}
|
||||
{% endblock %}
|
||||
|
||||
122
rowers/templates/upgradeconfirm.html
Normal file
122
rowers/templates/upgradeconfirm.html
Normal file
@@ -0,0 +1,122 @@
|
||||
{% extends "newbase.html" %}
|
||||
{% block title %}Rowsandall Paid Membership{% endblock title %}
|
||||
{% load rowerfilters %}
|
||||
{% block main %}
|
||||
|
||||
<h1>Confirm Your Payment</h1>
|
||||
|
||||
<h2>Order Overview</h2>
|
||||
|
||||
<ul class="main-content">
|
||||
<li class="grid_2">
|
||||
<p>
|
||||
<table class="plantable shortpadded" width="80%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Plan</th><td>{{ plan.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Payment Type</th><td>{{ plan.paymenttype }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Plan Duration</th><td>1 year starting today</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Total</th><td>€ {{ plan.price|currency }}
|
||||
{% if plan.paymenttype == 'recurring' %}
|
||||
/year
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
<p>
|
||||
<table class="plantable shortpadded" width="80%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Street Address</th><td>{{ user.rower.street_address }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>City</th><td>{{ user.rower.city }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Postal Code</th><td>{{ user.rower.postal_code }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Country</th><td>{{ user.rower.country }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
</li>
|
||||
<li class="grid_2">
|
||||
<p>
|
||||
<a href="/rowers/upgrade">Change Upgrade</a>
|
||||
</li>
|
||||
<li class="grid_4">
|
||||
<form id="payment-form" method="post" action="/rowers/upgradecheckouts"
|
||||
autocomplete="off">
|
||||
<section>
|
||||
<label for="amount">
|
||||
<div class="input-wrapper amount-wrapper">
|
||||
<input id="amount" name="amount" type="hidden" min="1" placeholder="Amount"
|
||||
value="{{ plan.price }}" readonly>
|
||||
</div>
|
||||
</label>
|
||||
<div class="bt-drop-in-wrapper">
|
||||
<div id="bt-dropin"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<input type="hidden" id="nonce" name="payment_method_nonce" />
|
||||
<input type="hidden" id="plan" name="plan" value="{{ plan.id }}">
|
||||
{% csrf_token %}
|
||||
<button type="submit" id="submit-button"><span>Upgrade to the € {{ plan.price|currency }} plan</span></button>
|
||||
</form>
|
||||
</li>
|
||||
<li class="grid_4">
|
||||
<p>
|
||||
Your upgrade will be effective immediately. For the current billing
|
||||
cycle, you will be charged for a prorated amount. For example, when
|
||||
you upgrade from a 15€ plan to a 65€ plan (a difference of
|
||||
50€) in the 6th month of the 12 month billing cycle, you
|
||||
will be charged 35€.
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<script src="https://js.braintreegateway.com/web/dropin/1.14.1/js/dropin.min.js"></script>
|
||||
<script>
|
||||
var form = document.querySelector('#payment-form');
|
||||
var client_token = '{{ client_token }}';
|
||||
braintree.dropin.create({
|
||||
authorization: client_token,
|
||||
container: '#bt-dropin',
|
||||
paypal: {
|
||||
flow: 'checkout'
|
||||
}
|
||||
}, function (createErr, instance) {
|
||||
form.addEventListener('submit', function (event) {
|
||||
event.preventDefault();
|
||||
instance.requestPaymentMethod(function (err, payload) {
|
||||
if (err) {
|
||||
console.log('Error', err);
|
||||
return;
|
||||
}
|
||||
// Add the nonce to the form and submit
|
||||
document.querySelector('#nonce').value = payload.nonce;
|
||||
form.submit();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
{% include 'menu_profile.html' %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -439,12 +439,15 @@ urlpatterns = [
|
||||
url(r'^laboratory/$', views.laboratory_view,name='laboratory'),
|
||||
url(r'^promembership', TemplateView.as_view(template_name='promembership.html'),name='promembership'),
|
||||
url(r'^checkout/(?P<planid>\d+)$',views.payment_confirm_view),
|
||||
url(r'^billing',views.billing_view,name='billing'),
|
||||
url(r'^paymentcompleted',views.payment_completed_view),
|
||||
url(r'^paidplans',views.paidplans_view,name='paidplans'),
|
||||
url(r'^me/cancelsubscriptions',views.plan_stop_view),
|
||||
url(r'^upgradecheckout/(?P<planid>\d+)$',views.upgrade_confirm_view),
|
||||
url(r'^billing$',views.billing_view,name='billing'),
|
||||
url(r'^upgrade$',views.upgrade_view,name='upgrade'),
|
||||
url(r'^paymentcompleted$',views.payment_completed_view),
|
||||
url(r'^paidplans$',views.paidplans_view,name='paidplans'),
|
||||
url(r'^me/cancelsubscriptions$',views.plan_stop_view),
|
||||
url(r'^me/cancelsubscription/(?P<id>[\w\ ]+.*)$',views.plan_tobasic_view),
|
||||
url(r'^checkouts',views.checkouts_view,name='checkouts'),
|
||||
url(r'^checkouts$',views.checkouts_view,name='checkouts'),
|
||||
url(r'^upgradecheckouts$',views.upgrade_checkouts_view,name='upgrade_checkouts'),
|
||||
url(r'^planrequired',views.planrequired_view),
|
||||
url(r'^starttrial$',views.start_trial_view),
|
||||
url(r'^startplantrial$',views.start_plantrial_view),
|
||||
|
||||
@@ -1109,6 +1109,40 @@ def billing_view(request):
|
||||
'planselectform':planselectform,
|
||||
})
|
||||
|
||||
@login_required()
|
||||
def upgrade_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']
|
||||
if billingaddressform.is_valid():
|
||||
url = reverse(upgrade_confirm_view,
|
||||
kwargs={
|
||||
'planid':plan.id
|
||||
})
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
else:
|
||||
billingaddressform = RowerBillingAddressForm(instance=r)
|
||||
planselectform = PlanSelectForm(paymentprocessor='braintree',
|
||||
rower=r)
|
||||
|
||||
return render(request,
|
||||
'upgrade.html',
|
||||
{'rower':r,
|
||||
'billingaddressform':billingaddressform,
|
||||
'planselectform':planselectform,
|
||||
})
|
||||
|
||||
@login_required()
|
||||
def plan_stop_view(request):
|
||||
r = getrequestrower(request)
|
||||
@@ -1148,6 +1182,27 @@ def plan_tobasic_view(request,id=0):
|
||||
|
||||
|
||||
|
||||
@login_required()
|
||||
def upgrade_confirm_view(request,planid = 0):
|
||||
try:
|
||||
plan = PaidPlan.objects.get(id=planid)
|
||||
except PaidPlan.DoesNotExist:
|
||||
messages.error(request,"Something went wrong. Please try again.")
|
||||
url = reverse(billing_view)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
r = getrequestrower(request)
|
||||
|
||||
client_token = braintreestuff.get_client_token(r)
|
||||
|
||||
return render(request,
|
||||
"upgradeconfirm.html",
|
||||
{
|
||||
'plan':plan,
|
||||
'client_token':client_token,
|
||||
'rower':r,
|
||||
})
|
||||
|
||||
@login_required()
|
||||
def payment_confirm_view(request,planid = 0):
|
||||
try:
|
||||
@@ -1197,7 +1252,37 @@ def checkouts_view(request):
|
||||
url = reverse(billing_view)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
url = reverse(payments_view)
|
||||
url = reverse(paidplans_view)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
@login_required()
|
||||
def upgrade_checkouts_view(request):
|
||||
|
||||
r = getrequestrower(request)
|
||||
|
||||
if request.method != 'POST':
|
||||
url = reverse(paidplans_view)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
form = BillingForm(request.POST)
|
||||
if form.is_valid():
|
||||
data = form.cleaned_data
|
||||
success = 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)
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
messages.error(request,"There was a problem with your payment")
|
||||
url = reverse(upgrade_view)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
else:
|
||||
messages.error(request,"There was an error in the payment form")
|
||||
url = reverse(upgrade_view)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
url = reverse(paidplans_view)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user