【问题标题】:Django Stripe account link return_url and refresh_url redirects causes user to be logged out of web application platformDjango Stripe 帐户链接 return_url 和 refresh_url 重定向导致用户退出 Web 应用程序平台
【发布时间】:2021-09-27 08:47:24
【问题描述】:

我正在将条带集成到我的 Django Web 应用程序平台中。当卖家使用 Stripe Connect 时,会为他们创建一个帐户,并使用指定的 return_url 和 refresh_url 创建一个 AccountLink,Stripe 使用它来重定向回我的 Web 应用程序。但是,当卖家被重定向回我的 Web 应用程序时,他们不再登录到 Web 应用程序。有没有比强制用户重新登录更好的解决方案?

以下是一些sn-ps的代码:

views.py

def stripe_on_boarding(request):
    if request.method == "GET":
        stripe_sk = settings.STRIPE_SECRET_KEY
        stripe.api_key = stripe_sk

        user = request.user
        account = None

        print("I'm logged in as and am onboarding stripe [" + user.first_name + "]")

        if user.stripe_account is None:
            account = stripe.Account.create(type='express')
            user.stripe_account = account.id
            user.save()
            print("Saved User Object!")

        else:
            account = stripe.Account.retrieve(user.stripe_account)

        if account is not None and not account.details_submitted:
            account_links = stripe.AccountLink.create(
                account=account.id,
                refresh_url='http://098c818fbf8a.ngrok.io/marketplace/stripe_on_boarding_refresh',
                return_url='http://098c818fbf8a.ngrok.io/marketplace/seller_return',
                type='account_onboarding',
            )

            return redirect(account_links.url)

        return render(request, 'become_seller_part_1.html', {'msg' : "You've already registered with stripe.", 'is_registered' : True})
    # TODO: render a page if this view was triggered by a method other than GET.

这可能是因为我使用 ngrok 重定向到我的本地主机吗?

【问题讨论】:

    标签: python django stripe-payments


    【解决方案1】:

    原来是因为我用的是ngrok。您必须在整个会话中使用相同的 URL;也就是说,在重定向到 ngrok URL 时,您无法以 localhost 用户身份登录并维持会话。

    解决方法是在以用户身份登录时使用ngrok URL。

    【讨论】:

      猜你喜欢
      • 2021-10-12
      • 1970-01-01
      • 2018-06-03
      • 1970-01-01
      • 2021-10-27
      • 1970-01-01
      • 2011-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多