StoreKit 2 wrapper for In-App Purchases.
.package(url: "https://github.com/tikhop/Mercato.git", .upToNextMajor(from: "1.0.1"))
- Swift 5.10+
- iOS 15.4+ / macOS 12.3+ / tvOS 17.0+ / watchOS 10.0+ / visionOS 1.0+
import Mercato
// Fetch products
let products = try await Mercato.retrieveProducts(
productIds: ["com.app.premium", "com.app.subscription"]
)
// Purchase
let purchase = try await Mercato.purchase(
product: product,
finishAutomatically: false
)
// Deliver content and finish
grantAccess(for: purchase.productId)
await purchase.finish()
// Current entitlements
for await result in Mercato.currentEntitlements {
let transaction = try result.payload
// Active subscriptions and non-consumables
}
// Live updates
for await result in Mercato.updates {
let transaction = try result.payload
await processTransaction(transaction)
await transaction.finish()
}
// Check eligibility
if await product.isEligibleForIntroOffer {
// Show intro pricing
}
// Product info
product.localizedPrice // "$9.99"
product.localizedPeriod // "1 month"
product.hasTrial // true/false
product.priceInDay // 0.33
let options = Mercato.PurchaseOptionsBuilder()
.setQuantity(3)
.setPromotionalOffer(offer)
.setAppAccountToken(token)
.build()
let purchase = try await Mercato.purchase(
product: product,
options: options,
finishAutomatically: false
)
do {
let purchase = try await Mercato.purchase(product: product)
} catch MercatoError.canceledByUser {
// User canceled
} catch MercatoError.purchaseIsPending {
// Ask to Buy
} catch MercatoError.productUnavailable {
// Product not found
}
// Check purchase status
let isPurchased = try await Mercato.isPurchased("com.app.premium")
// Get latest transaction
if let result = await Mercato.latest(for: productId) {
let transaction = try result.payload
}
// Sync purchases (rarely needed)
try await Mercato.syncPurchases()
See Usage.md for complete documentation.
Contributions are welcome. Please feel free to submit a Pull Request.
MIT. See LICENSE for details.