ruby-on-rails - 付款失败后阻止用户使用 SaaS 应用程序的最佳方法是什么

标签 ruby-on-rails paypal saas stripe-payments recurring-billing

我正在使用 Ruby on Rails 开发 SaaS 应用程序。每个用户都必须订阅一个特定的计划才能开始使用该应用程序。这一步是使用 Stripe 完成的

问题是如果自动支付订阅失败(他更换信用卡等),我不知道如何阻止该用户使用我的应用程序。我正在考虑使用用户模型中的一列将此用户标记为非事件状态并阻止他登录。但这并不像我预期的那样工作,因为我希望此用户能够登录但他必须更新他的订阅继续。

顺便说一下,我在 Rails 上看到很多 SaaS 示例,例如 https://github.com/RailsApps/rails-stripe-membership-saashttps://github.com/railscasts/289-paypal-recurring-billing但似乎他们不会在发生故障时处理来自提供商(Stripe 或 Paypal)的回发。

请让我知道您的想法以及你们如何在类似项目中处理这个问题。

提前致谢

最佳答案

Stripe 会定期为您从卡中扣款。您的应用程序不负责为已订阅您的服务的用户产生新费用。

来自 the docs

Stripe makes handling failed payments easy. Stripe can automatically retry a recurring payment after it fails, and can automatically cancel the customer's subscription if it repeatedly fails. How long to wait, and how many times to retry, can be easily set in your account settings.

我可能会在我的 User 模型上跟踪一个 :subscription_active bool 值或类似值。当用户登录时,您可以检查 API 以查看用户订阅的状态。 <强> API docs 关于响应中订阅的状态有这样的说法(强调我自己的):

Possible values are trialing, active, past_due, canceled, or unpaid. A subscription still in its trial period is trialing and moves to active when the trial period is over. When payment to renew the subscription fails, the subscription becomes past_due. After Stripe has exhausted all payment retry attempts, the subscription ends up with a status of either canceled or unpaid depending on your retry settings. Note that when a subscription has a status of unpaid, any future invoices will not be attempted until the customer’s card details are updated.

如果响应返回为上述粗体状态之一,请将用户的 :subscription_active 标记为 false。在需要有条件地为用户启用应用程序功能的任何地方检查 user.subscription_active?

关于ruby-on-rails - 付款失败后阻止用户使用 SaaS 应用程序的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18085777/

相关文章:

asp.net - 将 PayPal 凭据存储在共享主机上的 Web 应用程序 (asp.net) 中

azure - Windows Azure 与 Citrix Xenapp 与 Windows Azure 上的 Citrix XenDesktop

magento - 我可以在 Commercetools 平台中托管自己的数据库吗?

ruby-on-rails - 在 Rails 中搜索

asp.net - 什么是更快的 ASP.NET MVC 或 Ruby On Rails

ruby-on-rails - 简单地从Rails中的Ajax调用返回成功或失败

python - 为什么代码在收到响应后不执行

paypal - 如果 PayPal IPN Listener 脚本发现重复付款,PayPal 是否会取消交易?

mysql - 将以不同速度增长的表拆分到各自的数据库中是明智的做法吗?

ruby-on-rails - 如何测试一个对象是否是用 rspec 创建的?