Carousel fixes.
[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         order = PayUOrder.objects.create(
49             pos_id=self.pos_id,
50             customer_ip=request.META['REMOTE_ADDR'],
51             schedule=schedule,
52         )
53         return order.put()
54         
55
56 class PayPal(PaymentMethod):
57     slug='paypal'
58     name = 'PayPal (płatność odnawialna)'
59     template_name = 'club/payment/paypal.html'
60     is_recurring = True
61     is_onetime = True
62
63     def initiate(self, request, schedule):
64         return reverse('club_dummy_payment', args=[schedule.key])
65
66
67 methods = []
68
69 pos= getattr(settings, 'CLUB_PAYU_RECURRING_POS', None)
70 if pos:
71     payure_method = PayURe(pos)
72     methods.append(payure_method)
73 else:
74     payure_method = None
75
76 pos = getattr(settings, 'CLUB_PAYU_POS', None)
77 if pos:
78     payu_method = PayU(pos)
79     methods.append(payu_method)
80 else:
81     payu_method = None
82
83
84 #methods.append(PayPal())
85
86
87 method_by_slug = {
88     m.slug: m
89     for m in methods
90 }