clientseitig wird mit dem der JS-Funktion:
Code: Alles auswählen
onApprove: function (data) {
var url = "{% url 'payment_complete' %}"
return fetch(url, {
method: 'POST',
headers: {
'content-type': 'application/json',
'X-CSRFToken': csrftoken,
},
body: JSON.stringify({
transaction_id: data.orderID
})
})
}
die transaction_id einer Bezahlung an /payment_complete/ weitergereicht. Das funktioniert auch.
Serverseitig in der views.py versuche ich nun den Client je nachdem, ob die Bezahlung "approved" wurde oder "declined" zu redirecten. Der redirect auf 'checkout_success' wird ausgeführt. Das sehe ich in der Konsole:
Code: Alles auswählen
[24/Oct/2021 15:46:47] "GET /checkout_success/ HTTP/1.1" 200 5757
views.py:
Code: Alles auswählen
def payment_complete(request):
body = json.loads(request.body)
transaction_id = body["transaction_id"]
try:
response_for_order = GetOrder().get_order(transaction_id) #status der transaction abfragen
if response_for_order.result.status == 'APPROVED'
return redirect('checkout_success')
else:
return redirect('checkout_failed')
except:
print("something went wrong.")
return redirect('checkout_failed')