class OcrPurchaseTracker implements PurchaseEventsListener {

    @SuppressLint("CheckResult")
    public void initialize() {
        Logger.debug(this, "Initializing...");
        this.purchaseManager.addEventListener(this);

        this.identityManager.isLoggedInStream()
                .subscribeOn(subscribeOnScheduler)
                .filter(isLoggedIn -> isLoggedIn)
                .flatMap(aBoolean -> {
                    // Attempt to update our latest scan count
                    return fetchAndPersistAvailableRecognitions();
                })
                .flatMap(integer -> purchaseManager.getAllOwnedPurchases())
                .flatMap(managedProducts -> {
                     for (final ManagedProduct managedProduct : managedProducts) {
                        if (managedProduct.getInAppPurchase().getPurchaseFamilies().contains(PurchaseFamily.Ocr)) {
                            Logger.debug(OcrPurchaseTracker.this, "Found available OCR purchase: {}", managedProduct.getInAppPurchase());
                            if (!defaultInAppPurchaseConsumer.isConsumed(managedProduct, PurchaseFamily.Ocr)) {
                                return uploadOcrPurchase(managedProduct);
                            } else {
                                Logger.debug(OcrPurchaseTracker.this, "But {} was already consumed...", managedProduct.getInAppPurchase());
                            }
                        }
                    }
                    return Observable.empty();
                })
                .subscribe(o -> Logger.info(OcrPurchaseTracker.this, "Successfully initialized"),
                        throwable -> Logger.error(OcrPurchaseTracker.this, "Failed to initialize.", throwable));
    }

    @Inject public  OcrPurchaseTracker(@NonNull IdentityManager identityManager,
                              @NonNull WebServiceManager webServiceManager,
                              @NonNull PurchaseManager purchaseManager,
                              @NonNull PurchaseWallet purchaseWallet,
                              @NonNull DefaultInAppPurchaseConsumer defaultInAppPurchaseConsumer,
                              @NonNull LocalOcrScansTracker localOcrScansTracker);
    @VisibleForTesting  OcrPurchaseTracker(@NonNull IdentityManager identityManager,
                       @NonNull WebServiceManager webServiceManager,
                       @NonNull PurchaseManager purchaseManager,
                       @NonNull PurchaseWallet purchaseWallet,
                       @NonNull DefaultInAppPurchaseConsumer defaultInAppPurchaseConsumer,
                       @NonNull LocalOcrScansTracker localOcrScansTracker,
                       @NonNull Scheduler subscribeOnScheduler);

}