Recurring payment / subscription handling for Django, supporting different payment gateways
Project description
django-abo
==========
Recurring Payment / Subscription Handling for Django, supporting different payment gateways
**Currently django-abo is in alpha/beta phase, please use with caution!**
## Contribute
If you have a good idea or a specific problem, let us know! We'd love to get some feedback and we need more backends.
If you see a bug or want to contribute code in any way, please create a pull request on GitHub.
If you want to discuss changes (without comitting code), please create an issue on GitHub.
## Supported Backends
* [Paymill](https://www.paymill.com/)
## Installation
```bash
pip install django-abo
```
## Definitions
* *Plan* = something a customer can subscribe to, for example: "Premium Plan, 10$/month"
* *Subscription* = an actual subscription from a customer to a plan
## Usage
### 1. Setup settings
Add `abo` to your `INSTALLED_APPS`:
```python
INSTALLED_APPS = (
# ...
'abo',
)
```
Add these lines to your settings:
```python
ABO_BACKENDS = ('abo.backends.paymill', )
INSTALLED_APPS += ABO_BACKENDS
ABO_DEFAULT_BACKEND = 'abo.backends.paymill'
ABO_BACKENDS_SETTINGS = {
'abo.backends.paymill': {
'PAYMILL_PUBLIC_KEY': 'your public key',
'PAYMILL_PRIVATE_KEY': 'your private key',
'PAYMILL_WEBHOOK_HOST': '' # hint: use ngrok.com for testing
}
}
```
### 2. Setup URLs
Include the payment URLs in your `urls.py`:
```python
urlpatterns = patterns('',
# ...
url(r'payment/^', include('abo.urls')),
)
```
Now, open http://localhost:8000/payment/subscribe/
### 3. Optional: Custom templates
*django-abo* comes with it's own templates so you don't have to start from scratch.
You can override backend specific templates and generic templates.
1. Just create a `abo` subdirectory in your own templates directory and put your own templates there.
1. Make sure they have the same filename as the original ones.
For example, start with [subscription_success.html](https://github.com/ubergrape/django-abo/blob/master/abo/templates/subscription_success.html)
### 4. Optional: Create your own plan and subscription models
*django-abo* has two models you can easily extend. If you have ever swapped Django's default user model for your own, you'll see that the technique is very similar.
#### Example custom Subscription model
Let's say you have an `Organization` model in your `accounts` app and you want every `Subscription` object to belong to an organization.
1. Create an app, if you don't have one already, that should contain your own `Subscription` model. For example `payment`
1. Put your custom `Subscription` model in your `models.py`, subclassing `AbstractSubscription`.
```python
from django.db import models
from accounts.models import Organization
from abo.models import AbstractSubscription
class Organization(models.Model):
name
class Subscription(AbstractSubscription):
organization = models.ForeignKey(Organization, null=True)
```
1. Put this in your settings:
```python
SUBSCRIPTION_MODEL = 'payment.Subscription'
```
1. Create your own View for Paymill:
```python
from abo.backends.paymill.views import PaymillView
class CustomPaymillView(PaymillView):
def form_valid(self, form):
r = super(CustomPaymillView, self).form_valid(form)
# Let's assume you have a middleware that puts the organization in request.
self.subscription.organization = self.request.organization
self.subscription.save()
return r
```
1. Put it in your urls.py
```python
urlpatterns = patterns('',
# ...
url(r'^paymill/subscribe/$', CustomPaymillView.as_view(), name='abo-paymill-authorization'),
url(r'^', include('abo.urls')),
)
#### Custom Plan model
The same works for the `Plan` model. If you created your custom `Plan` model, let *django-abo* know where it is:
```python
PLAN_MODEL = 'payment.Plan'
```
## Inspirations
*django-abo* uses ideas from:
* [Django user model](https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model) - same techniques are used to make my Plan and Subscription model swappable
* [django-getpaid](https://github.com/cypreess/django-getpaid) - abstraction with backends etc.
* [django-paymill](https://github.com/ulfur/django-paymill/) - mainly event/webhook handling
* [django-stripe-payments](https://github.com/eldarion/django-stripe-payments) - some architecture details
Thanks to all contributers of theses projects
==========
Recurring Payment / Subscription Handling for Django, supporting different payment gateways
**Currently django-abo is in alpha/beta phase, please use with caution!**
## Contribute
If you have a good idea or a specific problem, let us know! We'd love to get some feedback and we need more backends.
If you see a bug or want to contribute code in any way, please create a pull request on GitHub.
If you want to discuss changes (without comitting code), please create an issue on GitHub.
## Supported Backends
* [Paymill](https://www.paymill.com/)
## Installation
```bash
pip install django-abo
```
## Definitions
* *Plan* = something a customer can subscribe to, for example: "Premium Plan, 10$/month"
* *Subscription* = an actual subscription from a customer to a plan
## Usage
### 1. Setup settings
Add `abo` to your `INSTALLED_APPS`:
```python
INSTALLED_APPS = (
# ...
'abo',
)
```
Add these lines to your settings:
```python
ABO_BACKENDS = ('abo.backends.paymill', )
INSTALLED_APPS += ABO_BACKENDS
ABO_DEFAULT_BACKEND = 'abo.backends.paymill'
ABO_BACKENDS_SETTINGS = {
'abo.backends.paymill': {
'PAYMILL_PUBLIC_KEY': 'your public key',
'PAYMILL_PRIVATE_KEY': 'your private key',
'PAYMILL_WEBHOOK_HOST': '' # hint: use ngrok.com for testing
}
}
```
### 2. Setup URLs
Include the payment URLs in your `urls.py`:
```python
urlpatterns = patterns('',
# ...
url(r'payment/^', include('abo.urls')),
)
```
Now, open http://localhost:8000/payment/subscribe/
### 3. Optional: Custom templates
*django-abo* comes with it's own templates so you don't have to start from scratch.
You can override backend specific templates and generic templates.
1. Just create a `abo` subdirectory in your own templates directory and put your own templates there.
1. Make sure they have the same filename as the original ones.
For example, start with [subscription_success.html](https://github.com/ubergrape/django-abo/blob/master/abo/templates/subscription_success.html)
### 4. Optional: Create your own plan and subscription models
*django-abo* has two models you can easily extend. If you have ever swapped Django's default user model for your own, you'll see that the technique is very similar.
#### Example custom Subscription model
Let's say you have an `Organization` model in your `accounts` app and you want every `Subscription` object to belong to an organization.
1. Create an app, if you don't have one already, that should contain your own `Subscription` model. For example `payment`
1. Put your custom `Subscription` model in your `models.py`, subclassing `AbstractSubscription`.
```python
from django.db import models
from accounts.models import Organization
from abo.models import AbstractSubscription
class Organization(models.Model):
name
class Subscription(AbstractSubscription):
organization = models.ForeignKey(Organization, null=True)
```
1. Put this in your settings:
```python
SUBSCRIPTION_MODEL = 'payment.Subscription'
```
1. Create your own View for Paymill:
```python
from abo.backends.paymill.views import PaymillView
class CustomPaymillView(PaymillView):
def form_valid(self, form):
r = super(CustomPaymillView, self).form_valid(form)
# Let's assume you have a middleware that puts the organization in request.
self.subscription.organization = self.request.organization
self.subscription.save()
return r
```
1. Put it in your urls.py
```python
urlpatterns = patterns('',
# ...
url(r'^paymill/subscribe/$', CustomPaymillView.as_view(), name='abo-paymill-authorization'),
url(r'^', include('abo.urls')),
)
#### Custom Plan model
The same works for the `Plan` model. If you created your custom `Plan` model, let *django-abo* know where it is:
```python
PLAN_MODEL = 'payment.Plan'
```
## Inspirations
*django-abo* uses ideas from:
* [Django user model](https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model) - same techniques are used to make my Plan and Subscription model swappable
* [django-getpaid](https://github.com/cypreess/django-getpaid) - abstraction with backends etc.
* [django-paymill](https://github.com/ulfur/django-paymill/) - mainly event/webhook handling
* [django-stripe-payments](https://github.com/eldarion/django-stripe-payments) - some architecture details
Thanks to all contributers of theses projects
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-abo-0.1.4.tar.gz
(21.4 kB
view details)
File details
Details for the file django-abo-0.1.4.tar.gz
.
File metadata
- Download URL: django-abo-0.1.4.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c085e29cd5b2ec3f93976bced7c6bd76429a7e1383b9e24cbe0a83ab4fbc9af |
|
MD5 | 0e45683fb663f46cbe24d38cd0389cd6 |
|
BLAKE2b-256 | 17dd3639fd612c31174ee4b0810d1599b511ebef45dd38b2e8156520dabfc77b |