Discourse 订阅插件

:discourse2: Summary The Discourse Subscriptions plugin allows site owners to sell recurring and one-time purchase subscriptions that grant access to a group on a Discourse instance.
:open_book: Install Guide This plugin is bundled with Discourse core. There is no need to install the plugin separately.

The Discourse Subscriptions plugin allows you to create one-time as well as recurring subscriptions that users can pay for in order to access gated content. This can be a great way to fund the hosting cost of your community.

Features

The Discourse Subscriptions plugin supports the following features:

The “Subscribe” button located in the top nav will take you to the Subscribe page /s where it lists the subscriptions you have configured for your site:

Once a user clicks on one of the “Subscribe” button for a specific plan it will open up the payment page for that plan:

After a user fills out their payment details and their address and click “Subscribe”, they are shown a “Thank you!” message and taken to their billing page:

The user is also automatically added to a group of your choosing so that you can easily see which users have subscribed as well as provide gated content in categories only that group can see.

Terms

  • Subscription - Subscriptions are a recurring payment plan which allow you to control access to content on your community. When a subscription is created or deleted, a user is added or removed from the user group you associate with your subscription plan. A subscription is made up of a product and plans.
  • Product - A product in Stripe’s terms is what you’re selling. A product can contain one or more plans.
    • To add a description to your product, add a metadata field named “description” and use that one instead. You can use Markdown.
  • Plan - A plan contains a price, recurring cycle, and associates with a group to which your subscribers gain access.

:police_car_light: Be very careful to keep your Stripe private keys safe and secure at all times.

:warning: If you were to shut down your instance of Discourse, uninstall this plugin or your site were to go offline, Stripe will continue to bill your customers for your service until the subscription is cancelled.

Configuration

  1. Install & enable the plugin
  2. Configure Payment Gateway (Stripe)
  3. Configure Webhooks & Events in Stripe
  4. Add your Stripe keys (public, secret, webhook secret) under Admin > Plugins > Installed > Subscriptions > Settings /admin/site_settings/category/discourse_subscriptions?filter=plugin%3Adiscourse-subscriptions.
  5. Create a group for your subscribers to join via purchase
  6. Create a product and plan under Admin > Plugins > Subscriptions
  7. Profit!

Set up your Payment Gateway.

Firstly, you’ll need an account with the Stripe payment gateway. To get started, you can set up an account in test mode and see how it all works without making any real transactions or having to set up a bank account. There is no test mode toggle in the plugin; instead, be sure to use your developer keys (they begin with pk_test, sk_test)

Set up Webhooks and Events in your Stripe account

:bomb: Webhooks are required to make subscription cancellations work fully. Be sure you have them configured correctly.

Once you have an account on Stripe, you’ll need to tell Stripe your website’s address so it can notify you about certain transactions. You can enter this in your Stripe dashboard under Endpoints > URL.

Webhooks address: [your server address]/s/hooks – where [your server address] is the URL of your Discourse install.

You’ll also need to tell Stripe which events it should notify you about via the webhook URL.

Currently, Discourse Subscriptions responds to the following events:

  • customer.subscription.deleted
  • customer.subscription.updated
  • checkout.session.completed

Add the Stripe API and Webhook keys to your plugin settings

Stripe needs to be authorized to communicate with your website. To do this, it publishes a pair of private and public API keys and a signing secret for your web hooks.

To authorize webhooks, add the API keys and webhook secret from Stripe to your settings page (under Developers).

:warning: Adding production keys will make live payments. If you plan to test, be sure to switch to View test data mode and get pk_test and sk_test keys under Developers.

In your Stripe account settings, see:

Add these keys under the appropriate settings in Admin > Plugins > Installed > Subscriptions > Settings /admin/site_settings/category/discourse_subscriptions?filter=plugin%3Adiscourse-subscriptions.

Set up your User Groups in Discourse

When a user successfully subscribes to your Discourse application, after their credit card transaction has been processed, they are added to a User Group. By assigning users to a User Group, you can manage what your users have access to on your website. User groups are a core functionality of Discourse and this plugin does nothing with them except add and remove users from the group you associated with your Plan.

Create one or more products with plans.

Under Admin > Plugins > Subscriptions, click add a new Product. Once you have a product saved, you can add plans to it. Keep in mind that the pricing and billing intervals of plans cannot be changed once you create them. This is to avoid confusion around subscription management.

If you take a look at your Stripe Dashboard, you’ll see all those products and plans are listed. Discourse Subscriptions does not create them locally. They are created in Stripe.

Testing

Test with these credit card numbers:

  • 4242 4242 4242 4242
  • 4111 1111 1111 1111 (no authentication required)
  • 4000 0027 6000 3184 (authentication required)

For more test card numbers: Test card numbers | Stripe Documentation

Visit /s and enter a few test transactions.

Going Live

Once you’re ready to go live, change your API and webhook secret keys to production keys. You will need to create new products and plans in live mode.

