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

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Automattic/MobilePay-Apple
A proof-of-concept app for developing MobilePayKit, an In-App Purchase library
.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 => 'git@github.com: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: 6
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

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