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):
12 expiration_reliable = False
16 def initiate(self, request, schedule):
17 return reverse('club_dummy_payment', args=[schedule.key])
20 class PayU(PaymentMethod):
22 expiration_reliable = True
25 template_name = 'club/payment/payu.html'
27 def __init__(self, pos_id):
30 def initiate(self, request, schedule):
31 # Create Order at once.
32 from .models import PayUOrder
33 order = PayUOrder.objects.create(
35 customer_ip=request.META['REMOTE_ADDR'],
41 class PayURe(PaymentMethod):
43 name = 'PayU recurring'
44 template_name = 'club/payment/payu-re.html'
46 expiration_reliable = True
50 def __init__(self, pos_id):
53 def initiate(self, request, schedule):
54 return reverse('club_payu_rec_payment', args=[schedule.key])
56 def pay(self, request, schedule):
57 # Create order, put it and see what happens next.
58 from .models import PayUOrder
59 if request is not None:
60 ip = request.META['REMOTE_ADDR']
63 order = PayUOrder.objects.create(
71 class PayPal(PaymentMethod):
74 template_name = 'club/payment/paypal.html'
78 def initiate(self, request, schedule):
79 app = request.GET.get('app')
80 return agreement_approval_url(schedule.amount, schedule.key, app=app)
82 def pay(self, request, schedule):
83 from datetime import date, timedelta, datetime
85 tomorrow = datetime(*(date.today() + timedelta(2)).timetuple()[:3], tzinfo=utc)
87 for ba in schedule.billingagreement_set.all():
88 active = ba.check_agreement()
94 schedule.expires_at = tomorrow
100 pos = getattr(settings, 'CLUB_PAYU_RECURRING_POS', None)
102 recurring_payment_method = PayURe(pos)
103 methods.append(recurring_payment_method)
105 recurring_payment_method = None
107 pos = getattr(settings, 'CLUB_PAYU_POS', None)
109 single_payment_method = PayU(pos)
110 methods.append(single_payment_method)
112 single_payment_method = None