pokus o result

This commit is contained in:
Martin Quarda 2024-08-05 18:53:08 +02:00
parent 6c2895b02a
commit d024364e00
4 changed files with 17 additions and 3 deletions

View File

@ -16,7 +16,7 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from alkatorapi.views import register, results, photos, payment_result
from alkatorapi.views import register, results, photos, payment_result, payment_state
urlpatterns = [
path('admin/', admin.site.urls),
@ -24,4 +24,5 @@ urlpatterns = [
path('api/results', results),
path('api/photos', photos),
path('api/payment_result', payment_result),
path('api/payment_state', payment_state),
]

View File

@ -36,4 +36,4 @@ class User(models.Model):
paid = models.BooleanField(default=False)
def __str__(self):
return f"<User {self.starting_number} {self.first_name} {self.last_name} {self.email} {self.duration} {self.alkator_category} {ALKATOR_CLASSES_DICT[self.alkator_class]}>"
return f"<User {self.starting_number} {self.first_name} {self.last_name} {self.email} {self.duration} {ALKATOR_CHOICES_DICT[self.alkator_category]} {ALKATOR_CLASSES_DICT[self.alkator_class]} {self.paid}>"

View File

@ -92,6 +92,14 @@ def payment_result(request):
return HttpResponse(status=200)
def payment_state(request):
id = request.GET['refId']
if User.objects.get(id=id).paid:
return HttpResponse('{"status":"success", "reason":"Úspěšná platba"}', content_type='application/json')
else:
return HttpResponse('{"status":"failed", "reason":"Zatím nemáme informace o provedené platbě. Zkuste reload nebo zkontrolujte email."}', content_type='application/json')
def results(request):
results = []
n = 1

View File

@ -30,6 +30,11 @@ class Main extends Component {
fetch(addr_prefix + "/api/photos").then(resp => resp.json()).then(json => {
this.setState({photos: json})
})
if(window.location.search){
fetch(addr_prefix + "/api/payment_state" + window.location.search).then(resp => resp.json()).then(json =>{
this.setState({status: json.status, text: json.reason})
})
}
window.addEventListener("hashchange", (e) => {this.onHashChange(e)})
}
closePhoto = () => {
@ -288,7 +293,7 @@ class Main extends Component {
<input type="checkbox" class="form-check-input" id="agreement" name="agreement" />
<label class="form-check-label" for="agreement">Souhlas se <a href="/public/ochrana_osobnich_udaju.pdf">zpracováním osobních údajů</a> a <a href="/public/reverz.pdf">podmínkami závodu</a>.</label>
</div>
<button type="submit" class="btn btn-primary">Odeslat</button>
<button type="submit" class="btn btn-primary">Odeslat a zaplatit</button>
</form>
<div class="container text-center social">
<div class="row">