Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
Redirecting a user to checkout page in Django

I want to redirect a user to checkout page that is automatically generated by the payment gateway. Anytime a user submits a request, the payment gateway returns a response in the format below. What i want to do is redirect the user to the checkout page to make payment.

 "status": true,
  "message": "Authorization URL created",
  "data": {
    "authorization_url": "https://checkout.paystack.com/eddno1f6rf411p0",
    "access_code": "eddno1f6rf411p0",
    "reference": "bpozkels2v"

def paystack(request):
    url = 'https://api.paystack.co/transaction/initialize'
    transaction_id = random.randint(100000000000, 999999999999)
    data = {
            "key": "PUBLIC_KEY",
            "ref": transaction_id,
            "amount": "000000000100",
            "callback": f"http://127.0.0.1:8000",
            "email": "email@me.com",
        }
    headers =  {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer SECRET_KEY',
        'Cache-Control': 'no-cache'
    }
    res = requests.post(url, data=json.dumps(data), headers=headers)
    response_data = res.json()
    print(response_data["authorization_url"])
    redirect(response_data["authorization_url"])

The error i get is

 KeyError at /paystack
'authorization_url'

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

GIven the response is as in the question text, you first should access the subdictionary for the "data" key, so:

response_data['data']['authorization_url']
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!