Forgotten req.
[wolnelektury.git] / src / club / payment_methods.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django.conf import settings
5 from django.urls import reverse
6
7
8 class PaymentMethod(object):
9     is_onetime = False
10     is_recurring = False
11
12     def initiate(self, request, schedule):
13         return reverse('club_dummy_payment', args=[schedule.key])
14
15
16 class PayU(PaymentMethod):
17     is_onetime = True
18     slug = 'payu'
19     template_name = 'club/payment/payu.html'
20
21     def __init__(self, pos_id):
22         self.pos_id = pos_id
23
24     def initiate(self, request, schedule):
25         # Create Order at once.
26         from .models import PayUOrder
27         order = PayUOrder.objects.create(
28             pos_id=self.pos_id,
29             customer_ip=request.META['REMOTE_ADDR'],
30             schedule=schedule,
31         )
32         return order.put()
33
34
35 class PayURe(PaymentMethod):
36     slug='payu-re'
37     template_name = 'club/payment/payu-re.html'
38     is_recurring = True
39
40     def __init__(self, pos_id):
41         self.pos_id = pos_id
42
43     def initiate(self, request, schedule):
44         return reverse('club_payu_rec_payment', args=[schedule.key])
45
46     def pay(self, request, schedule):
47         # Create order, put it and see what happens next.
48         from .models import PayUOrder
49         if request is not None:
50             ip = request.META['REMOTE_ADDR']
51         else:
52             ip = '127.0.0.1'
53         order = PayUOrder.objects.create(
54             pos_id=self.pos_id,
55             customer_ip=ip,
56             schedule=schedule,
57         )
58         return order.put()
59         
60
61 class PayPal(PaymentMethod):
62     slug='paypal'
63     template_name = 'club/payment/paypal.html'
64     is_recurring = True
65     is_onetime = True
66
67     def initiate(self, request, schedule):
68         return reverse('club_dummy_payment', args=[schedule.key])
69
70
71 pos = getattr(settings, 'CLUB_PAYU_RECURRING_POS', None)
72 if pos:
73     recurring_payment_method = PayURe(pos)
74 else:
75     recurring_payment_method = None
76
77 pos = getattr(settings, 'CLUB_PAYU_POS', None)
78 if pos:
79     single_payment_method = PayU(pos)
80 else:
81     single_payment_method = None