Skip to main content

django-askell

Áskell integration for Django and Wagtail (optional)

Build Status

Installation

pip install django-askell

Add the app to your INSTALLED_APPS

INSTALLED_APPS = [
    # ... other apps
    
    'askell',

    # ... other apps
]

Add the app urls to your project urls.py:

from django.urls import path, include

from askell.urls import urls as askell_urls

urlpatterns = [
    # ... your other urls
    path('askell/', include(askell_urls)),
    # ... more urls
]

Then go to Áskell, create a public/private key pair and add these keys to your settings file or environment in your project:

ASKELL_PUBLIC_KEY = 'my-public-key'
ASKELL_SECRET_KEY = 'my-secret-key'

To complete your setup, it is recommended to set up a webhook in Áskell's dashboard pointing to your website's URL. If your website has the domain https://example.com and you have added the app urls to your project, then the view that receives the webhooks is located at https://example.com/askell/webhook/.

Create your webhook, and then obtain your webhook secret and put it in your settings file or environment in your project:

ASKELL_WEBHOOK_SECRET = 'my-secret'

Webhook handlers

You can register new webhook handlers if you want to implement custom logic when something happens in Áskell. These are the default webhook handlers:

askell.webhook_handlers.payment_created
askell.webhook_handlers.payment_changed

Registering a new handler is simple:

from askell.webhooks import register_webhook_handler

@register_webhook_handler
def payment_settled(request, event, data):
    from .models import Payment
    if event == 'payment.changed':
        if data['state'] == 'settled':
            # do something here
    return True

V2 checkout sessions

For product/contract based subscriptions, create a scoped checkout session on your Django server and pass the returned browser-safe token to askell.js. Do not expose ASKELL_SECRET_KEY in the browser.

from askell.client import client


def create_membership_checkout(request):
    result = client.create_checkout_session(
        sales_channel='memberships',
        user=request.user,
        metadata={'source': 'membership-page'},
        expires_in_seconds=3600,
    )
    if result['status'] != 'success':
        # handle result['response'] or result['message']
        ...
    return JsonResponse({'sessionToken': result['response']['token']})

The package also includes a logged-in helper endpoint at /askell/checkout-session/. You can post a sales channel reference to it, or subclass CheckoutSessionView and set sales_channel to keep the channel fixed server-side.

from askell.views import CheckoutSessionView


class MembershipCheckoutSessionView(CheckoutSessionView):
    sales_channel = 'memberships'

Mount the widget with the token returned by your Django backend:

<script src="https://js.askell.is/v2/askell.js"></script>
<div id="askell-checkout"></div>
<script>
  fetch("/membership/checkout-session/", { method: "POST" })
    .then((response) => response.json())
    .then(({ sessionToken }) => {
      Askell.mountCheckout("#askell-checkout", {
        sessionToken: sessionToken,
        onSuccess: function (result) {
          console.log(result.contractId);
        }
      });
    });
</script>

Releasing

Bump the version in setup.py and release.sh, add release notes below and commit. Then run:

./docker-release.sh

This builds the package and uploads it to PyPI from a python:3.12-slim container, so it doesn't depend on your local Python. It reads PyPI credentials from ~/.pypirc or the TWINE_USERNAME and TWINE_PASSWORD environment variables, and refuses to run with uncommitted changes.

TODO

  • Document webhook handlers
  • [ ] Document views
  • Add V2 checkout session helper
  • Document product/contract entitlement helpers

Release notes

Version 0.1.26

  • The default payment_changed webhook handler creates the payment if payment.created hasn't been handled yet, instead of raising Payment.DoesNotExist
  • Add docker-release.sh for building and uploading releases from a Docker container

Version 0.1.25

  • Add V2 checkout session client helper and Django view for scoped checkout sessions
  • Add README documentation for creating browser-safe checkout sessions for askell.js
  • Add release extra dependencies and safer PyPI release scripts

Version 0.1.24

  • Checkout support updated

Version 0.1.23

  • Set default auto field to BigAutoField to prevent projects creating migrations for django-askell

Version 0.1.22

  • Support for refunding single payments

Version 0.1.21

  • Fixing a bug in the settings module

Version 0.1.20

  • Adding a setting to disable default webhook handlers. Also a new function to unregister webhook handlers.

Version 0.1.19

  • Adding payment method import method

Version 0.1.7

  • Fixed a bug in creating a customer

Version 0.1.6

  • Added support for multiple states

Version 0.1.5

  • Fixed a bug with imports

Version 0.1.4

  • Fixed a bug in the Payment detail view

Version 0.1.3

  • Fixed a bug in webhook handler

Version 0.1.2

  • Added logging mechanism for debugging

Version 0.1.1

  • Changed the way webhook handlers are imported and documented

Version 0.1

  • Support for creating Payment objects
  • Support for webhooks processing and verification
  • Default webhook handlers for payment created, and changed

Metadata

Release files for django-askell 0.1.26

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-askell 0.1.26
File Size Uploaded Provenance Actions
django_askell-0.1.26.tar.gz 16.5 kB Without provenance Details for django_askell-0.1.26.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-askell 0.1.26
File Interpreter ABI Platform Actions
django_askell-0.1.26-py3-none-any.whl Python 3 none any Details for django_askell-0.1.26-py3-none-any.whl

Total release size: 36.9 kB

Release files / django_askell-0.1.26.tar.gz

Download URL django_askell-0.1.26.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b1e18ced677cbff59eceb641746b02a84d7c5f5cf9cbfc8dc4e6d2e156bda6a3
BLAKE2b-256 checksum
How to use checksums
ca5d396544ee44bc8e739176ff83f4b1776fa6cca1158ac3b802fc7ba52357c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / django_askell-0.1.26-py3-none-any.whl

Download URL django_askell-0.1.26-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f1647f5a94691a6acb91dd76443238d2d99c73fd955bddee53749885a34a6ad
BLAKE2b-256 checksum
How to use checksums
445816af584d728419d202949a2524e1536da381d05fbd3e2774399e829020b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for django-askell 0.1.26

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page