Models

models Module

class spreedly.models.Fee(*args, **kwargs)[source]

A Fee for a given Plan.

Attr plan:ForeignKey(Plan)
Attr name:CharField(max_length=100)
Attr group:ForeignKey(FeeGroup)
Attr default_amount:
 DecimalField(default=0)
add_fee(user, description, amount=None)[source]

add a fee to the given user, with description and amount. if amount is not passed, then it will use default_amount if it is greater than 0.

if 404 or 422 are returned, the default action is not to save the line item to the db, this can be overriden with the setting SPREEDLY_SAVE_ON_FAIL, but it is not recomended as who knows what will happen.

Parameters:
  • user – the user to bill for the fee. they must be subscribed to self.plan
  • description – The description of the fee to appear on the invoice
  • amount – The amount to bill or None
Raises :

ValueError if the user is not subscribed to the plan or is subscribed to a different plan.

Raises :

Http404 if spreedly can’t find the plan, user, etc.

Raises :

HttpUnprocessableEntity if spreedly raised 422 for some reason.

class spreedly.models.FeeGroup(*args, **kwargs)[source]

FeeGroup(name)

class spreedly.models.LineItem(*args, **kwargs)[source]

This is an instance of a fee

class spreedly.models.Plan(*args, **kwargs)[source]

Subscription plan

start_trial(user)[source]

Check if a user is eligibile for a trial on this plan, and if so, start a plan.

Parameters:user – user object to check
Returns:py:class:Subscription
Raises :py:exc:Plan.NotEligibile if the user is not eligibile
trial_eligible(user)[source]

Is a customer/user eligibile for a trial? :param user: auth.User

class spreedly.models.PlanManager[source]

Manager that handles syncing plans and finding enabled plans

enabled()[source]
Returns:Returns all enabled Plans
sync_plans()[source]

Gets a full list of plans from spreedly, and updates the local db to match it

class spreedly.models.Subscription(*args, **kwargs)[source]

Class that manages the details for a specific auth.User‘s subscription to a plan. Since a user can only have one subscription, this is sometimes treated as a user profile class.

add_fee(fee, units, description)[source]

Add a fee to the subscription

Parameters:
  • feeFee to add to the linked user
  • units – the number of units the charge is for (100kb, 4 nights, etc.)
  • description – a description of the charge
Returns:

None

Raises :

Http404 if incorrect subscriber, HttpUnprocessableEntity for any other 422 error

allow_free_trial()[source]

Allow a free Trial

Returns:Subscription
Raises :Exception (of some kind) if bad juju
create_complimentary_subscription(time, unit, feature_level)[source]
Raises :NotImplementedError cause it isn’t implemented
ending_this_month[source]

Will this plan end within the next 30 days

subscription_active[source]

gets the status based on current active status and active_until

update_subscription(data=None)[source]

update a subscription with supplied data

Project Versions

Table Of Contents

Previous topic

spreedly

Next topic

Views

This Page