Remove obsolete jsonfield dependency.
[wolnelektury.git] / src / club / payment_methods.py
1 from django.conf import settings
2 from django.urls import reverse
3
4
5 class PaymentMethod(object):
6     is_onetime = False
7     is_recurring = False
8
9     def initiate(self, request, schedule):
10         return reverse('club_dummy_payment', args=[schedule.key])
11
12
13 class PayU(PaymentMethod):
14     is_onetime = True
15     slug = 'payu'
16     name = 'PayU'
17     template_name = 'club/payment/payu.html'
18
19     def __init__(self, pos_id):
20         self.pos_id = pos_id
21
22     def initiate(self, request, schedule):
23         # Create Order at once.
24         from .models import PayUOrder
25         order = PayUOrder.objects.create(
26             pos_id=self.pos_id,
27             customer_ip=request.META['REMOTE_ADDR'],
28             schedule=schedule,
29         )
30         return order.put()
31
32
33 class PayURe(PaymentMethod):
34     slug='payu-re'
35     name = 'PayU (płatność odnawialna)'
36     template_name = 'club/payment/payu-re.html'
37     is_recurring = True
38
39     def __init__(self, pos_id):
40         self.pos_id = pos_id
41
42     def initiate(self, request, schedule):
43         return reverse('club_payu_rec_payment', args=[schedule.key])
44
45     def pay(self, request, schedule):
46         # Create order, put it and see what happens next.
47         from .models import PayUOrder
48         if request is not None:
49             ip = request.META['REMOTE_ADDR']
50         else:
51             ip = '127.0.0.1'
52         order = PayUOrder.objects.create(
53             pos_id=self.pos_id,
54             customer_ip=ip,
55             schedule=schedule,
56         )
57         return order.put()
58         
59
60 class PayPal(PaymentMethod):
61     slug='paypal'
62     name = 'PayPal (płatność odnawialna)'
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 methods = []
72
73 pos= getattr(settings, 'CLUB_PAYU_RECURRING_POS', None)
74 if pos:
75     payure_method = PayURe(pos)
76     methods.append(payure_method)
77 else:
78     payure_method = None
79
80 pos = getattr(settings, 'CLUB_PAYU_POS', None)
81 if pos:
82     payu_method = PayU(pos)
83     methods.append(payu_method)
84 else:
85     payu_method = None
86
87
88 #methods.append(PayPal())
89
90
91 method_by_slug = {
92     m.slug: m
93     for m in methods
94 }