Stripe Setup
Prodly uses Stripe to handle subscription payments and credit purchases. All plan‑specific settings, including Stripe Price IDs, are managed directly from the Admin Panel → Settings page. This guide walks you through the complete Stripe integration – from creating products to configuring webhooks – without ever needing to edit code manually.
Prerequisites
- A Stripe account (sign up at stripe.com )
- Your Prodly application already installed and running
- Admin access to the Prodly admin panel
Step‑by‑Step Integration
1. Create a Stripe Account and Get API Keys
- Go to the Stripe Dashboard and log in (or create a new account).
- If you haven’t already, activate your account by providing business details (you can use test mode first).
- Navigate to Developers → API keys.
- Copy the following keys:
- Publishable key (starts with
pk_test_) - Secret key (starts with
sk_test_)
- Publishable key (starts with
Use test keys during development. Switch to live keys only when you are ready to go live.
2. Add Stripe Environment Variables
Add the keys to your .env.local file:
STRIPE_SECRET_KEY=sk_test_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_WEBHOOK_SECRET= # You will fill this later after creating the webhook-
STRIPE_SECRET_KEY– your secret key (keep it safe, never expose it client‑side). -
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY– your publishable key (safe to use on the frontend). -
STRIPE_WEBHOOK_SECRET– will be set after configuring the webhook (step 6).
3. Create Products and Prices in Stripe
In Stripe, products represent what you sell, and prices define the cost and billing interval.
-
In the Stripe Dashboard, go to Products → Add Product.
-
Create two products with monthly recurring prices:
-
Pro – e.g., $15.00/month
- After creation, copy the Price ID (starts with
price_). - Example:
price_1T4Gva0nFlRU9YFbswMyH3tw
- After creation, copy the Price ID (starts with
-
Enterprise – e.g., $50.00/month
- Copy its Price ID as well.
- Example:
price_1T4Gvb0nFlRU9YFbswMyH4ux
-
4. Enter Price IDs into the Admin Panel
-
Log in to your Prodly admin panel.
-
Navigate to Admin Panel → Settings.
-
You will see groups like General, Free Plan, Pro Plan, Enterprise Plan.
-
In the Pro Plan group, locate the setting for the Stripe Price ID (e.g., Stripe Price ID for Pro). If it doesn’t exist, you can add it directly in the database (the admin panel automatically displays all settings from the settings table).
-
Key: Stripe Price ID for Pro
-
Value: paste your Pro Price ID (e.g.,
price_1T4Gva0nFlRU9YFbswMyH3tw) -
Plan price in cents:
1500
-
In the Enterprise Plan group, do the same for Stripe Price ID for Enterprise.
-
Click Save All at the top or bottom of the page.
settings table via your database client. After insertion, they will be editable in the admin panel. 5. Checkout Session Creation (Already Implemented)
Your application already contains the necessary API route to create a Stripe Checkout session.
File: src/app/api/stripe/create-checkout-session/route.ts
This endpoint reads the appropriate Price ID from the database based on the selected plan, so no code changes are needed. It returns a session URL that redirects the user to Stripe’s payment page.
6. Configure the Webhook in Stripe Dashboard
The webhook listens for events from Stripe (successful payment, subscription updates) and updates your database accordingly.
For Local Development
You need to expose your local server to the internet so Stripe can reach it. Use Stripe CLI (recommended) or ngrok.
A. Using Stripe CLI:
-
Install the Stripe CLI from stripe.com/docs/stripe-cli .
-
Run:
stripe login
stripe listen --forward-to localhost:3000/api/stripe/webhookThe CLI will output a webhook signing secret. Copy it and add to your .env.local:
STRIPE_WEBHOOK_SECRET=whsec_...B. Using ngrok:
-
Start your Next.js app (
npm run dev). -
In another terminal, run:
ngrok http 3000-
Copy the generated HTTPS URL (e.g.,
https://abc123.ngrok.io). -
In Stripe Dashboard, go to Developers → Webhooks → Add endpoint.
-
Enter your ngrok URL +
/api/stripe/webhook(e.g.,https://abc123.ngrok.io/api/stripe/webhook). -
Select events to listen to:
-
checkout.session.completed -
customer.subscription.updated -
customer.subscription.deleted
- After creation, click Click to reveal in the Signing secret section and copy the secret. Add it to your
.env.localasSTRIPE_WEBHOOK_SECRET.
For Production
When your app is live on Vercel (or another platform), create a new webhook endpoint pointing to:
https://yourdomain.com/api/stripe/webhookSubscribe to the same events, copy the signing secret, and set it as STRIPE_WEBHOOK_SECRET in your hosting environment (e.g., Vercel Environment Variables).
7. Webhook Handler (Already Implemented)
Your project includes a webhook handler at src/app/api/stripe/webhook/route.ts. It processes Stripe events and updates user credits accordingly. When a checkout.session.completed event is received, it:
-
Extracts the user ID from
client_reference_id -
Determines which Price ID was used
-
Looks up the corresponding credits from the plan configuration (which can also be stored in settings, e.g.,
pro_credits,enterprise_credits)
Increments the user’s credits_remaining in the database
No additional coding is required – just ensure your database has the necessary columns and functions (like increment_credits).
8. Test the Integration
-
Make sure your app is running and the webhook is listening (Stripe CLI or ngrok active).
-
Go to your pricing page and click Subscribe on a plan.
-
You will be redirected to Stripe’s Checkout page. Use the test card:
-
Card number:
4242 4242 4242 4242 -
Expiry: any future date
-
CVC: any 3 digits
-
-
After successful payment, you should be redirected back to your app.
-
Check that the user’s credits have increased. You can verify in the database or via the user dashboard.
-
In Stripe Dashboard, navigate to Events to confirm that the
checkout.session.completedevent was sent and received successfully.
Admin Panel Settings Reference
After completing the steps above, your settings table should contain entries similar to these:
Stripe / Plan Keys
| Key | Example Value | Description |
|---|---|---|
| stripe_price_id_pro | price_1T4Gva0nFlRU9YFbswMyH3tw | Price ID for the Pro monthly plan |
| stripe_price_id_enterprise | price_1T4Gvb0nFlRU9YFbswMyH4ux | Price ID for the Enterprise monthly plan |
| pro_credits | 500 | Credits granted for Pro plan |
| enterprise_credits | 5000 | Credits granted for Enterprise plan |
You can edit these values anytime via the admin panel – the changes take effect immediately without redeploying.
🆘 Troubleshooting
| Problem | Solution |
|---|---|
| Checkout session not created (500 error) | Check that STRIPE_SECRET_KEY is set correctly and that the Price ID exists in your Stripe account. Also verify that the Price ID is correctly entered in the admin panel. |
| Webhook returns 400 (signature mismatch) | Ensure the STRIPE_WEBHOOK_SECRET in your environment matches the signing secret shown in the Stripe Dashboard for your endpoint. |
| User credits not updated after payment | Check the webhook logs in Stripe Dashboard. Make sure your endpoint is reachable and that the event is being processed. Verify the database update logic in the webhook handler. |
| Price ID not appearing in admin panel | Insert the keys manually into the settings table via your database client. They will then be editable in the admin UI. |
| Stripe CLI not forwarding | Make sure you are running stripe listen in the correct directory and that your Next.js app is running on port 3000. |
Conclusion
You have now fully integrated Stripe payments into Prodly without writing any code. All plan configurations are managed through the admin panel, making future updates simple and safe. Users can purchase subscriptions, and credits are automatically added upon successful payment.
For further customization, refer to the Stripe API documentation and the Prodly source code.