class OcrPurchaseTracker implements PurchaseEventsListener {

    @Override
    public void onPurchaseSuccess(@NonNull InAppPurchase inAppPurchase, @NonNull PurchaseSource purchaseSource) {
        if (inAppPurchase.getPurchaseFamilies().contains(PurchaseFamily.Ocr)) {
            final ManagedProduct managedProduct = purchaseWallet.getLocalInAppManagedProduct(inAppPurchase);
            if (managedProduct != null) {
                this.identityManager.isLoggedInStream()
                        .subscribeOn(subscribeOnScheduler)
                        .filter(isLoggedIn -> isLoggedIn)
                        .flatMap(aBoolean -> uploadOcrPurchase(managedProduct))
                        .subscribe(o -> { /*onNext*/ },
                                throwable -> Logger.error(OcrPurchaseTracker.this, "Failed to upload purchase of " + managedProduct.getInAppPurchase(), throwable),
                                () -> Logger.info(OcrPurchaseTracker.this, "Successfully uploaded and consumed purchase of {}.", managedProduct.getInAppPurchase())
                        );
            }
        }
    }

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

}