djstripe.management.commands.djstripe_sync_models
Module for the djstripe_sync_model management command to sync all Stripe objects to the local db.
By default this syncs every secret/restricted API key found in the database as well as the keys defined in your Django settings (STRIPE_SECRET_KEY, STRIPE_TEST_SECRET_KEY and STRIPE_LIVE_SECRET_KEY). This means it works with environment-variable-only setups, without first adding keys via the admin.
Invoke like so: 1) To sync all Objects for all API keys: python manage.py djstripe_sync_models
2) To sync all Objects only for sk_test_XXX API key:
python manage.py djstripe_sync_models --api-keys sk_test_XXX
3) To sync all Objects only for sk_test_XXX and sk_test_YYY API keys:
python manage.py djstripe_sync_models --api-keys sk_test_XXX sk_test_XXX
OR
python manage.py djstripe_sync_models --api-keys sk_test_XXX --api-keys sk_test_XXX
4) To only sync Stripe Accounts for all API keys:
python manage.py djstripe_sync_models Account
5) To only sync Stripe Accounts for sk_test_XXX API key:
python manage.py djstripe_sync_models Account --api-keys sk_test_XXX
6) To only sync Stripe Accounts for sk_test_XXX and sk_test_YYY API keys:
python manage.py djstripe_sync_models Account --api-keys sk_test_XXX sk_test_YYY
7) To only sync Stripe Accounts and Charges for sk_test_XXX and sk_test_YYY API keys:
python manage.py djstripe_sync_models Account Charge --api-keys sk_test_XXX sk_test_YYY
Command
Bases: BaseCommand
Sync models from stripe.
help
attribute help
add_arguments
add_arguments(self, parser)
get_api_keys
get_api_keys(self, api_keys: list[str] | None) -> list[str]
Resolve the secret API keys to sync.
If keys are passed explicitly (via --api-keys), they are validated and used as-is, whether or not they exist in the database. Otherwise, every secret/restricted key in the database is used, merged with the keys defined in the Django settings (so environment-variable-only setups work without first adding keys to the admin).
get_default_list_kwargs
get_default_list_kwargs(model, accounts_set, api_key: str)
Returns default sequence of kwargs to sync all Stripe Accounts
get_list_kwargs
get_list_kwargs(self, model, api_key: str)
Returns a sequence of kwargs dicts to pass to model.api_list
This allows us to sync models that require parameters to api_list
:param model: :return: Sequence[dict]
get_list_kwargs_country_spec
get_list_kwargs_country_spec(default_list_kwargs)
Returns sequence of kwargs to sync Country Specs for all Stripe Accounts
get_list_kwargs_fee_refund
get_list_kwargs_fee_refund(default_list_kwargs)
Returns sequence of kwargs to sync Application Fee Refunds for all Stripe Accounts
get_list_kwargs_il
get_list_kwargs_il(default_list_kwargs)
Returns sequence of kwargs to sync Line Items for all Stripe Accounts
get_list_kwargs_pm
get_list_kwargs_pm(default_list_kwargs)
Returns sequence of kwargs to sync Payment Methods for all Stripe Accounts
get_list_kwargs_si
get_list_kwargs_si(default_list_kwargs)
Returns sequence of kwargs to sync Subscription Items for all Stripe Accounts
get_list_kwargs_sis
get_list_kwargs_sis(default_list_kwargs)
Returns sequence of kwargs to sync Usage Record Summarys for all Stripe Accounts
get_list_kwargs_tax_id
get_list_kwargs_tax_id(default_list_kwargs)
Returns sequence of kwargs to sync Tax Ids for all Stripe Accounts
get_list_kwargs_trr
get_list_kwargs_trr(default_list_kwargs)
Returns sequence of kwargs to sync Transfer Reversals for all Stripe Accounts
get_list_kwargs_txcd
get_list_kwargs_txcd(default_list_kwargs)
Returns sequence of kwargs to sync Tax Codes for all Stripe Accounts
get_stripe_account
get_stripe_account(cls, api_key: str, *args, **kwargs)
Get set of all stripe account ids including the Platform Acccount
handle
handle(self, *args, *, api_keys: list[str], fail_on_error = None, **options)
start_sync
start_sync(self, items, instance, api_key: str)
sync_bank_accounts_and_cards
sync_bank_accounts_and_cards(self, instance, *, stripe_account, api_key)
Syncs Bank Accounts and Cards for both customers and all external accounts
sync_model
sync_model(self, model, api_key: str) -> bool
Sync a single model for a single API key.
Returns True if the model synced without any errors, and False if the whole (model, api_key) sync failed or any individual object failed to sync. Per-object errors are reported and counted but don't abort the run. KeyboardInterrupt/SystemExit are never swallowed.