Simple payment for Django
Project description
Install django-mooch using pip and add mooch to your INSTALLED_APPS.
Add a moochers app:
from collections import OrderedDict from django.conf import settings from django.conf.urls import include, url from mooch.banktransfer import BankTransferMoocher from mooch.postfinance import PostFinanceMoocher from mooch.stripe import StripeMoocher from myapp.models import Thing # Inherit mooch.models.Payment app_name = 'mooch' # This is the app namespace. moochers = OrderedDict(( ('postfinance', PostFinanceMoocher( model=Thing, pspid='thing', live=False, sha1_in=settings.POSTFINANCE_SHA1_IN, sha1_out=settings.POSTFINANCE_SHA1_OUT, app_name=app_name, )), ('stripe', StripeMoocher( model=Thing, publishable_key=settings.STRIPE_PUBLISHABLE_KEY, secret_key=settings.STRIPE_SECRET_KEY, app_name=app_name, )), ('banktransfer', BankTransferMoocher( model=Thing, autocharge=True, # Mark all payments as successful. app_name=app_name, )), ] urlpatterns = [ url(r'', moocher.urls) for moocher in moochers.values() ]
Include the moochers app / URLconf somewhere in your other URLconfs.
Add a payment page:
def pay(request, id): instance = get_object_or_404(Thing.objects.all(), id=id) return render(request, 'pay.html', { 'thing': instance, 'moochers': [ moocher.payment_form(request, instance) for moocher in moochers.values() ], })
Maybe send a confirmation mail when charges happen (an example template for this is actually included with the project). Please note that contrary to most other projects, django-mooch uses the moocher instance as sender, not the class:
from mooch.mail import render_to_mail from mooch.signals import post_charge # The signal handler receives the moocher instance, the payment and # the request. def send_mail(sender, payment, request, **kwargs): render_to_mail('mooch/thanks_mail', { 'payment': payment, }, to=[payment.email]).send(fail_silently=True) # Connect the signal to our moocher instances (moochers may be used more than once on the same website): for moocher in moochers.values(): post_charge.connect(send_mail, sender=moocher)
If you want to differentiate between moochers (for example to send a different mail for bank transfers, because the payment has not actually happened yet) set the sender argument when connecting as follows:
# Some stuff you'll have to imagine... sorry. post_charge.connect(thank_you_mail, moochers['postfinance']) post_charge.connect(thank_you_mail, moochers['stripe']) post_charge.connect(please_pay_mail, moochers['banktransfer'])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-mooch-0.4.2.tar.gz
.
File metadata
- Download URL: django-mooch-0.4.2.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d12322704b313bf97e5af2c94a98e299f3f6424d81e8d68d94dac04adc9731c |
|
MD5 | 1d76b57c181d9f762c8dd2531830c31a |
|
BLAKE2b-256 | 14c345da296bc8c1bf75d3fa49bdb7121dc5147836f117cd2b690eab3a155e52 |
File details
Details for the file django_mooch-0.4.2-py2.py3-none-any.whl
.
File metadata
- Download URL: django_mooch-0.4.2-py2.py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dc78ed6374d46e13c07a87fc2da6df9ba6646cb869f818f574c79fc23c5bea5 |
|
MD5 | 7d358b1b57da01c94b8d9f4fc85a05bf |
|
BLAKE2b-256 | dac9f0c25cd303cd945f09beb65f864e7fd4d4ec54b3c09927e84917b37adbb3 |