- active = check_agreement(resource.id)
- BillingAgreementModel.objects.create(
- agreement_id=resource.id, user=request.user, plan=plan, active=active, token=token)
- return render(request, 'paypal/return.html', {'resource': resource})
+ active = check_agreement(resource.id) or False
+ BillingAgreement.objects.create(
+ agreement_id=resource.id, schedule=schedule, plan=plan, active=active, token=token)
+ if active:
+ schedule.set_payed()
+ else:
+ resource = None
+ if app:
+ if getattr(resource, 'error', None):
+ return HttpResponseAppRedirect('wolnelekturyapp://paypal_error')
+ else:
+ return HttpResponseAppRedirect('wolnelekturyapp://paypal_return')
+ else:
+ return HttpResponseRedirect(schedule.get_thanks_url())