Do be aware that if if you don’t properly configure Stripe webhooks, and recurring payments fail to process for any reason (expired credit card, etc.), users will still have access to the group . To have Stripe automatically cancel subscriptions, be sure to set your Manage failed payments settings similar to the below image and configure webhooks as described above.

Update Payment Info

Users can update their card used for individual subscriptions by visiting the billing page and clicking the edit button next to the subscription which will open up this screen:

Stripe Checkout with Stripe Pricing Tables

You can also opt to replace the Subscription Plugin product and checkout pages and instead use Stripe Checkout with Stripe Pricing Tables.

In your Stripe Dashboard:

  1. After you’ve created the products on Discourse, Go to Products > Product catalog
  2. Click on the product you’d like to include in the pricing table
  3. Click Edit product
  4. More Options and enter the following under Metadata:
    • Key: group_name
    • Value: The group’s name on Discourse (e.g., trust_level_0)
  5. Click Update product to save

:red_exclamation_mark: Make sure the group name matches the group that is selected under User_Groups on Discourse

Create your Stripe pricing table

  1. Go to Products > Pricing tables
  2. Create a new table and add the products you just created
  3. After publishing the table, copy the pricing table ID found within the embed code (it starts with prctbl_...)
  4. Paste the pricing table ID into your discourse_subscriptions_pricing_table_id and enable the subscriptions pricing table setting.
  5. Click the green checkmarks to save both settings.

Recommended step:

When setting up the Pricing Table inside of Stripe it is recommended to link the user to your site after checkout is complete otherwise they will stay on a Stripe confirmation page without a link back to your site.

Redirecting to https://<your-site>/my/billing/subscriptions is a good choice for subscriptions. For one-off payments you could link directly to https://<your-site>/my/billing/payments.

Automatic Tax Collecting

To enable Automatic Tax Collecting check the Site Setting box for discourse_subscriptions_enable_automatic_tax.

If you enable it, but you have not configured your Stripe instance properly to collect tax users may see this popup after completing the checkout process:

There is this guide for more info, but there shouldn’t be much to do since the plugin is now passing in the appropriate automatic_tax[enabled]=true parameter (step 5).

Be sure you configure your registrations (step 4) as well:

Here is an example Discourse Subscription Plugin transaction in Stripe showing that tax was automatically collected:

Settings

Name Description
discourse subscriptions enabled Enable the Discourse Subscriptions plugin.
discourse subscriptions extra nav subscribe Show the subscribe button in the primary navigation
discourse subscriptions public key Stripe Publishable Key
discourse subscriptions secret key Stripe Secret Key
discourse subscriptions webhook secret Stripe Webhook Secret
discourse subscriptions currency Default Currency Code. This can be overridden when creating a subscription plan.
discourse subscriptions campaign enabled Enables a campaign banner to promote supporting this community financially.
discourse subscriptions campaign goal The numerical goal for your support campaign (subscribers or amount raised).
discourse subscriptions campaign type Selects the type of campaign to run (subscribers or monthly amount raised).
discourse subscriptions campaign banner location Selects the location of the campaign banner (top or sidebar).
discourse subscriptions campaign banner bg image Upload a custom image to use as the background on the campaign banner.
discourse subscriptions campaign banner shadow color Selects the color of the campaign banner drop shadow.
discourse subscriptions campaign show contributors Show avatars of the most recent purchases of subscription products.
discourse subscriptions campaign product The Stripe product id to send supporters when they click the button on the campaign. If this setting is blank, supporters will be directed to the main products page.
discourse subscriptions campaign grant Grants the user a free month of subscriptions
discourse subscriptions pricing table id The Stripe pricing table id from the embed code
discourse subscriptions pricing table enabled Enables using the Stripe pricing table and replaces the existing subscribe page
discourse_subscriptions_enable_automatic_tax Toggles if sales tax is going to be collected. Requires some setup in Stripe.
discourse_subscriptions_enable_verbose_logging Enables more verbose logging to aid in debugging. Please do not leave permanently enabled in production.

:discourse2: Hosted by us? This plugin is available on our Pro, Business, and Enterprise hosting plans Subscriptions | Discourse - Civilized Discussion

Last edited by @tobiaseigen 2025-07-16T21:50:25Z

Last checked by @MarkDoerr 2024-07-11T20:25:35Z

Check documentPerform check on document:
138 个赞

5 个帖子已拆分为新主题:测试模式中存在类似对象错误

设置 Sidebar 似乎无效(最新 Discourse aeb3d717dc,最新插件 cc43d32a)。

1 个赞

我也收到了这个日志消息:

