Swiftpack.co - Automattic/MobilePay-Apple as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Automattic.
Automattic/MobilePay-Apple 0.0.1
A proof-of-concept app for developing MobilePayKit, an In-App Purchase library
⭐️ 8
🕓 2 years ago
iOS macOS
.package(url: "https://github.com/Automattic/MobilePay-Apple.git", from: "0.0.1")

MobilePayKit

Client library for making in-app purchases on iOS and macOS Automattic apps

Introduction

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.

Features

  • ☑ iOS and macOS compatible
  • Consumable in-app purchases support
  • Non-Consumable in-app purchases support
  • Auto-Renewable Subscriptions in-app purchases support
  • Non-Renewable Subscriptions in-app purchases support
  • ☐ Restoring purchases

Requirements

  • iOS 13+
  • macOS 10.15+
  • Swift 5.3

Installation

Cocoapods

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'

Swift Package Manager

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"))
]

Usage

Check out the iOS and macOS examples under the Example directory for more information on how to make in-app purchases via MobilePayKit.

Import MobilePayKit

Import the MobilePayKit module in your project.

import MobilePayKit

Configuring 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>"
)

Fetching products

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)")
    }
}

Purchasing a product

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)")
    }
}

Testing in-app purchases

Testing locally via Xcode

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.

  1. Click on your app's scheme at the top of Xcode and select Edit Scheme
  2. Select Run
  3. Select Options
  4. Change the StoreKit Configuration to point to Configuration.storekit (the local StoreKit file)

Testing via the App Store Connect Sandbox

TBD

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MobilePayKit is available under the GPL license. See the LICENSE file for more info.

GitHub

link
Stars: 8
Last commit: 11 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics