Testing Stripe webhook
This tutorial will show you how you can test your Stripe payment gateway webhooks.
Here we use flask to create a simple webhook receiver, If the webhook receives a POST it will respond with a message. The flask application is set to run in port 8080.
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route('/', methods=['POST']) #You may add other route eg: '/webhook'
data = request.get_json(silent=True)
print(data) #Prints payload
return jsonify('Yey! Success') #Returns happy message
if __name__ == '__main__':
app.run(port=8080) #Running on port 8080
You can then run your code.
loclx tunnel http --basic-auth stripeuser:stripepwd
# also using in-built basic authentication feature (Optional)
LocalXpose should provide you with http/https tunnel endpoints.
- Click on 'Add endpoint'.
- Enter your LocalXpose URL in format https://<username>:<password>@<localxposeurl>
- Select event/s you want to generate.
- Save by clicking 'Add endpoint'.
In order to test the working of your setup, we can trigger webhook events.
- Click on 'Send test webhook'
- Select the event you want to trigger.
- Confirm by clicking 'Send test webhook'
You should see the return message from our webhook 'Yey! Success'.
> Your pairing code is: gems-pretty-holy-honor
> Press Enter to open up the browser (^C to quit)
stripe listen --forward-to https://stripeuser:[email protected]
# Ideally you would want to setup a listner in server, but if you can't, you can
# forward using localxpose's url to forward webhook events like such.
stripe trigger payment_intent.created
You should receive the event and it will be forwarded to your webhook.