我对 Django 还很陌生,正在尝试通过 Stripe 设置定期付款。我正在使用 Django 2.0 并已成功设置单次充电测试用例。但是,我不熟悉如何创建定期付款,并且我正在从事的项目需要它。
对于单次付款,我有以下内容:
观看次数
stripe.api_key = settings.STRIPE_SECRET_KEY
def checkout(request):
"""Stripe check out"""
new_tier = models.PaymentTier(
level = "Tier 3",
year = 2018
)
if request.method == "POST":
token = request.POST.get("stripeToken")
try:
charge = stripe.Charge.create(
amount = 2000,
currency = "usd",
source = token,
description = "Tier 3 subscription for Elite Fitness"
)
new_tier.charge_id = charge.id
except stripe.error.CardError as ce:
return False, ce
else:
new_tier.save()
return redirect("thank_you_page")
def payment_form(request):
"""Render stripe payment form template"""
context = {"stripe_key": settings.STRIPE_PUBLIC_KEY}
return render(request, "stripe-template.html", context)
def thank_you_page(request):
"""Successful payment processed"""
return render(request,'thank_you_page.html')
stripe-template.html
<form action="checkout/" method="POST"> {% csrf_token %}
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key={{stripe_key}} # Make sure to wrap the variable name with double {}
data-amount="2000"
data-name="company name here"
data-description="Elite Fitness Subscription"
data-image="picture.png"
data-currency="usd">
</script>
</form>
我很难在网上找到专门涵盖定期付款的内容。如果有人知道如何设置它们(即使通过dj-stripe
或pinax
),我们将非常感谢任何帮助。
最佳答案
您应该看看 Billing Quickstart - 文档。它逐步概述了如何设置订阅(或定期付款)。其要点是,你先create a product ,然后 create a plan使用该产品,create a customer您想为谁重复计费,那么attach that plan as a subscription给客户。
关于python - 使用 Stripe 和 Django 进行定期付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51050116/