Utilities

Last Updated 2018-05-24

Subscriber Has Active Subscription Check

utils.subscriber_has_active_subscription(plan=None)

Helper function to check if a subscriber has an active subscription.

Throws improperlyConfigured if the subscriber is an instance of AUTH_USER_MODEL and get_user_model().is_anonymous == True.

Activate subscription rules (or):
  • customer has active subscription
If the subscriber is an instance of AUTH_USER_MODEL, active subscription rules (or):
  • customer has active subscription
  • user.is_superuser
  • user.is_staff
Parameters:
  • subscriber (dj-stripe subscriber) – The subscriber for which to check for an active subscription.
  • plan (Plan or string (plan ID)) – The plan for which to check for an active subscription. If plan is None and there exists only one subscription, this method will check if that subscription is active. Calling this method with no plan and multiple subscriptions will throw an exception.

Supported Currency Choice Generator

utils.get_supported_currency_choices()

Pull a stripe account’s supported currencies and returns a choices tuple of those supported currencies.

Parameters:api_key (str) – The api key associated with the account from which to pull data.

Clear Expired Idempotency Keys

utils.clear_expired_idempotency_keys()

Convert Stripe Timestamp to Datetime

utils.convert_tstamp()

Convert a Stripe API timestamp response (unix epoch) to a native datetime.

Return type:datetime

Friendly Currency Amount String

utils.get_friendly_currency_amount(currency)