Skip to content

iOSWizards/AwesomePurchase

Repository files navigation

AwesomePurchase

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 9 or Higher
  • Swift 5.0

Installation

AwesomePurchase is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "AwesomePurchase", git: 'https://github.com/iOSWizards/AwesomePurchase', tag: '0.1.6'

Usage

Initiating Store

AwesomePurchase.start(with: ["identifier1", "identifier2", ...])

Test Environment

AwesomePurchase.start(with: ["identifier1", "identifier2", ...], isProduction: false)

Requesting Products

Single Product

AwesomePurchase.shared.product(withIdentifier: "PRODUCT IDENTIFIER") { (product, message) in
    // any further action
}

All Available Products

AwesomePurchase.shared.products { (success, products, message) in
    // any further action
}

Purchasing Products

AwesomePurchase.shared.purchaseProduct(withIdentifier: "PRODUCT IDENTIFIER") { (success, receipt, message) in
    // any further action
}

Subscription Protocol

In order to make the usability for Subscription simpler, you can take advantage of the Subscription Protocol. Ideally, you should create a helper class to handle the subscription and be responsible for any change in the subscripton state.

Here's an example of the implementation:

import AwesomePurchase
import StoreKit

enum SubscriptionId: String {
    case monthly = "IDENTIFIER 1"
    case yearly = "IDENTIFIER 2"
}

class AwesomePurchaseHelper: AwesomePurchaseSubscriptionProtocol {

    static var shared = AwesomePurchaseHelper()

    var products: [SKProduct] = []
    var iapHelper: AwesomePurchaseStore?

    var appStoreSecret: String {
        return "yourAppStoreSecret"
    }

    static func start() {
        AwesomePurchase.start(with: [SubscriptionId.monthly.rawValue, SubscriptionId.yearly.rawValue], isProduction: false)

        shared.addPurchaseObservers()

        shared.updateProducts { (products) in
            shared.products = products
        }
    }

    func receiptConfirmed(isValid: Bool) {
        // take action
    }
    
}

Subscription Status Update Protocol

In order to update your view according to Subscription status update, implement the AwesomePurchaseSubscriptionStatusProtocol.

extension YourView: AwesomePurchaseSubscriptionStatusProtocol {
    func updatedSubscriptionStatus() {
        // update UI
    }
}

License

AwesomePurchase is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published