Я сейчас пытаюсь внедрить платежную систему из документации компании, ожидаю, что их API вызовет мой проект по номеру
и со вкладки запроса возвращается правильный URL-адрес. Однако ответа на этот URL нет, вместо этого сразу же появляется запрос на получение с URL
http://127.0.0.1: 8000 / корзина / оплата / проверка /? Resp = {% 22name % 22% 3A% 22opop% 22% 2C% 22data% 22% 3A {% 22data% 22% 3A {% 22id% 22% 3A1249370% 2C% 22txRef% 22% 3A% 22user-1-тележка-22% 22% 2C % 22orderRef% 22% 3A% 22URF_1588046289399_3226935% 22% 2C% 22flwRef% 22% 3A% 22FLW-MOCK-d92dbe44cad98158ebf026c29eaf91df% 22% 2C% 22redirectUrl% 22% 3A% 1016 * * 2 * * * * * *%% * * 2 * * * * * *% * * * * *% * 3 *}
Я понятия не имею, что вызывает это, и надеялся, что кто-нибудь может помочь мне отследить это.
Просмотры
@csrf_exempt
def verifyPayment(request):
# ref = json.loads(request.GET['resp'])
# ref_code = ref['tx']['txRef']
ref_code = request.GET.get('txref')
if ref_code != None:
cart_id = ref_code.split('-')[3]
cart = Cart(request, id=cart_id)
data = {
# this is the reference from the payment button response after customer paid.
# "txref": "user-%s-cart-%s"%(request.user,cart.cart.id),
"txref": ref_code,
# this is the secret key of the pay button generated
"SECKEY": "FLWSECK_TEST"
}
if cart.items_available():
r = requests.post(
'https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify', data=data)
response = r.json()
if response['status'] == 'success':
# confirm that the amount for that transaction is the amount you wanted to charge
if response['data']['chargecode'] == '00':
# a = cart.summary_delivery()
if response['data']['amount'] == float(cart.summary_delivery()):
print("Payment successful then give value")
payment = response
cart.mark_items_paid()
cart.complete(request, cart_id)
cart.sendResturantOrder(cart.groupCartOrders(), response['data']['meta'][0]['metavalue'])
payment = 'success'
else:
payment = "failure"
return render(request, 'payment/payment.html', {'payment': payment})
def processPayment(request):
cart = Cart(request)
payment = 'error one or more items may not be available'
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = CheckoutForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
if cart.items_available():
address = "%s,Apt: %s, %s, %s" % (
form.cleaned_data['street'], form.cleaned_data['apartment'], form.cleaned_data['city'], form.cleaned_data['state'])
headers = {
'content-type': 'application/json',
}
data = json.dumps({"txref": "user-%s-cart-%s" % (request.user.id, cart.cart.id), "PBFPubKey": "FLWPUBK_TEST",
"customer_email": request.user.email, "amount": cart.summary_delivery(), "currency": "NGN", "redirect_url": request.build_absolute_uri(reverse("verify-payment")), "meta": [{
'metaname': "address",
'metavalue': address
}], })
r = requests.post(
'https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/hosted/pay', headers=headers, data=data)
response = r.json()
return HttpResponseRedirect(response['data']['link'])
else:
return render(request, 'payment/payment.html', {'payment': payment})
Форма
class CheckoutForm(forms.Form):
phone_number = PhoneNumberField(label="Phone:")
street = forms.CharField(label='Street', max_length=150)
apartment = forms.CharField(label='Apartment', max_length=40,required=False)
city = forms.CharField(label='City', max_length=40)
state = forms.CharField(label='State', max_length=40)
Шаблон
<form action="{% url 'process-payment'%}" class="billing-form checkout-form" method="POST">
{% csrf_token %}
<div class="row">
{{form}}
</div>
<div class="row mt-2">
<button type="submit" class="btn food__btn">Place order</button>
</div>
</form>
URL
path('cart/payment/verify/', views.verifyPayment, name="verify-payment"),
path('cart/payment/', views.processPayment, name="process-payment"),