Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Configuration

mikemee edited this page Sep 15, 2015 · 8 revisions

Before utilizing library capabilities it must be configured.

The best place for it by far is Application.onCreate() callback.

Define BillingListener

BillingListener - is you main entry point for all incoming billing events. It's strongly recommended to save all intermediate results to some kind of persistent storage (DataBase, ContentProvider, SharedPreferences etc.).

You can implement BillingListener from scratch or extend pre-defined DefaultBillingListener which will do following things:

  • Attempt to consume any Consumable items purchased by user.
  • Attempt to fully load user inventory, if it was loaded only partially.
final BillingListener myListener = new SimpleBillingListener() {
    // Handle desired callbacks.
    @Override
    public void onConsume(@NonNull final ConsumeResponse consumeResponse) {
        super.onConsume(consumeResponse);
        if (consumeResponse.isSuccessful()) {
            MyPresistentStorage.awardCoins();
        }
    }
}

Define Configuration

There are several options available in Configuration object, check JavaDoc for more details.

final Configuration configuration = new Configuration.Builder()
        // Billing providers will be prioritized in the same order you added them
        .addBillingProvider(provider1)
        .addBillingProvider(provider2)
        .setBillingListener(myListener)
        .build();

Initialize library

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        OPFIab.init(this, configuration);
    }
}

Now library should be properly initialized, all that's left is just Pick Provider.