This app can be used to add support for the spreedly subscription service to your django app.
Note this app is still in development, if you find issues or bugs, please submit them here:
django-paid-subscriptions issue tracker
The app currently covers:
- syncing subscriptions with your spreedly account.
- listing available subscriptions on your site.
- letting a user choose and signup for a subscription from your site.
- letting spreedly checkin and relay currently user subscription info.
- disabling part of your site for non-subscribed users (optional)
- redirecting users to the subscription page when their subscription expires.
This code is currently only tested on django trunk, but should work without issue on 1.1
- python 2.5
- pyspreedly <- included as a submodule of this project
- LOGIN_URL variable in your settings file
-
Checkout the project into a folder called
spreedly
on your python path:git clone git:https://github.com/chrisdrackett/django-spreedly.git spreedly
-
Update the submodules (this gets the python tender API wrapper)
cd spreedly/ git submodule update --init
-
Add
spreedly
to your installed apps, and add the following tosettings.py
:SPREEDLY_AUTH_TOKEN = 'your auth token' SPREEDLY_SITE_NAME = 'your site name' SITE_URL = 'https://www.yoursitesurl.com'
-
The following can also be added, they are optional:
SPREEDLY_RETURN_URL = '/welcome/'
SPREEDLY_URL ='/register/'
SPREEDLY_LIST_TEMPLATE = 'path/to/your/template.html'
SPREEDLY_USERS_ONLY = True
URL paths that a user without a subscription can vist without being redirected to the subscription list:
SPREEDLY_ALLOWED_PATHS = ['/login', '/logout']
SPREEDLY_CONFIRM_EMAIL = 'path/to/your/template.txt'
SPREEDLY_CONFIRM_EMAIL_SUBJECT = 'This is a new subject'
SPREEDLY_EMAIL_SENT_TEMPLATE = 'path/to/your/template.html'
SPREEDLY_GIFT_EMAIL = 'path/to/your/template.txt'
SPREEDLY_GIFT_EMAIL_SUBJECT = 'This is a new subject'
SPREEDLY_SITE_URL = 'something.com'
-
Add the middleware to your
settings.py
MIDDLEWARE_CLASSES:'spreedly.middleware.SpreedlyMiddleware'
-
Add the following to urlpatterns in
urls.py
:import spreedly.settings as spreedly_settings (r'^%s' % spreedly_settings.SPREEDLY_URL[1:], include('spreedly.urls')),
-
Run syncdb
After the app is installed, you can start creating subscriptions!
The app is designed to work with the following flow:
- new user enters user information and chooses a plan
- inactive user object is created and the user is sent an email with a link to spreedly to pay for plan
- after successful payment, user is directed back to your site
- the app will check with spreedly for users status
- if the user has an active subscription, the user object will be set to active and the user will be given a login url
If you want to make your site subscription only you can set the SPREEDLY_USERS_ONLY to True. This will redirect any anonymous user (or user with an inactive subscription) who visits a page not in the SPREEDLY_ALLOWED_PATHS list to your SPREEDLY_URL
Spreedly is sent a redirect url that will check and see if the user has signed up and activate their account. A user may not click on this link and in that case their account won't be active, unless:
Spreedly will ping a url with subscriptions change, and django-spreedly is setup to listen for this.
in your spreedly setting is the following: 'Subscribers Changed Notification URL'
if you are using the default settings for django-spreedly, the url you should put in this field is:
https://mysite.com/subscriptions/spreedly_listener/
if you changed SPREEDLY_URL, you'll need to substitute that for subscriptions.
If you want to add a fallback, you can also add the following to your login view after a user is logged in (but before you check if they are active):
from spreedly.functions import get_subscription
if not user.is_active:
get_subscription(user)