# 订阅出现500错误的问题

**URL:** <https://meta.discourse.org/t/problem-with-500-error-with-subscriptions/360808>\
**Category:** Support\
**Tags:** subscriptions\
**Created:** [2025年四月7日 21:28 UTC](https://meta.discourse.org/t/problem-with-500-error-with-subscriptions/360808 "2025-04-07T21:28:36Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)\
**Post date:** [2025年四月9日 16:53 UTC](https://meta.discourse.org/t/problem-with-500-error-with-subscriptions/360808/6 "2025-04-09T16:53:46Z")

</div>

我猜这只是针对这个网站？你在其他网站上没有看到这个吗？是的，有一个“bug”，我们不应该返回 500，但可能有一些“坏”数据，比如缺少计划或类似的东西。也许它在 Stripe 中被删除了，但从未在插件数据库中更新。

你能运行这些 rails 控制台命令来帮助我调试吗？

```plaintext
Stripe.api_key = SiteSetting.discourse_subscriptions_secret_key
user = User.find_by(username: 'xxx')
customer = DiscourseSubscriptions::Customer.find_by(user_id: user.id)
subs = ::Stripe::Subscription.list(customer: stripe_customer_id, status: 'all')[:data]
subs.count # 注意他们有多少订阅
subscription = subs.first # 更改此项并为每个订阅运行以下行
price_id = subscription[:items][:data].first[:price][:id]
plans = ::Stripe::Price.list(expand: ['data.product'], limit: 100)
plan = plans[:data].find { |p| p[:id] == price_id }
plan

```

我猜计划或 plan 会返回 nil，但这将帮助我们缩小问题的范围。你能告诉我他们有多少订阅以及是否有任何计划丢失吗？

很可能是一个代码修复，我将只为这些用户返回任何订阅（如果有错误），但如果他们实际上有一个订阅，那并没有真正解决问题。也许我会让它返回一个错误，比如“已找到订阅，但加载其计划详细信息时出错，请联系管理员寻求帮助”。

---

_[View the full topic](https://meta.discourse.org/t/problem-with-500-error-with-subscriptions/360808)._
