Skip to content
/ Mercato Public

Mercato is a lightweight StoreKit 2 wrapper that makes it easy to add in-app purchases and subscriptions to your iOS, macOS, tvOS, watchOS, and visionOS apps.

License

Notifications You must be signed in to change notification settings

tikhop/Mercato

Repository files navigation

Mercato

License Platform Swift

StoreKit 2 wrapper for In-App Purchases.

Installation

Swift Package Manager

.package(url: "https://github.com/tikhop/Mercato.git", .upToNextMajor(from: "1.0.1"))

Requirements

  • Swift 5.10+
  • iOS 15.4+ / macOS 12.3+ / tvOS 17.0+ / watchOS 10.0+ / visionOS 1.0+

Usage

Basic Purchase

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()

Transaction Monitoring

// 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()
}

Subscription Features

// 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

Purchase Options

let options = Mercato.PurchaseOptionsBuilder()
    .setQuantity(3)
    .setPromotionalOffer(offer)
    .setAppAccountToken(token)
    .build()

let purchase = try await Mercato.purchase(
    product: product,
    options: options,
    finishAutomatically: false
)

Error Handling

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
}

Utilities

// 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()

Documentation

See Usage.md for complete documentation.

Contributing

Contributions are welcome. Please feel free to submit a Pull Request.

License

MIT. See LICENSE for details.

About

Mercato is a lightweight StoreKit 2 wrapper that makes it easy to add in-app purchases and subscriptions to your iOS, macOS, tvOS, watchOS, and visionOS apps.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 2

  •  
  •  

Languages