Reactive wrapper around the Android Billing API that makes in app purchases and subscriptions really easy to handle. I've been using this library in my apps for years and it has been working nicely.
The core functionality is provided via an interface:
interface RxBilling {
fun queryInAppPurchases(vararg skuIds: String): Observable<InventoryInApp>
fun querySubscriptions(vararg skuIds: String): Observable<InventorySubscription>
fun isBillingForInAppSupported(): Completable
fun isBillingForSubscriptionsSupported(): Completable
fun purchase(inventory: Inventory, developerPayload: String): Single<PurchaseResponse>
fun getPurchasedInApps(): Observable<PurchasedInApp>
fun getPurchasedSubscriptions(): Observable<PurchasedSubscription>
fun acknowledgePurchase(purchased: Purchased): Single<Integer>
fun consumePurchase(purchased: Purchased): Single<Integer>
fun destroy()
@interface BillingResponse {
const val SERVICE_TIMEOUT = -3
const val FEATURE_NOT_SUPPORTED = -2
const val SERVICE_DISCONNECTED = -1
const val OK = 0
const val USER_CANCELED = 1
const val SERVICE_UNAVAILABLE = 2
const val BILLING_UNAVAILABLE = 3
const val ITEM_UNAVAILABLE = 4
const val DEVELOPER_ERROR = 5
const val ERROR = 6
const val ITEM_ALREADY_OWNED = 7
const val ITEM_NOT_OWNED = 8
const val NETWORK_ERROR = 12
}
}
The actual interface also contains documentation.
This library offers different implementations based on different Google Play Billing library versions.
implementation 'com.vanniktech:rxbilling-google-play-library-v7:0.10.0'
class YourActivity extends Activity {
private RxBilling rxBilling;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate();
rxBilling = new com.vanniktech.rxbilling.google.play.library.v7.RxBillingGooglePlayLibraryV7(this);
// Use rxBilling to call your desired methods.
}
@Override public void onDestroy() {
super.onDestroy();
rxBilling.destroy();
}
}
implementation 'com.vanniktech:rxbilling-google-play-library-v6:0.10.0'
class YourActivity extends Activity {
private RxBilling rxBilling;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate();
rxBilling = new com.vanniktech.rxbilling.google.play.library.v6.RxBillingGooglePlayLibraryV6(this);
// Use rxBilling to call your desired methods.
}
@Override public void onDestroy() {
super.onDestroy();
rxBilling.destroy();
}
}
implementation 'com.vanniktech:rxbilling-google-play-library-v5:0.10.0'
class YourActivity extends Activity {
private RxBilling rxBilling;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate();
rxBilling = new com.vanniktech.rxbilling.google.play.library.v5.RxBillingGooglePlayLibraryV5(this);
// Use rxBilling to call your desired methods.
}
@Override public void onDestroy() {
super.onDestroy();
rxBilling.destroy();
}
}
There's also a dedicated testing artifact, which provides a MockRxBilling class.
implementation 'com.vanniktech:rxbilling-testing:0.10.0'
Copyright (C) 2018 Vanniktech - Niklas Baudy
Licensed under the Apache License, Version 2.0