Mercato is a lightweight In-App Purchases (StoreKit 2) library for iOS, tvOS, watchOS, macOS, and Mac Catalyst.

Overview

Mercato

License Platform Language

Mercato is a lightweight In-App Purchases (StoreKit 2) library for iOS, tvOS, watchOS, macOS, and Mac Catalyst.

Installation

Swift Package Manager

To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift:

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

Then, specify "Mercato" as a dependency of the Target in which you wish to use Mercato.

Lastly, run the following command:

swift package update

CocoaPods

In progress...

Then, run the following command:

$ pod install

In any swift file you'd like to use Mercato, import the framework with import Mercato.

Requirements

  • iOS 15.0 / OSX 12.0 / watchOS 8.0
  • Swift 5.5

Usage

Listen for transaction updates

Start transaction update listener as soon as your app launches so you don't miss a single transaction. This is important, for example, to handle transactions that may have occured after purchase returns, like an adult approving a child's purchase request or a purchase made on another device.

If your app has unfinished transactions, you receive them immediately after the app launches

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
	Mercato.listenForTransactions(finishAutomatically: false) { transaction in
		//Deliver content to the user.
		
		//Finish transaction
		await transaction.finish()
	}
	
	return true
}

Fetching products

do
{
	let productIds: Set<String> = ["com.test.product.1", "com.test.product.2", "com.test.product.3"]
	let products = try await Mercato.retrieveProducts(productIds: productIds)
	
	//Show products to the user
}catch{
	//Handle errors
}

Purchase a product

try await Mercato.purchase(product: product, quantity: 1, finishAutomatically: false, appAccountToken: nil, simulatesAskToBuyInSandbox: false)

Offering in-app refunds

try await Mercato.beginRefundProcess(for: product, in: windowScene)

Restore completed transactions

In general users won't need to restore completed transactions when your app is reinstalled or downloaded on a new device. Everything should automatically be fetched by StoreKit and stay up to date. In the rare case that a user thinks they should have a transaction but you don't see it, you have to provide UI in your app that allows users to initiate the sync. It should be very rare that a user needs to initiate a sync manually. Automatic synchronization should cover the majority of cases.

try await Mercato.restorePurchases()

Essential Reading

License

Mercato is released under an MIT license. See LICENSE for more information.

Comments
  • Is this Production ready?

    Is this Production ready?

    In the examples I do not see anywhere switch cases for failed purchasings (as in SwiftyStoreKit, etc.) ?

    How about restoring purchases? How to check if IAP was already purchased before? Reinstalling the app, etc.

    question 
    opened by sabiland 7
  • Return cached products if requested identifiers match

    Return cached products if requested identifiers match

    Hey @tikhop , thanks for this wonderful library!

    I noticed that there is a property on ProductService for keeping cached array od Product but it wasn't being used anywhere. I've modified the class a little to return the cached products if their id values match given set of product identifiers.

    opened by wiencheck 1
  • Purchase not working in iOS 16

    Purchase not working in iOS 16

    When I try to make a purchase using command below nothing happens. The purchase sheet doesn't show up in iOS 16:

    try await Mercato.purchase(product: product, quantity: 1, finishAutomatically: false, appAccountToken: nil, simulatesAskToBuyInSandbox: false)
    

    Is anyone else having the same problem? Thanks for your help!

    opened by neowinston 5
  • European 2FA issues

    European 2FA issues

    Hello, when trying to subscribe to autorenewable stuff in Europe, there is a two factor authentication with the bank. This causes the app to re-enter the App Store app, and then you have to manually return to the client app. Mercato doesn't "catch" this re-opening and it causes a weird state...

    bug 
    opened by christianthorwest 2
  • watchOS compilation errors

    watchOS compilation errors

    This library looks perfect for my fairly simple independent watchOS app's needs, thanks for sharing!

    Unfortunately, v0.0.1, as well as the current HEAD revision, don't build under a watchOS deployment target, giving these errors;

    Mercato/Sources/Mercato/Mercato.swift:56:59: Cannot find type 'UIWindowScene' in scope
    Mercato/Sources/Mercato/Mercato.swift:118:72: Cannot find type 'UIWindowScene' in scope
    Mercato/Sources/Mercato/Mercato.swift:125:73: Cannot find type 'UIWindowScene' in scope
    Mercato/Sources/Mercato/Mercato.swift:134:55: Cannot find type 'UIWindowScene' in scope
    Mercato/Sources/Mercato/Mercato.swift:61:39: Value of type 'Transaction' has no member 'beginRefundRequest'
    Mercato/Sources/Mercato/Mercato.swift:136:22: Type 'AppStore' has no member 'showManageSubscriptions'
    

    (paths trimmed for clarity)

    I've seen these errors both in my actual project, and in an out of the box Swift-based Xcode watchOS app project template, each with Mercato imported using Xcode's package management UI

    My experience isn't deep in writing this sort of cross-platform code, but it seems as though the code specific to iOS isn't guarded sufficiently for the watchOS platform. If you have suggestions I'm all ears!

    bug 
    opened by ticky 3
Releases(0.0.3)
Owner
Pavel T
Pavel T
StoreKitPlus contains additional functionality for working with StoreKit 2.

About StoreKitPlus StoreKitPlus adds extra functionality for working with StoreKit 2, like extensions, observable state, services, etc. StoreKitPlus h

