Orchardcore subscriptions

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore subscriptions is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for the CrestApps Orchard Core Subscriptions module (CrestApps.OrchardCore.Subscriptions, CrestApps.OrchardCore.Subscriptions.Tenants, CrestApps.OrchardCore.Subscriptions.Installments). Covers plans with the Subscription stereotype and SubscriptionPart (billing cycle, setup fee, cycle limit, d

How to use this skill

Skill file

CrestApps Orchard Core Subscriptions

Subscriptions sells recurring plans built on content items and keeps a durable agreement for every subscriber. It owns no payment code: a plan is bought through the shared checkout like any other purchase, and the agreement is created only from payment attempts the checkout confirmed.

Related skills: orchardcore-checkout (the purchase), orchardcore-payments (Stripe recurring billing, installment plans), orchardcore-pay-later (offline recurring commitments), orchardcore-products (plans are products), orchardcore-memberships (one-off role grants from an order), orchardcore-taxation, orchardcore-reports.

Features

| Feature ID | Name | Depends on |

| --- | --- | --- |

| CrestApps.OrchardCore.Subscriptions | Subscriptions | OrchardCore.Contents, OrchardCore.ContentTypes, OrchardCore.Title, CrestApps.OrchardCore.Users, CrestApps.OrchardCore.Products, CrestApps.OrchardCore.Checkout, CrestApps.OrchardCore.Receipts |

| CrestApps.OrchardCore.Subscriptions.Tenants | Subscriptions - Sites (default tenant only) | Subscriptions, OrchardCore.Tenants |

| CrestApps.OrchardCore.Subscriptions.Installments | Subscriptions - Installment Plans | Transactions, Checkout, OrchardCore.Users (see orchardcore-payments) |

Payment options come from provider modules: enable CrestApps.OrchardCore.Stripe and/or CrestApps.OrchardCore.PayLater. There is no Subscriptions - Stripe feature. Install CrestApps.OrchardCore.Subscriptions in the web project; contracts are in CrestApps.OrchardCore.Subscriptions.Abstractions (CrestApps.OrchardCore.Subscriptions.Services and .Models).

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "CrestApps.OrchardCore.Subscriptions",
        "CrestApps.OrchardCore.Stripe",
        "CrestApps.OrchardCore.Products.Listing"
      ],
      "disable": []
    }
  ]
}

The Commerce starter recipe (CommerceStarter) enables the suite, creates a Member role, a Membership Plan type with an entitlement, a $10 monthly plan and a Plans listing at /plans.

Guidelines

Plans

Give a content type the Subscription stereotype (SubscriptionConstants.Stereotype); it gets SubscriptionPart and ProductPart, kept on the type. SubscriptionPart:

| Property | Meaning |

| --- | --- |

| BillingDuration, DurationType | Cycle length, Year, Month, Week or Day |

| InitialAmount, InitialAmountDescription | Optional one-time setup fee |

| BillingCycleLimit | Cycles billed before the agreement ends |

| SubscriptionDayDelay | Delayed start (billing begins later, card attached now) |

| TrialDays | Free trial; the gateway is told, so it survives restarts |

| Sort | Order in a listing's Recommended sort when the Product part has no position |

SubscriptionPartSettings.ContentTypes names content the subscriber fills in during checkout (the Content step). The price comes from ProductPart (or the Product prices part for monthly/annual or per-seat choices) through IProductSnapshotResolver, in the plan's own currency. List plans with a Product Listing (there is no built-in plans page). SubscriptionEntitlementPart.RoleNames (attach Subscription Entitlements) lists the roles a subscriber holds.

