X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/48a8d1d73adefae7f0c58015494ce956d7cd70df..ca336bd1f9658cf713681d1412d4153e5c4d9c93:/src/club/payment_methods.py diff --git a/src/club/payment_methods.py b/src/club/payment_methods.py index 363d4451c..29221ee6d 100644 --- a/src/club/payment_methods.py +++ b/src/club/payment_methods.py @@ -1,11 +1,11 @@ +from django.conf import settings from django.urls import reverse class PaymentMethod(object): is_recurring = False - @classmethod - def get_payment_url(cls, schedule): + def initiate(self, request, schedule): return reverse('club_dummy_payment', args=[schedule.key]) @@ -14,9 +14,18 @@ class PayU(PaymentMethod): name = 'PayU' template_name = 'club/payment/payu.html' - @classmethod - def get_payment_url(cls, schedule): - return reverse('club_dummy_payment', args=[schedule.key]) + def __init__(self, pos_id): + self.pos_id = pos_id + + def initiate(self, request, schedule): + # Create Order at once. + from .models import PayUOrder + order = PayUOrder.objects.create( + pos_id=self.pos_id, + customer_ip=request.META['REMOTE_ADDR'], + schedule=schedule, + ) + return order.put() class PayURe(PaymentMethod): @@ -25,10 +34,22 @@ class PayURe(PaymentMethod): template_name = 'club/payment/payu-re.html' is_recurring = True - @classmethod - def get_payment_url(cls, schedule): - return reverse('club_dummy_payment', args=[schedule.key]) + def __init__(self, pos_id): + self.pos_id = pos_id + def initiate(self, request, schedule): + return reverse('club_payu_rec_payment', args=[schedule.key]) + + def pay(self, request, schedule): + # Create order, put it and see what happens next. + from .models import PayUOrder + order = PayUOrder.objects.create( + pos_id=self.pos_id, + customer_ip=request.META['REMOTE_ADDR'], + schedule=schedule, + ) + return order.put() + class PayPalRe(PaymentMethod): slug='paypal-re' @@ -36,16 +57,29 @@ class PayPalRe(PaymentMethod): template_name = 'club/payment/paypal-re.html' is_recurring = True - @classmethod - def get_payment_url(cls, schedule): + def initiate(self, request, schedule): return reverse('club_dummy_payment', args=[schedule.key]) -methods = [ - PayU, - PayURe, - PayPalRe, -] +methods = [] + +pos = getattr(settings, 'CLUB_PAYU_POS', None) +if pos: + payu_method = PayU(pos) + methods.append(payu_method) +else: + payu_method = None + +pos= getattr(settings, 'CLUB_PAYU_RECURRING_POS', None) +if pos: + payure_method = PayURe(pos) + methods.append(payure_method) +else: + payure_method = None + + +methods.append(PayPalRe()) + method_by_slug = { m.slug: m