Skip to main content

Stripe Integrations

stripe-integrations is an open source Python package that simplifies the integration of Stripe payments into your Django web application. Its key features include:

  • Full support for Stripe's B2C Subscription.
  • Management commands that help synchronize customer data, cards, subscriptions, coupons, prices, and products from Stripe.
  • Built-in webhook handling for secure communication with Stripe.
  • A wide range of functions for creating and managing customers, subscriptions, and other Stripe-related operations within your Django web application.

Table of Contents

💾 Installation

You can easily install or upgrade to the latest version of the package using pip:

pip install stripe-integrations

🚀 Quickstart

To get started quickly, follow these steps:

  1. Install the package using pip:
pip install stripe-integrations
  1. Add stripe_integrations to your INSTALLED_APPS setting:
INSTALLED_APPS = [
    ...,
    'stripe_integrations',
]
  1. Create models to manage Stripe data using the abstract base classes provided in stripe_integrations.models. For example:
from stripe_integrations.models import StripeBaseCustomer, StripeBaseCard, StripeBaseSubscription, StripeBaseProduct, StripeBasePrice, StripeBaseCoupon, StripeBaseEvent
from users.models import User


class Customer(StripeBaseCustomer):
    user = models.ForeignKey(
        User,
        on_delete=models.CASCADE,
        related_name="stripe_customers",
    )
    # Add custom fields as per project requirement


class Card(StripeBaseCard):
    customer = models.ForeignKey(
        Customer,
        on_delete=models.CASCADE,
        related_name="cards",
    )
    # Add custom fields as per project requirement


class Subscription(StripeBaseSubscription):
    customer = models.ForeignKey(
        Customer,
        on_delete=models.CASCADE,
        related_name="subscriptions",
        help_text="The customer associated with this subscription",
    )
    # Add custom fields as per project requirement


class Product(StripeBaseProduct):
    # Add custom fields as per project requirement
    pass


class Price(StripeBaseProduct):
    product = models.ForeignKey(
        Product,
        on_delete=models.CASCADE,
        related_name="prices",
    )
    # Add custom fields as per project requirement


class Coupon(StripeBaseCoupon):
    # Add custom fields as per project requirement
    pass


class Event(StripeBaseEvent):
    # Add custom fields as per project requirement
    pass
  1. Database migration

After implementing the models, create a migration file using the following command:

python manage.py makemigrations

Once the migration file has been created, apply the migrations to the database using the following command:

python manage.py migrate
  1. In your settings, update the model paths in STRIPE_CONFIG:
STRIPE_CONFIG = {
    "API_VERSION": "2022-11-15", # Stripe API Version
    "API_KEY": "api_key", # Stripe Secret Key
    "CUSTOMER_MODEL": "project_name.app.models.Customer",
    "CARD_MODEL": "project_name.app.models.Card",
    "PRODUCT_MODEL": "project_name.app.models.Product",
    "PRICE_MODEL": "project_name.app.models.Price",
    "COUPON_MODEL": "project_name.app.models.Coupon",
    "EVENT_MODEL": "project_name.app.models.Event",
    "SUBSCRIPTION_MODEL": "project_name.app.models.Subscription",
    "CUSTOMER_FIELD_NAME": "customer", # Field name used to have foreign key relation with `Customer` model
    "USER_FIELD_NAME": "user", # Field name that is used by `Customer` model to have foreign relation to `User` model
}
  1. Implement APIs

You can use the appropriate actions to build payment APIs. Here are some examples:

  • Creating a customer
from stripe_integrations.actions.customers import StripeCustomer

# Pass user model instance and email as argument
customer = StripeCustomer.create(user, billing_email)
  • Creating a subscription
from stripe_integrations.actions.subscriptions import StripeSubscription

# Pass customer model instance and prices(List of stripe price ids) to subscribe as argument
subscription = StripeSubscription.create(customer, prices)

Code of Conduct

In order to foster a kind, inclusive, and harassment-free community, we have a code of conduct, which can be found here. We ask you to treat everyone as a smart human programmer that shares an interest in Python and stripe-integrations with you.

Release files for stripe-integrations 0.0.1

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

Source distribution (sdist)

Source distribution for stripe-integrations 0.0.1
File Size Uploaded
stripe_integrations-0.0.1.tar.gz 23.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stripe-integrations 0.0.1
File Interpreter ABI Platform
stripe_integrations-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 56.4 kB

Release files / stripe_integrations-0.0.1.tar.gz

Download URL stripe_integrations-0.0.1.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
12a09dc83d25763e0e9a2b40f69e99b8b55a89a8d35a7f74484d66cf1aeaf315
BLAKE2b-256 checksum
How to use checksums
adba9493487cb7b9f480b329dab4d875b0cab7f2d3f6f35c8b9e20d52944df3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.9.16 Linux/5.15.0-1036-azure

Release files / stripe_integrations-0.0.1-py3-none-any.whl

Download URL stripe_integrations-0.0.1-py3-none-any.whl
Size 33.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f533c02e46199414112af09acd30365ccba5f04c068a60a5c094ba16c5a040f
BLAKE2b-256 checksum
How to use checksums
17fe184e3ac55b3b2e7cb21ed6fbf8ac388a1336ab346f5bdaa164c27d82bf25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.9.16 Linux/5.15.0-1036-azure

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

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