basic withdraw and upgrade
This commit is contained in:
@@ -27,6 +27,8 @@ from rowers.tasks import (
|
|||||||
#handle_send_email_transaction_notification,
|
#handle_send_email_transaction_notification,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from rowers import credits
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
@@ -268,6 +270,7 @@ def update_subscription(rower,data,method='up'):
|
|||||||
if result.is_success:
|
if result.is_success:
|
||||||
yesterday = (timezone.now()-datetime.timedelta(days=1)).date()
|
yesterday = (timezone.now()-datetime.timedelta(days=1)).date()
|
||||||
rower.paidplan = plan
|
rower.paidplan = plan
|
||||||
|
eurocredits = credits.upgrade(int(amount),rower)
|
||||||
rower.planexpires = result.subscription.billing_period_end_date
|
rower.planexpires = result.subscription.billing_period_end_date
|
||||||
rower.teamplanexpires = result.subscription.billing_period_end_date
|
rower.teamplanexpires = result.subscription.billing_period_end_date
|
||||||
rower.clubsize = plan.clubsize
|
rower.clubsize = plan.clubsize
|
||||||
|
|||||||
26
rowers/credits.py
Normal file
26
rowers/credits.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from rowers.models import Rower
|
||||||
|
|
||||||
|
class InsufficientCreditError(Exception):
|
||||||
|
"""Raised when trying to subtract more than available"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def upgrade(amount, rower):
|
||||||
|
if rower.eurocredits > amount:
|
||||||
|
return rower.eurocredits
|
||||||
|
else:
|
||||||
|
rower.eurocredits = amount
|
||||||
|
rower.save()
|
||||||
|
return rower.eurocredits
|
||||||
|
return rower.eurocredits
|
||||||
|
|
||||||
|
def withdraw(amount, rower):
|
||||||
|
if rower.eurocredits < amount:
|
||||||
|
rower.eurocredits = 0
|
||||||
|
rower.save()
|
||||||
|
raise InsufficientCreditError
|
||||||
|
else:
|
||||||
|
rower.eurocredits = rower.eurocredits - amount
|
||||||
|
rower.save()
|
||||||
|
return rower.eurocredits
|
||||||
|
|
||||||
|
return rower.eurocredits
|
||||||
@@ -878,6 +878,8 @@ class Rower(models.Model):
|
|||||||
null=True,blank=True,
|
null=True,blank=True,
|
||||||
default='braintree')
|
default='braintree')
|
||||||
|
|
||||||
|
eurocredits = models.IntegerField(default=0)
|
||||||
|
|
||||||
paidplan = models.ForeignKey(PaidPlan,null=True,default=None,on_delete=models.SET_NULL)
|
paidplan = models.ForeignKey(PaidPlan,null=True,default=None,on_delete=models.SET_NULL)
|
||||||
|
|
||||||
planexpires = models.DateField(default=current_day)
|
planexpires = models.DateField(default=current_day)
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ from __future__ import unicode_literals
|
|||||||
from rowers.views.statements import *
|
from rowers.views.statements import *
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
|
|
||||||
|
from rowers import credits
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def braintree_webhook_view(request):
|
def braintree_webhook_view(request):
|
||||||
with open('braintreewebhooks.log','a') as f:
|
with open('braintreewebhooks.log','a') as f:
|
||||||
@@ -212,6 +214,11 @@ def purchase_checkouts_view(request):
|
|||||||
return HttpResponseRedirect(reverse('rower_select_instantplan'))
|
return HttpResponseRedirect(reverse('rower_select_instantplan'))
|
||||||
|
|
||||||
amount, success = braintreestuff.make_payment(r,data)
|
amount, success = braintreestuff.make_payment(r,data)
|
||||||
|
diff = plan.price - amount
|
||||||
|
|
||||||
|
eurocredits = credits.withdraw(diff,r)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
messages.info(request,"Your payment was completed and the sessions are copied to your calendar")
|
messages.info(request,"Your payment was completed and the sessions are copied to your calendar")
|
||||||
@@ -251,7 +258,6 @@ def purchase_checkouts_view(request):
|
|||||||
plan.name,
|
plan.name,
|
||||||
startdate,
|
startdate,
|
||||||
enddate)
|
enddate)
|
||||||
print(job,'noot')
|
|
||||||
|
|
||||||
url = reverse('plannedsessions_view')
|
url = reverse('plannedsessions_view')
|
||||||
timeperiod = startdate.strftime('%Y-%m-%d')+'/'+enddate.strftime('%Y-%m-%d')
|
timeperiod = startdate.strftime('%Y-%m-%d')+'/'+enddate.strftime('%Y-%m-%d')
|
||||||
|
|||||||
@@ -2621,10 +2621,24 @@ def rower_view_instantplan(request,id='',userid=0):
|
|||||||
'id':id,
|
'id':id,
|
||||||
})
|
})
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
# check if plan is free or credits are sufficient
|
||||||
|
if plan.price > 0:
|
||||||
|
if plan.price > r.eurocredits:
|
||||||
|
messages.error(request,'You did not have enough credit to purchase this plan')
|
||||||
|
url = reverse('rower_view_instantplan',kwargs={
|
||||||
|
'id':id,
|
||||||
|
})
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|
||||||
form = InstantPlanSelectForm(request.POST,targets=targets)
|
form = InstantPlanSelectForm(request.POST,targets=targets)
|
||||||
|
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
if plan.price > 0:
|
||||||
|
eurocredits = credits.withdraw(plan.price,r)
|
||||||
|
|
||||||
plansteps = response.json()
|
plansteps = response.json()
|
||||||
name = form.cleaned_data['name']
|
name = form.cleaned_data['name']
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user