Prompt

How do I build a billing system with monthly and annual plans?

Technology / Payments Infrastructure1 observationLast seen Oct 15, 2026

Latest observation

Oct 15, 2026OpenAI APIWeb search: off

Here’s a practical way to build a billing system that supports monthly and annual plans.

1. Define your billing model

Start by deciding what you bill for:

  • Plans: e.g. Basic, Pro, Enterprise
  • Billing intervals: monthly, annual
  • Prices: one price per plan per interval
  • Billing behavior:
    • auto-renew or manual renewal
    • prorations when upgrading/downgrading
    • trials
    • taxes/VAT
    • coupons/discounts
    • refunds

A simple model is:

  • Plan
  • Price
  • Subscription
  • Invoice
  • Payment
  • Customer

2. Suggested database tables

A common schema:

plans

  • id
  • name
  • description
  • active

prices

  • id
  • plan_id
  • currency
  • interval (month or year)
  • amount_cents
  • active

customers

  • id
  • email
  • name
  • billing_address
  • tax_id

subscriptions

  • id
  • customer_id
  • price_id
  • status (trialing, active, past_due, canceled)
  • current_period_start
  • current_period_end
  • cancel_at_period_end
  • trial_end
  • renewal_date

invoices

  • id
  • customer_id
  • subscription_id
  • amount_cents
  • currency
  • status (draft, open, paid, failed, void)
  • due_date
  • period_start
  • period_end

payments

  • id
  • invoice_id
  • provider
  • provider_payment_id
  • amount_cents
  • status
  • paid_at

3. Core billing flow

A. Customer chooses a plan

Example:

  • Basic Monthly: $10/month
  • Basic Annual: $100/year

You create a subscription linked to the selected price.

B. Generate invoice

On subscription start or renewal:

  • create an invoice for the next billing period
  • calculate taxes/discounts
  • attempt payment automatically if stored payment method exists

C. Process payment

If payment succeeds:

  • mark invoice as paid
  • extend subscription period by 1 month or 1 year

If payment fails:

  • mark invoice as failed
  • retry according to a dunning policy
  • possibly move subscription to past_due

4. Monthly vs annual logic

The main difference is the billing interval and renewal period.

Monthly plan

  • invoice every 1 month
  • current_period_end = current_period_start + 1 month

Annual plan

  • invoice every 1 year
  • current_period_end = current_period_start + 1 year

Use a date library to handle:

  • leap years
  • month-end edge cases
  • timezone consistency

5. Handle upgrades and downgrades

When a customer switches plans:

  • If switching mid-cycle, decide whether to:
    • prorate the difference
    • apply changes next renewal
  • Common approach:
    • compute unused value of old plan
    • compute remaining value of new plan
    • invoice/refund the difference

Example:

  • Monthly plan upgraded halfway through the month to annual
  • You charge annual price minus remaining monthly credit

6. Build a billing scheduler

You need a background job that runs daily/hourly:

  • find subscriptions whose current_period_end is near or past due
  • generate renewal invoices
  • charge payment method
  • update subscription dates
  • send receipts and failure emails

This can be done with:

  • cron jobs
  • queue workers
  • scheduled tasks

7. Payment provider integration

Usually you should not store raw card data yourself. Use:

  • Stripe
  • Paddle
  • Braintree
  • Adyen

The provider handles:

  • PCI compliance
  • card tokenization
  • recurring payments
  • webhooks for success/failure

You should listen for webhooks like:

  • invoice.paid
  • invoice.payment_failed
  • customer.subscription.updated
  • charge.refunded

8. Important business rules

Decide in advance:

  • Do annual plans discount compared to monthly x 12?
  • Are renewals automatic?
  • Can users switch between monthly and annual anytime?
  • Do cancellations take effect immediately or end of period?
  • Do you allow partial refunds?
  • How do taxes work by country?
  • What happens if payment fails multiple times?

9. Example subscription state machine

Typical states:

  • trialing
  • active
  • past_due
  • canceled
  • unpaid

Transitions:

  • trialing -> active
  • active -> past_due on failed payment
  • past_due -> active on successful retry
  • active -> canceled

10. Minimal implementation approach

If you want something simple, implement:

  1. Plan and price tables
  2. Customer table
  3. Subscription table
  4. Invoice generation job
  5. Payment provider integration
  6. Webhook handler
  7. Renewal scheduler
  8. Email notifications

11. Example pseudo-flow

User signs up
→ choose Monthly or Annual
→ create subscription
→ create invoice
→ charge payment method
→ if success:
    subscription active
    set next renewal date
→ if failure:
    mark past_due
    retry later

12. Recommended approach if you’re starting from scratch

If possible:

  • use Stripe Billing or a similar service
  • keep your own internal tables for app access, entitlements, and subscription status
  • let the billing provider handle invoicing, proration, retries, and taxes where possible

This reduces complexity a lot.

If you want, I can also give you:

  1. a database schema in SQL,
  2. a backend design in Node/Python/Ruby, or
  3. a Stripe-based implementation example.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.