Skip to main content

Wrapper package for python stripe with Django and/or DRF

Project description

Django Silly Stripe

It is a wrapper based on the use of python's stripe API. The aim is to make it as simple as possible to use.

For now, only stripe checkout is supported, in order to handle subscriptions only.

Installation

pip install django-silly-stripe

./manage.py migrate

settings.py

INSTALLED_APPS = [
    'django_silly_stripe',  # <-- BEFORE admin>

    # ...
]


SILLY_STRIPE = {
    # keys (should be imported from environment)
    'DSS_SECRET_KEY': 'sk_xxxxxx'
    'DSS_PUBLIC_KEY': 'pk_xxxxxx',
    'DSS_RESTRICTED_KEY': 'rk_xxxxxx',  # optionnal
    'DSS_WEBHOOK_SECRET': 'wk_xxxxxx',
    # ... read the wiki to see more options
}

urls.py

urlpatterns = [
    # ...
    path('', include('django_silly_stripe.urls')),
]

Once you have created your products (and prices) witin stripe online:

Go in the admin interface, and press the big green button "Stripe: get prices & products" to populate the database with them.

Classic Django usage

In a classic template some_page.html

<script>
// Subscribe button
    let subscribe = document.getElementById('subscribe');
    document.addEventListener('DOMContentLoaded', () => {
        subscribe.addEventListener('click', () => {
            axios({
            method: 'post',
            url: '{% url "dss_checkout" %}',
            data: {
                // the price id should be given via the context of the view,
                // not hard coded like here
                'priceId': 'price_1NT4BqCyzfytDBEqarffvBjA',
            },
            headers: {
                'X-CSRFToken': '{{ csrf_token }}',
            }
            }).then(response => {
            console.log(response.data);
            window.location.href = response.data.url;
            }).catch(error => {
            console.log(error);
            })
        });
    });


// Cancel subscription button
  let cancelSub = document.getElementById('cancel-sub');
  document.addEventListener('DOMContentLoaded', () => {
    cancelSub.addEventListener('click', () => {
      console.log('cancel sub')
      axios({
        method: 'put',
        url: '{% url "dss_subscription_cancel" %}',
        data: {
          'subId': '{{ subscription.id }}',
        },
        headers: {
          'X-CSRFToken': '{{ csrf_token }}',
        }
      }).then(response => {
        console.log(response.data);
        location.reload();
      }).catch(error => {
        console.log(error);
      })
    });
  });
</script>

SPA Django usage

Same as classic, but use the headers you need instead of CSRF tokens.

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-silly-stripe-1.0.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

django_silly_stripe-1.0.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file django-silly-stripe-1.0.0.tar.gz.

File metadata

  • Download URL: django-silly-stripe-1.0.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for django-silly-stripe-1.0.0.tar.gz
Algorithm Hash digest
SHA256 224cfe7cb10e6a4fa1ed2f0c1a29402497c54f4553d4fda07659506ad1afc239
MD5 878e426fe9566acfed9dbf01d914478c
BLAKE2b-256 4f2d2fd82e41a66ce2cf73f977e0d86833ccf531783c4cfe9446582087fa993f

See more details on using hashes here.

File details

Details for the file django_silly_stripe-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_silly_stripe-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5068db3ee2ebbec43f8cdffda76e837ed5fb1ec42719ffcc1f57c3699fa79ad
MD5 799679bf102707ec98dbcb823218e3c4
BLAKE2b-256 47085fb68f7bdaba7fa195f27ddb1bbd4badc0930e728cf6da72a6029871d34b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page