Verbeteringen aan de Subscriptions Plugin

Hello, I have made the following changes to this plugin and wanted to know if the Discourse team is open to a PR.

Would also love if others can do an extensive testing. I am right now testing the flows with whatever scenarios are critical to me.


The original plugin is an excellent foundation but is primarily focused on recurring subscriptions via Stripe. Have made the following changes:

Summary of New Features & Enhancements

1. Multi-Provider Payment System (feat. Razorpay) The plugin is no longer hard-coded to Stripe. It now uses a provider-based architecture that allows for multiple payment gateways.

  • Razorpay Integration: Razorpay has been fully integrated as a second payment provider. This is crucial for communities in markets like India where Razorpay is a preferred gateway.
  • Secure Webhooks: The Razorpay integration is robust and includes a secure webhook handler to confirm payments server-to-server, ensuring no subscriptions are missed if a user closes their browser post-payment.

2. One-Time, Time-Limited Subscriptions This introduces a new, flexible product type beyond standard recurring subscriptions.

  • Expiring Access: Admins can now create one-time payment plans that grant group access for a fixed duration (e.g., a 7-day event pass, a 30-day trial, or a 90-day package).
  • Automated Expiration: A daily background job runs automatically to check for expired subscriptions and remove users from the relevant groups, ensuring access control is fully automated.

3. Complete Pricing Page Overhaul The default user-facing subscription page has been completely rebuilt to improve conversions and user experience.

  • Modern Card-Based UI: The old product list is replaced by a clean, responsive, card-based layout that is easier to read and compare.
  • Theme-Aware: The new design uses Discourse’s theme variables and is fully compatible with both light and dark modes.
  • Single-Page Checkout: The entire checkout process now happens on the pricing page. Clicking “Subscribe” reveals a payment form directly on the page, eliminating a redundant step and reducing user friction.

4. Advanced Upselling & Value-Display Logic The new pricing cards are designed to be powerful upselling tools.

  • Effective Monthly Cost: The UI automatically calculates and displays the effective “cost per month” for all plan types (including 3-month or yearly one-time plans), allowing users to easily compare the value of different options.
  • Explicit Savings: A “Save ₹X” badge is automatically displayed on longer-term plans, clearly communicating the benefit of choosing a higher-value plan over the baseline.

5. Unified Admin & User Dashboards Both the admin and user billing pages have been refactored to be simpler and more powerful.

  • Single Unified View: Instead of separate lists for different payment types, there is now a single table that shows all subscriptions from all providers (Stripe, Razorpay, Manual).
  • Clear Information: These views clearly show the provider, status, expiry/renewal date, and amount for every transaction, giving both admins and users a complete history of their entitlements.

6. Manual Subscription Management for Admins A new set of tools has been added to give administrators more control.

  • Grant Subscription: Admins can now manually grant any subscription plan to any user for a specific duration. This is perfect for handling offline payments, providing complimentary access, or making corrections.
  • Revoke Access: Access for non-recurring plans can be immediately revoked from the admin dashboard.

7. Critical Bug Fix for Group Management

  • A major bug in the original group removal logic has been fixed. When a subscription is canceled or revoked, the system now performs a “safety check” to see if the user has any other active subscriptions for the same group. The user will only be removed from the group if they have no other valid way of accessing it, preventing users from being incorrectly removed.
5 likes

Kunt u een link naar uw github-repo opnemen?

1 like

Ja, ja, natuurlijk… geef me een dag. Sommige bugs met betrekking tot het verwerken van oude Stripe-gegevens worden opgelost wanneer we overschakelen naar deze pluginversie met nieuwe velden.

Have updated the first post with the repo.

Setup and Configuration Guide

This guide will walk you through setting up the necessary payment providers and creating your first products and plans.

1. Provider Setup

First, navigate to Admin > Settings > Plugins and select your primary payment provider from the discourse_subscriptions_payment_provider setting. Then, follow the instructions for your chosen provider below.

A) Configuring Stripe

If you chose Stripe as your provider:

  1. Fill in API Keys: In your Discourse settings, provide your Stripe API keys:
  • discourse_subscriptions_public_key (Your Stripe Publishable key)
  • discourse_subscriptions_secret_key (Your Stripe Secret key)
  1. Set up the Webhook: This step is crucial for tracking recurring payments, cancellations, and other subscription events.
  • In your Stripe Dashboard, navigate to Developers > Webhooks.
  • Click “Add an endpoint”.
  • For the Endpoint URL, enter:https://your-discourse-url.com/s/hooks
  • Click “Select events” and add the following three events:
    • checkout.session.completed
    • customer.subscription.deleted
    • customer.subscription.updated
  • Click “Add endpoint”.
  • On the next page, find the Signing secret (it starts with whsec_...).
  • Copy this secret and paste it into the discourse_subscriptions_webhook_secret setting in Discourse.
B) Configuring Razorpay

If you chose Razorpay as your provider:

  1. Fill in API Keys:
  • In your Razorpay Dashboard, go to Settings > API Keys to generate a new key pair.
  • Copy your keys and paste them into the corresponding Discourse settings:
    • discourse_subscriptions_razorpay_key_id
    • discourse_subscriptions_razorpay_key_secret
  1. Set up the Webhook: This step is crucial for confirming that a payment was successfully captured.
  • In your Razorpay Dashboard, go to Settings > Webhooks.
  • Click “+ Add New Webhook”.
  • For the Webhook URL, enter:https://your-discourse-url.com/s/hooks/razorpay
  • Create a Secret and keep it safe for the next step.
  • Under Active Events, select only payment.captured.
  • Click “Create Webhook”.
  • Copy the secret you just created and paste it into the discourse_subscriptions_razorpay_webhook_secret setting in Discourse.

