InAppMachine 1.1.3

InAppMachine 1.1.3

Maintained by Abhishek.



InAppMachine

CI Status Version License Platform

A Easy Wrapper Around StoreKit framework for iOS.

Features

v1.1.1

  • Updated Documentation
  • Restore InApp Purchase
  • Get Recipts for InApp Purcahse

v1.1.0

  • Closure based API for InApp Purcahse
  • Request and Purchase InApp Products

Installation

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

pod 'InAppMachine'

Create on iTunes Connect

Step1. Login to your iTunes Account.

Step2. Switch to 'My Apps' and open your app.

Step3. Go to 'Features' section of the app and create InApp Product.

[Incomplete]

Intialize InAppMachine

Step1: InAppMachine follows singleton, so first you shoud access its singleton object rather than creating one,

import UIKit
import InAppMachine

class ViewController: UIViewController {

    // Add This One
    let inappMachine = InAppMachine.shared

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }
    
}

Step2:

Now, You have to tell InAppMachine about the Product ID(s) which you have made on iTunes connect. Say, you have created a consumable product named 'co.in.greensyntax.restman.developer.program'

So, you have to adopt 'InAppPurchaseSource' protocol and satisfy the stubs (i.e. products).

import UIKit
import InAppMachine

class ViewController: UIViewController, InAppPurchaseSource {

// Change as per your ProductID
var products: [String] = ["co.in.greensyntax.restman.developer.program"]

let inappMachine = InAppMachine.shared

    override func viewDidLoad() {
        super.viewDidLoad()
    
        // Next, I have set the dataSource with the instance of my object.
        inappMachine.dataSource = self
    }

}

Request Products

Step3: Now, we'll check wheather our ProductID are valid or not. So, we'll call the request method for checking the validity of product.

inappMachine.requestFor(inAppProducts: { (products) in
    
    //onSuccess
    for product in products {
    
        // Valid Product Deatils
        print(product.description)
    }
}) { (error) in
    
    //onError you'll get an error of type InAppError
    print(error?.localizedText)
}

With these details, you can prepare your Purchase View where you can show Products Details.

Purchase

Step4:

And, On Purchase affirmation, you can initiate purchase event with valid Product object. For purchasing, you need an instance of 'InAppProduct' which you got on InApp request call (step3).

self.inappMachine.purcahseFor(product: product, onSuccess: { (transaction: InAppTransaction) in

    //onSuccessfull Transaction
    print(transaction.description)

}, onFailed: { (error) in

    //onFailed Transaction
    print(error)
})

Restore

Recipts

Recipts Validation is usally done to validate the purchase, wheather it's a genuine purchase or not. Say, You have purcahse a InApp product and notifed the your App Server via API that you have purchase this subscription. Now, it's alway a good idea to validate every purchase using reciopts.

// Get Recipts Data to Validate the Purchase
let recipts = inappMachine.getReciptData()

Contributor

Abhishek Kumar Ravi

License

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