Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda