Commit 0b1a338a authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg

Add iDeal Payment to registrations

parent 867f9dfc
......@@ -336,10 +336,12 @@ class Payment(models.Model):
CASH = 'cash_payment'
CARD = 'card_payment'
ONLINE = 'online_payment'
PAYMENT_TYPE = (
(CASH, _('cash payment')),
(CARD, _('card payment')),
(ONLINE, _('online payment')),
)
type = models.CharField(
......
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "payment processed"|capfirst %} - {% trans "registration"|capfirst %} — {{ block.super }}{% endblock %}
{% block body %}
<h1>{% trans "registration" %}</h1>
<p class="tcenter">
{% blocktrans %}
Your payment has been processed.
{% endblocktrans %}
</p>
{% endblock %}
......@@ -3,7 +3,9 @@ from django.views.generic import TemplateView
from registrations.views import (BecomeAMemberView, ConfirmEmailView,
EntryAdminView, MemberRegistrationFormView,
PaymentAdminView, RenewalFormView)
PaymentAdminView, RenewalFormView,
StartOnlinePaymentView,
ProcessOnlinePaymentView)
app_name = "registrations"
......@@ -28,4 +30,10 @@ urlpatterns = [
PaymentAdminView.as_view(), name='admin-process'),
url('^confirm-email/(?P<pk>[\w-]+)/$',
ConfirmEmailView.as_view(), name='confirm-email'),
url(r'^online-payment/(?P<pk>[\w-]+)/$',
StartOnlinePaymentView.as_view(),
name='start-online-payment'),
url(r'^online-payment/(?P<pk>[\w-]+)/confirm$',
ProcessOnlinePaymentView.as_view(),
name='process-online-payment'),
]
import Mollie
from django.contrib import messages
from django.contrib.admin.utils import model_ngettext
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.shortcuts import redirect
from django.http import HttpResponse
from django.shortcuts import redirect, get_object_or_404
from django.template.defaultfilters import floatformat
from django.urls import reverse
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views import View
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import FormView
from django.views.generic.base import TemplateResponseMixin, TemplateView
from django.views.generic.base import TemplateResponseMixin, TemplateView, \
RedirectView
from members.models import Membership
from registrations import emails, forms, services
from registrations.models import Entry, Payment, Registration, Renewal
from thaliawebsite.settings import settings
from thaliawebsite.templatetags.baseurl import baseurl
class BecomeAMemberView(TemplateView):
......@@ -193,3 +198,57 @@ class RenewalFormView(FormView):
renewal = form.save()
emails.send_new_renewal_board_message(renewal)
return redirect('registrations:renew-success')
class StartOnlinePaymentView(RedirectView):
request = None
def dispatch(self, request, *args, **kwargs):
self.request = request
return super().dispatch(request, *args, **kwargs)
def get_redirect_url(self, *args, **kwargs):
mollie = Mollie.API.Client()
mollie.setApiKey(settings.MOLLIE_API_KEY)
payment = get_object_or_404(Payment, pk=kwargs['pk'])
if payment.processed:
return 'https://thalia.nu/'
data = {
'amount': float(payment.amount),
'description': str(payment.entry),
'webhookUrl': baseurl({'request': self.request}) + reverse(
'registrations:process-online-payment', args=[payment.pk]),
'redirectUrl': 'https://thalia.nu/',
'metadata': {
'type': 'registration',
'payment': str(payment.pk)
}
}
mollie_payment = mollie.payments.create(data)
return mollie_payment.getPaymentUrl()
@method_decorator(csrf_exempt, name='dispatch')
class ProcessOnlinePaymentView(View):
http_method_names = ['post']
def dispatch(self, request, *args, **kwargs):
id = request.POST.get('id')
mollie = Mollie.API.Client()
mollie.setApiKey(settings.MOLLIE_API_KEY)
mollie_payment = mollie.payments.get(id)
if mollie_payment.isPaid():
services.process_payment(
Payment.objects.filter(pk=kwargs['pk']), Payment.ONLINE)
return HttpResponse(status=200)
class CompletedOnlinePaymentView(TemplateView):
template_name = 'registrations/completed_payment.html'
......@@ -260,6 +260,9 @@ PHOTO_UPLOAD_SIZE = 1920, 1080
# API key for wiki
WIKI_API_KEY = 'debug'
# API key for Mollie
MOLLIE_API_KEY = 'test_88gS2yGPdmcSP5x37spHwzevuCUTvh'
# CORS config
CORS_ORIGIN_ALLOW_ALL = True
CORS_URLS_REGEX = r'^/api/.*$'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment