GithubHelp home page GithubHelp logo

tallhasarwar / inapppurchasemanager Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 9 KB

Very simple In-App PurchaseManager in Swift for iOS for buy single product with productID

Swift 100.00%
swift5 inapppurchase native swift iap-verification manager purchase ios

inapppurchasemanager's Introduction

InAppPurchaseManager

Very simple InAppPurchaseManager to purchase single item with ProductID or to get list of product to select and then purchase selected product in native swift

you can get the status of purchase with purchase product and transaction information

Ho to use

To use just download and include InAppPurchaseManager.swift into your project

Buy single product with product ID

To buy single product with Bundle Identifier call the method purchaseProductWithID and pass your product ID which you set on AppStoreConnect:

      InAppPurchaseManager.shared.purchaseProductWithID(productIdentifier: "Your Product ID here") { (status, product, transaction) in
          switch status {
            case .purchasing:
                print(status.message)
            case .purchased:
                if let tran = transaction, let prod = product {
                    print("Transaction:\(tran.transactionIdentifier ?? "") \nProduct:\(prod.localizedTitle)")
                }
                else {
                    print("Unable to get purchase information")
                }
            case .setProductIds:
                print(status.message)
            case .purchaseFailed:
                print(status.message)
            case .disabled:
                print(status.message)
            case .restored:
                print(status.message)
            case .unknown:
                print(status.message)
            case .deferred:
                print(status.message)
          }
      }

Get list of products with product IDs

To get a list of products from app store with array of Bundle Identifier call the method fetchProductsList and pass array with product IDs which you set on AppStoreConnect:

        let listOfID = ["Your 1st product ID here","Your 2nd product ID here","Your 3rd product ID here"]
        
        InAppPurchaseManager.shared.fetchProductsList(productIDsList: listID) { (productsList) in 
        
                //You can show the productList in tableview and get the selected product
                let selectedProduct = productsList.first // chose from didselectrow function
                
        }
        

Purchase selected product

You can pass the selectedProduct to purchase method

        InAppPurchaseManager.shared.purchase(product: product!) { (status, product, transaction) in

            switch status {
              case .purchasing:
                  print(status.message)
              case .purchased:
                  if let tran = transaction, let prod = product {
                      SwiftOverlays.removeAllBlockingOverlays()
                      print("Transaction:\(tran.transactionIdentifier ?? "") \nProduct:\(prod.localizedTitle)")
                  }
                  else {
                      print("Unable to get purchase information")
                  }
              case .setProductIds:
                  print(status.message)
              case .purchaseFailed:
                  print(status.message)
              case .disabled:
                  print(status.message)
              case .restored:
                  print(status.message)
              case .deferred:
                  print(status.message)
              case .unknown:
                  print(status.message)
            }
        }

If you want to add something, feel free to send me pull requests!

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.