#paulC.

1 messages · Page 1 of 1 (latest)

mystic epochBOT
dire geyser
#

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']))`
agile siren
#

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.

dire geyser
#

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 ?

agile siren
#

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.

dire geyser
#

O! My bad

#

but where is it used in the post route ?

#

I cant see any refence to it

agile siren
dire geyser
#

Thanks , looking into it rn !

twilit python
#

👋 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

dire geyser
#

Hey ! Figured it out. For some reason the API key in the snippet was not the same as the key under the 'reveal' button