#Beikeni-webhook

1 messages · Page 1 of 1 (latest)

wet trench
#

👋 happy to help

#

could you please provide the Webhook Endpoint id we_xxx so I could take a look at it?

hybrid patio
#

whsec_QenZdd0fwpojNOmoGoLmywxuT4AUFp5u

#

it's a test endpoint

#

Thank you for answering so quickly btw

wet trench
#

just for the sake of clarity this id whsec_QenZdd0fwpojNOmoGoLmywxuT4AUFp5u is not the Webhook Endpoint id, this is the webhook secret and unfortunately I can't use it to take a look on your webhook

hybrid patio
#

ah sorry, ok

#

just a sec

#

we_1KX6pUFTv35B9Lv0lxUcngLc

#

here

#

sorry for the misunderstanding

wet trench
#

on it thanks

hybrid patio
#

💯

wet trench
#

your webhook endpoint is returning a 404 not found for the url configured for your endpoint

#

try to make sure that the endpoint exists and takes a POST request

hybrid patio
#

the webhook is there, and i can see the request coming in. The problem is that the line "event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret
)" doesnt work

#

i mean, the endpoint is there, the request comes in normally, i can print it and see the data from the payment

#

but it fails to generate a valid signature

#

but im using the stripe built in signature verification tool so i dont know what im doing wrong

#

It throws this error: stripe.error.SignatureVerificationError

wet trench
#

could you paste the endpoint code please?

hybrid patio
#

`@csrf_exempt
def webhook_received(request):
"""
Stripe Notes
The order with which the webhook events will come in
1. customer.subscription.created
2. invoice.created
3. invoice.paid
4. charge.created (if there’s a charge)
"""

user = None

endpoint_secret = settings.STRIPE_ENDPOINT_SECRET

payload = request.body
# print(f"PAYLOAD ::: {payload}")

sig_header = request.META['HTTP_STRIPE_SIGNATURE']

event = None

try:
    print("try kona2 webhook_received")
    event = stripe.Webhook.construct_event(
        payload, sig_header, endpoint_secret
    )
    print("try kona2 webhook_received OK")
except ValueError as e:
    print("Invalid payload:", e)
    # Invalid payload
    connection.close()
    print("CHECKPOINT kona2 create_checkout_session end 1")
    return HttpResponse(status=400)
except stripe.error.SignatureVerificationError as e:
    print("Invalid signature:", e)
    # Invalid signature
    connection.close()
    print("CHECKPOINT kona2 create_checkout_session end 2")
    return HttpResponse(status=400)`
#

As you can see, the signature header comes along with the request being received. I don't see how that can be wrong 🤷‍♂️

wet trench
#

are you returning HTTPResponse(status=200) at the ends?

hybrid patio
#

yeah

#

return JsonResponse({'status': 200})

#

i didnt paste the whole function cause its a bit long

wet trench
#

no worries

hybrid patio
#

and anyway it never gets past the row where it tries to run construct_event

#

Hey i figure id out

#

The developer who built this messed up in linking the correct .env file 🤦‍♂️

#

I thought i checked it already but i guess i wasnt thorough enough

wet trench
#

could you please check that the key you're using is the right one? whsec_QenZdd0fwpojNOmoGoLmywxuT4AUFp5u

hybrid patio
#

yeah exactly, the key was wrong

wet trench
#

Sorry my bad I wrote the message a while ago and thought I sent it 🤦

hybrid patio
#

Ahah, no problem, im just happy it works now

#

Thanks for your help, have a good day!

wet trench
#

let me know if you need any more help