Skip to content

tdascoli/Rx3Billing

Repository files navigation

Rx3Billing

RxJava 3.0 wrapper on Google Play Billing library.

This repository started as a personal usage of github user hero rx-billing library. You can check his work here.

Download

Gradle:
dependencies {
  implementation 'com.github.tdascoli:Rx3Billing:1.0.3'
}
allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Usage

Initialize RxBilling Instance

RxBilling billingClient;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    billingClient = new RxBilling().set(this);
}

...or you can inject with dagger

@Provides
@PerApplication
public RxBilling provideRxBilling() {
    return new RxBilling()
}
@Inject
RxBilling billingClient;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    billingClient.set(this);
}

Purchase

billingClient
    .purchase("product.test.1", null, BillingClient.SkuType.INAPP)
    .subscribe(purchases -> Log.d("IAP", purchases.get(0).getOrderId()));

Query purchases

billingClient
    .queryPurchases()
    .subscribe(purchases -> {
        for (Purchase purchase : purchases) {
            Log.d("IAP", purchase.getOrderId());
        }
    });

Get sku details

List<String> ids = new ArrayList<>();
ids.add("test.product.1");

billingClient
    .getSkuDetails(ids)
    .subscribe(details -> {
        for (SkuDetails detail: details) {
            Log.d("IAP", detail.getPrice());
        }
    });

Consume

billingClient
    .consume("purchaseToken")
    .subscribe(token -> Log.d("IAP", token));

Buy Me a Coffee at ko-fi.com

License

MIT License

Copyright (c) 2020 Thomas D'Ascoli

Permission is hereby granted, free of charge, to any person obtaining a 
copy of this software and associated documentation files (the "Software"), 
to deal in the Software without restriction, including without limitation 
the rights to use, copy, modify, merge, publish, distribute, sublicense, 
and/or sell copies of the Software, and to permit persons to whom the 
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included 
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
OTHER DEALINGS IN THE SOFTWARE.