Stripe Subscription Creation Notifier API Webhook

Test this app for free
116
import os
from fastapi import FastAPI
from starlette.responses import JSONResponse

app = FastAPI()

@app.post('/webhook')
async def respond_to_webhook(request):
    data = await request.json()
    #stripe subscription created event
    if data['type'] == 'customer.subscription.created':
        print(data)
    else:
        print("The secret is wrong")
    return JSONResponse(status_code=200)

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8080)
Get full code

Created: | Last Updated:

This app will react to a Stripe API webhook and print the received data. It's a good starting point to hook up additional functionality to then create some event in a database or create a notification or for example enable access for a customer. Stripe Subscription Creation Notifier API Webhook template will also print a message if the secret is wrong.

Introduction to the Stripe Subscription Creation Notifier API Webhook Template

Welcome to the Stripe Subscription Creation Notifier API Webhook Template! This template is designed to help you quickly set up a webhook listener for Stripe subscription creation events. When a new subscription is created in Stripe, this app will capture the event data and print it out, providing a solid foundation for you to add additional functionality, such as updating a database, sending notifications, or granting customer access.

Getting Started with the Template

To begin using this template, simply click on the "Start with this Template" button. This will initialize the template in the Lazy Builder interface, where you can customize it according to your needs.

Initial Setup

Before you can test the webhook, you'll need to set up your Stripe account to send webhook events to your Lazy app. Here's how to do it:

  • Log in to your Stripe dashboard.
  • Navigate to the Developers section and click on Webhooks.
  • Click on "Add endpoint" and enter the URL provided by Lazy for your app. This URL will be available after you deploy the app using the Test button.
  • Select the "customer.subscription.created" event from the list of events.
  • Click "Add endpoint" to save your new webhook.

Stripe will now send a webhook event to your Lazy app whenever a new subscription is created.

Test: Pressing the Test Button

Once you have set up the webhook in Stripe, return to the Lazy Builder interface and press the "Test" button. This will deploy your app and start the webhook listener. Lazy will provide you with a server link that you can use to interact with the API.

Using the App

With the app deployed and the webhook configured, Stripe will send subscription creation events to your app's endpoint. The app will print the event data, allowing you to verify that everything is working correctly. You can view the printed data in the Lazy CLI output.

Integrating the App

After confirming that the webhook is functioning as expected, you may want to integrate the app with other systems or services. Depending on your requirements, you might:

  • Update a customer database with the new subscription information.
  • Send a notification to an administrator or the customer.
  • Trigger access permissions for the new subscriber.

To achieve these integrations, you will need to modify the app's code to include the necessary logic and possibly interact with other APIs or databases. This will require additional coding and setup based on the specific services you are using.

Remember, the Lazy platform handles the deployment and environment configuration, so you can focus on building and integrating your app without worrying about the underlying infrastructure.

If you need further guidance on integrating with specific services or databases, refer to the documentation provided by those services or seek assistance from a developer with the appropriate expertise.

Good luck with your Stripe Subscription Creation Notifier API Webhook, and happy building on Lazy!

Technologies

Streamline Stripe Payments with Lazy AI Templates: Automate Billing, Invoices, Payments and More  Streamline Stripe Payments with Lazy AI Templates: Automate Billing, Invoices, Payments and More

Similar templates