【问题标题】:Recurring payments using Stripe and Django使用 Stripe 和 Django 进行定期付款
【发布时间】:2018-12-05 14:26:39
【问题描述】:

我对 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')

条纹模板.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-stripepinax),我们将不胜感激。

【问题讨论】:

    标签: python django stripe-payments


    【解决方案1】:

    从 2020 年开始,实际上建议为此使用 PaymentIntents。 Stripe 在他们的文档中有 an excellent guide 说明如何做到这一点,现在该文档贯穿了整个流程并涵盖了诸如 3D 安全之类的内容。

    有关 Django 特定主题的详细介绍,请参阅这篇文章:How to Create a Subscription SaaS Application with Django and Stripe

    【讨论】:

      【解决方案2】:

      您应该查看Billing Quickstart-文档。它逐步概述了如何设置订阅(或定期付款)。它的要点是,您首先create a product,然后create a plan 使用该产品,create a customer 要为其重复计费,然后attach that plan as a subscription 给客户。

      【讨论】:

        【解决方案3】:

        您需要create a plan,指定定期付款价格和持续时间,然后将您的条纹客户注册到计划using subscriptions

        【讨论】:

          猜你喜欢
          • 2015-06-13
          • 1970-01-01
          • 2022-01-17
          • 2017-04-16
          • 1970-01-01
          • 2021-07-24
          • 2015-08-23
          • 1970-01-01
          • 2022-12-16
          相关资源
          最近更新 更多