Client library for making in-app purchases on iOS and macOS Automattic apps
MobilePayKit is a client library for making in-app purchases. This project facilitates in-app purchases by coordinating requests to:
Realistically this library is only useful for Automattic-based projects, but the idea is to share what we've made.
To integrate MobilePayKit into your Xcode project via CocoaPods, specify it in your Podfile
:
pod 'MobilePayKit', :git => '[email protected]:Automattic/MobilePay-Apple.git', :branch => 'develop'
To integrate MobilePayKit into your Xcode project via Swift Package Manager, add MobilePayKit as a dependency in Package.swift
:
dependencies: [
.package(url: "https://github.com/Automattic/MobilePay-Apple", .upToNextMajor(from: "0.0.1"))
]
Check out the iOS and macOS examples under the Example directory for more information on how to make in-app purchases via MobilePayKit.
Import the MobilePayKit module in your project.
import MobilePayKit
Before you call any MobilePayKit methods, configure a MobilePayKit shared instance by setting the WordPress oAuth token as well as the app's bundle ID.
MobilePayKit.configure(
oAuthToken: "<token>",
bundleId: "<bundleId>"
)
Fetch products that are available for in-app purchases.
MobilePayKit.shared.fetchProducts { [weak self] result in
switch result {
case .success(let products):
print("Fetched products: \(products)")
case .failure(let error):
print("Error fetching products: \(error.localizedDescription)")
}
}
Purchase a product using the product identifier.
MobilePayKit.shared.purchaseProduct(with: identifier) { [weak self] result in
switch result {
case .success(let transaction):
print("Purchased product: \(transaction.payment.productIdentifier)")
case .failure(let error):
print("Error purchasing product: \(error.localizedDescription)")
}
}
To test in-app purchases locally, each developer will have to modify their Xcode scheme to let Xcode know to use the local Configuration.storekit
file. Check out the Apple documentation on testing locally via Xcode for more information.
Configuration.storekit
(the local StoreKit file)TBD
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MobilePayKit is available under the GPL license. See the LICENSE file for more info.
link |
Stars: 8 |
Last commit: 2 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics