#Adaxer

1 messages · Page 1 of 1 (latest)

sand meteorBOT
winter sable
#

Where are you getting that error?

brave kayak
#

It says that something is wrong with my code but I'm unsure what.

winter sable
#

Can you link the Event ID?

brave kayak
#

Certainly, evt_1N0pzZEKarudGTfPSckvvFDI.

winter sable
#

Should look like --> evt_abc123

#

That's an internal server error with your webhook handler. So wherever you're listening for webhooks, your server is sending back a bunch of raw HTML instead of a HTTP 200 code

brave kayak
#

Is there any guide on how to properly handle webhooks?

winter sable
brave kayak
#

I tried that and the interactive guide, both of them returns the same.

#

It seems like it returns the django error html page, but it shouldn't...

#

endpoint_secret = 'whsec_kX...'

@csrf_exempt
def stripe_webhook(request):

    event = None
    payload = request.data

    try:
        event = json.loads(payload)
    except:
        return jsonify(success=False)
    if endpoint_secret:
        # Only verify the event if there is an endpoint secret defined
        # Otherwise use the basic event deserialized with json
        sig_header = request.headers.get('stripe-signature')
        try:
            event = stripe.Webhook.construct_event(
                payload, sig_header, endpoint_secret
            )
        except stripe.error.SignatureVerificationError as e:
            return jsonify(success=False)

    if event.type == 'checkout.session.completed':
      # do something

    return jsonify(success=True)
#

There's nowhere it returns the html of the page, right?

winter sable
#

I'm not sure. I don't have access to your server, so you'd need to put console.log(); lines throughout to see which line is doing this. For what it's worth, I think you may want to switch to Python on the docs and use this line to return the status code 200 return HttpResponse(status=200)

brave kayak
#

It is in fact already python, but flask instead of django.

#

It doesn't change anything, I don't know really.

winter sable
#

Ah, maybe its this?

from flask import make_response

response.status_code = 200
return response

#

I would still add print() statements throughout if this doesn't work to make sure you know what you're actually sending back