Salesman Stripe
Stripe payment integration for Salesman.
Installation
Install the package using pip:
pip install django-salesman-stripe
Add to your setting file:
INSTALLED_APPS += ['salesman_stripe']
SALESMAN_PAYMENT_METHODS = ['salesman_stripe.payment.StripePayment']
SALESMAN_STRIPE_SECRET_KEY = '<stripe-secret-key>'
SALESMAN_STRIPE_WEBHOOK_SECRET = '<stripe-webhook-secret>'
Local setup
To simulate webhooks while in development you can use the Stripe CLI. After you've installed the CLI, you can run:
stripe listen --forward-to localhost:8000/api/payment/stripe/webhook/
This will connect the webhook and output the signing secret for SALESMAN_STRIPE_WEBHOOK_SECRET setting.
Additional settings
Optional additional settings that you can override:
# Payment method label used when displayed in the basket.
SALESMAN_STRIPE_PAYMENT_LABEL = 'Pay with Stripe'
# Default ISO currency used for payments (https://stripe.com/docs/currencies)
SALESMAN_STRIPE_DEFAULT_CURRENCY = 'usd'
# URL to redirect to when Stripe payment is cancelled.
SALESMAN_STRIPE_CANCEL_URL = '/stripe/cancel/'
# URL to redirect to when Stripe payment is successfull.
SALESMAN_STRIPE_SUCCESS_URL = '/stripe/success/'
# Default paid status for fullfiled orders.
SALESMAN_STRIPE_PAID_STATUS = 'PROCESSING'
Customer syncing
It is recommended to enable Stripe customer syncronization with your User model. This will require an extra field on your User model which will hold the Stripe customer ID. Easiest way to do this is to define a custom user model:
# shop/models.py
from salesman_stripe.models import StripeCustomerMixin
class User(StripeCustomerMixin, AbstractUser):
pass
You should then register your custom user model in settings.py:
AUTH_USER_MODEL = 'shop.User'
An alternative approach would be to override the get_stripe_customer_id and save_stripe_customer_id
methods in a custom StripePayment class, see more in advanced usage section below.
Advanced usage
To gain more control feel free to extend the StripePayment class with your custom functionality:
# shop/payment.py
from salesman_stripe.payment import StripePayment
from salesman_stripe.conf import app_settings
class MyStripePayment(StripePayment):
def get_stripe_customer_data(self, obj, request):
# https://stripe.com/docs/api/customers/create
data = super().get_stripe_customer_data(obj, request)
if obj.user and obj.user.phone_number:
data['phone'] = obj.user.phone_number
return data
def get_currency(self, request):
currency = request.GET.get('currency', None)
# Check currency is valid for Stripe...
return currency or app_settings.SALESMAN_STRIPE_DEFAULT_CURRENCY
Make sure to use your payment method in settings.py:
SALESMAN_PAYMENT_METHODS = ['shop.payment.MyStripePayment']
The StripePayment class is setup with extending in mind, feel free to explore other methods.
Metadata
Release files for django-salesman-stripe 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-salesman-stripe-0.1.6.tar.gz | 8.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_salesman_stripe-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.4 kB
Release files / django-salesman-stripe-0.1.6.tar.gz
| Download URL | django-salesman-stripe-0.1.6.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
866f2c2f55fb10cad6013d7e8d7880203b61cd63ecd9f5829759ac068e72f4a7
|
|
BLAKE2b-256 checksum How to use checksums |
c2cc0ccac3fa8873256d5b5abaad95e1d2e4f6a6a1f646d6e4ed63b0f21563e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.15 CPython/3.11.2 Linux/5.15.0-1033-azure
|
Release files / django_salesman_stripe-0.1.6-py3-none-any.whl
| Download URL | django_salesman_stripe-0.1.6-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d7e5ee4efdf911add27985898f5d1872967465856aa9eeec126f9f360ebcdec6
|
|
BLAKE2b-256 checksum How to use checksums |
d8e8516a95ba8ee50f13a820ad7fadda04d63caa2a997e76ba57a74b654b38a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.15 CPython/3.11.2 Linux/5.15.0-1033-azure
|