Giter Club home page Giter Club logo

mercato's Introduction

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.

mercato's People

Contributors

tikhop avatar wiencheck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mercato's Issues

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!

Feature Request

This is a great little repo!

Any chance of adding handling for BillingRetry and Grace period transaction states?

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

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!

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.