{
  "steps": [
    {
      "name": "ContentDefinition",
      "ContentTypes": [
        {
          "Name": "MembershipPlan",
          "DisplayName": "Membership Plan",
          "Settings": { "ContentTypeSettings": { "Creatable": true, "Listable": true, "Stereotype": "Subscription" } },
          "ContentTypePartDefinitionRecords": [
            { "PartName": "TitlePart", "Name": "TitlePart" },
            { "PartName": "ProductPart", "Name": "ProductPart", "Settings": { "ProductPartSettings": { "DefaultCurrency": "USD" } } },
            { "PartName": "SubscriptionPart", "Name": "SubscriptionPart" },
            { "PartName": "SubscriptionEntitlementPart", "Name": "SubscriptionEntitlementPart" }
          ]
        }
      ]
    },
    {
      "name": "Content",
      "data": [
        {
          "ContentItemId": "monthlyplan00000000000000a",
          "ContentType": "MembershipPlan",
          "DisplayText": "Monthly membership",
          "Published": true,
          "Latest": true,
          "TitlePart": { "Title": "Monthly membership" },
          "ProductPart": { "Price": 10, "Currency": "USD" },
          "SubscriptionPart": { "BillingDuration": 1, "DurationType": "Month", "TrialDays": 14 },
          "SubscriptionEntitlementPart": { "RoleNames": [ "Member" ] }
        }
      ]
    }
  ]
}

With CrestApps.OrchardCore.Recipes enabled, JSON Schema is contributed for SubscriptionPart, SubscriptionSummaryPart and (with Sites) TenantOnboardingPart.

Buying a plan

