Giter Club home page Giter Club logo

goostore's Introduction

GOOStore

Store Manager for SwiftUI and In-App Purchases


๐Ÿ’ถ About GOOStore

GOOStore is a Library prepared to use In-App Purchases in iOS and macOS developments with SwiftUI


โš™๏ธ Installation

Setup your XCode Project and App Store Connect

First of all you need to add In-App Purchases capabilities in your app

  • In Xcode select your Target and change to the Signing & Capabilites tab.
  • Add In-App Purchase capability.

Add your In-App Purchases in App Store Connect

  • Consumable purchases - for example dev.goojoob.MyApp.10lives and dev.goojoob.MyApp.50lives
  • Non-Consumable - for example dev.goojoob.MyApp.ProUser

Setup with Swift Package Manager


๐Ÿ”ง Usage

Declare your available products id's and quantity as a Dictionary.

  • Consumable items need a quantity you may treat when the purchase is done
  • Non-Consumable items don't need a quantity, so you may use a number to identify it
let myProducts: [String: Int] = ["dev.goojoob.MyApp.10lives": 10, "dev.goojoob.MyApp.50lives": 50, "dev.goojoob.MyApp.ProUser": 999]

Create a StateObject var in your View with your products:

import GOOStore

//...

@StateObject private var storeManager: GOOStore = GOOStore(products: myProducts)

Show your products in a View (this design is up to you):

ForEach(storeManager
    .myProducts
    .sorted(by: { $0.price.floatValue < $1.price.floatValue }), id: \.self) { product in
        HStack {
            VStack(alignment: .leading) {
                Text(product.localizedTitle)
                Text(product.localizedDescription)
            }

            Spacer()

            Button {
                storeManager.purchaseProduct(product: product)
            } label: {
                HStack {
                    Text("\(product.localizedPrice ?? "00")")
                    Image(systemName: "creditcard")
                }
            }
        }
    }

Let Restore Purchases available (for example in the toolbar):

.toolbar {
    ToolbarItem(placement: .navigationBarTrailing) {
        Button {
            storeManager.restoreProducts()
        } label: {
            Text("Restore Purchases")
        }
    }
}

Process the purchase/restore in a View:

  • Variable lastBuy is a tuple containing the las item purchased, its productId and quantity
.onChange(of: storeManager.transactionState) { transactionState in
    switch transactionState {
    case .purchased:
        print("StoreManager - Purchased: '\(storeManager.lastBuy.productId)' Quantity: \(storeManager.lastBuy.quantity)")
        //treat your purchase
    case .restored:
        //treat your restored purchases
    default:
        break
    }
}

๐Ÿ‘จโ€๐Ÿ’ป Compatibility

  • macOS 10.15+
  • iOS 13.0+

๐Ÿ› ๏ธ Created with


โœ’๏ธ Author

Goojoob.dev - Original development - goojoob


๐Ÿ“„ License

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International license (CC BY 4.0).


๐ŸŽ Thank You

  • Talk to others about this project ๐Ÿ“ข
  • We can have a โ˜• whenever you want

goostore's People

Contributors

goojoob 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.