Awesome Open Source
Awesome Open Source

rx-billing

RxJava bindings for Google Play Billing

Installation

Your top-level build.gradle:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

In module-level build.gradle:

dependencies {
    implementation 'com.github.mu29:rx-billing:0.5'
}

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));

Author

InJung Chung / @mu29

License

MIT


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Java (689,295
Android (40,882
Rxjava2 (1,344
Rxjava (1,322
Billing (233
Related Projects