1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.conf import settings
5 from django.urls import reverse
6 from paypal.rest import agreement_approval_url
9 class PaymentMethod(object):
13 def initiate(self, request, schedule):
14 return reverse('club_dummy_payment', args=[schedule.key])
17 class PayU(PaymentMethod):
21 template_name = 'club/payment/payu.html'
23 def __init__(self, pos_id):
26 def initiate(self, request, schedule):
27 # Create Order at once.
28 from .models import PayUOrder
29 order = PayUOrder.objects.create(
31 customer_ip=request.META['REMOTE_ADDR'],
37 class PayURe(PaymentMethod):
39 name = 'PayU recurring'
40 template_name = 'club/payment/payu-re.html'
43 def __init__(self, pos_id):
46 def initiate(self, request, schedule):
47 return reverse('club_payu_rec_payment', args=[schedule.key])
49 def pay(self, request, schedule):
50 # Create order, put it and see what happens next.
51 from .models import PayUOrder
52 if request is not None:
53 ip = request.META['REMOTE_ADDR']
56 order = PayUOrder.objects.create(
64 class PayPal(PaymentMethod):
67 template_name = 'club/payment/paypal.html'
71 def initiate(self, request, schedule):
72 app = request.GET.get('app')
73 return agreement_approval_url(schedule.amount, schedule.key, app=app)
75 def pay(self, request, schedule):
76 from datetime import date, timedelta, datetime
78 tomorrow = datetime(*(date.today() + timedelta(2)).timetuple()[:3], tzinfo=utc)
80 for ba in schedule.billingagreement_set.all():
81 active = ba.check_agreement()
87 schedule.expires_at = tomorrow
93 pos = getattr(settings, 'CLUB_PAYU_RECURRING_POS', None)
95 recurring_payment_method = PayURe(pos)
96 methods.append(recurring_payment_method)
98 recurring_payment_method = None
100 pos = getattr(settings, 'CLUB_PAYU_POS', None)
102 single_payment_method = PayU(pos)
103 methods.append(single_payment_method)
105 single_payment_method = None