GithubHelp home page GithubHelp logo

isabella232 / mobilepay-apple Goto Github PK

View Code? Open in Web Editor NEW

This project forked from automattic/mobilepay-apple

0.0 0.0 0.0 277 KB

A proof-of-concept app for developing MobilePayKit, an In-App Purchase library

License: GNU General Public License v2.0

Shell 1.10% Ruby 3.82% Swift 95.07%

mobilepay-apple's Introduction

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.

mobilepay-apple's People

Contributors

alisoftware avatar jkmassel avatar leandroalonso avatar momo-ozawa avatar

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.