payments (certego_saas.apps.payments)

admin.py


class certego_saas.apps.payments.admin.CustomerAdmin(model, admin_site)[source]

Bases: django.contrib.admin.options.ModelAdmin

Django’s ModelAdmin for Customer.

cache.py


certego_saas.apps.payments.cache.cache_memoize(*args, **kwargs)[source]

Custom cache_memoize.

certego_saas.apps.payments.cache.get_cache()[source]

Attempts to get the certego_saas.payments cache otherwise fallback to default cache

consts.py


exceptions.py


exception certego_saas.apps.payments.exceptions.CustomerCantSubmitMultipleProfilesException(detail=None, code=None)[source]

Bases: rest_framework.exceptions.PermissionDenied

exception certego_saas.apps.payments.exceptions.CustomerCantSubmitPrivateException(detail=None, code=None)[source]

Bases: rest_framework.exceptions.PermissionDenied

exception certego_saas.apps.payments.exceptions.CustomerWithoutSubscription(appname: str, detail=None, code=None)[source]

Bases: rest_framework.exceptions.APIException

Raised when a given user/customer has no active subscription on stripe.

models.py


class certego_saas.apps.payments.models.AppChoices(value)[source]

Bases: django.db.models.enums.TextChoices

An enumeration.

class certego_saas.apps.payments.models.Customer(*args, **kwargs)[source]

Bases: django.db.models.base.Model

A wrapper class over stripe-python SDK combined with django’s User model that provides utilities for retrieving customer and their subscription details.

exception CustomerWithoutSubscription(appname: str, detail=None, code=None)

Bases: rest_framework.exceptions.APIException

Raised when a given user/customer has no active subscription on stripe.

create_billing_portal_session(return_url) → stripe.api_resources.billing_portal.session.Session[source]

uses :meth:stripe.billing_portal.Session.create.

create_checkout_session(price_id, success_url, cancel_url) → stripe.api_resources.checkout.session.Session[source]

uses :meth:stripe.checkout.Session.create.

get_stripe_customer() → stripe.api_resources.customer.Customer[source]

Returns instance of stripe.Customer for user.

  • (uses :meth:stripe.Customer.retrieve()

class certego_saas.apps.payments.models.Subscription(*args, **kwargs)[source]

Bases: certego_saas.ext.models.AppSpecificModel

Each Customer can have maximum len(AppChoices) number of related Subscription objects; one subscription for each app name (i.e. DRAGONFLY, INTELOWL, etc.).

property can_submit_private

metadata.submission_type == "private"

property concurrent_profiles

metadata.max_submissions

get_subscription(expand=None) → stripe.api_resources.subscription.Subscription[source]

Returns customer’s active subscription.

  • (uses :meth:stripe.Subscription.retrieve()

property monthly_submissions_limit

metadata.max_submissions

property priority

metadata.priority

subscribed_product() → stripe.api_resources.product.Product[source]

Product details for the active subscription.

permissions.py


class certego_saas.apps.payments.permissions.UserHasActiveSubscription[source]

Bases: rest_framework.permissions.BasePermission

Allows access to customers who have an active stripe subscription.

  • Should be used along with rest_framework.permissions.IsAuthenticated.

serializers.py


class certego_saas.apps.payments.serializers.InvoiceSerializer(*args, **kwargs)[source]

Bases: rest_framework.serializers.Serializer

Useful fields from stripe.Invoice

class certego_saas.apps.payments.serializers.ProductPriceSerializer(*args, **kwargs)[source]

Bases: rest_framework.serializers.Serializer

Represents a combination of stripe.Product and stripe.Price.

class certego_saas.apps.payments.serializers.SubscriptionSerializer(*args, **kwargs)[source]

Bases: rest_framework.serializers.Serializer

Useful fields from stripe.Subscription + custom fields

throttling.py


class certego_saas.apps.payments.throttling.SubscriptionRateThrottle[source]

Bases: rest_framework.throttling.BaseThrottle

Restrict access if User.stripe.monthly_submissions_limit has been exhausted.

allow_request(request, view)[source]

Return True if the request should be allowed, False otherwise.

wait()[source]

calculates distance in seconds from current time to 1st of next month.

utils.py


certego_saas.apps.payments.utils.get_default_product() → dict[source]

returns default product based on whether stripe is running in livemode or testmode

certego_saas.apps.payments.utils.get_products() → List[Dict][source]

Returns list of stripe plans/products.

Alias for stripe.Price.list(expand=["data.product"]).

certego_saas.apps.payments.utils.get_products_prices_map() → Dict[str, Dict][source]

Returns dict mapping of stripe plans/products.

Alias for stripe.Price.list(expand=["data.product"]).