#rhino_webhooks

1 messages ยท Page 1 of 1 (latest)

nimble sailBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1289168325426937857

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

open cape
#

Hello, please share your code

rare ermine
#
request_data = request.data
    sig_header = request.headers.get("Stripe-Signature")
    print("----------------- Stripe Sig -----------------")
    print(sig_header)
    print("----------------- Stripe Sig -----------------")
    print("----------------- Stripe Data -----------------")
    print(request_data)
    print("----------------- Stripe Data -----------------")
    
    try:
        event = stripe.Webhook.construct_event(
            request_data, sig_header, ENDPOINT_SECRET
        )
    except ValueError as e:
        # Invalid payload
        print('Error parsing payload: {}'.format(str(e)))
        return "Error parsing payload", 400
    except stripe.error.SignatureVerificationError as e:
        # Invalid signature
        print("----------------- Stripe Sig Error -----------------")
        print('Error verifying webhook signature: {}'.format(str(e)))
        print("----------------- Stripe Sig Error -----------------")
        return str(e), 400
#

This is my code

#

using Flask for the server

open cape
#

This issue is normally one of two things:

  • whsec_xxx is wrong โ€“ maybe you're using it the secret for a different endpoint
  • your endpint/code is malforming the request payload before you pass it to construct_event. It requires the raw payload
rare ermine
#

whsec_xxx is wrong โ€“ maybe you're using it the secret for a different endpoint

This could be, however the developer who creates the payment session uses the same key as I do.

your endpint/code is malforming the request payload before you pass it to construct_event. It requires the raw payload

I get the request payload with request.data in flask. Is this wrong?

open cape
rare ermine
# open cape How to know because you've only send a snippet of your endpoint, but the example...

I'll provide the whole endpoint code snippet.

@app.route('/stripe-webhook',methods=['POST'])
def stripeWebhook():
    # Get the JSON body of the request
    
    ### Signature verification
    request_data = request.data
    sig_header = request.headers.get("Stripe-Signature")
    print("----------------- Stripe Sig -----------------")
    print(sig_header)
    print("----------------- Stripe Sig -----------------")
    print("----------------- Stripe Data -----------------")
    print(request_data)
    print("----------------- Stripe Data -----------------")
    
    try:
        event = stripe.Webhook.construct_event(
            request_data, sig_header, ENDPOINT_SECRET
        )
    except ValueError as e:
        # Invalid payload
        print('Error parsing payload: {}'.format(str(e)))
        return "Error parsing payload", 400
    except stripe.error.SignatureVerificationError as e:
        # Invalid signature
        print("----------------- Stripe Sig Error -----------------")
        print('Error verifying webhook signature: {}'.format(str(e)))
        print("----------------- Stripe Sig Error -----------------")
        return str(e), 400
    
    
    data = request.get_json()
    print("---------------")
    print(data)
    print("---------------")
    # Extract method, body, headers, and path from the request
    method = request.method
    body = data if data else {}
    headers = dict(request.headers)
    path = request.path

    # Print the values for debugging
    #print({"method": method, "body": body, "headers": headers, "asset-path": path})

    # Push the request to the Stripe webhook handler
    responseObject = push_req_to_stripe_webhook(method, body, headers, path)
   
    return jsonify(responseObject)
#

However I did just notice the endpoint secret you and the docs are reffering to begins with "whsec_", and the secret I use begins with "sk_live_".

Can you tell me where I can find the correct endpoint secret on the stripe dashboard?

open cape
#

and the secret I use begins with "sk_live".
That's your API key. The whsec_xxx is found in the Dashboard for thew webhook endpoint

#

It's the signing secret unique to the endpoint the events are being sent to

rare ermine
#

Okay! I see

#

I'll try to find it, one sec

#

It worked!

#

Thank you!