Git Product home page Git Product logo

gyinpurchase's Introduction

Overview

GYInpurchase is a simple example to show how to use in-app purchase. (这个是一个简单的实例demo来展示如何使用内购)

How to use

//购买
let productIdentifiers: Set<String> = ["a", "b", "c"]

Inpurchase.default.start(productIdentifiers: productIdentifiers, successBlock: { () -> Order in
    return (productIdentifiers: "a", applicationUsername: "该用户的id或用户的唯一标识符")
}, receiptBlock: { (receipt, transaction, queue) in
    //交易成功返回了凭证
    let data = InpurchaseAPIData(accountID: transaction.payment.applicationUsername,
                                 transactionID: transaction.transactionIdentifier,
                                 receiptData: receipt)
    LPNetworkManager.request(Router.verifyReceipt(data)).showToast().loading(in: self.view).success {[weak self] in
        showToast("购买成功")
        // 记住一定要请求自己的服务器成功之后, 再移除此次交易
        queue.finishTransaction(transaction)

        }.fail {
            print("向服务器发送凭证失败")
    }
}, failBlock: { (error) in
    print(error)
})

//应用启动后
Inpurchase.default.unFinishedTransaction = {(receipt, transaction, queue) in
    // 如果存在掉单情况就会走这里
    let data = InpurchaseAPIData(accountID: transaction.payment.applicationUsername,
                                 transactionID: transaction.transactionIdentifier,
                                 receiptData: receipt)
    LPNetworkManager.request(Router.verifyReceipt(data)).showToast().loading(in: self.view).success {[weak self] in
        showToast("恢复购买成功")
        // 记住一定要请求自己的服务器成功之后, 再移除此次交易
        queue.finishTransaction(transaction)

        }.fail {
            print("向服务器发送凭证失败")
    }
}

Author

gaoyu, [email protected]

License

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

gyinpurchase's People

Contributors

gaoyuexit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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