def register(request, slug): logger = logging.getLogger(__name__) # # create a file handler logger.info('views::register() - start') event = get_object_or_404(Event, slug=slug) now = datetime.datetime.now() if event.start_registration > now or event.end_registration < now: return HttpResponse(_("Inschrijving gesloten.")) #SubscribeForm = SubscribeFormBuilder(event) if request.method == "POST": logger.info('views::register() - form POST') form = SubscribeForm(event, request.POST) if form.is_valid(): # Store the data subscription = fill_subscription(form, event) if not subscription: # Error Filling subscription error_str = "Error in saving form." logger.error(error_str) return HttpResponse(_(error_str)) if subscription.event_option.price <= 0: subscription.payed = True subscription.send_confirmation_email() subscription.save() logger.info('views::register() - registered for a free event.') return HttpResponse(_("Dank voor uw inschrijving")) # You need to pay response = mollie.fetch( settings.MOLLIE['partner_id'], # Partner id subscription.event_option.price, # Amount form.cleaned_data["issuer"].safe_id(), # Bank ID subscription.event_option.name, # Description settings.MOLLIE['report_url'], # Report url settings.MOLLIE['return_url'], # Return url settings.MOLLIE['profile_key'], # Return url ) err = mollie.get_error(response) if err: error_str = "views::register() - Technische fout, probeer later opnieuw." + "\n\n%d: %s" % (err[0], err[1]) logger.error(error_str) return HttpResponse(_(error_str)) subscription.trxid = response.order.transaction_id subscription.save() logger.info(response.order.URL) return HttpResponseRedirect(str(response.order.URL)) else: form = SubscribeForm(event) c = { "event": event, "request": request, "form": form, } c.update(csrf(request)) return render_to_response("form.html", c)
def register(request, slug): event = get_object_or_404(Event, slug=slug) now = datetime.datetime.now() if event.start_registration > now or event.end_registration < now: return HttpResponse(_("Inschrijving gesloten.")) #SubscribeForm = SubscribeFormBuilder(event) if request.method == "POST": form = SubscribeForm(event, request.POST) if form.is_valid(): # Store the data subscription = fill_subscription(form, event) if not subscription: # Error Filling subscription return HttpResponse(_("Error in saving form.")) if subscription.event_option.price <= 0: subscription.payed = True subscription.send_confirmation_email() subscription.save() return HttpResponse(_("Dank voor uw inschrijving")) # You need to pay oIDC = iDEALConnector() req = oIDC.RequestTransaction( issuerId=form.cleaned_data["issuer"].safe_id(), purchaseId=subscription.gen_subscription_id(), amount=subscription.event_option.price, description=_safe_string(subscription.event_option.__unicode__()), entranceCode=subscription.gen_subscription_id() ) if type(req) != AcquirerTransactionResponse: return HttpResponse(_("Technische fout, probeer later opnieuw.")) sUrl = req.getIssuerAuthenticationURL() # store the transaction ID, can later be used to check the status of the transaction transactionId = req.getTransactionID() subscription.trxid = transactionId subscription.save() return HttpResponseRedirect(sUrl) else: form = SubscribeForm(event) c = { "event": event, "request": request, "form": form, } c.update(csrf(request)) return render_to_response("form.html", c)
def register(request, slug): logger = logging.getLogger(__name__) # Get the event event = get_object_or_404(Event, slug=slug) # If not staff, check if allowed if not request.user.is_staff: now = datetime.datetime.now() if event.start_registration > now or event.end_registration < now: return event_message(request, event, _("Inschrijving gesloten.")) if event.is_full(): return event_message(request, event, _("Helaas is het maximum aantal inschrijvingen bereikt.")) # If this is not a POST request if request.method != "POST": # then just create the form... form = SubscribeForm(event) c = {"event": event, "request": request, "form": form, "user_is_staff": request.user.is_staff} c.update(csrf(request)) return render_to_response("subscribe/form.html", c) # It is a POST request, check if the form is valid... form = SubscribeForm(event, request.POST) if not form.is_valid(): c = {"event": event, "request": request, "form": form, "user_is_staff": request.user.is_staff} c.update(csrf(request)) return render_to_response("subscribe/form.html", c) # It is a POST request, and the form is valid, check if this is the confirmation page if 'registration_preview' not in request.POST and not form.is_free_event: form.confirm_page() c = {"event": event, "request": request, "form": form, "user_is_staff": request.user.is_staff} c.update(csrf(request)) return render_to_response("subscribe/form.html", c) # Maybe this is just a test of the confirmation email? if 'testsubmit' in request.POST: subscription = fill_subscription(form, event) msg = subscription.send_confirmation_email() subscription.delete() msg = '<br/>'.join(escape(msg).split('\n')) return event_message(request, event, mark_safe("De volgende email is verstuurd:<br/><br/>{}".format(msg))) # We confirmed. Create the subscription in the database... subscription = fill_subscription(form, event) # Check if the subscription form could be saved if not subscription: # Error Filling subscription error_str = "Error in saving form." return HttpResponse(_(error_str)) # Check (again) if maybe the number of registrations is over the limit... if subscription in event.get_registrations_over_limit(): subscription.delete() if event.is_full(): error_str = "De inschrijving kan niet worden voltooid, omdat het maximum aantal inschrijvingen is bereikt." else: error_str = "De inschrijving kan niet worden voltooid, omdat een van de gekozen opties het maximum aantal inschrijvingen heeft bereikt." return event_message(request, event, _(error_str)) # Check if we need to pay or not... if subscription.price <= 0: subscription.paid = True subscription.send_confirmation_email() subscription.save() return event_message(request, event, _("Inschrijving geslaagd. Ter bevestiging is een e-mail verstuurd.")) # Payment required... try: mollie = Mollie.API.Client() mollie.setApiKey(settings.MOLLIE_KEY) # METADATA TOEVOEGEN webhookUrl = request.build_absolute_uri(reverse("webhook", args=[subscription.id])) redirectUrl = request.build_absolute_uri(reverse("return_page", args=[subscription.id])) payment = mollie.payments.create({ 'amount': float(subscription.price) / 100.0, 'description': subscription.event.name, 'webhookUrl': webhookUrl, 'redirectUrl': redirectUrl, }) subscription.trxid = payment["id"] subscription.save() return HttpResponseRedirect(payment.getPaymentUrl()) except Mollie.API.Error as e: error_str = "register: Technische fout, probeer later opnieuw.\n\n" + str(e) logger.error(error_str) return event_message(request, event, _(error_str))