Skip to main content

Simple payment for Django

Project description

  1. Install django-mooch using pip and add mooch to your INSTALLED_APPS.

  2. Add the following settings:

  3. Add a moochers app:

    from django.conf.urls import include, url
    from mooch.postfinance import PostFinanceMoocher
    from mooch.stripe import StripeMoocher
    from myapp.models import Thing  # Inherit mooch.models.Payment
    postfinance_moocher = PostFinanceMoocher(model=Thing)
    stripe_moocher = StripeMoocher(model=Thing)
    moochers = [postfinance_moocher, stripe_moocher]
    app_name = 'mooch'  # This is important
    urlpatterns = [
        url(r'^postfinance/', include(postfinance_moocher.urls)),
        url(r'^stripe/', include(stripe_moocher.urls)),
  4. Include the moochers app / URLconf somewhere in your other URLconfs.

  5. 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
  6. Maybe send a confirmation mail when charges happen (an example template for this is actually included with the project):

    from mooch.mail import render_to_mail
    from mooch.signals import post_charge
    # The signal handler receives the moocher class, the payment and
    # the request.
    def send_mail(sender, payment, **kwargs):
        render_to_mail('mooch/thanks_mail', {
            'payment': payment,
        }, to=[]).send(fail_silently=True)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-mooch, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size django_mooch-0.1.0-py2.py3-none-any.whl (14.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size django-mooch-0.1.0.tar.gz (10.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page