#rhino_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ 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.
Hello, please share your code
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
This issue is normally one of two things:
whsec_xxxis 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
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?
How to know because you've only send a snippet of your endpoint, but the example here works: https://docs.stripe.com/webhooks?lang=python#verify-webhook-signatures-with-official-libraries
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?