# 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](#-installation)
- [🚀 Quickstart](#-quickstart)
- [📜 Code of Conduct](#code-of-conduct)
## 💾 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:
```commandline
pip install stripe-integrations
```
2. Add `stripe_integrations` to your INSTALLED_APPS setting:
```python
INSTALLED_APPS = [
...,
'stripe_integrations',
]
```
3. Create models to manage Stripe data using the abstract base classes provided in `stripe_integrations.models`. For example:
```python
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
```
4. 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
```
5. In your settings, update the model paths in `STRIPE_CONFIG`:
```python
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
}
```
6. Implement APIs
You can use the appropriate actions to build payment APIs. Here are some examples:
- Creating a customer
```python
from stripe_integrations.actions.customers import StripeCustomer
# Pass user model instance and email as argument
customer = StripeCustomer.create(user, billing_email)
```
- Creating a subscription
```python
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](CODE_OF_CONDUCT.md). We ask you to treat everyone as a smart human programmer that shares an interest in Python and `stripe-integrations` with you.
Raw data
{
"_id": null,
"home_page": "https://twopointone.github.io/stripe-integrations",
"name": "stripe-integrations",
"maintainer": "Vikalp Jain",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "vikalp@twopointone.com",
"keywords": "stripe-integrations",
"author": "Two Point One",
"author_email": " oss@twopointone.com ",
"download_url": "https://files.pythonhosted.org/packages/ad/ba/9493487cb7b9f480b329dab4d875b0cab7f2d3f6f35c8b9e20d52944df3e/stripe_integrations-0.0.1.tar.gz",
"platform": null,
"description": "# Stripe Integrations\n\n`stripe-integrations` is an open source Python package that simplifies the integration of Stripe payments into your Django web application. Its key features include:\n\n- Full support for Stripe's B2C Subscription.\n- Management commands that help synchronize customer data, cards, subscriptions, coupons, prices, and products from Stripe.\n- Built-in webhook handling for secure communication with Stripe.\n- A wide range of functions for creating and managing customers, subscriptions, and other Stripe-related operations within your Django web application.\n\n## Table of Contents\n\n- [\ud83d\udcbe Installation](#-installation)\n- [\ud83d\ude80 Quickstart](#-quickstart)\n- [\ud83d\udcdc Code of Conduct](#code-of-conduct)\n\n## \ud83d\udcbe Installation\n\nYou can easily install or upgrade to the latest version of the package using pip:\n\n```\npip install stripe-integrations\n```\n\n## \ud83d\ude80 Quickstart\n\nTo get started quickly, follow these steps:\n\n1. Install the package using pip:\n\n```commandline\npip install stripe-integrations\n```\n\n2. Add `stripe_integrations` to your INSTALLED_APPS setting:\n\n```python\nINSTALLED_APPS = [\n ...,\n 'stripe_integrations',\n]\n```\n\n3. Create models to manage Stripe data using the abstract base classes provided in `stripe_integrations.models`. For example:\n\n```python\nfrom stripe_integrations.models import StripeBaseCustomer, StripeBaseCard, StripeBaseSubscription, StripeBaseProduct, StripeBasePrice, StripeBaseCoupon, StripeBaseEvent\nfrom users.models import User\n\n\nclass Customer(StripeBaseCustomer):\n user = models.ForeignKey(\n User,\n on_delete=models.CASCADE,\n related_name=\"stripe_customers\",\n )\n # Add custom fields as per project requirement\n\n\nclass Card(StripeBaseCard):\n customer = models.ForeignKey(\n Customer,\n on_delete=models.CASCADE,\n related_name=\"cards\",\n )\n # Add custom fields as per project requirement\n\n\nclass Subscription(StripeBaseSubscription):\n customer = models.ForeignKey(\n Customer,\n on_delete=models.CASCADE,\n related_name=\"subscriptions\",\n help_text=\"The customer associated with this subscription\",\n )\n # Add custom fields as per project requirement\n\n\nclass Product(StripeBaseProduct):\n # Add custom fields as per project requirement\n pass\n\n\nclass Price(StripeBaseProduct):\n product = models.ForeignKey(\n Product,\n on_delete=models.CASCADE,\n related_name=\"prices\",\n )\n # Add custom fields as per project requirement\n\n\nclass Coupon(StripeBaseCoupon):\n # Add custom fields as per project requirement\n pass\n\n\nclass Event(StripeBaseEvent):\n # Add custom fields as per project requirement\n pass\n```\n\n4. Database migration\n\nAfter implementing the models, create a migration file using the following command:\n\n```\npython manage.py makemigrations\n```\n\nOnce the migration file has been created, apply the migrations to the database using the following command:\n\n```\npython manage.py migrate\n```\n\n5. In your settings, update the model paths in `STRIPE_CONFIG`:\n\n```python\nSTRIPE_CONFIG = {\n \"API_VERSION\": \"2022-11-15\", # Stripe API Version\n \"API_KEY\": \"api_key\", # Stripe Secret Key\n \"CUSTOMER_MODEL\": \"project_name.app.models.Customer\",\n \"CARD_MODEL\": \"project_name.app.models.Card\",\n \"PRODUCT_MODEL\": \"project_name.app.models.Product\",\n \"PRICE_MODEL\": \"project_name.app.models.Price\",\n \"COUPON_MODEL\": \"project_name.app.models.Coupon\",\n \"EVENT_MODEL\": \"project_name.app.models.Event\",\n \"SUBSCRIPTION_MODEL\": \"project_name.app.models.Subscription\",\n \"CUSTOMER_FIELD_NAME\": \"customer\", # Field name used to have foreign key relation with `Customer` model\n \"USER_FIELD_NAME\": \"user\", # Field name that is used by `Customer` model to have foreign relation to `User` model\n}\n```\n\n6. Implement APIs\n\nYou can use the appropriate actions to build payment APIs. Here are some examples:\n\n- Creating a customer\n\n```python\nfrom stripe_integrations.actions.customers import StripeCustomer\n\n# Pass user model instance and email as argument\ncustomer = StripeCustomer.create(user, billing_email)\n```\n\n- Creating a subscription\n\n```python\nfrom stripe_integrations.actions.subscriptions import StripeSubscription\n\n# Pass customer model instance and prices(List of stripe price ids) to subscribe as argument\nsubscription = StripeSubscription.create(customer, prices)\n```\n\n## Code of Conduct\n\nIn order to foster a kind, inclusive, and harassment-free community, we have a code of conduct, which can be found [here](CODE_OF_CONDUCT.md). We ask you to treat everyone as a smart human programmer that shares an interest in Python and `stripe-integrations` with you.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django + Stripe made easy",
"version": "0.0.1",
"project_urls": {
"Documentation": "https://twopointone.github.io/stripe-integrations",
"Homepage": "https://twopointone.github.io/stripe-integrations",
"Repository": "https://github.com/twopointone/stripe-integrations"
},
"split_keywords": [
"stripe-integrations"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "17fe184e3ac55b3b2e7cb21ed6fbf8ac388a1336ab346f5bdaa164c27d82bf25",
"md5": "df0e6d3023b52c524cd759f802807433",
"sha256": "1f533c02e46199414112af09acd30365ccba5f04c068a60a5c094ba16c5a040f"
},
"downloads": -1,
"filename": "stripe_integrations-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "df0e6d3023b52c524cd759f802807433",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 32994,
"upload_time": "2023-05-02T07:39:02",
"upload_time_iso_8601": "2023-05-02T07:39:02.736943Z",
"url": "https://files.pythonhosted.org/packages/17/fe/184e3ac55b3b2e7cb21ed6fbf8ac388a1336ab346f5bdaa164c27d82bf25/stripe_integrations-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "adba9493487cb7b9f480b329dab4d875b0cab7f2d3f6f35c8b9e20d52944df3e",
"md5": "118293d5ef1e0ca9b68b8d844c0c878f",
"sha256": "12a09dc83d25763e0e9a2b40f69e99b8b55a89a8d35a7f74484d66cf1aeaf315"
},
"downloads": -1,
"filename": "stripe_integrations-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "118293d5ef1e0ca9b68b8d844c0c878f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 23393,
"upload_time": "2023-05-02T07:39:04",
"upload_time_iso_8601": "2023-05-02T07:39:04.320374Z",
"url": "https://files.pythonhosted.org/packages/ad/ba/9493487cb7b9f480b329dab4d875b0cab7f2d3f6f35c8b9e20d52944df3e/stripe_integrations-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-02 07:39:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "twopointone",
"github_project": "stripe-integrations",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "stripe-integrations"
}