Django+条纹设计
dj-stripe的Python项目详细描述
DJ条纹
Django的条纹型号。
简介
dj stripe实现了django的所有条带模型。 设置webhook并开始接收模型更新。 然后您将拥有django模型中所有可用条带模型的副本,不需要api流量!
完整的文档可在此处获得: https://dj stripe.readthedocs.io/
功能
- 订阅
- 个人收费
- 条纹源
- 条带v2和v3支持
- 使用Stripe API进行测试(请参阅https://dj-stripe.readthedocs.io/en/latest/api_versions.html" rel="nofollow">https://dj stripe.readthedocs.io/en/latest/api_versions.html)
要求
- django>;=2.0
- python=3.4
- 仅支持条带。对于PayPal,请改为参见DJ PayPal。
- PostgreSQL引擎(推荐):>;=9.4
- mysql引擎:mariadb>;=10.2或mysql>;=5.7
快速启动
安装DJ磁条:
pip install dj-stripe
将djStripe添加到已安装的应用程序中
INSTALLED_APPS=(..."djstripe",...)
告诉stripe关于webhook的信息(stripe webhook docs可以在这里找到 )使用上面url.py步骤中端点的完整url(例如https://example.com/stripe/webhook)。
添加条带键并设置操作模式:
STRIPE_LIVE_PUBLIC_KEY=os.environ.get("STRIPE_LIVE_PUBLIC_KEY","<your publishable key>")STRIPE_LIVE_SECRET_KEY=os.environ.get("STRIPE_LIVE_SECRET_KEY","<your secret key>")STRIPE_TEST_PUBLIC_KEY=os.environ.get("STRIPE_TEST_PUBLIC_KEY","<your publishable key>")STRIPE_TEST_SECRET_KEY=os.environ.get("STRIPE_TEST_SECRET_KEY","<your secret key>")STRIPE_LIVE_MODE=False# Change to True in productionDJSTRIPE_WEBHOOK_SECRET="whsec_xxx"# Get it from the section in the Stripe dashboard where you added the webhook endpoint
通过stripe.com仪表板添加一些付款计划。
添加到URL.py:
path("stripe/",include("djstripe.urls",namespace="djstripe")),
运行命令:
python manage.py migrate python manage.py djstripe_init_customers python manage.py djstripe_sync_plans_from_stripe
运行测试
假设测试是针对postgresql运行的:
createdb djstripe pip install tox tox