add payment_link and banks
This commit is contained in:
1 parent
2ae79b1ca4
commit
de3135b588
100 files changed
+6167
-47
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import re
|
||||
|
||||
from django.contrib.auth import logout
|
||||
from django.db import transaction
|
||||
from django.db.models import F
|
||||
from django.shortcuts import redirect, render
|
||||
from django.utils import timezone
|
||||
from django.views.decorators.cache import never_cache
|
||||
from django.views.decorators.http import require_http_methods
|
||||
|
||||
from . import access, services
|
||||
from .models import PaymentAccessLink
|
||||
|
||||
|
||||
@never_cache
|
||||
@require_http_methods(['GET', 'POST'])
|
||||
def open_link(request, token):
|
||||
link = access.active_links().filter(token_hash=access.token_digest(token)).first() if re.fullmatch(r'[A-Za-z0-9_-]{43}', token) else None
|
||||
if link is None:
|
||||
return access.unavailable_link(request)
|
||||
if request.user.is_authenticated and request.user.pk != link.customer_id:
|
||||
confirmed = request.method == 'POST' and request.POST.get('action') == 'logout_and_open' and request.POST.get('account_id') == str(request.user.pk)
|
||||
if not confirmed:
|
||||
response = render(request, 'payments/link_confirmation.html')
|
||||
response['Referrer-Policy'] = 'same-origin'
|
||||
response['X-Robots-Tag'] = 'noindex, nofollow'
|
||||
return response
|
||||
logout(request)
|
||||
if not request.user.is_authenticated:
|
||||
access.grant_payment_access(request, link)
|
||||
with transaction.atomic():
|
||||
PaymentAccessLink.objects.filter(pk=link.pk).update(view_count=F('view_count') + 1, last_used_at=timezone.now())
|
||||
services.audit(None, 'PAYMENT_LINK_OPENED', link, {
|
||||
'ip_address': request.META.get('REMOTE_ADDR', ''),
|
||||
'user_agent': request.META.get('HTTP_USER_AGENT', '')[:500]})
|
||||
target = link.receipt or link.notice
|
||||
response = redirect('payments:receipt_detail' if link.receipt_id else 'payments:notice_detail', public_id=target.public_id)
|
||||
response['Referrer-Policy'] = 'no-referrer'
|
||||
response['X-Robots-Tag'] = 'noindex, nofollow'
|
||||
return response
|
||||
Reference in new issue
Block a user