Stripe integration for Django-based projects
Project description
Stripe integration for Django-based projects
This project’s target is to make the Stripe API easier to use in Django-based applications. At the moment the library supports:
charging users
Installation
Add aa_stripe to your app’s INSTALLED_APPS, and also set STRIPE_API_KEY in project settings. After all please migrate the app (./manage.py migrate aa_stripe).
Add aa_stripe.api_urls into your url conf.
Usage
Creating a token for user
Use stripe.js (https://stripe.com/docs/stripe.js) to get single use token (stripe.js->createToken) and send it to API using /aa-stripe/tokens to create Customer for the user. It runs:
customer = stripe.Customer.create(source=data["id"]) # data is the response dictionary from Stripe API (in front-end) token = StripeToken.objects.create(user=request.user, content=data, customer_id=customer["id"])
This endpoint requires authenticated user. In case you need diferent implementation (like one call with register) you’ll have to adjust your code.
Charging
First of all, make sure to obtain Stripe user token from the Stripe API, and then save it to aa_stripe.models.StripeToken, for example:
import stripe from aa_stripe.models import StripeToken customer = stripe.Customer.create(source=data["id"]) # data is the response dictionary from Stripe API (in front-end) token = StripeToken.objects.create(user=request.user, content=data, customer_id=customer["id"])
To charge users, create an instance of aa_stripe.models.StripeCharge model and then call the charge() method:
c = StripeCharge.objects.create(user=user, token=token, amount=500, # in cents description="Charge for stuff", # sent to Stripe comment="Comment for internal information") c.charge()
There is also a management command called charge_stripe in case you need to process all the remaining charges.
Support
Django 1.11
Python 2.7, 3.4-3.6
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aa_stripe-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18713261c377e21d36849462ccffd40d5449d37f4be8eaabbbd78caf103771d4 |
|
MD5 | 0a10e9d1a650a2754b13afd83d268459 |
|
BLAKE2b-256 | 9016fe7891bf746383c16e54f9bca7d64d7b4fca54a3dd79f596808de0d55c5b |