From 1a12630094dd57a463a8a1d4f64744e3b3b245af Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Fri, 6 Jul 2018 14:00:54 +0200 Subject: [PATCH] minor changes in paypal --- src/paypal/rest.py | 4 ++-- src/paypal/templates/paypal/form.html | 17 +++++++++++------ src/paypal/views.py | 5 +++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/paypal/rest.py b/src/paypal/rest.py index 68ac30ff5..a2e22322f 100644 --- a/src/paypal/rest.py +++ b/src/paypal/rest.py @@ -74,8 +74,8 @@ def create_agreement(amount): plan_id = plan.plan_id start = (timezone.now() + timedelta(0, 3600*24)).astimezone(pytz.utc).strftime('%Y-%m-%dT%H:%M:%SZ') billing_agreement = BillingAgreement({ - "name": "Subskrypcja klubu WL", - "description": "Cykliczne wspieranie Wolnych Lektur kwotą %s złotych" % amount, + "name": u"Subskrypcja klubu WL", + "description": u"Stałe wsparcie Wolnych Lektur kwotą %s złotych" % amount, "start_date": start, "plan": { "id": plan_id, diff --git a/src/paypal/templates/paypal/form.html b/src/paypal/templates/paypal/form.html index b2e6a0c7d..de8382f26 100644 --- a/src/paypal/templates/paypal/form.html +++ b/src/paypal/templates/paypal/form.html @@ -4,10 +4,15 @@ {% block title %}{% trans "Subscription" %}{% endblock %} {% block body %} -
- {% csrf_token %} - {{ form.as_p }} - {# paypal submit button #} - -
+ {# https://www.facebook.com/sharer/sharer.php?u=https%3A//wolnelektury.pl{% url 'paypal_form' %} #} + {% if user.is_authenticated %} +
+ {% csrf_token %} + {{ form.as_p }} + {# paypal submit button #} + +
+ {% else %} + {% trans "You must be logged in to subscribe." %} + {% endif %} {% endblock %} \ No newline at end of file diff --git a/src/paypal/views.py b/src/paypal/views.py index a4c04ce08..81c198559 100644 --- a/src/paypal/views.py +++ b/src/paypal/views.py @@ -6,7 +6,7 @@ from decimal import Decimal from django.contrib.auth.decorators import login_required from django.http import Http404 -from django.http.response import HttpResponseRedirect +from django.http.response import HttpResponseRedirect, HttpResponseForbidden from django.shortcuts import render from paypal.forms import PaypalSubscriptionForm @@ -14,9 +14,10 @@ from paypal.rest import execute_agreement, check_agreement, agreement_approval_u from paypal.models import BillingAgreement as BillingAgreementModel, BillingPlan -@login_required def paypal_form(request): if request.POST: + if not request.user.is_authenticated(): + return HttpResponseForbidden() form = PaypalSubscriptionForm(data=request.POST) if form.is_valid(): amount = form.cleaned_data['amount'] -- 2.20.1