Daniel Saidi 26 Nov 16, 2022
Apphud SDK is a lightweight open-source Swift library to manage auto-renewable subscriptions and other in-app purchases in your iOS app.

Apphud SDK Apphud SDK is a lightweight open-source Swift library to manage auto-renewable subscriptions and other in-app purchases in your iOS app. No

Apphud 143 Dec 16, 2022
Apple's Framework to support in-app purchases and interaction with the App Store

Apple's Framework to support in-app purchases and interaction with the App Store.

paigeshin 0 Dec 5, 2021
MerchantKit - A modern In-App Purchases management framework for iOS developers

MerchantKit dramatically simplifies the work indie developers have to do in order to add premium monetizable components to their applications. Track purchased products, offer auto-renewing subscriptions, restore transactions, and much more.

Benjamin Mayo 1.1k Dec 17, 2022
InAppPurchase - A Simple and Lightweight framework for In App Purchase

InAppPurchase A Simple, Lightweight and Safe framework for In App Purchase Feature Simple and Light ?? Support Promoting In-App Purchases ?? No need t

Jin Sasaki 269 Dec 15, 2022
🍎 An App to check whether a non-App Store app is in App Store.

AppStorify ?? An App to check whether a non-App Store app is in App Store. Benfits Use App Store's upgrade mechanism instead of app's. App Store apps

seedgou 58 Dec 7, 2022
An easy way to access reviews for your app instead of writing repetitive and redundant codes for every app.

AppStoreReviewManager An easy way to access reviews for your app instead of writing repetitive and redundant codes for every app. Requirements iOS 9.0

Jinya 4 Dec 23, 2022
Appirater - A utility that reminds your iPhone app's users to review the app.

Introduction Appirater is a class that you can drop into any iPhone app (iOS 4.0 or later) that will help remind your users to review your app on the

Arash Payan 4.7k Jan 7, 2023
Harpy - Notify users when a new version of your app is available and prompt them to upgrade.

After 6 years of Harpy and 4 years of Siren, I have decided to deprecate Harpy in favor of Siren. Why? Siren is written in Swift and has a feature set

Arthur Ariel Sabintsev 2.6k Dec 29, 2022
Siren - Notify users when a new version of your app is available and prompt them to upgrade.

Siren ?? Notify users when a new version of your app is available and prompt them to upgrade. Table of Contents Meta About Features Screenshots Ports

Arthur Ariel Sabintsev 4.1k Dec 27, 2022
An App where you can find product and see its detail.

MeliProductos Project ???? > An App where you can find product and see its detail. ???? > Una App donde puedes encontrar tus productos y ver su detall

Joaquin Segovia 3 May 6, 2022
AppVersion - Keep users on the up-to date version of your App.

?? App Version Don't let you users to get stuck on outdated version of your app. Automatic update tracking using Semantic Versioning Buil-in UI alerts

Ameba Labs 31 Sep 30, 2022
SwiftyStoreKit is a lightweight In App Purchases framework for iOS, tvOS, watchOS, macOS, and Mac Catalyst ⛺

SwiftyStoreKit is a lightweight In App Purchases framework for iOS, tvOS, watchOS, macOS, and Mac Catalyst. Features Super easy-to-use block-based API

Andrea Bizzotto 6.1k Jan 7, 2023
🚀 Create XCFrameworks with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XCFrameworks for iOS, Mac Catalyst, tvOS, macOS, and watchOS.

Surmagic ?? Create XCFramework with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XC

Muhammed Gurhan Yerlikaya 260 Dec 28, 2022
In-app purchases and subscriptions made easy. Support for iOS, iPadOS, watchOS, and Mac.

In-app purchases and subscriptions made easy. Support for iOS, iPadOS, watchOS, and Mac.

RevenueCat 1.6k Jan 6, 2023
Lightweight In App Purchases Swift framework for iOS 8.0+, tvOS 9.0+ and macOS 10.10+ ⛺

SwiftyStoreKit is a lightweight In App Purchases framework for iOS, tvOS, watchOS, macOS, and Mac Catalyst. Features Super easy-to-use block-based API

Andrea Bizzotto 6.1k Jan 7, 2023
StoreKitPlus contains additional functionality for working with StoreKit 2.

About StoreKitPlus StoreKitPlus adds extra functionality for working with StoreKit 2, like extensions, observable state, services, etc. StoreKitPlus h

Daniel Saidi 26 Nov 16, 2022
Lightweight Networking and Parsing framework made for iOS, Mac, WatchOS and tvOS.

NetworkKit A lightweight iOS, Mac and Watch OS framework that makes networking and parsing super simple. Uses the open-sourced JSONHelper with functio

Alex Telek 30 Nov 19, 2022
Apphud SDK is a lightweight open-source Swift library to manage auto-renewable subscriptions and other in-app purchases in your iOS app.

Apphud SDK Apphud SDK is a lightweight open-source Swift library to manage auto-renewable subscriptions and other in-app purchases in your iOS app. No

Apphud 143 Dec 16, 2022
A lightweight iOS library for In-App Purchases

#RMStore A lightweight iOS library for In-App Purchases. RMStore adds blocks and notifications to StoreKit, plus receipt verification, content downloa

Robot Media 2.4k Dec 19, 2022