Sign up links to Subscription/Signup/{contentItemId} (route SubscriptionSignup). SubscriptionsController prices the plan through SubscriptionPlanPricing (a plan without a currency or a recurring price shows This plan can't be bought right now and logs why), then calls ICheckoutEngine.StartAsync with ReferenceType = "Subscription" (SubscriptionCheckout.ReferenceType), the plan id and version, and the buyer's PriceSelection.

Steps: a concealed plan step carrying the recurring line and setup fee, Content (when ContentTypes is set), Registration (visitor not signed in; hidden again once they sign in), Site details (Sites), Payment. A guest's account is created before money moves and deleted if the checkout fails (only the account this checkout created). Allow guest sign-up in Settings > Subscriptions lets buyers subscribe without an account. SubscriptionPlanCheckoutHandler refuses to complete an invoice that bills nothing recurring.

The agreement

Subscription (CatalogItem, collection Subscription): owner, ProviderKey, ProviderSubscriptionId, Status, Amount, TaxAmount, cycle, CyclesBilled, CurrentPeriodStartUtc, CurrentPeriodEndUtc, NextBillingUtc, TrialEndsUtc, PastDueSinceUtc, GraceEndsUtc, CancelAtPeriodEnd, Lines, Events, Entitlements, and IsCurrent(utcNow). SubscriptionStatus: Active, Trialing, PastDue, Canceled, Expired, Paused, Incomplete. Read with ISubscriptionStore (GetByOwnerAsync, GetByProviderSubscriptionIdAsync, GetByCheckoutSessionAsync, PageAsync); write with ISubscriptionManager.

ISubscriptionLifecycleService:

| Method | Effect |

| --- | --- |

| RecordRenewalAsync(id, periodStartUtc, context) | Advances one cycle from the previous period end; the same cycle twice advances once |

| MarkPastDueAsync(id, reason) | Starts dunning; a second failure does not restart the grace clock |

| CancelAsync(id, atPeriodEnd, reason, source) | Stops billing at the gateway; at period end keeps the paid-through date |

| PauseAsync(id, reason) / ResumeAsync(id) | Suspends and resumes collection at the gateway (pause_collection on Stripe) |

| ExpireAsync(id, reason) | Ends the agreement |

| SyncFromProviderAsync(id, context) | Adopts the gateway's period and status; never revives a local cancellation or undoes a local pause |

SubscriptionLifecycleBackgroundTask (every 30 minutes) expires agreements past their grace window and closes those that billed every cycle; it never charges. Gateways (Stripe) bill renewals and report them by webhook; offline agreements (Pay Later) are advanced by the sweep and invoiced by the Pay Later renewal task. SubscriptionSettings (Settings > Subscriptions, group subscriptions): Currency, AllowGuestSignup, and DunningGraceDays (7), which the settings page does not show (set it with the Settings recipe step).

React to every change with ISubscriptionLifecycleHandler (SubscriptionLifecycleHandlerBase), whose SubscriptionLifecycleContext has Subscription, PreviousStatus, Source and StatusChanged.

Member-only access

using CrestApps.OrchardCore.Subscriptions.Services;

public sealed class PremiumContentGate
{
    private readonly ISubscriptionAccessService _access;

    public PremiumContentGate(ISubscriptionAccessService access)
    {
        _access = access;
    }

    public Task<bool> CanReadAsync(string userId)
        => _access.HasEntitlementAsync(userId, "Role", "Member");
}

HasEntitlementAsync(userId, kind, value) (no value matches any of the kind), GetEntitlementsAsync(userId), GetCurrentSubscriptionsAsync(userId). Built-in kinds: Role and Tenant (SubscriptionConstants.EntitlementKinds). Roles from the plan's SubscriptionEntitlementPart are copied onto the agreement at creation and applied while it is current by RoleSubscriptionEntitlementApplier, through IRoleGrantService (source Subscription, keyed by the subscription id). When the subscription ends the role is removed only when nothing else (such as an active membership) still grants it, and never when the user had it before; SubscriptionRoleGrantSource reports grants of subscriptions made before grants were recorded.

A custom kind: put a SubscriptionEntitlement { Kind, Value, Data } on the agreement (the Sites feature adds its Tenant entitlement from its checkout handler and saves through ISubscriptionManager), and register an applier:

using CrestApps.OrchardCore.Subscriptions.Services;

public sealed class SeatEntitlementApplier : ISubscriptionEntitlementApplier
{
    public string Kind => "Seats";

    public Task ApplyAsync(SubscriptionEntitlementContext context)
    {
        // context.Subscription.OwnerId gets context.Entitlement.Value seats.
        return Task.CompletedTask;
    }

    public Task RevokeAsync(SubscriptionEntitlementContext context)
    {
        // Called when the agreement stops being current.
        return Task.CompletedTask;
    }
}

// services.AddScoped<ISubscriptionEntitlementApplier, SeatEntitlementApplier>();

Workflow events

With OrchardCore.Workflows: Subscription Started (SubscriptionStartedEvent), Subscription Renewed, Subscription Past Due, Subscription Canceled, Subscription Expired. Each carries the subscription id, title, owner, current and previous status, amount, access-through date and grace end, and is correlated by subscription id. Only a real status change raises one. Sites adds Subscribed tenant setup succeeded and failed events.

Selling sites

Subscriptions - Sites (default tenant only) sells whole Orchard Core sites. Attach TenantOnboardingPart (RecipeName, FeatureProfile) to the plan. The buyer names the site and its administrator on the Site details step; name, domain and prefix clashes are refused before payment. Completion records a TenantProvisioningJob; TenantProvisioningBackgroundTask (every minute) builds it under a lock with back-off, then marks it abandoned after repeated failures. The administrator password is data-protected, unprotected just before setup, and dropped at a terminal outcome.

Screens, reports, permissions

Upgrading from 2.x

Troubleshooting

| Symptom | Cause |

| --- | --- |

| This plan can't be bought right now | No currency on the plan or its type, or the price does not recur |

| Subscriber charged after canceling | Pre-3.0 behavior; cancel now reaches the gateway. Check the provider supports recurring cancel |

| Renewals not recorded | Stripe webhook not re-provisioned (Connect again) |

| Role not removed | The agreement is still current (paid period or grace window) |

| Site never created | Background tasks off, onboarding database misconfigured, or job abandoned (see Site provisioning and the log) |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.