This commit is contained in:
Martin Quarda 2024-10-13 08:46:22 +02:00
parent 2274bac99e
commit 02f919f296

View File

@ -19,7 +19,7 @@ import PIL.Image
import random
from collections import OrderedDict
from .models import User, ALKATOR_CHOICES_DICT, ALKATOR_CLASSES, Profile, Racer, Invoice, Product
from .models import User, ALKATOR_CHOICES_DICT, ALKATOR_CLASSES, Profile, Racer, Invoice, Product, InvoiceProduct
from alkator.settings import COMGATE_MERCHANT, COMGATE_SECRET, COMGATE_TEST
@ -113,8 +113,6 @@ def register_racer(request):
if product.quantity <= 0:
return HttpResponse('{"reason":"Jsme vyprodaní!"}', status=400, content_type='application/json')
product.quantity -= 1
product.save()
invoice = Invoice(
invoice_id=invoice_id,
@ -148,7 +146,7 @@ def register_racer(request):
'label': 'Startovné na závod Alkátor Race Dolní Čermná 2025',
'email': user.email,
'fullName': f"{profile.first_name} {profile.last_name}",
'refId': f'{racer.invoice_id}',
'refId': f'{invoice.invoice_id}',
'secret': COMGATE_SECRET,
'prepareOnly': 'true',
}
@ -161,6 +159,9 @@ def register_racer(request):
invoice.delete()
return HttpResponse('{"reason":"Chyba na straně platební brány: ' + result['message'][0] + ', zkuste prosím registraci později."}', status=400, content_type='application/json')
product.quantity -= 1
product.save()
invoice.trans_id = result['transId'][0]
invoice.save()