works but cannot change address
This commit is contained in:
@@ -84,6 +84,212 @@ def billing_view(request):
|
||||
'planselectform':planselectform,
|
||||
})
|
||||
|
||||
@login_required()
|
||||
def buy_trainingplan_view(request,id=0):
|
||||
if not PAYMENT_PROCESSING_ON:
|
||||
url = reverse('promembership')
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
r = request.user.rower
|
||||
|
||||
plan = get_object_or_404(InstantPlan,pk=id)
|
||||
|
||||
if r.paymentprocessor != 'braintree':
|
||||
messages.error(request,"This purchase is currently only available through BrainTree (by PayPal)")
|
||||
|
||||
if id == 0 or id is None:
|
||||
messages.error(request,"There was an error accessing this plan")
|
||||
url = reverse('rower_view_instantplan',kwargs={
|
||||
'id':plan.uuid,
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
if request.method == 'POST':
|
||||
billingaddressform = RowerBillingAddressForm(instance=r)
|
||||
form = TrainingPlanForm(request.POST,user=request.user)
|
||||
if billingaddressform.is_valid():
|
||||
cd = billingaddressform.cleaned_data
|
||||
for attr, value in cd.items():
|
||||
setattr(r, attr, value)
|
||||
r.save()
|
||||
|
||||
# redirect to payment confirmation view
|
||||
if form.is_valid():
|
||||
cd = form.cleaned_data
|
||||
|
||||
enddate = cd['enddate']
|
||||
rowers = cd['rowers']
|
||||
notes = cd['notes']
|
||||
status = cd['status']
|
||||
|
||||
# get target and set enddate
|
||||
try:
|
||||
target = cd['target']
|
||||
except KeyError:
|
||||
try:
|
||||
targetid = request.POST['target']
|
||||
|
||||
if targetid != '':
|
||||
target = TrainingTarget.objects.get(id=int(targetid))
|
||||
else:
|
||||
target = None
|
||||
except KeyError:
|
||||
target = None
|
||||
|
||||
if target:
|
||||
enddate = target.date
|
||||
|
||||
pars = {
|
||||
'name':cd['name'],
|
||||
'enddate':enddate,
|
||||
'notes':notes,
|
||||
'status':status,
|
||||
'rower':rowers[0].id,
|
||||
}
|
||||
params = urllib.parse.urlencode(pars)
|
||||
url = reverse('confirm_trainingplan_purchase_view',kwargs={'id':plan.id})
|
||||
url = url + "?%s" % params
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
else:
|
||||
form = TrainingPlanForm(user=request.user)
|
||||
billingaddressform = RowerBillingAddressForm(instance=r)
|
||||
|
||||
return render(request,
|
||||
'buy_trainingplan.html',
|
||||
{
|
||||
'rower':r,
|
||||
'plan':plan,
|
||||
'billingaddressform':billingaddressform,
|
||||
'form':form,
|
||||
})
|
||||
|
||||
@login_required()
|
||||
def purchase_checkouts_view(request):
|
||||
if not PAYMENT_PROCESSING_ON:
|
||||
url = reverse('promembership')
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
r = request.user.rower
|
||||
|
||||
if request.method != 'POST':
|
||||
url = reverse('rower_view_instantplan',kwargs={
|
||||
'id':plan.uuid,
|
||||
})
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
form = TrainingPlanBillingForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
||||
data = form.cleaned_data
|
||||
|
||||
plan = InstantPlan.objects.get(id=data['plan'])
|
||||
authorizationstring = 'Bearer '+settings.WORKOUTS_FIT_TOKEN
|
||||
url = settings.WORKOUTS_FIT_URL+"/trainingplan/"+str(plan.uuid)
|
||||
headers = {'Authorization':authorizationstring}
|
||||
response = requests.get(url=url,headers=headers)
|
||||
if response.status_code != 200:
|
||||
messages.error(request,"Could not connect to the training plan server")
|
||||
return HttpResponseRedirect(reverse('rower_select_instantplan'))
|
||||
|
||||
amount, success = braintreestuff.make_payment(r,data)
|
||||
|
||||
if success:
|
||||
messages.info(request,"Your payment was completed and the sessions are copied to your calendar")
|
||||
plansteps = response.json()
|
||||
name = data['name']
|
||||
enddate = data['enddate']
|
||||
notes = data['notes']
|
||||
status = data['status']
|
||||
startdate = enddate-datetime.timedelta(days=plan.duration)
|
||||
p = TrainingPlan(
|
||||
name=name,
|
||||
#target=target,
|
||||
manager=r,
|
||||
startdate=startdate,
|
||||
enddate=enddate,status=status,
|
||||
notes=notes,
|
||||
)
|
||||
|
||||
p.save()
|
||||
|
||||
p.rowers.add(r)
|
||||
|
||||
create_sessions_from_json(plansteps,[r],startdate,r.user)
|
||||
|
||||
url = reverse('plannedsessions_view')
|
||||
timeperiod = startdate.strftime('%Y-%m-%d')+'/'+enddate.strftime('%Y-%m-%d')
|
||||
url = url+'?when='+timeperiod
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
messages.error(request,"There was a problem with your payment")
|
||||
url = reverse('rower_view_instantplan',kwargs={
|
||||
'id':plan.uuid,
|
||||
})
|
||||
return HttpResponseRedirect(url)
|
||||
elif 'tac' not in request.POST:
|
||||
try:
|
||||
planid=int(request.POST['plan'])
|
||||
enddate = request.POST['enddate']
|
||||
rower = r.id
|
||||
# incomplete
|
||||
except IndexError:
|
||||
messages.error(request,"There was an error in the payment form")
|
||||
url = reverse("purchase_checkouts_view")
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
url = reverse('rower_view_instantplan',kwargs={
|
||||
'id':plan.uuid,
|
||||
})
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
@login_required()
|
||||
def confirm_trainingplan_purchase_view(request,id = 0):
|
||||
if not PAYMENT_PROCESSING_ON:
|
||||
url = reverse('promembership')
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
r = request.user.rower
|
||||
|
||||
plan = get_object_or_404(InstantPlan,pk=id)
|
||||
|
||||
if r.paymentprocessor != 'braintree':
|
||||
messages.error(request,"This purchase is currently only available through BrainTree (by PayPal)")
|
||||
|
||||
if id == 0 or id is None:
|
||||
messages.error(request,"There was an error accessing this plan")
|
||||
url = reverse('rower_view_instantplan',kwargs={
|
||||
'id':plan.uuid,
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
client_token = braintreestuff.get_client_token(r)
|
||||
|
||||
enddate = request.GET.get('enddate',None)
|
||||
name = request.GET.get('name','')
|
||||
status = request.GET.get('status',True)
|
||||
notes = request.GET.get('notes','')
|
||||
if enddate is None:
|
||||
messages.error(request,"There was an error accessing this plan")
|
||||
url = reverse('rower_view_instantplan',kwargs={
|
||||
'id':plan.uuid,
|
||||
})
|
||||
|
||||
return render(request,
|
||||
'confirm_trainingplan.html',
|
||||
{
|
||||
'plan':plan,
|
||||
'client_token':client_token,
|
||||
'rower':r,
|
||||
'enddate':enddate,
|
||||
'status':status,
|
||||
'name':name,
|
||||
'notes':notes,
|
||||
})
|
||||
|
||||
@login_required()
|
||||
def upgrade_view(request):
|
||||
if not PAYMENT_PROCESSING_ON:
|
||||
|
||||
Reference in New Issue
Block a user