#mxd

1 messages ยท Page 1 of 1 (latest)

polar sphinxBOT
ashen coral
#

Hello ๐Ÿ‘‹
Are you seeing any errors in your server log aside from the 500 error?

stone umbra
#

no

#
@app.route('/webhook', methods=['POST'])
def webhook():
    event = None
    payload = request.data
    sig_header = request.headers['STRIPE_SIGNATURE']

    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'] == 'customer.subscription.created':
      subscription = event['data']['object']
    elif event['type'] == 'customer.subscription.deleted':
      subscription = event['data']['object']
    elif event['type'] == 'customer.subscription.updated':
      subscription = event['data']['object']
    # ... handle other event types
    else:
      print('Unhandled event type {}'.format(event['type']))

    return jsonify(success=True)
``` do I need to change 'STRIPE_SIGNATURE' ?
ashen coral
#

you don't need to change it, no. It is delivered as part of the event payload.
Can you try adding some print statements in the exceptions?

Something must be triggering this 500 response code

stone umbra
ashen coral
#

Oh from the error it looks like your server isn't even routing the request to your "/webhook" route

#

The code seems to be running into some error way before that.

stone umbra
ashen coral
#

Oh that's not how webhooks are supposed to work. Webhooks are supposed to be used server-side. If you're redirecting your users to this route client-side then that won't really work.

stone umbra
#

oh..

ashen coral
#

We have a video that goes into details
https://www.youtube.com/watch?v=oYSLhriIZaA

Just a heads up, the video is from 2019 so you may see some different code/logic, but I'd recommend watching it to learn basics about webhooks.

stone umbra
#

I watched that already

ashen coral
#

Ah I was just about to link that video here

faint viper
#

Hi ๐Ÿ‘‹

@ashen coral had to step out. Are you still experiencing this error when testing your webhook endpoint?

stone umbra
#

yeah I probably need to do something to get more info on the 500 error

faint viper
#
  1. How are you testing events?
  2. Are you using the Stripe CLI to forward events to your local machine?
stone umbra
#

so the problem starts when I SUBSCRIBE, it doesnt redirect me to the mysite.com/member

#

which I set up in the product page

#

the payment goes through, but Redirect and Webhook failure

faint viper
#

Okay, so it's generally a good idea to test locally using stripe listen to forward webhook events to your Flask app running on your local machine when you first start

stone umbra
#

ok

#

ill try that