2. Creating Products and Plans

Navigate to Admin > Plugins > Subscriptions to manage your products and plans.

Create a Product
  1. Go to the Products tab.
  2. Click “Create New Product”.
  3. Fill in the details. The “Description” field supports markdown and will be shown to users on the new pricing page.
Create Plans for the Product
  1. After creating a product, click the edit icon (✎) next to it.
  2. In the “Pricing Plans” section, click “Add New Plan”.
  3. You can create two types of plans:
  • To Create a Recurring Plan (e.g., Monthly/Yearly):
    • Check the “Recurring Plan?” box.
    • Set the Amount and Billing Interval (month, year, etc.).
    • Assign it to a User Group.
  • To Create a One-Time, Time-Limited Plan (e.g., 30-Day Pass):
    • Leave the “Recurring Plan?” box unchecked.
    • Set the Amount.
    • A new field, “Duration (in days)”, will appear. Enter the number of days the user should have access (e.g., 30).
    • Assign it to a User Group.

3. New Administrative Tools

This version includes new tools for manually managing subscriptions.

  • Granting a Subscription:
    • From the main Admin > Plugins > Subscriptions page, click the “Grant Subscription” button.
    • In the modal that appears, select a username and a plan.
    • If the chosen plan is a one-time plan, you can specify a duration in days. If you leave this blank, the user will be granted permanent access to the associated group.
  • Revoking a Subscription:
    • Navigate to the Subscriptions tab in the admin section.
    • Any non-recurring subscription (i.e., Manual or Razorpay) will have a “Revoke Access” button.
    • Clicking this will immediately remove the user from the associated group, ending their access.
3 likes

Ik heb de repository bijgewerkt met de volgende wijzigingen/fixes. Ik ben nu klaar om het op mijn productiesite te installeren en te gebruiken.

Samenvatting van stabiliteits- en beveiligingsverbeteringen

1. Moderne Stripe Checkout Integratie De plugin is bijgewerkt om de moderne, op redirects gebaseerde Stripe Checkout flow te gebruiken.

  • Wat dit betekent: In plaats van een creditcardformulier op de pagina, worden gebruikers nu naar een beveiligde, door Stripe gehoste pagina gestuurd om hun betaling te voltooien.
  • Waarom het beter is: Dit is de aanbevolen aanpak van Stripe. Het verbetert de beveiliging, vermindert de PCI-compliance last van uw site en biedt een betere gebruikerservaring met ondersteuning voor methoden zoals Apple Pay en Google Pay.

2. Rotsvaste Herankooplogica De logica die voorkomt dat gebruikers een product opnieuw kopen waarvoor ze al een actief abonnement hebben, is volledig herzien.

  • De Fix: We hebben de product_id toegevoegd aan elk lokaal abonnementsrecord. De controle is nu een eenvoudige, razendsnelle query tegen uw lokale database met nul externe API-aanroepen, waardoor deze 100% betrouwbaar is.
  • Het Resultaat: Een gebruiker met een actief abonnement (doorlopend of tijdelijk) wordt nu correct geblokkeerd om hetzelfde product opnieuw te kopen totdat het verloopt.

3. Gegevensintegriteit op Alle Dashboards De gebruikersfacturatiepagina en het admin-dashboard voor abonnementen zijn gecorrigeerd om ervoor te zorgen dat ze altijd nauwkeurige, realtime gegevens weergeven.

  • De Fix: Beide pagina’s halen nu de nieuwste status en vernieuwings-/verloopdatums voor elk abonnement rechtstreeks op bij de betalingsprovider (Stripe).
  • Het Resultaat: Wat u in het adminpaneel ziet, komt altijd perfect overeen met wat de gebruiker ziet, en beide zullen de ware status van het abonnement in Stripe weerspiegelen. De bugs die “N.v.t.” voor plandetails of onjuiste “actieve” statussen weergeven, zijn opgelost.

4. Robuuste Webhook- en Taakverwerking

  • Geen Dubbele Abonnementen Meer: De webhook-handler is gecorrigeerd om de volgorde van gebeurtenissen van Stripe correct af te handelen, zodat één transactie precies één abonnementsrecord aanmaakt.
  • Betrouwbare Verloop Taak: De dagelijkse achtergrondtaak die eenmalige abonnementen laat verlopen, is versterkt. Het stelt nu correct de vereiste API-sleutel in en laat een abonnement verlopen, zelfs als het oorspronkelijke abonnement uit Stripe is verwijderd, zodat uw groepsrechten altijd nauwkeurig zijn.
2 likes

Wauw, bedankt voor al deze wijzigingen!

Zoals het er nu voor staat, kunnen we niet zomaar heel grote wijzigingen in één keer samenvoegen. Als je deze wilt samenvoegen in de discourse-subscriptions plugin, moet je elke wijziging afzonderlijk opsplitsen en aparte PR’s maken met tests. Zorg er ook voor dat er geen brekende wijzigingen zijn voor bestaande gebruikers die momenteel de subscriptions plugin gebruiken en al veel abonnees hebben.

6 likes

Zeker, dank u wel. Ik zal de tijd nemen en meerdere PR’s aanmaken nadat de specificaties zijn uitgewerkt.

6 likes