Giter VIP home page Giter VIP logo

reactiveplaybilling's Introduction

Reactive Play Billing

This project acts us a simple wrapper for the Play Billing Library from Google for Android. This allows you to interact with the library in a reactive manner and use it within your reactive streams.

Functionality

Reactive Play Billing currently supports most of the operations that you will find within the library itself.

Connecting to Play Billing

You can connect to Play Billing by using the connect() method and subscribing to changes in the connection status.

reactiveBilling.connect()
        .subscribe({
                // Play billing connection successful
        }, {
                // Play billing connection failed / disconnected
        })

Observing purchase changes

You can observe purchase change by using the observePurchaseUpdates() method. This will be called when the user purchases and item / subscription to provide you with the status of the change. You must subbscribe to this method if you are carrying our purchases.

reactiveBilling.observePurchaseUpdates()
        .subscribe({
                // Purchase complete, handle result
        }, {
                // Purchase failed, handle result
        })

Querying in-app items for purchase

You can query items that are available for purchase using the queryItemsForPurchase() method. When calling, you need to pass in a list of SKU ids that you wish to retrieve the details for. If successful this will return you a list of SkuDetail instances. Otherwise, a QueryItemsForPurchaseError will be returned.

reactiveBilling.queryItemsForPurchase(skuList)
        .subscribe({
                // Handle items returned
        }, {
                // Handle item retrieval failure
        })

Querying subscriptions for purchase

You can query subscriptions that are available for purchase using the querySubscriptionsForPurchase() method. When calling, you need to pass in a list of SKU ids that you wish to retrieve the details for. If successful this will return you a list of SkuDetail instances. Otherwise, a QueryItemsForSubscriptionError will be returned.

reactiveBilling.querySubscriptionsForPurchase(skuList)
        .subscribe({
                // Handle items returned
        }, {
                // Handle item retrieval failure
        })

Purchasing an in-app Item

You can purchase in-app items by calling the purchaseItem() method. When calling this you need to pass in the SKU of the item which you wish to perform the purchase request on, followed by a reference to the current activity - this is required for activity result events.

A succesfull request will return an instance of the PurchaseResponse class. An unsuccessful request will return an ItemsForPurchaseQueryError.

reactiveBilling.purchaseItem(sku, activity)
        .subscribe({
                // Handle purchase success
        }, {
                // Handle purchase failure
        })

Purchasing a subscription

You can purchase subcsriptions by calling the purchaseSubscription() method. When calling this you need to pass in the SKU of the subscription which you wish to perform the purchase request on, followed by a reference to the current activity - this is required for activity result events.

A succesfull request will return an instance of the SubscriptionResponse class. An unsuccessful request will return an SubscriptionError.

reactiveBilling.purchaseSubscription(sku, activity)
        .subscribe({
                // Handle subscription success
        }, {
                // Handle subscription failure
        })

Querying purchases

You can query previous purchases for the current user by using the queryPurchaseHistory() observable. This will return you a list of Purchase instances upona successful request, but a QueryPurchasesError if the request fails.

reactiveBilling.queryPurchaseHistory()
        .subscribe({
                // Handle purchase history
        }, {
                // Handle failure
        })

Querying subscriptions

You can query subscriptions for the current user by using the querySubscriptionHistory() observable. This will return you a list of Purchase instances upona successful request, but a QuerySubscriptionsError if the request fails.

reactiveBilling.querySubscriptionHistory()
        .subscribe({
                // Handle purchase history
        }, {
                // Handle failure
        })

Consuming a purchase

You can consume an item that has been purchases by using consumeItem(). When calling this you need to pass in a reference to the purchase token for the desired item. A successful call will return a ConsumptionResponse instance and upon a failure a ConsumptionError will be returned.

reactiveBilling.consumePurchase()
        .subscribe({
                // Handle consumption success
        }, {
                // Handle consumption failure
        })

Installing

Until we get this onto maven central (we will do once the library has had some more usage for a v1 release) you will need to use Jitpack. This can be done like so:

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}
dependencies {
    compile 'com.github.bufferapp:ReactivePlayBilling:-SNAPSHOT'
}

reactiveplaybilling's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reactiveplaybilling's Issues

Advise on retry policies is much appreciated.

Hi! I am exited about using ReactivePlayBilling in my app, but I am quite new to RxJava.
I wonder if it is necessary to have a retry policy as Google advises. For my onBillingServiceDisconnected() in my app I am considering emitting a Throwable in onError() instead of onNext():

open fun connect(): Observable<ConnectionResult> {
    return Observable.create {
        billingClient.startConnection(object : BillingClientStateListener {
            override fun onBillingSetupFinished(@BillingClient.BillingResponse
                                                responseCode: Int) {
                if (responseCode == BillingClient.BillingResponse.OK) {
                    it.onNext(ConnectionResult.ConnectionSuccess(responseCode))
                } else {
                    it.onNext(ConnectionResult.ConnectionFailure(responseCode))
                }
            }

            override fun onBillingServiceDisconnected() {
                // What if I change to emitting an error?
                it.onError(Throwable("Google Play Billing - connection closed."))
                //it.onNext(ConnectionResult.ConnectionFailure())
            }
        })
    }
}

Then I can chain on a retry/retryWhen, hoping to re-establish the connection. Is this a reasonable approach or am I missing something?

I am a bit worried about getting this error:
https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingResponse.html#SERVICE_DISCONNECTED
Google says "Play Store service is not connected now - potentially transient state." I don't know if it means that the connection will re-appear and thus the stream should not be closed.

Implement queryPurchases

This library currently only implements queryPurchaseHistoryAsync() which returns all purchases, even refunded ones.

queryPurchases() returns only the uses current purchases (I think).

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.