💰 A tiny library for iOS InApp Payment
Swift Ruby
Switch branches/tags
Clone or download
thoughts2binary
thoughts2binary Added Travis
Latest commit 8c3e848 Jun 10, 2018
Permalink
Failed to load latest commit information.
Example Added Travis Jun 9, 2018
InAppMachine Added Travis Jun 9, 2018
.gitignore Initial commit Mar 15, 2018
.swift-version Add Swift Version Mar 15, 2018
.travis.yml Added Travis Jun 9, 2018
InAppMachine.podspec Added Travis Jun 9, 2018
LICENSE v1.1.1 May 30, 2018
README.md v1.1.1 May 31, 2018
_Pods.xcodeproj Initial commit Mar 15, 2018

README.md

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.