flutterwave standard integration Key error, Please, what could be wrong with my code?

52 Views Asked by At

Here is the view to my flutter_api view.

def flutter_api(request,username,email,phone_no,price):
    auth_token= get_env_variable('SECRET_KEY')#env('SECRET_KEY')
    hed = {'Authorization': f"Bearer {auth_token}"}
    data = {
            "tx_ref":''+str(math.floor(1000000 + random.random()*9000000)),
            "amount":price,
            "currency":"NGN",
            "redirect_url":"http://localhost:8000/payments/verify_payment",
            "payment_options":"card, ussd, mobilemoneynigeria",
            "meta":{
                "consumer_id":23,
                "consumer_mac":"92a3-912ba-1192a"
            },
            "customer":{
                "email":email,
                "phonenumber":phone_no,
                "name":username
            },
            "customizations":{
                "title":"ADi meals limited",
                "description":"Your Number one Food and Soup service",
                "logo":"https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg"
            }
            }
    url = 'https://api.flutterwave.com/v3/payments'
    response = requests.post(url, json=data, headers=hed)
    response_data=response.json()
    link=response_data['data'], response_data['link']
    return link

it throws this error after running server

Internal Server Error: /payments/flutter_api/sharperleinado/[email protected]/0815 667 7751/650.0 Traceback (most recent call last): File "C:\Users\USER\Documents\ADi meals mobile\my_site\venv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner response = get_response(request) File "C:\Users\USER\Documents\ADi meals mobile\my_site\venv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\USER\Documents\ADi meals mobile\my_site\payments\views.py", line 95, in flutter_api link=response_data['data'], response_data['link'] KeyError: 'link' [23/Sep/2023 16:16:35] "GET /payments/flutter_api/sharperleinado/[email protected]/0815%20667%207751/650.0 HTTP/1.1" 500 69757

0

There are 0 best solutions below