Documentation

    Documentation

    Documentation

    Ring Platform Logo

    Завантаження документації...

    Підготовка контенту платформи Ring

    Ring Platform Logo

    Завантаження документації...

    Підготовка контенту платформи Ring

    Ring Platform Logo

    Завантаження документації...

    Підготовка контенту платформи Ring

    1. /
    2. /SubscriptionConductor

    Updated Jun 30, 20267 min listen

    1. /
    2. /SubscriptionConductor

    Updated Jun 30, 20267 min listen

    1. /
    2. /SubscriptionConductor

    Updated Jun 30, 20267 min listen

    Concepts, value, and typical clone scenarios — less code.

    Welcome to Ring
    Quick Reference
    Getting Started
    Prerequisites
    Installation
    First Success Validation
    Next Steps
    Architecture
    Data Model
    Real Time
    Discovery Mutation Sync
    Security
    Backend Services
    k8s-postgres-fcm Mode
    Firebase Integration
    Features
    Authentication
    Email AI-CRM
    Entities
    Opportunities
    Notifications
    Push Notifications with FCM (Ring-Powered)
    Tunnel Protocol
    Wallet & Credit System
    Multi-Vendor Store
    Referral Codes (Refcodes)
    Affiliate & Referral Enablement
    Payments Overview
    PaymentConductor
    SubscriptionConductor
    VideoConductor
    News Module - Digital Newspaper Experience
    Member Blogs
    Public Profile Pages
    Username Reservation System
    Scientific Editor
    Locale System
    Security & Compliance
    NFT Marketplace
    Token Staking System
    Performance Optimization Patterns
    Mobile Experience
    Wallet
    Wallet Security Tips
    API
    Authentication
    Email AI-CRM API
    Entities
    Opportunities
    Messaging API
    Notifications API
    Wallet API
    Store API
    Admin API
    Customization
    Quick Start — Your First Ring Clone
    Customization Guide
    Token Economics Setup
    Payment Gateway Integration
    Reference Ring deployments
    Branding
    Themes
    Web3
    Token launch jurisdictions
    Deployment
    Self-hosted deployment
    Vercel
    Docker
    Monitoring & Analytics
    Performance Optimization
    Backup & Recovery
    Development
    Local Setup
    Code Structure
    Documentation components
    Community tooling
    Ring MCP Server
    Generative Images (ImageConductor)
    Autonomous Newsroom (Grok)
    OSS vs enterprise
    Whitelabel Navigation
    Best Practices
    Workflow
    Code Style
    Performance
    Testing
    Deployment
    Debugging
    Contributing
    MCP
    ring-image-create
    ring-video-create
    Examples
    Quick Start
    White Label
    Real World
    Integrations
    Ethereum wallets (Wagmi v3)

    Quick entry (CTOs · auditors · agents)

    Welcome — mission & audiences
    Quick Reference
    Getting started
    Architecture & Auth.js
    Backend modes & databases (DB_BACKEND_MODE)
    Self-hosted
    Ring MCP Tools
    Ring MCP Server
    Token economics
    Token launch jurisdictions
    Deploy (Docker · k8s)
    Security & compliance reads
    ringdom.org — LegioX homebase
    Source — MIT license (GitHub)

    Concepts, value, and typical clone scenarios — less code.

    Welcome to Ring
    Quick Reference
    Getting Started
    Prerequisites
    Installation
    First Success Validation
    Next Steps
    Architecture
    Data Model
    Real Time
    Discovery Mutation Sync
    Security
    Backend Services
    k8s-postgres-fcm Mode
    Firebase Integration
    Features
    Authentication
    Email AI-CRM
    Entities
    Opportunities
    Notifications
    Push Notifications with FCM (Ring-Powered)
    Tunnel Protocol
    Wallet & Credit System
    Multi-Vendor Store
    Referral Codes (Refcodes)
    Affiliate & Referral Enablement
    Payments Overview
    PaymentConductor
    SubscriptionConductor
    VideoConductor
    News Module - Digital Newspaper Experience
    Member Blogs
    Public Profile Pages
    Username Reservation System
    Scientific Editor
    Locale System
    Security & Compliance
    NFT Marketplace
    Token Staking System
    Performance Optimization Patterns
    Mobile Experience
    Wallet
    Wallet Security Tips
    API
    Authentication
    Email AI-CRM API
    Entities
    Opportunities
    Messaging API
    Notifications API
    Wallet API
    Store API
    Admin API
    Customization
    Quick Start — Your First Ring Clone
    Customization Guide
    Token Economics Setup
    Payment Gateway Integration
    Reference Ring deployments
    Branding
    Themes
    Web3
    Token launch jurisdictions
    Deployment
    Self-hosted deployment
    Vercel
    Docker
    Monitoring & Analytics
    Performance Optimization
    Backup & Recovery
    Development
    Local Setup
    Code Structure
    Documentation components
    Community tooling
    Ring MCP Server
    Generative Images (ImageConductor)
    Autonomous Newsroom (Grok)
    OSS vs enterprise
    Whitelabel Navigation
    Best Practices
    Workflow
    Code Style
    Performance
    Testing
    Deployment
    Debugging
    Contributing
    MCP
    ring-image-create
    ring-video-create
    Examples
    Quick Start
    White Label
    Real World
    Integrations
    Ethereum wallets (Wagmi v3)

    Quick entry (CTOs · auditors · agents)

    Welcome — mission & audiences
    Quick Reference
    Getting started
    Architecture & Auth.js
    Backend modes & databases (DB_BACKEND_MODE)
    Self-hosted
    Ring MCP Tools
    Ring MCP Server
    Token economics
    Token launch jurisdictions
    Deploy (Docker · k8s)
    Security & compliance reads
    ringdom.org — LegioX homebase
    Source — MIT license (GitHub)

    Concepts, value, and typical clone scenarios — less code.

    Welcome to Ring
    Quick Reference
    Getting Started
    Prerequisites
    Installation
    First Success Validation
    Next Steps
    Architecture
    Data Model
    Real Time
    Discovery Mutation Sync
    Security
    Backend Services
    k8s-postgres-fcm Mode
    Firebase Integration
    Features
    Authentication
    Email AI-CRM
    Entities
    Opportunities
    Notifications
    Push Notifications with FCM (Ring-Powered)
    Tunnel Protocol
    Wallet & Credit System
    Multi-Vendor Store
    Referral Codes (Refcodes)
    Affiliate & Referral Enablement
    Payments Overview
    PaymentConductor
    SubscriptionConductor
    VideoConductor
    News Module - Digital Newspaper Experience
    Member Blogs
    Public Profile Pages
    Username Reservation System
    Scientific Editor
    Locale System
    Security & Compliance
    NFT Marketplace
    Token Staking System
    Performance Optimization Patterns
    Mobile Experience
    Wallet
    Wallet Security Tips
    API
    Authentication
    Email AI-CRM API
    Entities
    Opportunities
    Messaging API
    Notifications API
    Wallet API
    Store API
    Admin API
    Customization
    Quick Start — Your First Ring Clone
    Customization Guide
    Token Economics Setup
    Payment Gateway Integration
    Reference Ring deployments
    Branding
    Themes
    Web3
    Token launch jurisdictions
    Deployment
    Self-hosted deployment
    Vercel
    Docker
    Monitoring & Analytics
    Performance Optimization
    Backup & Recovery
    Development
    Local Setup
    Code Structure
    Documentation components
    Community tooling
    Ring MCP Server
    Generative Images (ImageConductor)
    Autonomous Newsroom (Grok)
    OSS vs enterprise
    Whitelabel Navigation
    Best Practices
    Workflow
    Code Style
    Performance
    Testing
    Deployment
    Debugging
    Contributing
    MCP
    ring-image-create
    ring-video-create
    Examples
    Quick Start
    White Label
    Real World
    Integrations
    Ethereum wallets (Wagmi v3)

    Quick entry (CTOs · auditors · agents)

    Welcome — mission & audiences
    Quick Reference
    Getting started
    Architecture & Auth.js
    Backend modes & databases (DB_BACKEND_MODE)
    Self-hosted
    Ring MCP Tools
    Ring MCP Server
    Token economics
    Token launch jurisdictions
    Deploy (Docker · k8s)
    Security & compliance reads
    ringdom.org — LegioX homebase
    Source — MIT license (GitHub)
    Docs
    Features
    Docs
    Features
    Docs
    Features

    SubscriptionConductor

    Filter this page with Founder / Developer in the docs sidebar. Founders learn what each provider costs and how to set fees; developers get the architecture, provider module contracts, and cron pipeline details.

    SubscriptionConductor (v1, Phase S4) is Ring Platform's multi-provider membership subscription billing system. One SSOT ledger (subscription_ledger) tracks all subscriber state regardless of payment method. Six provider modules implement a shared SubscriptionProviderModule contract, and five cron pipelines keep subscriptions current.

    Implementation: lib/payments/subscription/.

    What founders get from SubscriptionConductor

    Your platform earns recurring revenue through membership subscriptions — with zero platform fees on internal methods (credit balance, RING token, NFT gate). Choose which gateways to enable, set fee pass-through, and watch net revenue in the admin dashboard.

    Feature status

    ProviderDetailsGatewayStatus
    Credit Balanceauto-deduct from internal fiat USD creditsCredit Points✅ Live
    WayForPayCard (hosted page) + recToken recurring (regularApi)WayForPay (UAH)✅ Live
    StripeStripe Subscriptions API (Phase S3)Stripe (USD)✅ Live (Phase S3)
    Native Tokenon-chain Solana recurring via Membership.solNative Token (RING)✅ Live (Phase S6)
    NFT Gatesoulbound certificate 12-month gateNFT Certificate🟡 Phase S7 (stub)
    PayPalPayPal recurring billingPayPal (USD)🟡 Phase S8 (stub)

    Fee rates & net revenue

    Each gateway deducts its own fee. Internal methods (credit balance, RING token, NFT gate) charge 0% — every dollar goes to your platform.

    ProviderFee %Fixed FeeCurrency
    WayForPay2.5%—UAH
    Stripe2.9%$0.30USD
    Credit Balance0%—USD
    Native Token0%—RING (Tokens)
    NFT Gate0%—RING
    PayPal2.9%$0.30USD

    Net revenue formula: net = gross - (gross × feePercent / 100) - feeFixed. The calculateNetRevenue() function in subscription-config.ts computes this server-side; the admin dashboard displays gross, fee, and net per subscription.

    Configuration (ring-config.json)

    All provider settings live in ring-config.json under payment.gateways:

    • cardPaymentProcessor — default card gateway (wayforpay or stripe). Override per-deployment with PAYMENT_MEMBERSHIP_PROCESSOR=stripe.
    • supportedMethods — providers shown to users at checkout.
    • futureMethods — providers tagged as "Coming Soon" in the UI.
    • gateways.<provider>.feePercent — percentage fee deducted before your net revenue.

    Admin dashboard

    Superadmins access /admin/subscriptions for:

    • Subscription list — filter by provider, status, user; each row shows gross, fee, and net revenue.
    • Aggregated stats — /api/admin/subscriptions/stats returns total_active, due_for_payment, breakdowns by_provider and by_method.
    • Revenue tracking — calculateNetRevenue() is called per row so founders see real take-home amounts after gateway fees.

    Architecture

    Provider registry

    Six provider modules implement the SubscriptionProviderModule contract (lib/payments/subscription/subscription-types.ts). The conductor resolves them by provider ID:

    Provider IDModuleSource
    credit_balanceringCreditSubscriptionProviderproviders/ring-credit-subscription.ts
    native_tokennativeTokenSubscriptionProviderproviders/native-token-subscription.ts
    stripestripeSubscriptionProviderproviders/stripe-subscription.ts
    wayforpaywayforpaySubscriptionProviderproviders/wayforpay-subscription.ts
    nft_gatenftGateSubscriptionProviderproviders/subscription-provider-stubs.ts
    paypal

    Related

    • PaymentConductor — one-time payment orchestration
    • WayForPay integration
    • Wallet & Credits
    • Store — membership checkout flow
    • Admin dashboard

    SubscriptionConductor

    Filter this page with Founder / Developer in the docs sidebar. Founders learn what each provider costs and how to set fees; developers get the architecture, provider module contracts, and cron pipeline details.

    SubscriptionConductor (v1, Phase S4) is Ring Platform's multi-provider membership subscription billing system. One SSOT ledger (subscription_ledger) tracks all subscriber state regardless of payment method. Six provider modules implement a shared SubscriptionProviderModule contract, and five cron pipelines keep subscriptions current.

    Implementation: lib/payments/subscription/.

    What founders get from SubscriptionConductor

    Your platform earns recurring revenue through membership subscriptions — with zero platform fees on internal methods (credit balance, RING token, NFT gate). Choose which gateways to enable, set fee pass-through, and watch net revenue in the admin dashboard.

    Feature status

    ProviderDetailsGatewayStatus
    Credit Balanceauto-deduct from internal fiat USD creditsCredit Points✅ Live
    WayForPayCard (hosted page) + recToken recurring (regularApi)WayForPay (UAH)✅ Live
    StripeStripe Subscriptions API (Phase S3)Stripe (USD)✅ Live (Phase S3)
    Native Tokenon-chain Solana recurring via Membership.solNative Token (RING)✅ Live (Phase S6)
    NFT Gatesoulbound certificate 12-month gateNFT Certificate🟡 Phase S7 (stub)
    PayPalPayPal recurring billingPayPal (USD)🟡 Phase S8 (stub)

    Fee rates & net revenue

    Each gateway deducts its own fee. Internal methods (credit balance, RING token, NFT gate) charge 0% — every dollar goes to your platform.

    ProviderFee %Fixed FeeCurrency
    WayForPay2.5%—UAH
    Stripe2.9%$0.30USD
    Credit Balance0%—USD
    Native Token0%—RING (Tokens)
    NFT Gate0%—RING
    PayPal2.9%$0.30USD

    Net revenue formula: net = gross - (gross × feePercent / 100) - feeFixed. The calculateNetRevenue() function in subscription-config.ts computes this server-side; the admin dashboard displays gross, fee, and net per subscription.

    Configuration (ring-config.json)

    All provider settings live in ring-config.json under payment.gateways:

    • cardPaymentProcessor — default card gateway (wayforpay or stripe). Override per-deployment with PAYMENT_MEMBERSHIP_PROCESSOR=stripe.
    • supportedMethods — providers shown to users at checkout.
    • futureMethods — providers tagged as "Coming Soon" in the UI.
    • gateways.<provider>.feePercent — percentage fee deducted before your net revenue.

    Admin dashboard

    Superadmins access /admin/subscriptions for:

    • Subscription list — filter by provider, status, user; each row shows gross, fee, and net revenue.
    • Aggregated stats — /api/admin/subscriptions/stats returns total_active, due_for_payment, breakdowns by_provider and by_method.
    • Revenue tracking — calculateNetRevenue() is called per row so founders see real take-home amounts after gateway fees.

    Architecture

    Provider registry

    Six provider modules implement the SubscriptionProviderModule contract (lib/payments/subscription/subscription-types.ts). The conductor resolves them by provider ID:

    Provider IDModuleSource
    credit_balanceringCreditSubscriptionProviderproviders/ring-credit-subscription.ts
    native_tokennativeTokenSubscriptionProviderproviders/native-token-subscription.ts
    stripestripeSubscriptionProviderproviders/stripe-subscription.ts
    wayforpaywayforpaySubscriptionProviderproviders/wayforpay-subscription.ts
    nft_gatenftGateSubscriptionProviderproviders/subscription-provider-stubs.ts
    paypal

    Related

    • PaymentConductor — one-time payment orchestration
    • WayForPay integration
    • Wallet & Credits
    • Store — membership checkout flow
    • Admin dashboard

    SubscriptionConductor

    Filter this page with Founder / Developer in the docs sidebar. Founders learn what each provider costs and how to set fees; developers get the architecture, provider module contracts, and cron pipeline details.

    SubscriptionConductor (v1, Phase S4) is Ring Platform's multi-provider membership subscription billing system. One SSOT ledger (subscription_ledger) tracks all subscriber state regardless of payment method. Six provider modules implement a shared SubscriptionProviderModule contract, and five cron pipelines keep subscriptions current.

    Implementation: lib/payments/subscription/.

    What founders get from SubscriptionConductor

    Your platform earns recurring revenue through membership subscriptions — with zero platform fees on internal methods (credit balance, RING token, NFT gate). Choose which gateways to enable, set fee pass-through, and watch net revenue in the admin dashboard.

    Feature status

    ProviderDetailsGatewayStatus
    Credit Balanceauto-deduct from internal fiat USD creditsCredit Points✅ Live
    WayForPayCard (hosted page) + recToken recurring (regularApi)WayForPay (UAH)✅ Live
    StripeStripe Subscriptions API (Phase S3)Stripe (USD)✅ Live (Phase S3)
    Native Tokenon-chain Solana recurring via Membership.solNative Token (RING)✅ Live (Phase S6)
    NFT Gatesoulbound certificate 12-month gateNFT Certificate🟡 Phase S7 (stub)
    PayPalPayPal recurring billingPayPal (USD)🟡 Phase S8 (stub)

    Fee rates & net revenue

    Each gateway deducts its own fee. Internal methods (credit balance, RING token, NFT gate) charge 0% — every dollar goes to your platform.

    ProviderFee %Fixed FeeCurrency
    WayForPay2.5%—UAH
    Stripe2.9%$0.30USD
    Credit Balance0%—USD
    Native Token0%—RING (Tokens)
    NFT Gate0%—RING
    PayPal2.9%$0.30USD

    Net revenue formula: net = gross - (gross × feePercent / 100) - feeFixed. The calculateNetRevenue() function in subscription-config.ts computes this server-side; the admin dashboard displays gross, fee, and net per subscription.

    Configuration (ring-config.json)

    All provider settings live in ring-config.json under payment.gateways:

    • cardPaymentProcessor — default card gateway (wayforpay or stripe). Override per-deployment with PAYMENT_MEMBERSHIP_PROCESSOR=stripe.
    • supportedMethods — providers shown to users at checkout.
    • futureMethods — providers tagged as "Coming Soon" in the UI.
    • gateways.<provider>.feePercent — percentage fee deducted before your net revenue.

    Admin dashboard

    Superadmins access /admin/subscriptions for:

    • Subscription list — filter by provider, status, user; each row shows gross, fee, and net revenue.
    • Aggregated stats — /api/admin/subscriptions/stats returns total_active, due_for_payment, breakdowns by_provider and by_method.
    • Revenue tracking — calculateNetRevenue() is called per row so founders see real take-home amounts after gateway fees.

    Architecture

    Provider registry

    Six provider modules implement the SubscriptionProviderModule contract (lib/payments/subscription/subscription-types.ts). The conductor resolves them by provider ID:

    Provider IDModuleSource
    credit_balanceringCreditSubscriptionProviderproviders/ring-credit-subscription.ts
    native_tokennativeTokenSubscriptionProviderproviders/native-token-subscription.ts
    stripestripeSubscriptionProviderproviders/stripe-subscription.ts
    wayforpaywayforpaySubscriptionProviderproviders/wayforpay-subscription.ts
    nft_gatenftGateSubscriptionProviderproviders/subscription-provider-stubs.ts
    paypal

    Related

    • PaymentConductor — one-time payment orchestration
    • WayForPay integration
    • Wallet & Credits
    • Store — membership checkout flow
    • Admin dashboard
    paypalSubscriptionProvider
    providers/subscription-provider-stubs.ts

    Credit Balance, Stripe, WayForPay, and Native Token have full implementations. NFT Gate and PayPal are stubs.

    Future features

    Phase S7 (planned): NFT Gate — soulbound 12-month membership certificate.

    Phase S8 (planned): PayPal recurring billing integration.

    subscription_ledger schema

    SSOT collection: subscription_ledger. Schema defined in lib/payments/subscription/subscription-ledger-schema.ts (Zod).

    Key fields:

    FieldTypeDescription
    idstringLedger row ID (sub_<ts>_<userIdSuffix>)
    user_idstringOwner user ID
    providerenumstripe, wayforpay, credit_balance, native_token, nft_gate, paypal
    gatewaystringHuman-readable label (e.g. "Stripe", "WayForPay")
    methodenumcard, credit_balance, crypto, nft
    statusenumactive, expired, cancelled, suspended, grace_period
    amountnumberSubscription price (minor units)
    currencystringBilling currency
    gateway_fee_percentnumberPercentage fee (e.g. 2.9)
    gateway_fee_fixednumberFixed fee in minor units (e.g. 30 for Stripe)
    stripe_subscription_idstring?Stripe reference (if Stripe provider)
    wayforpay_rec_tokenstring?WayForPay recurring token
    solana_tx_signaturestring?On-chain transaction signature
    nft_mint_addressstring?NFT certificate mint address
    start_timenumberSubscription start (ms epoch)
    next_payment_duenumberNext payment due timestamp
    failed_attemptsnumberConsecutive payment failures (max 3 → auto-expiry)
    auto_renewbooleanAuto-renew flag
    total_paidstringLifetime total paid
    payments_countnumberSuccessful payment count

    Conductor API

    SubscriptionConductor (lib/payments/subscription/subscription-conductor.ts) exposes:

    OperationSignatureDescription
    createSubscription(input: CreateSubscriptionInput) → CreateSubscriptionResultRoute to provider module, insert ledger row
    cancelSubscription(userId, provider, gatewayRef?) → CancelSubscriptionResultCancel at provider + mark ledger rows cancelled
    renewSubscription(userId, provider, gatewayRef?) → RenewSubscriptionResultRenew at provider + update ledger
    getSubscription(userId) → SubscriptionLedgerRow | nullLatest active subscription for user
    getSubscriptions(filter) → SubscriptionLedgerRow[]Query by user, provider, status, method, due window
    getStats() → SubscriptionStatsAggregate counts by status, provider, method
    calculateNetRevenue(row) → { gross, fee, net, currency }Per-row net revenue

    API routes

    MethodPathPurposeAuth
    POST/api/membership/subscription/createCreate subscription via conductorSession
    GET/api/membership/subscription/statusGet subscription status + balanceSession
    POST/api/membership/subscription/cancelCancel subscriptionSession
    POST/api/membership/payment/tokenProcess native token paymentSession
    POST/api/membership/payment/creditProcess credit balance paymentSession
    GET/api/membership/payment/creditGet credit balance pricing infoSession
    GET/api/admin/subscriptionsList all subscriptionsSuperadmin
    GET/api/admin/subscriptions/statsAggregated statsSuperadmin

    Cron pipelines

    Five cron pipelines registered in lib/processes/registry.ts under the membership category:

    Pipeline IDCron PathHandlerSchedule
    subscription-expiry-check/api/cron/subscription-expiryrunSubscriptionExpiryCheckDaily midnight
    credit-balance-monthly/api/cron/credit-balance-monthlyrunCreditBalanceMonthlyHourly
    subscription-payment/api/cron/subscription-paymentrunSubscriptionPaymentCheckDaily 2am
    solana-batch-payment/api/cron/solana-batch-paymentrunSolanaBatchPaymentDaily 3am
    nft-gate-expiry/api/cron/nft-gate-expiryrunNftGateExpiryDaily 4am

    Pipelines are triggered via HTTP cron jobs hitting the cronPath endpoints. Handlers import from lib/processes/subscription/:

    • expiry-check.ts — marks overdue subscriptions as expired and downgrades user roles
    • credit-balance-monthly.ts — deducts monthly fee from user credit balance
    • subscription-payment.ts — processes Stripe/WayForPay recurring charges
    • solana-nft-stubs.ts — batch RING token transfers and NFT gate expiry

    Adding a new provider

    1. Implement SubscriptionProviderModule contract in providers/<name>-subscription.ts
    2. Register in subscription-conductor.ts providerRegistry Map
    3. Add gateway config to ring-config.json payment.gateways.<provider>
    4. Add to SUBSCRIPTION_PROVIDERS array in subscription-ledger-schema.ts
    5. Update getMembershipPaymentOptions() in subscription-config.ts
    6. If needed, add a cron pipeline handler in lib/processes/subscription/

    Environment variables

    Smoke tests

    5 smoke test suites exercise the full subscription pipeline (AI-RING/scripts/):

    SuitePrefixCoverage
    smoke-subscription-conductor.ctssmk39_13 pipelines (conductor create/cancel/renew, ledger SSOT, Stripe API, WayForPay, config)
    smoke-subscription-cron.ctssmk40_5 cron pipelines (expiry, credit, payment, solana, nft)
    smoke-subscription-cron-http.ctssmk41_5 HTTP cron routes with CRON_SECRET auth
    smoke-subscription-stripe.ctssmk39_Stripe API + webhook (customer, price, subscription, cancel, dispatch, zod)
    smoke-subscription-admin.ctssmk42_Admin dashboard list + stats endpoints

    Run via scripts/run-all-smokes.sh. Canonical pipeline registry: PIPELINES.md.

    json
    
    {
      "payment": {
        "cardPaymentProcessor": "wayforpay",
        "supportedMethods": ["wayforpay", "credit_balance", "native_token"],
        "futureMethods": ["stripe", "paypal", "nft_gate"],
        "gateways": {
          "wayforpay": { "enabled": true, "feePercent": 2.5, "currency": "UAH" },
          "stripe": { "enabled": false, "feePercent": 2.9, "feeFixedCents": 30, "currency": "USD" },
          "credit_balance": { "enabled": true, "feePercent": 0, "currency": "USD" },
          "native_token": { "enabled": true, "feePercent": 0, "currency": "RING", "label": "Tokens" },
          "paypal": { "enabled": false, "feePercent": 2.9, "feeFixedCents": 30, "currency": "USD" },
          "nft_gate": { "enabled": false, "feePercent": 0, "currency": "RING", "label": "NFT Certificate" }
        }
      }
    }
    text
    
    Membership upgrade / checkout
            ↓
    lib/payments/subscription/subscription-conductor.ts
            ↓
    Provider modules: stripe | wayforpay | credit_balance | native_token | nft_gate | paypal
            ↓
    subscription_ledger (PostgreSQL — provider-agnostic SSOT)
            ↓
    Cron pipelines: expiry + payment + credit-balance + solana-batch + nft-gate
    bash
    
    PAYMENT_MEMBERSHIP_PROCESSOR=wayforpay    # Override card gateway for membership
    WAYFORPAY_MERCHANT_ACCOUNT=your_merchant
    WAYFORPAY_SECRET_KEY=your_secret
    STRIPE_SECRET_KEY=sk_live_...
    STRIPE_WEBHOOK_SECRET=whsec_...
    paypalSubscriptionProvider
    providers/subscription-provider-stubs.ts

    Credit Balance, Stripe, WayForPay, and Native Token have full implementations. NFT Gate and PayPal are stubs.

    Future features

    Phase S7 (planned): NFT Gate — soulbound 12-month membership certificate.

    Phase S8 (planned): PayPal recurring billing integration.

    subscription_ledger schema

    SSOT collection: subscription_ledger. Schema defined in lib/payments/subscription/subscription-ledger-schema.ts (Zod).

    Key fields:

    FieldTypeDescription
    idstringLedger row ID (sub_<ts>_<userIdSuffix>)
    user_idstringOwner user ID
    providerenumstripe, wayforpay, credit_balance, native_token, nft_gate, paypal
    gatewaystringHuman-readable label (e.g. "Stripe", "WayForPay")
    methodenumcard, credit_balance, crypto, nft
    statusenumactive, expired, cancelled, suspended, grace_period
    amountnumberSubscription price (minor units)
    currencystringBilling currency
    gateway_fee_percentnumberPercentage fee (e.g. 2.9)
    gateway_fee_fixednumberFixed fee in minor units (e.g. 30 for Stripe)
    stripe_subscription_idstring?Stripe reference (if Stripe provider)
    wayforpay_rec_tokenstring?WayForPay recurring token
    solana_tx_signaturestring?On-chain transaction signature
    nft_mint_addressstring?NFT certificate mint address
    start_timenumberSubscription start (ms epoch)
    next_payment_duenumberNext payment due timestamp
    failed_attemptsnumberConsecutive payment failures (max 3 → auto-expiry)
    auto_renewbooleanAuto-renew flag
    total_paidstringLifetime total paid
    payments_countnumberSuccessful payment count

    Conductor API

    SubscriptionConductor (lib/payments/subscription/subscription-conductor.ts) exposes:

    OperationSignatureDescription
    createSubscription(input: CreateSubscriptionInput) → CreateSubscriptionResultRoute to provider module, insert ledger row
    cancelSubscription(userId, provider, gatewayRef?) → CancelSubscriptionResultCancel at provider + mark ledger rows cancelled
    renewSubscription(userId, provider, gatewayRef?) → RenewSubscriptionResultRenew at provider + update ledger
    getSubscription(userId) → SubscriptionLedgerRow | nullLatest active subscription for user
    getSubscriptions(filter) → SubscriptionLedgerRow[]Query by user, provider, status, method, due window
    getStats() → SubscriptionStatsAggregate counts by status, provider, method
    calculateNetRevenue(row) → { gross, fee, net, currency }Per-row net revenue

    API routes

    MethodPathPurposeAuth
    POST/api/membership/subscription/createCreate subscription via conductorSession
    GET/api/membership/subscription/statusGet subscription status + balanceSession
    POST/api/membership/subscription/cancelCancel subscriptionSession
    POST/api/membership/payment/tokenProcess native token paymentSession
    POST/api/membership/payment/creditProcess credit balance paymentSession
    GET/api/membership/payment/creditGet credit balance pricing infoSession
    GET/api/admin/subscriptionsList all subscriptionsSuperadmin
    GET/api/admin/subscriptions/statsAggregated statsSuperadmin

    Cron pipelines

    Five cron pipelines registered in lib/processes/registry.ts under the membership category:

    Pipeline IDCron PathHandlerSchedule
    subscription-expiry-check/api/cron/subscription-expiryrunSubscriptionExpiryCheckDaily midnight
    credit-balance-monthly/api/cron/credit-balance-monthlyrunCreditBalanceMonthlyHourly
    subscription-payment/api/cron/subscription-paymentrunSubscriptionPaymentCheckDaily 2am
    solana-batch-payment/api/cron/solana-batch-paymentrunSolanaBatchPaymentDaily 3am
    nft-gate-expiry/api/cron/nft-gate-expiryrunNftGateExpiryDaily 4am

    Pipelines are triggered via HTTP cron jobs hitting the cronPath endpoints. Handlers import from lib/processes/subscription/:

    • expiry-check.ts — marks overdue subscriptions as expired and downgrades user roles
    • credit-balance-monthly.ts — deducts monthly fee from user credit balance
    • subscription-payment.ts — processes Stripe/WayForPay recurring charges
    • solana-nft-stubs.ts — batch RING token transfers and NFT gate expiry

    Adding a new provider

    1. Implement SubscriptionProviderModule contract in providers/<name>-subscription.ts
    2. Register in subscription-conductor.ts providerRegistry Map
    3. Add gateway config to ring-config.json payment.gateways.<provider>
    4. Add to SUBSCRIPTION_PROVIDERS array in subscription-ledger-schema.ts
    5. Update getMembershipPaymentOptions() in subscription-config.ts
    6. If needed, add a cron pipeline handler in lib/processes/subscription/

    Environment variables

    Smoke tests

    5 smoke test suites exercise the full subscription pipeline (AI-RING/scripts/):

    SuitePrefixCoverage
    smoke-subscription-conductor.ctssmk39_13 pipelines (conductor create/cancel/renew, ledger SSOT, Stripe API, WayForPay, config)
    smoke-subscription-cron.ctssmk40_5 cron pipelines (expiry, credit, payment, solana, nft)
    smoke-subscription-cron-http.ctssmk41_5 HTTP cron routes with CRON_SECRET auth
    smoke-subscription-stripe.ctssmk39_Stripe API + webhook (customer, price, subscription, cancel, dispatch, zod)
    smoke-subscription-admin.ctssmk42_Admin dashboard list + stats endpoints

    Run via scripts/run-all-smokes.sh. Canonical pipeline registry: PIPELINES.md.

    json
    
    {
      "payment": {
        "cardPaymentProcessor": "wayforpay",
        "supportedMethods": ["wayforpay", "credit_balance", "native_token"],
        "futureMethods": ["stripe", "paypal", "nft_gate"],
        "gateways": {
          "wayforpay": { "enabled": true, "feePercent": 2.5, "currency": "UAH" },
          "stripe": { "enabled": false, "feePercent": 2.9, "feeFixedCents": 30, "currency": "USD" },
          "credit_balance": { "enabled": true, "feePercent": 0, "currency": "USD" },
          "native_token": { "enabled": true, "feePercent": 0, "currency": "RING", "label": "Tokens" },
          "paypal": { "enabled": false, "feePercent": 2.9, "feeFixedCents": 30, "currency": "USD" },
          "nft_gate": { "enabled": false, "feePercent": 0, "currency": "RING", "label": "NFT Certificate" }
        }
      }
    }
    text
    
    Membership upgrade / checkout
            ↓
    lib/payments/subscription/subscription-conductor.ts
            ↓
    Provider modules: stripe | wayforpay | credit_balance | native_token | nft_gate | paypal
            ↓
    subscription_ledger (PostgreSQL — provider-agnostic SSOT)
            ↓
    Cron pipelines: expiry + payment + credit-balance + solana-batch + nft-gate
    bash
    
    PAYMENT_MEMBERSHIP_PROCESSOR=wayforpay    # Override card gateway for membership
    WAYFORPAY_MERCHANT_ACCOUNT=your_merchant
    WAYFORPAY_SECRET_KEY=your_secret
    STRIPE_SECRET_KEY=sk_live_...
    STRIPE_WEBHOOK_SECRET=whsec_...
    paypalSubscriptionProvider
    providers/subscription-provider-stubs.ts

    Credit Balance, Stripe, WayForPay, and Native Token have full implementations. NFT Gate and PayPal are stubs.

    Future features

    Phase S7 (planned): NFT Gate — soulbound 12-month membership certificate.

    Phase S8 (planned): PayPal recurring billing integration.

    subscription_ledger schema

    SSOT collection: subscription_ledger. Schema defined in lib/payments/subscription/subscription-ledger-schema.ts (Zod).

    Key fields:

    FieldTypeDescription
    idstringLedger row ID (sub_<ts>_<userIdSuffix>)
    user_idstringOwner user ID
    providerenumstripe, wayforpay, credit_balance, native_token, nft_gate, paypal
    gatewaystringHuman-readable label (e.g. "Stripe", "WayForPay")
    methodenumcard, credit_balance, crypto, nft
    statusenumactive, expired, cancelled, suspended, grace_period
    amountnumberSubscription price (minor units)
    currencystringBilling currency
    gateway_fee_percentnumberPercentage fee (e.g. 2.9)
    gateway_fee_fixednumberFixed fee in minor units (e.g. 30 for Stripe)
    stripe_subscription_idstring?Stripe reference (if Stripe provider)
    wayforpay_rec_tokenstring?WayForPay recurring token
    solana_tx_signaturestring?On-chain transaction signature
    nft_mint_addressstring?NFT certificate mint address
    start_timenumberSubscription start (ms epoch)
    next_payment_duenumberNext payment due timestamp
    failed_attemptsnumberConsecutive payment failures (max 3 → auto-expiry)
    auto_renewbooleanAuto-renew flag
    total_paidstringLifetime total paid
    payments_countnumberSuccessful payment count

    Conductor API

    SubscriptionConductor (lib/payments/subscription/subscription-conductor.ts) exposes:

    OperationSignatureDescription
    createSubscription(input: CreateSubscriptionInput) → CreateSubscriptionResultRoute to provider module, insert ledger row
    cancelSubscription(userId, provider, gatewayRef?) → CancelSubscriptionResultCancel at provider + mark ledger rows cancelled
    renewSubscription(userId, provider, gatewayRef?) → RenewSubscriptionResultRenew at provider + update ledger
    getSubscription(userId) → SubscriptionLedgerRow | nullLatest active subscription for user
    getSubscriptions(filter) → SubscriptionLedgerRow[]Query by user, provider, status, method, due window
    getStats() → SubscriptionStatsAggregate counts by status, provider, method
    calculateNetRevenue(row) → { gross, fee, net, currency }Per-row net revenue

    API routes

    MethodPathPurposeAuth
    POST/api/membership/subscription/createCreate subscription via conductorSession
    GET/api/membership/subscription/statusGet subscription status + balanceSession
    POST/api/membership/subscription/cancelCancel subscriptionSession
    POST/api/membership/payment/tokenProcess native token paymentSession
    POST/api/membership/payment/creditProcess credit balance paymentSession
    GET/api/membership/payment/creditGet credit balance pricing infoSession
    GET/api/admin/subscriptionsList all subscriptionsSuperadmin
    GET/api/admin/subscriptions/statsAggregated statsSuperadmin

    Cron pipelines

    Five cron pipelines registered in lib/processes/registry.ts under the membership category:

    Pipeline IDCron PathHandlerSchedule
    subscription-expiry-check/api/cron/subscription-expiryrunSubscriptionExpiryCheckDaily midnight
    credit-balance-monthly/api/cron/credit-balance-monthlyrunCreditBalanceMonthlyHourly
    subscription-payment/api/cron/subscription-paymentrunSubscriptionPaymentCheckDaily 2am
    solana-batch-payment/api/cron/solana-batch-paymentrunSolanaBatchPaymentDaily 3am
    nft-gate-expiry/api/cron/nft-gate-expiryrunNftGateExpiryDaily 4am

    Pipelines are triggered via HTTP cron jobs hitting the cronPath endpoints. Handlers import from lib/processes/subscription/:

    • expiry-check.ts — marks overdue subscriptions as expired and downgrades user roles
    • credit-balance-monthly.ts — deducts monthly fee from user credit balance
    • subscription-payment.ts — processes Stripe/WayForPay recurring charges
    • solana-nft-stubs.ts — batch RING token transfers and NFT gate expiry

    Adding a new provider

    1. Implement SubscriptionProviderModule contract in providers/<name>-subscription.ts
    2. Register in subscription-conductor.ts providerRegistry Map
    3. Add gateway config to ring-config.json payment.gateways.<provider>
    4. Add to SUBSCRIPTION_PROVIDERS array in subscription-ledger-schema.ts
    5. Update getMembershipPaymentOptions() in subscription-config.ts
    6. If needed, add a cron pipeline handler in lib/processes/subscription/

    Environment variables

    Smoke tests

    5 smoke test suites exercise the full subscription pipeline (AI-RING/scripts/):

    SuitePrefixCoverage
    smoke-subscription-conductor.ctssmk39_13 pipelines (conductor create/cancel/renew, ledger SSOT, Stripe API, WayForPay, config)
    smoke-subscription-cron.ctssmk40_5 cron pipelines (expiry, credit, payment, solana, nft)
    smoke-subscription-cron-http.ctssmk41_5 HTTP cron routes with CRON_SECRET auth
    smoke-subscription-stripe.ctssmk39_Stripe API + webhook (customer, price, subscription, cancel, dispatch, zod)
    smoke-subscription-admin.ctssmk42_Admin dashboard list + stats endpoints

    Run via scripts/run-all-smokes.sh. Canonical pipeline registry: PIPELINES.md.

    json
    
    {
      "payment": {
        "cardPaymentProcessor": "wayforpay",
        "supportedMethods": ["wayforpay", "credit_balance", "native_token"],
        "futureMethods": ["stripe", "paypal", "nft_gate"],
        "gateways": {
          "wayforpay": { "enabled": true, "feePercent": 2.5, "currency": "UAH" },
          "stripe": { "enabled": false, "feePercent": 2.9, "feeFixedCents": 30, "currency": "USD" },
          "credit_balance": { "enabled": true, "feePercent": 0, "currency": "USD" },
          "native_token": { "enabled": true, "feePercent": 0, "currency": "RING", "label": "Tokens" },
          "paypal": { "enabled": false, "feePercent": 2.9, "feeFixedCents": 30, "currency": "USD" },
          "nft_gate": { "enabled": false, "feePercent": 0, "currency": "RING", "label": "NFT Certificate" }
        }
      }
    }
    text
    
    Membership upgrade / checkout
            ↓
    lib/payments/subscription/subscription-conductor.ts
            ↓
    Provider modules: stripe | wayforpay | credit_balance | native_token | nft_gate | paypal
            ↓
    subscription_ledger (PostgreSQL — provider-agnostic SSOT)
            ↓
    Cron pipelines: expiry + payment + credit-balance + solana-batch + nft-gate
    bash
    
    PAYMENT_MEMBERSHIP_PROCESSOR=wayforpay    # Override card gateway for membership
    WAYFORPAY_MERCHANT_ACCOUNT=your_merchant
    WAYFORPAY_SECRET_KEY=your_secret
    STRIPE_SECRET_KEY=sk_live_...
    STRIPE_WEBHOOK_SECRET=whsec_...