Locale.
[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     name = 'PayU'
20     template_name = 'club/payment/payu.html'
21
22     def __init__(self, pos_id):
23         self.pos_id = pos_id
24
25     def initiate(self, request, schedule):
26         # Create Order at once.
27         from .models import PayUOrder
28         order = PayUOrder.objects.create(
29             pos_id=self.pos_id,
30             customer_ip=request.META['REMOTE_ADDR'],
31             schedule=schedule,
32         )
33         return order.put()
34
35
36 class PayURe(PaymentMethod):
37     slug='payu-re'
38     name = 'PayU (płatność odnawialna)'
39     template_name = 'club/payment/payu-re.html'
40     is_recurring = True
41
42     def __init__(self, pos_id):
43         self.pos_id = pos_id
44
45     def initiate(self, request, schedule):
46         return reverse('club_payu_rec_payment', args=[schedule.key])
47
48     def pay(self, request, schedule):
49         # Create order, put it and see what happens next.
50         from .models import PayUOrder
51         if request is not None:
52             ip = request.META['REMOTE_ADDR']
53         else:
54             ip = '127.0.0.1'
55         order = PayUOrder.objects.create(
56             pos_id=self.pos_id,
57             customer_ip=ip,
58             schedule=schedule,
59         )
60         return order.put()
61         
62
63 class PayPal(PaymentMethod):
64     slug='paypal'
65     name = 'PayPal (płatność odnawialna)'
66     template_name = 'club/payment/paypal.html'
67     is_recurring = True
68     is_onetime = True
69
70     def initiate(self, request, schedule):
71         return reverse('club_dummy_payment', args=[schedule.key])
72
73
74 pos = getattr(settings, 'CLUB_PAYU_RECURRING_POS', None)
75 if pos:
76     recurring_payment_method = PayURe(pos)
77 else:
78     recurring_payment_method = None
79
80 pos = getattr(settings, 'CLUB_PAYU_POS', None)
81 if pos:
82     single_payment_method = PayU(pos)
83 else:
84     single_payment_method = None