Welcome to the Create Subscription with Stripe API template! This template is designed to help you integrate a custom Stripe subscription API into your software applications with ease. It includes a backend service set up using FastAPI, which is compatible with any price point established through the Stripe API. The backend service is responsible for creating a Stripe subscription and is configured to allow all CORS. It also logs requests and subscription statuses. The template is perfect for builders who want to add subscription functionality to their applications without delving into the complexities of backend development.
To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code.
Before testing the app, you'll need to set up an environment secret for the Stripe secret key:
STRIPE_SECRET_KEY
.Once you have set up the environment secret, press the "Test" button. This will begin the deployment of the app and launch the Lazy CLI. The CLI will handle the deployment process, and you won't need to install any libraries or set up your environment.
After pressing the "Test" button, Lazy will provide you with a dedicated server link. This link is where you can interact with the API to create Stripe subscriptions. Additionally, Lazy will provide a link to the FastAPI documentation, which you can use to explore the API endpoints and their specifications.
To integrate the backend service with your front-end application, follow these steps:
"PUBLISHABLE STRIPE API KEY"
with your actual publishable API key from Stripe."YOUR SERVER LINK"
with the server link provided by Lazy after pressing the "Test" button."PRICE_ID"
, "CUSTOMER_ID"
, and "PAYMENT_METHOD_ID"
with the actual IDs you want to use for the transaction.create_subscription()
function to initiate the creation of a Stripe subscription.Here is the sample front-end integration script with placeholders for your specific values:
<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe("PUBLISHABLE STRIPE API KEY");
function getUTMParameters() {
const params = new URLSearchParams(window.location.search);
return {
utm_source: params.get('utm_source') || '',
utm_medium: params.get('utm_medium') || '',
utm_campaign: params.get('utm_campaign') || '',
utm_term: params.get('utm_term') || '',
utm_content: params.get('utm_content') || ''
};
}
async function create_subscription() {
const months = 1;
const utmParams = getUTMParameters();
const response = await fetch("YOUR SERVER LINK/create-subscription", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
months,
price: 'PRICE_ID',
customer_id: 'CUSTOMER_ID',
payment_method: 'PAYMENT_METHOD_ID',
...utmParams
})
});
const { subscriptionId } = await response.json();
return subscriptionId;
}
</script>
By following these steps, you can seamlessly integrate the Create Subscription with Stripe API template into your application and start creating subscriptions for your customers.
This is a FastAPI-based application that uses Google’s Gmail API to fetch and display emails based on user-defined search queries. It provides a /search_emails endpoint for email searches and a /oauth2callback endpoint for OAuth2 callbacks. The app requires the environment variables CLIENT_ID, CLIENT_SECRET, and REDIRECT_URI for OAuth2 authentication. These credentials pertain to your Google API and must be set correctly for the application to function as expected.