Hi flutterwave, I’m getting this error:
return {“error”: False, “status”: responseJson[“status”],“validationRequired”: True, “txRef”: txRef, “flwRef”: responseJson[“data”][“flwRef”], “chargeResponseMessage”: responseJson[“data”][“chargeResponseMessage”]}
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: ‘flwRef’
when charging the payment is taking place successfully but the view still generate that error so there is no return.
this my code bellow:
def process_payment(request, *args, **kwargs):
res = {}
if request.method == 'POST':
body = request.body.decode('utf-8') # Decode the byte string into a Unicode string
data = urllib.parse.parse_qs(body) # Parse the form data into a dictionary
# Access the form data using the parameter names as keys
csrf_token = data.get('csrfmiddlewaretoken', [''])[0]
promo_code = data.get('promo_code', [''])[0]
payment_method = data.get('payment_method', [''])[0]
country = data.get('country', [''])[0]
card_number = data.get('card_number', [''])[0]
cvv = data.get('cvv', [''])[0]
expired_month = data.get('expired_month', [''])[0]
expired_year = data.get('expired_year', [''])[0]
mobile_phone = data.get('mobile_phone', [''])[0]
ip = get_client_ip(request)
firstname = request.user.first_name
lastname = request.user.last_name
currency = 'XAF'
order = Order.objects.get(customer=request.user.customer, complete=False)
email = request.user.email
if payment_method.upper() == "MOBILE":
print('payment in processing mode just wait a bit.')
payment = Payment.objects.create(
order=order,
mobile_phone=mobile_phone,
country=country,
total_transaction=order.get_cart_total_price,
currency=currency,
payment_method=payment_method,
ip_address=ip
)
payload = {
"currency": currency,
"country": country,
"expirymonth": expired_month,
"expiryyear": expired_year,
"amount": order.get_cart_total_price,
"email": email,
"phonenumber": mobile_phone,
"IP": ip,
'lastname': lastname,
"firstname": firstname,
"txRef": payment.transaction_id,
"redirect_url": "http://localhost:8000/receivepayment",
}
try:
res = rave.Francophone.charge(payload) # this is where the error is taking place
if "flwRef" in res and "txRef" in res:
flwRef = res["flwRef"]
txRef = res["txRef"]
print(f"flwRef: {flwRef}, txRef: {txRef}")
else:
print("Error: 'flwRef' or 'txRef' not found in responseJson")
res = rave.Francophone.verify(res["txRef"])
print(res)
except RaveExceptions.TransactionChargeError as e:
print(e.err)
print(e.err["flwRef"])
except RaveExceptions.TransactionVerificationError as e:
print(e.err["errMsg"])
print(e.err["txRef"])
return JsonResponse({'detail': res}, safe=False)
Thank in advanced for helping.