#paulC.
1 messages · Page 1 of 1 (latest)
Hello ! Here is the code if you're wondering : `@app.route('/stripe-webhook', methods=['POST'])
def stripe_webhook():
event = None
payload = request.data
sig_header = request.headers['STRIPE_SIGNATURE']
print(sig_header)
try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret
)
except ValueError as e:
# Invalid payload
raise e
except stripe.error.SignatureVerificationError as e:
# Invalid signature
raise e
# Handle the event
if event['type'] == 'checkout.session.async_payment_succeeded':
print('HARAMBE')
elif event['type'] == 'checkout.session.completed':
print('HARAMBE2')
elif event['type'] == 'subscription_schedule.canceled':
print('HARAMBE3')
# ... handle other event types
else:
print('Unhandled event type {}'.format(event['type']))`
Hi, typically you get this error "stripe.error.SignatureVerificationError: No signatures found matching the expected signature for payload" because you're not using the exact webhook key, or you're not passing the raw request body.
But where would I get the API key for the webhook (if not from the code snippet)?
When you say webhook key do you refer to the endpoint_secret on the create a webhook page ?
The API key and the webhook secret key are separate. You get the webhook secret key from the Dashboard, https://dashboard.stripe.com/test/webhooks. Once you click on the webhook endpoint, you'll see the following option to reveal the key.
You'd want to review this, https://stripe.com/docs/webhooks/signatures. It's important that you're passing the raw request body into construct_event and that nothing has parsed or modified it.
Thanks , looking into it rn !
👋 We have to run for the week end so we're going to archive this thread. If you have any follow up questions, please reach out to our support team directly for help: https://support.stripe.com/contact
Hey ! Figured it out. For some reason the API key in the snippet was not the same as the key under the 'reveal' button