How to add subscriptions to a Replit app
Suppose your Replit app, Client Reports Pro, offers one free sample report. Customers pay $15 a month for live reports, starting at signup. If someone cancels halfway through the month, they can keep reading until the paid month ends. If their renewal fails, they need a link to update their card.
Choose where subscriptions are managed
If you use Replit’s Stripe connector, you’ll need a web app with a backend and a Core or Pro plan. Ask Agent to add the $15 monthly subscription. Start in the Stripe sandbox. When you’re ready to accept customers, use Replit’s Publish pane to connect the Replit Integrated Payments app to your verified live Stripe account and publish the app. To manage Stripe yourself, follow Replit’s setup for your own keys. Use one Stripe method per environment.
For the Spiffy route, you’ll need a paid Spiffy plan with a connected gateway, plus a Replit backend you can publish with a database and sign-in. Spiffy handles recurring billing and the customer portal. Your app keeps track of which customers can read reports.
Set up the offer in Spiffy
- In Products, create a Subscription called Client Reports Pro. Set the price to $15 USD, choose Monthly, and leave the trial off. Create a Subscription checkout with this product. Preview it, confirm it shows $15 per month starting today, then publish and copy the hosted link.
- In Settings → Portal, copy the customer portal link. Enable self-cancellation if customers should be able to cancel there.
- In Account Settings → API → Credentials, create a private API key. Ask Spiffy support to enable your account’s webhook secret. In Replit Secrets, save the API key as
SPIFFY_API_KEYand the webhook secret asSPIFFY_WEBHOOK_SECRET. Keep both values out of Agent chat.
Find the monthly price ID
Ask Agent to run this product lookup once from the server:
Use the stored
SPIFFY_API_KEYas the bearer token for requests tohttps://api.spiffy.co. CallGET /v2/products?search=Client%20Reports%20Proand find Client Reports Pro by its exact name in the results. Use its product ID inGET /v2/products/{id}?include=options. Find the USD price for 1500 cents billed every month underdata.options[].prices[]and return that price’sid. If you can’t identify one exact match, stop and show me what you found.
Save the confirmed price ID in Replit Secrets as SPIFFY_PRICE_ID. Your app will check it when someone subscribes.
Build and publish the Replit app
Replace the two URL placeholders with the checkout and portal links you copied. Paste this prompt into Agent.
For signed-in buyers, add a $15/month Subscribe button linked to [SPIFFY_CHECKOUT_URL] and a Manage billing link to [SPIFFY_PORTAL_URL]. Ask buyers to pay with their verified app email. Create a signed-in /billing/return page that checks their saved report access. Keep reports locked until payment is confirmed.
Create a public HTTPS webhook endpoint that checks Spiffy’s bearer token against SPIFFY_WEBHOOK_SECRET. Use SPIFFY_API_KEY on the server to look up the order and subscription. Open reports only after a successful payment for SPIFFY_PRICE_ID matches one verified buyer. Save the subscription and each paid period in the database. Credit each paid month once, even if a renewal succeeds late or the same notification arrives twice. After a failed renewal, show Manage billing and keep the last paid-through date. A scheduled cancellation keeps reports open through that date. An immediate cancellation closes them as soon as it’s confirmed. Check access on every report request. Give me the paths for the return page and webhook so I can copy their full addresses after publishing.
In Publishing → Adjust settings → Production app secrets, check that all three settings are available to the published backend. Publish the app, then copy the full HTTPS addresses for the return page and the webhook. Use the published deployment address for both.
Connect the published app to Spiffy
- In the checkout’s Custom Thank You Page setting, enter the return page URL and turn off Send Order Details Through URL. Sign in with an unpaid account and open that URL. Reports should still be locked.
- Open Client Reports Pro in Spiffy. In its automations, add Custom Webhooks → Send Webhook once for each of the six events below. Use the same published webhook URL each time. Have the receiver log only the event name and record IDs.
Decide when the app should show reports
At signup, match the checkout email to a verified app account. If the emails differ, resolve the mismatch before opening reports. Save the app user ID, plan ID and paid-through date under the Spiffy subscription ID. That gives your server a record to update at renewal or cancellation and to check each time the buyer opens a report.
| What happens in Spiffy | What the app does |
|---|---|
| Subscription Started | Verify that the first payment succeeded and that the subscription is for Client Reports Pro. Once you confirm payment, save the end of the first paid month. A free trial can trigger this event before the buyer pays. |
| Subscription Payment | Confirm the renewal and move the paid-through date to the end of the newly paid period. This event also covers the first successful payment after a trial. For the initial charge on a plan without a trial, use Subscription Started. |
| Subscription Payment Failed | Show a link to update the card in the portal. Keep the last confirmed paid-through date and apply any extra grace period you've chosen. |
| Subscription Canceling | Show the date access will end. A customer who cancels in the portal keeps the rest of their paid billing cycle. |
| Subscription Canceled | Close reports when a scheduled cancellation takes effect. If your team cancels immediately, close them as soon as the app confirms the cancellation. |
| Subscription Unpaid | Honor any remaining paid time and any grace period you’ve chosen. Close reports when that time runs out. |
Verify the first payment
When Subscription Started arrives, use its order and subscription IDs to fetch GET /v2/orders/{id} with include=items,payments,customer and GET /v2/subscriptions/{id} with include=payments. Match the subscription’s order_id and order_item_id to the purchased item. Check the monthly plan’s price ID against product_option_price_id on the subscription. That field can be empty on the order item.
Find the successful payment for that item and match the checkout email to one verified app account. Save the payment and the month it covers together. If you see the signup charge again in the subscription’s payment history, you’ve already credited that month.
Verify each renewal
Fetch the subscription with include=payments. Spiffy groups retries under the original payment. Find the notification’s payment_id in that subscription’s payments or their retry attempts, and confirm that the matching attempt succeeded.
Use the subscription ID and original payment group ID together as a unique database key. Write that key and the period it covers in one transaction. If the key already exists, the app has already credited the period. For a late notification, check the current subscription state first. An old payment event should never reopen reports after an immediate cancellation.
Keep the paid-through date in your app. Spiffy’s next_payment_at tells you when the next charge is scheduled. It can move forward even if the charge fails. Suppose a buyer’s paid month ends on February 2 and the renewal fails that day. Their cutoff stays February 2. If the retry succeeds on February 3, it pays for the billing month from February 2 to March 2.
If a buyer updates their card, wait for a successful payment before extending access. Check the retry schedule and what happens after the final retry. Those settings determine whether Spiffy or your gateway marks the subscription unpaid, cancels it, or leaves billing active.
Test a signup and a month of billing
In a test app, sign in with an account you control and open the thank-you URL before paying. Reports should still be locked. Then try each case below with test records. Open the report URL directly each time to check what the server lets that buyer read.
| Test | Expected result |
|---|---|
| First payment succeeds | The buyer can open a live report. A different signed-in user still sees the sample. |
| Renewal succeeds | The access end date moves forward once, even if the same event arrives twice. |
| Renewal fails, then succeeds after a card update | The buyer sees Manage billing. The failed charge leaves the paid-through date alone. A successful retry credits the original billing period once. |
| Buyer cancels halfway through the month | The app shows the end date. Reports remain available before it and close when it passes. |
| Merchant cancels immediately | Reports close as soon as the app applies the confirmed cancellation. |
For the Replit Stripe connector, open Preview, confirm you are in the Stripe sandbox, and sign up with Stripe's test card 4242 4242 4242 4242, a future expiration date, and any three-digit CVC. Use Stripe’s billing simulations where available to test upcoming renewals, failed payments, and cancellation.
In Spiffy, use Send Test with a test endpoint that checks receipt and the bearer secret. The sample can omit the event name. Use representative billing events and test records to check report access. If your Spiffy gateway is Stripe, keep card tests in the Stripe sandbox. When your first customer subscribes through Spiffy, check their paid order and report access, then confirm Manage billing opens the customer portal.