StoreKit2 1.0.1
dotnet add package StoreKit2 --version 1.0.1
NuGet\Install-Package StoreKit2 -Version 1.0.1
<PackageReference Include="StoreKit2" Version="1.0.1" />
<PackageVersion Include="StoreKit2" Version="1.0.1" />
<PackageReference Include="StoreKit2" />
paket add StoreKit2 --version 1.0.1
#r "nuget: StoreKit2, 1.0.1"
#addin nuget:?package=StoreKit2&version=1.0.1
#tool nuget:?package=StoreKit2&version=1.0.1
MAUI StoreKit2 IAP Module
A .NET MAUI binding library that provides seamless integration with iOS StoreKit2 In-App Purchase functionality.
Overview
This library enables .NET MAUI applications to leverage Apple's modern StoreKit2 framework for handling in-app purchases on iOS. It provides a C# wrapper around the native StoreKit2 APIs, making it easy to integrate IAP functionality into your cross-platform MAUI applications.
Features
- ✅ Product Information Retrieval: Fetch product details from the App Store
- ✅ Purchase Processing: Handle consumable, non-consumable, and subscription purchases
- ✅ Purchase Restoration: Restore previous purchases for users
- ✅ Transaction Verification: Built-in transaction verification using StoreKit2
- ✅ Purchase Status Checking: Check the current entitlement status of products
- ✅ Async/Await Support: Modern async programming patterns
- ✅ Delegate Pattern: Event-driven callbacks for purchase events
- ✅ iOS 15+ Support: Takes advantage of the latest StoreKit2 features
Requirements
- iOS 15.0+ (StoreKit2 requirement)
- .NET 8.0 or later
- MAUI Project targeting iOS
Prerequisites
App Store Connect Setup
- Create your app in App Store Connect
- Configure In-App Purchase products with the same product IDs used in your code
- Create sandbox test users for testing
iOS Project Requirements
- iOS 15.0+ deployment target
- Valid Bundle ID matching App Store Connect
- StoreKit capability enabled in your iOS project
Installation
NuGet Package
dotnet add package StoreKit2
Or add to your .csproj
file:
<PackageReference Include="StoreKit2" Version="1.0.0" />
Manual Installation
- Clone this repository
- Add the project reference to your MAUI project:
<ProjectReference Include="path/to/MAUI.StoreKit2/MAUI.StoreKit2.csproj" />
- Build and run
Quick Start
1. Initialize the Payment Manager
using StoreKit2;
// Get the shared instance
var paymentManager = PaymentManager.Shared;
// Set up delegate for callbacks
paymentManager.Delegate = new PaymentManagerDelegateImpl();
2. Create a Delegate Implementation
public class PaymentManagerDelegateImpl : PaymentManagerDelegate
{
public override void PaymentManagerDidFinishPurchase(string productId, PaymentTransaction transaction)
{
Console.WriteLine($"Purchase completed: {productId}");
// Handle successful purchase
}
public override void PaymentManagerDidFailPurchase(string productId, string error)
{
Console.WriteLine($"Purchase failed: {productId}, Error: {error}");
// Handle purchase failure
}
public override void PaymentManagerDidUpdateProducts(PaymentProduct[] products)
{
Console.WriteLine($"Products loaded: {products.Length}");
// Update UI with product information
}
public override void PaymentManagerDidRestorePurchases(PaymentTransaction[] transactions)
{
Console.WriteLine($"Restored {transactions.Length} purchases");
// Handle restored purchases
}
}
3. Load Products
string[] productIds = { "com.yourapp.product1", "com.yourapp.product2" };
paymentManager.RequestProductsWithProductIds(productIds, (success, error) =>
{
if (success)
{
Console.WriteLine("Products loaded successfully");
var products = paymentManager.GetAllProducts;
// Display products in your UI
}
else
{
Console.WriteLine($"Failed to load products: {error}");
}
});
4. Make a Purchase
paymentManager.PurchaseProductWithProductId("com.yourapp.product1", null, (success, error) =>
{
if (success)
{
Console.WriteLine("Purchase initiated successfully");
}
else
{
Console.WriteLine($"Purchase failed: {error}");
}
});
5. Restore Purchases
paymentManager.RestorePurchasesWithCompletion((success, error) =>
{
if (success)
{
Console.WriteLine("Purchases restored successfully");
}
else
{
Console.WriteLine($"Restore failed: {error}");
}
});
6. Check Purchase Status
paymentManager.CheckPurchaseStatusWithProductId("com.yourapp.product1", (hasPurchase, transaction) =>
{
if (hasPurchase)
{
Console.WriteLine($"User owns this product. Transaction ID: {transaction.TransactionId}");
}
else
{
Console.WriteLine("User does not own this product");
}
});
API Reference
PaymentManager
The main class for handling in-app purchases.
Properties
Shared
: Static singleton instanceDelegate
: Delegate for receiving purchase events
Methods
RequestProductsWithProductIds()
: Load product information from the App StorePurchaseProductWithProductId()
: Initiate a purchase for a specific productRestorePurchasesWithCompletion()
: Restore previous purchasesGetProductWithProductId()
: Get product information by IDAllProducts
: Get all loaded productsCheckPurchaseStatusWithProductId()
: Check if user owns a specific product
PaymentProduct
Represents a product available for purchase.
Properties
ProductId
: Unique product identifierDisplayName
: Localized product nameProductDescription
: Localized product descriptionPrice
: Product price as NSDecimalNumberDisplayPrice
: Formatted price stringProductType
: Product type (consumable, nonConsumable, etc.)
PaymentTransaction
Represents a completed transaction.
Properties
TransactionId
: Unique transaction identifierProductId
: Associated product identifierPurchaseDate
: Date of purchaseIsUpgraded
: Whether this is an upgrade transactionRevocationDate
: Date of revocation (if applicable)RevocationReason
: Reason for revocation (if applicable)
Product Types
The library supports all StoreKit2 product types:
- Consumable: Products that can be purchased multiple times
- Non-Consumable: Products that are purchased once
- Auto-Renewable: Subscriptions that renew automatically
- Non-Renewable: Subscriptions that don't renew automatically
Error Handling
The library provides comprehensive error handling through:
- Completion callbacks with success/error parameters
- Delegate methods for handling purchase failures
- Detailed error messages for debugging
Testing
For testing in-app purchases:
- Use Apple's sandbox environment
- Create test user accounts in App Store Connect
- Configure your products in App Store Connect
- Test on physical devices (StoreKit2 doesn't work in simulator)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed information
- Provide sample code and error messages when applicable
Author
Yuting Li
Shanghai Jiuqianji Technology Co., Ltd.
Acknowledgments
- Apple's StoreKit2 documentation and samples
- The .NET MAUI community for guidance and support
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-ios18.0 is compatible. net9.0-ios was computed. net10.0-ios was computed. |
-
net8.0-ios18.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.