弃用通知:图标名称“donate”已更新为“circle-dollar-to-slot”。请在您的代码中使用新名称。旧名称将在 2025 年第二季度移除。[deprecation id: discourse.fontawesome-6-upgrade] [info: https://meta.discourse.org/t/325349]

编辑:为此创建了一个 PR

3 个赞

2 篇帖子已合并到现有主题:"Support Us" Banner Not Updating

嗯……在本地,当我切换到侧边栏时,它会显示在侧边栏中。

如果您将其放在侧边栏中,我们会添加此 CSS 类,您可以检查您的页面并搜索 subscription-campain-sidebar

它只是停留在顶部吗?

我现在明白了。我将“类别”页面设为了默认页面。它显然不会显示在那里。它在“最新”列表中显示。所以它工作正常。谢谢!

3 个赞

它应该真的显示在“类别”页面(或其他默认页面)上,不是吗?

1 个赞

由于中国大陆的限制,Stripe 通过审核较为困难。您能考虑集成支付宝或微信支付的接口吗?

2 个赞

过去类似的问题的答案是“要做的是为支付宝或微信支付创建一个插件”。discourse.org 的收入来自付费托管的用户,我不认为他们有很多想要支付宝或微信支付的企业客户,所以你需要询问 Marketplace 或自己开发。也许你可以让支付宝或微信支付资助开发。

3 个赞

我已经完成了 1-5,但我猜我是笨蛋或者瞎了。我似乎找不到在我的服务器上设置产品和计划的界面。

哎呀,算了……我找到了。最后一块拼图是我不理解这个:

  • 要为您的产品添加描述,请添加一个名为“description”的元数据字段,并改用该字段。您可以使用 Markdown。

我相信我已经正确设置了一切。如果我检查设置:
订阅按钮将显示嵌入式定价表,并将使用 Stripe Checkout。
然后购买可以正常工作,但是,如果我不选中它并使用内置界面,我会收到错误框,例如:

\u003e期望存在类型为 card 的付款方式,但此 PaymentIntent 没有付款方式且未提供任何付款方式。请尝试再次提供 payment_method 或 payment_method_data 参数。

或者

\u003e此客户没有附加的付款来源或默认付款方式。请考虑添加默认付款方式。有关更多信息,请访问 https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority.

顶部的错误是非定期计划,底部是定期计划。\n有什么线索可以解决它吗?我更喜欢内置界面。

我解决了这个问题,看起来在我测试环境中玩弄用户时,Stripe 不喜欢我将同一个 Discourse 用户与不同的“订阅用户”一起使用。

另外,楼主应该澄清一下

\u003e要为您的产品添加描述,请添加一个名为“description”的元数据字段,然后改用该字段。您可以使用 Markdown。

转到 Stripe Dashboard,单击产品目录,单击产品,然后单击价格。在这里,您将找到可以添加描述的元数据字段。

但是,对我来说似乎不起作用。我添加了一个测试描述,在使用 Stripe 表格或内置布局时都没有任何变化。

已将 6 篇帖子合并到一个现有主题中:向 Discourse 订阅添加不同的支付方式

一篇帖子被合并到一个现有主题中:向 Discourse 订阅添加不同的支付方式

当我尝试创建产品时,我只会收到“500”错误。我正在测试环境中进行配置。我能检查什么来找出服务器错误的原因?

优惠券上也有类似的情况

是否在 {YOURFORUM}/logs 中同时创建了一个条目?

2 个赞

哇哦.. 真不知道有这样一个页面。显示无效的 API 密钥。我输入了一些垃圾内容作为密钥,以便现在可以继续前进并配置订阅包,稍后在我准备好测试时再回到密钥。

1 个赞

插件配置得很顺利,但后来我才意识到,这个插件只支持定期订阅,不支持一次性订阅(在规定期限后过期)。

例如,收取 X 金额 30 天。 30 天后,用户将从高级群组中移除。如果他们愿意,可以再次购买。通常我提供 1 个月、3 个月、12 个月的会员资格。

Stripe 要求我注册为公司才能支持定期付款。我在 XenForo 上进行一次性付款,XenForo 的原生功能会处理订阅过期和从群组成员资格中移除。

这完全打乱了我一个月内迁移到 discourse 的计划。 :cry:

我有一个解决方案。我可以帮助你创建一个 github action,它将从数据浏览器中提取数据,其中包括用户名和组 ID,以便将他们从中移除,然后相应地更改他们的组。

我正在为一个迁移到 Discourse 的客户做这件事,他们有一个包含日期的自定义字段。因此,我们需要将用户移动到一个即将过期的组,给他们一个横幅,然后在时间到期时将他们从付费组中移除。

如果你有预算,你可以联系我或在 Marketplace 中提问。我计划写一篇关于它的博客文章,其中包含一个通用示例,如果我能抽出时间的话。

6 个赞

你好,直到 Stripe 回调成功之前,订阅功能都能正常工作。我正在使用 Stripe 定价表。

我可以在 admin/plugins/discourse-subscriptions/subscriptions 页面看到订阅已成功注册。

但是,用户尚未被移至所需的用户组。

我已经配置了产品,其产品名称与 Stripe 上的完全一致,并且我还创建了一个已选择用户组的定价计划。我将定价计划的价格设置为零,因为我认为对于 Stripe 定价表配置来说,价格无关紧要。

我还遗漏了什么?