HyperSaaS
BackendSubscriptions

Management Commands

Django commands for setting up plans in Stripe and syncing Stripe data.

One command pushes your plans to Stripe; the others pull Stripe's data into the local database, for initial setup, disaster recovery or reconciliation.

sync_stripe_plans

Makes Stripe's products and prices match subscriptions/plans.py, then pulls them into the database:

python manage.py sync_stripe_plans --dry-run   # show what would change
python manage.py sync_stripe_plans
python manage.py sync_stripe_plans --skip-db   # change Stripe only
OptionDescription
--dry-runOnly show what would change
--skip-dbDon't pull the result into this database

What it does:

  • Creates or updates one product per paid plan, tagged with metadata.plan
  • Creates monthly and yearly prices with lookup keys (pro_month, pro_year). A changed price becomes a new price that takes over the lookup key; the old one is archived, and existing subscribers keep paying it until they change plan
  • Archives products that aren't a plan
  • Sets the billing portal's default configuration to offer exactly these plans and prices

Running it again changes nothing. Run it in test mode while developing, and once with the live key before launch. See Plans.

pull_stripe

Orchestrates a full sync of all Stripe data:

python manage.py pull_stripe

Runs these commands in sequence:

  1. update_stripe_products — Syncs products and prices
  2. update_stripe_customers — Syncs customer records
  3. update_stripe_subscriptions — Syncs subscription data

update_stripe_products

Fetches all products and prices from Stripe and updates local records:

python manage.py update_stripe_products

What it does:

  • Creates/updates Product records (id, name, description, active)
  • Creates/updates Price records (id, product, amount, frequency, currency)
  • Copies each product's metadata.plan into Product.plan
  • Syncs feature mappings from product metadata

update_stripe_customers

Links Stripe customers to the accounts their metadata.user_id names:

python manage.py update_stripe_customers
python manage.py update_stripe_customers --limit 50
python manage.py update_stripe_customers --starting_after cus_abc123
OptionDefaultDescription
-l, --limit100Max customers to fetch (max 100)
-s, --starting_after—Pagination cursor (Stripe customer ID)

What it does:

  • Fetches customers from Stripe
  • Creates or updates StripeUser records for customers whose metadata.user_id is an account here, which checkout sets
  • Skips every other customer. It never matches a customer to an account by email, and never creates accounts

update_stripe_subscriptions

Fetches subscriptions and updates local records:

python manage.py update_stripe_subscriptions
python manage.py update_stripe_subscriptions --limit 50
python manage.py update_stripe_subscriptions --starting_after sub_abc123
OptionDefaultDescription
-l, --limit100Max subscriptions to fetch (max 100)
-s, --starting_after—Pagination cursor (Stripe subscription ID)

What it does:

  • Fetches subscriptions from Stripe
  • Creates/updates Subscription records with all fields
  • Recreates SubscriptionItem records from subscription line items
  • Links subscriptions to StripeUser records

When to Use

ScenarioCommand
Initial deploymentsync_stripe_plans
After changing plans.pysync_stripe_plans
After restoring databasepull_stripe
Verify webhook data integritypull_stripe
Paginate through large customer listsupdate_stripe_customers --limit 100 --starting_after cus_...
Debug subscription issuesupdate_stripe_subscriptions

Docker Usage

# Local
docker compose -f docker-compose.local.yml run --rm django python manage.py pull_stripe

# Production
docker compose -f docker-compose.production.yml run --rm django python manage.py pull_stripe

On this page