#_sidharth

1 messages · Page 1 of 1 (latest)

idle ospreyBOT
raw sandal
#

Hey Orakaro!

#
@router.post("/payment-webhook")
async def stripe_webhook(request: Request):
    data = await request.body()
    sig_header = request.headers['HTTP_STRIPE_SIGNATURE']

    try:
        event = stripe.Webhook.construct_event(
            payload=data,
            sig_header=sig_header,
            secret=config.webhook_secret
        )

    except ValueError as e:
        logger.error(str(e))
        raise AppHTTPException(
            status_code=status.HTTP_403_FORBIDDEN,
            detail=str(e)
        )

    except stripe.error.SignatureVerificationError as e:
        logger.error(str(e))
        raise AppHTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail=str(e)
        )

    event_type = event['type']
    session = event['data']['object']
    line_items = stripe.checkout.Session.list_line_items(session['id'])
    plan_id = line_items['metadata']['planId']
    if event_type == 'checkout.session.expired':
        logger.error(f"Payment failed. {session}")
        return ErrorResponse(body="Payment failed. Please try again")

    elif event_type == 'checkout.session.completed':
        #DO SOMETHING

so above is the code for webhook

dusty solstice
#

404 means it can't find your endpoint

#

Have you tried curl your own endpoint ?

raw sandal
#

also this is the dashboard screenshot

#

anyways tried curling and as i didnt pass the HTTP_STRIPE_SIGNATURE. it gave me an error

#

500

dusty solstice
#

Okie but that means it can find your endpoint

#

where do you get 404?

raw sandal
#

i get 404 in both the IDE and ngrok console

dusty solstice
#

How did you trigger it?

raw sandal
#

once a checkout is success, this end point gets triggered , giving me a 404

#

Orakaro I'm sry , i just noticed that the endpoint had some prefixes ..lemme try it and get back to u

raw sandal
#

@dusty solstice So i tried with the prefix and it got hit this time. Even though I'm thrown an error - KeyError: 'HTTP_STRIPE_SIGNATURE'

Any ideas?

dusty solstice
#

if you prints all the headers, do you see anything?

raw sandal
#

ok lemme check that

raw sandal
#

So this is what i got in header -

`
Headers({'host': '833e-2401-4900-1cde-2-6478-b422.ngrok-free.app', 'user-agent': 'Stripe/1.0 (+https://stripe.com/docs/webhooks)', 'content-length': '3026', 'accept': '/; q=0.5, application/xml', 'cache-control': 'no-cache', 'content-type': 'application/json; charset=utf-8', 'stripe-signature': 't=1697004558,v1=db998096b41f4682e5c3109d3194a2ceb2d2673e,v0=2064e3f1254a1ce0a6b4b7e5b5cda36ad17', 'x-forwarded-for': '13.235.122.149', 'x-forwarded-proto': 'https', 'accept-encoding': 'gzip'})

`

#

updated the code to below:

#

now im getting No signatures found matching the expected signature for payload
Error: 'str' object has no attribute 'dict'

@dusty solstice

dusty solstice
#

First you don't even have stripe-signature, correct?

#

Something in the framework may have alterred, modified the request object