This demo project showcases how to integrate and implement Apple's StoreKit 2 framework with iaptic (formerly Fovea.Billing) for secure server-side validation of in-app purchases in iOS applications.
This uses the iaptic-storekit2 package.
StoreKit 2 is Apple's latest framework for handling in-app purchases, providing a modern Swift API with async/await support. This demo app demonstrates how to:
- Load and display products from the App Store
- Handle purchases with StoreKit 2
- Validate transactions using iaptic's server-side validation service
- Observe transaction updates
- Restore purchases
- Manage user entitlements
- ✅ Modern SwiftUI interface
- ✅ StoreKit 2 integration with async/await API
- ✅ Server-side transaction validation with iaptic
- ✅ Transaction verification using JWS (JSON Web Signatures)
- ✅ Subscription management
- ✅ Entitlement tracking
- ✅ Comprehensive logging for debugging
- iOS 15.0+
- Xcode 13.0+
- Swift 5.5+
- An iaptic account (for server-side validation)
- SubscriptionsManager: Handles product fetching, purchases, and transaction validation
- EntitlementManager: Manages user access to premium features
- ContentView: UI for displaying products and purchase options
- Clone this repository
- Open the project in Xcode
- Update the iaptic configuration in
SubscriptionsManager.swift
with your own details:self.iaptic = Iaptic( appName: "YOUR_APP_NAME", publicKey: "YOUR_PUBLIC_KEY" )
- Configure your StoreKit products in App Store Connect
- For testing, you can use StoreKit testing configuration
This demo uses iaptic to handle server-side validation of StoreKit transactions. Key benefits include:
- Secure validation without complex server implementation
- Cross-platform support for your purchase system
- Protection against common hacking attempts
- Dashboard for monitoring purchases
- Subscription status management
StoreKit 2 offers significant improvements over the original StoreKit:
- Async/await API for simpler code
- Built-in receipt validation
- JWS transaction verification
- Automatic transaction syncing across devices
- More reliable transaction handling
- Entitlement status information on-device
The app demonstrates:
-
Product Loading:
func loadProducts() async { do { self.products = try await Product.products(for: productIDs) .sorted(by: { $0.price > $1.price }) } catch { print("❌ Failed to fetch products!") } }
-
Purchase Handling:
func buyProduct(_ product: Product) async { // Purchase implementation using StoreKit 2 }
-
Transaction Verification:
func verifyWithIaptic(jwsRepresentation: String, productID: String) async { // Server-side validation with iaptic }
-
Transaction Observation:
func observeTransactionUpdates() -> Task<Void, Never> { // Observing transaction updates with StoreKit 2 }
-
Restoring Purchases:
func restorePurchases() async { // Restore implementation }
The application includes extensive debug logging to help you understand the StoreKit 2 workflow:
- 🚀 Initialization logs
- 📦 Purchase process logs
- ✅ Verification logs
- 🔄 Restoration logs
This demo project is available under the MIT license.