Base solution for your next web application
Open Closed

Billing for Add-on Licenses - request for help or best practices for Stripe integration #12614


User avatar
0
eric_pulaski created

We are trying to work with the out-of-the box integration with Stripe, or as least as much as possible. I believe we understand how to get this working for Editions, including initial purchase and upgrades, but what about for add on licenses? For example, we have a "Starter" edition and want to offer customers licenses for "Additional Widgets" within their Edition. The Edition has a tenant feature called "Max Allowed Widgets", and we can track how many Widgets the tenant is using in their database, but is there a recommended way to use the existing UI for purchasing add-on licenses (such as "additional widgets", "additional user", etc.) within an Edition, or is this all custom code we need to write (mostly) from scratch, using the existing way this works for Editions as a guide?

Any help you can offer would be appreciated. Thanks in advance. -Eric

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

2 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @eric_pulaski

    I’d like to summarize the current state of add on licensing in ASP.NET Zero (such as additional widgets, additional users, etc.).

    Current Structure

    ASP.NET Zero’s payment system works as follows:

    1. Edition based Payment: The system is built around the SubscriptionPayment and SubscriptionPaymentProduct entities.

    2. Feature System: Features can be defined per Edition (via AppFeatureProvider), such as MaxUserCount.

    3. Stripe Integration: Out of the box support exists for Edition purchase, upgrade, and subscription extension.

    Status of Add on Licenses

    Unfortunately, ASP.NET Zero does not provide a built in UI or infrastructure for add on licenses.

    The existing system supports:

    • Initial Edition purchase
    • Edition upgrade
    • Subscription extension
    • Trial to paid conversion

    Recommended Approaches

    For add on licenses, you can apply one of the following approaches:

    Manually Updating Tenant Feature Values (Simple Approach)

    • You can update a tenant’s feature values from the Host Admin panel.
    • This is supported via TenantAppService.UpdateTenantFeatures().
    • Payments can be handled separately in Stripe, and the feature value can be updated manually afterward.

    Custom Add on Payment System (Recommended)

    You can model your solution after the existing subscription flow. By taking the existing structure as a reference:

    // Create an AddOnAppService similar to SubscriptionAppService
    public async Task<long> StartPurchaseAddOn(PurchaseAddOnInput input)
    {
        var tenant = await TenantManager.GetByIdAsync(AbpSession.GetTenantId());
        
        return await _paymentManager.CreatePayment(new SubscriptionPayment
        {
            TenantId = tenant.Id,
            SuccessUrl = input.SuccessUrl,
            ErrorUrl = input.ErrorUrl,
            IsRecurring = false,
            SubscriptionPaymentProducts = new List<SubscriptionPaymentProduct>
            {
                new(
                    description: $"Additional {input.AddOnType} x {input.Count}",
                    amount: CalculateAddOnPrice(input),
                    count: input.Count,
                    extraProperties: new ExtraPropertyDictionary
                    {
                        {"AddOnType", input.AddOnType},
                        {"TenantId", tenant.Id.ToString()},
                        {"FeatureName", "MaxAllowedWidgets"} // Feature to be updated
                    }
                )
            }
        });
    }
    

    To update the feature value after a successful payment:

    // In PaymentAppService.cs or an event handler
    await TenantManager.SetFeatureValueAsync(
        tenantId, 
        "MaxAllowedWidgets", 
        newValue.ToString()
    );
    

    UI Layer

    • Use subscription-management.component.ts as a reference.
    • Add a new “Purchase Add ons” section.
    • Reuse the existing gateway selection and payment flow.

    For add on licenses, you will need to write mostly custom code, but you can still reuse the existing payment infrastructure (SubscriptionPayment, PaymentManager, Stripe integration). Rather than building everything from scratch, the recommended approach is to replicate the Edition upgrade flow and adapt it for add ons.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    eric_pulaski created

    This for your reply, which was exactly what I was looking for. I have one follow-up question, and I'll create a new support ticket for that.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)