Learn how to integrate Lovable with Stripe in simple, step-by-step instructions. Set up secure, seamless payments to boost your business efficiency.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
config.ts in your project’s root directory.
export const STRIPESECRETKEY = 'YOURSTRIPESECRET_KEY';
export const STRIPEPUBLISHABLEKEY = 'YOURSTRIPEPUBLISHABLE_KEY';
index.html).<head> or just before the closing </body> tag:
stripeIntegration.ts in your project’s source directory.
import Stripe from 'stripe';
import { STRIPESECRETKEY } from './config';
const stripe = new Stripe(STRIPESECRETKEY, {
apiVersion: '2020-08-27',
});
export default stripe;
createCheckoutSession.ts in your source directory.
import type { Request, Response } from 'express';
import stripe from './stripeIntegration';
export const createCheckoutSession = async (req: Request, res: Response) => {
try {
const session = await stripe.checkout.sessions.create({
paymentmethodtypes: ['card'],
mode: 'payment',
line_items: [{
price_data: {
currency: 'usd',
product_data: {
name: 'Test Product',
},
unit_amount: 2000,
},
quantity: 1,
}],
success_url: 'https://your-success-url.com/success',
cancel_url: 'https://your-cancel-url.com/cancel',
});
res.status(200).json({ sessionId: session.id });
} catch (error: any) {
res.status(500).json({ error: error.message });
}
};
router.ts or similar) where you define your API endpoints.
import express from 'express';
import { createCheckoutSession } from './createCheckoutSession';
const router = express.Router();
router.post('/create-checkout-session', createCheckoutSession);
export default router;
/create-checkout-session are handled accordingly.
import { loadStripe } from '@stripe/stripe-js';
import { STRIPEPUBLISHABLEKEY } from './config';
const stripePromise = loadStripe(STRIPEPUBLISHABLEKEY);
export const redirectToCheckout = async () => {
const stripe = await stripePromise;
if (!stripe) {
console.error('Stripe failed to load.');
return;
}
const response = await fetch('/create-checkout-session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
});
const { sessionId } = await response.json();
const { error } = await stripe.redirectToCheckout({ sessionId });
if (error) {
console.error('Stripe Checkout error', error);
}
};
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.