Gerald Versluis introduces a new .NET MAUI sample for integrating cross-platform in-app billing, guiding developers through platform-specific APIs and architectural best practices.

Implementing Cross-Platform In-App Billing in .NET MAUI Applications

Author: Gerald Versluis

With the discontinuation of the InAppBillingPlugin, .NET MAUI developers now have a new resource for implementing in-app purchases in their applications. This new BillingService sample demonstrates how to integrate billing on Android, iOS, Mac Catalyst, and Windows using platform-specific APIs behind a unified interface.

BillingService Sample Overview

  • Platforms Supported:
    • Android: Google Play Billing Client v7
    • iOS/Mac Catalyst: StoreKit 1
    • Windows: Microsoft Store APIs

The BillingService sample helps developers:

  • Maintain clean architectures (dependency injection, MVVM)
  • Use a unified IBillingService interface for all platforms
  • Replace now-discontinued plugins with comprehensive code examples

Architecture

Unified Interface

A central IBillingService interface allows your app to access billing features on any supported platform:

public interface IBillingService {
    Task<bool> InitializeAsync();
    Task<IEnumerable<Product>> GetProductsAsync();
    Task<PurchaseResult> PurchaseAsync(string productId);
    Task<bool> RestorePurchasesAsync();
    bool IsProductOwned(string productId);
}

Platform-Specific Implementations

  • Android, iOS (Mac Catalyst), and Windows have dedicated implementation files selected via conditional compilation.
  • iOS/Mac Catalyst share a StoreKit-based implementation.

Dependency Injection

BillingService is registered in MauiProgram.cs:

builder.Services.AddSingleton<IBillingService, Services.BillingService>();
builder.Services.AddTransient<ProductsViewModel>();

Patterns and Best Practices

  • Unified code via interfaces and conditional compilation
  • Dependency injection integration
  • MVVM architecture for maintainability
  • Platform-specific error handling and user feedback

StoreKit Migration Note

  • StoreKit 1 is currently used for iOS/Mac Catalyst, with Apple recommending StoreKit 2 for the future.
  • The sample will be updated once .NET for iOS supports StoreKit 2.
  • Apps using StoreKit 1 will keep working, but future improvements will require migration.

Security Reminder

For production apps, implement server-side receipt verification and purchase validation for fraud prevention. This sample demonstrates client-side integration patterns only.

Getting Started

  1. View the sample source on GitHub
  2. Browse live samples and docs
  3. Clone, configure, and run on your local setup

Platform-Specific Product Setup Guides

Key Takeaways for Developers

  • Implement in-app purchases consistently across all .NET MAUI-supported platforms
  • Use modern architectural patterns for maintainable, scalable code
  • Prepare for StoreKit 2 migration on Apple platforms
  • Reference detailed documentation for setup and testing

Resources

By following this sample, you can implement robust in-app billing for your cross-platform .NET MAUI apps and stay current with API changes across major app stores.

This post appeared first on “Microsoft .NET Blog”. Read the entire article here