שיפורים ל-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 לייקים

האם תוכל לכלול קישור למאגר ה-github שלך?

לייק 1

כן כן בוודאי.. רק תנו לי יום אחד. מתקנים כמה באגים הקשורים לטיפול בנתוני Stripe ישנים כאשר נעבור לגרסת הפלאגין הזו עם שדות חדשים.

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 לייקים

עדכנתי את ה-repo עם השינויים/תיקונים הבאים. אני מוכן כעת להתקין ולהשתמש בו באתר הייצור שלי.

סיכום שיפורי יציבות ואבטחה

1. אינטגרציית Stripe Checkout מודרנית התוסף עודכן לשימוש בזרימת ה-Stripe Checkout המודרנית, מבוססת ההפניה.

  • מה זה אומר: במקום טופס כרטיס אשראי בדף, משתמשים מופנים כעת לדף מאובטח, המתארח על ידי Stripe, להשלמת התשלום שלהם.
  • למה זה עדיף: זו הגישה המומלצת של Stripe. היא משפרת את האבטחה, מפחיתה את עומס תאימות ה-PCI של האתר שלך, ומספקת חווית משתמש טובה יותר עם תמיכה בשיטות כמו Apple Pay ו-Google Pay.

2. לוגיקת קנייה מחדש איתנה במיוחד הלוגיקה שמונעת ממשתמשים לקנות מחדש מוצר שיש להם כבר מנוי פעיל עליו, עברה שיפוץ מלא.

  • התיקון: הוספנו את ה-product_id לכל רשומת מנוי מקומית. הבדיקה היא כעת שאילתה פשוטה ומהירה ביותר נגד מסד הנתונים המקומי שלך עם אפס קריאות API חיצוניות, מה שהופך אותה לאמינה ב-100%.
  • התוצאה: משתמש עם מנוי פעיל (מחזורי או מוגבל בזמן) ייחסם כעת כראוי מלרכוש מחדש את אותו מוצר עד שיפוג תוקפו.

3. שלמות נתונים בכל לוחות המחוונים דף החיוב של המשתמש ולוח המחוונים של מנויי המנהל תוקנו כדי להבטיח שהם תמיד יציגו נתונים מדויקים בזמן אמת.

  • התיקון: שני הדפים כעת מאחזרים את הסטטוס האחרון ותאריכי החידוש/פג תוקף עבור כל מנוי ישירות מספק התשלומים (Stripe).
  • התוצאה: מה שאתה רואה בפאנל הניהול תמיד יתאים באופן מושלם למה שהמשתמש רואה, ושניהם ישקפו את המצב האמיתי של המנוי ב-Stripe. הבאגים שמציגים “N/A” עבור פרטי תוכנית או סטטוסים לא נכונים של “פעיל” נפתרו.

4. עיבוד Webhook ועבודות (Jobs) חזק

  • אין יותר מנויים כפולים: מטפל ה-webhook תוקן כדי לטפל כראוי ברצף האירועים מ-Stripe, ולהבטיח שטרנזקציה אחת תיצור בדיוק רשומה אחת של מנוי.
  • עבודת פג תוקף אמינה: העבודה היומית ברקע שמפוגרת תוכניות חד-פעמיות חוזקה. היא כעת מגדירה כראוי את ה-API key הנדרש ותפוג תוקף למנוי גם אם התוכנית המקורית נמחקה מ-Stripe, מה שמבטיח שהרשאות הקבוצה שלך תמיד יהיו מדויקות.
2 לייקים

וואו, תודה על כל השינויים האלה!

כפי שהם כרגע, אנחנו לא יכולים פשוט למזג שינויים גדולים בבת אחת. אם תרצה שהשינויים האלה ימוזגו לתוך תוסף discourse-subscriptions תצטרך לפצל כל שינוי בנפרד וליצור PRs נפרדים עם בדיקות. כמו כן, אנא ודא שאין שינויים ששוברים את התאימות למשתמשים קיימים שכבר משתמשים בתוסף המנויים ויש להם כבר מנויים רבים.

6 לייקים

בטח, תודה. אקח לי זמן ואצור מספר PRs לאחר שאעבוד על המפרטים.

6 לייקים