@Test public void initializeWithConsumablePurchasesOwned() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseItem(InAppPurchase.OcrScans50)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseData(InAppPurchase.OcrScans50, PURCHASE_STATE_PURCHASED)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>(Collections.singletonList(getInAppDataSignature()))); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); final ManagedProduct consumablePurchase = new ConsumablePurchase(InAppPurchase.OcrScans50, getInAppPurchaseData(InAppPurchase.OcrScans50, PURCHASE_STATE_PURCHASED), PURCHASE_TOKEN, IN_APP_DATA_SIGNATURE); verify(purchaseWallet).updateLocalInAppPurchasesInWallet(updateManagedProductsCaptor.capture()); when(purchaseWallet.getActiveLocalInAppPurchases()).thenReturn(updateManagedProductsCaptor.getValue()); assertEquals(Collections.singleton(consumablePurchase), updateManagedProductsCaptor.getValue()); verify(purchaseWallet, times(2)).getActiveLocalInAppPurchases(); verifyNoMoreInteractions(purchaseWallet); }
@SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") public void initialize(@NonNull Application application) { Logger.debug(PurchaseManager.this, "Initializing the purchase manager"); application.registerActivityLifecycleCallbacks(new PurchaseManagerActivityLifecycleCallbacks(this)); Observable.fromCallable(purchaseWallet::getActiveLocalInAppPurchases) .subscribeOn(subscribeOnScheduler) .subscribe(); getAllOwnedPurchases() .subscribeOn(subscribeOnScheduler) .subscribe(managedProducts -> Logger.debug(PurchaseManager.this, "Successfully initialized all user owned purchases {}.", managedProducts), throwable -> Logger.error(PurchaseManager.this, "Failed to initialize all user owned purchases.", throwable)); remoteSubscriptionManager.getNewRemoteSubscriptions() .subscribe(newInAppSubscriptions -> { for (RemoteSubscription newRemoteSubscription : newInAppSubscriptions) { for (final PurchaseEventsListener listener : listeners) { listener.onPurchaseSuccess(newRemoteSubscription.getInAppPurchase(), PurchaseSource.Remote); } } }, throwable -> Logger.error(this, "Failed to fetch our remote subscriptions")); }
PurchaseManager { @SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") public void initialize(@NonNull Application application) { Logger.debug(PurchaseManager.this, "Initializing the purchase manager"); application.registerActivityLifecycleCallbacks(new PurchaseManagerActivityLifecycleCallbacks(this)); Observable.fromCallable(purchaseWallet::getActiveLocalInAppPurchases) .subscribeOn(subscribeOnScheduler) .subscribe(); getAllOwnedPurchases() .subscribeOn(subscribeOnScheduler) .subscribe(managedProducts -> Logger.debug(PurchaseManager.this, "Successfully initialized all user owned purchases {}.", managedProducts), throwable -> Logger.error(PurchaseManager.this, "Failed to initialize all user owned purchases.", throwable)); remoteSubscriptionManager.getNewRemoteSubscriptions() .subscribe(newInAppSubscriptions -> { for (RemoteSubscription newRemoteSubscription : newInAppSubscriptions) { for (final PurchaseEventsListener listener : listeners) { listener.onPurchaseSuccess(newRemoteSubscription.getInAppPurchase(), PurchaseSource.Remote); } } }, throwable -> Logger.error(this, "Failed to fetch our remote subscriptions")); } }
PurchaseManager { @SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") public void initialize(@NonNull Application application) { Logger.debug(PurchaseManager.this, "Initializing the purchase manager"); application.registerActivityLifecycleCallbacks(new PurchaseManagerActivityLifecycleCallbacks(this)); Observable.fromCallable(purchaseWallet::getActiveLocalInAppPurchases) .subscribeOn(subscribeOnScheduler) .subscribe(); getAllOwnedPurchases() .subscribeOn(subscribeOnScheduler) .subscribe(managedProducts -> Logger.debug(PurchaseManager.this, "Successfully initialized all user owned purchases {}.", managedProducts), throwable -> Logger.error(PurchaseManager.this, "Failed to initialize all user owned purchases.", throwable)); remoteSubscriptionManager.getNewRemoteSubscriptions() .subscribe(newInAppSubscriptions -> { for (RemoteSubscription newRemoteSubscription : newInAppSubscriptions) { for (final PurchaseEventsListener listener : listeners) { listener.onPurchaseSuccess(newRemoteSubscription.getInAppPurchase(), PurchaseSource.Remote); } } }, throwable -> Logger.error(this, "Failed to fetch our remote subscriptions")); } @Inject  PurchaseManager(@NonNull Context context,
                           @NonNull RemoteSubscriptionManager remoteSubscriptionManager,
                           @NonNull PurchaseWallet purchaseWallet,
                           @NonNull Analytics analytics); @VisibleForTesting  PurchaseManager(@NonNull Context context,
                    @NonNull RemoteSubscriptionManager remoteSubscriptionManager,
                    @NonNull PurchaseWallet purchaseWallet,
                    @NonNull Analytics analytics,
                    @NonNull Scheduler subscribeOnScheduler,
                    @NonNull Scheduler observeOnScheduler); }
PurchaseManager { @SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") public void initialize(@NonNull Application application) { Logger.debug(PurchaseManager.this, "Initializing the purchase manager"); application.registerActivityLifecycleCallbacks(new PurchaseManagerActivityLifecycleCallbacks(this)); Observable.fromCallable(purchaseWallet::getActiveLocalInAppPurchases) .subscribeOn(subscribeOnScheduler) .subscribe(); getAllOwnedPurchases() .subscribeOn(subscribeOnScheduler) .subscribe(managedProducts -> Logger.debug(PurchaseManager.this, "Successfully initialized all user owned purchases {}.", managedProducts), throwable -> Logger.error(PurchaseManager.this, "Failed to initialize all user owned purchases.", throwable)); remoteSubscriptionManager.getNewRemoteSubscriptions() .subscribe(newInAppSubscriptions -> { for (RemoteSubscription newRemoteSubscription : newInAppSubscriptions) { for (final PurchaseEventsListener listener : listeners) { listener.onPurchaseSuccess(newRemoteSubscription.getInAppPurchase(), PurchaseSource.Remote); } } }, throwable -> Logger.error(this, "Failed to fetch our remote subscriptions")); } @Inject  PurchaseManager(@NonNull Context context,
                           @NonNull RemoteSubscriptionManager remoteSubscriptionManager,
                           @NonNull PurchaseWallet purchaseWallet,
                           @NonNull Analytics analytics); @VisibleForTesting  PurchaseManager(@NonNull Context context,
                    @NonNull RemoteSubscriptionManager remoteSubscriptionManager,
                    @NonNull PurchaseWallet purchaseWallet,
                    @NonNull Analytics analytics,
                    @NonNull Scheduler subscribeOnScheduler,
                    @NonNull Scheduler observeOnScheduler); void addEventListener(@NonNull PurchaseEventsListener listener); void removeEventListener(@NonNull PurchaseEventsListener listener); @SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") void initialize(@NonNull Application application); void onActivityResumed(@NonNull Activity activity); void onActivityPaused(); void initiatePurchase(@NonNull final InAppPurchase inAppPurchase, @NonNull final PurchaseSource purchaseSource); @VisibleForTesting void sendMockPurchaseRequest(@NonNull InAppPurchase inAppPurchase); boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data); @NonNull Observable<Set<ManagedProduct>> getAllOwnedPurchases(); @NonNull Observable<Set<AvailablePurchase>> getAllAvailablePurchases(); @NonNull Observable<Set<InAppPurchase>> getAllAvailablePurchaseSkus(); @NonNull Completable consumePurchase(@NonNull final ConsumablePurchase consumablePurchase); }
PurchaseManager { @SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") public void initialize(@NonNull Application application) { Logger.debug(PurchaseManager.this, "Initializing the purchase manager"); application.registerActivityLifecycleCallbacks(new PurchaseManagerActivityLifecycleCallbacks(this)); Observable.fromCallable(purchaseWallet::getActiveLocalInAppPurchases) .subscribeOn(subscribeOnScheduler) .subscribe(); getAllOwnedPurchases() .subscribeOn(subscribeOnScheduler) .subscribe(managedProducts -> Logger.debug(PurchaseManager.this, "Successfully initialized all user owned purchases {}.", managedProducts), throwable -> Logger.error(PurchaseManager.this, "Failed to initialize all user owned purchases.", throwable)); remoteSubscriptionManager.getNewRemoteSubscriptions() .subscribe(newInAppSubscriptions -> { for (RemoteSubscription newRemoteSubscription : newInAppSubscriptions) { for (final PurchaseEventsListener listener : listeners) { listener.onPurchaseSuccess(newRemoteSubscription.getInAppPurchase(), PurchaseSource.Remote); } } }, throwable -> Logger.error(this, "Failed to fetch our remote subscriptions")); } @Inject  PurchaseManager(@NonNull Context context,
                           @NonNull RemoteSubscriptionManager remoteSubscriptionManager,
                           @NonNull PurchaseWallet purchaseWallet,
                           @NonNull Analytics analytics); @VisibleForTesting  PurchaseManager(@NonNull Context context,
                    @NonNull RemoteSubscriptionManager remoteSubscriptionManager,
                    @NonNull PurchaseWallet purchaseWallet,
                    @NonNull Analytics analytics,
                    @NonNull Scheduler subscribeOnScheduler,
                    @NonNull Scheduler observeOnScheduler); void addEventListener(@NonNull PurchaseEventsListener listener); void removeEventListener(@NonNull PurchaseEventsListener listener); @SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") void initialize(@NonNull Application application); void onActivityResumed(@NonNull Activity activity); void onActivityPaused(); void initiatePurchase(@NonNull final InAppPurchase inAppPurchase, @NonNull final PurchaseSource purchaseSource); @VisibleForTesting void sendMockPurchaseRequest(@NonNull InAppPurchase inAppPurchase); boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data); @NonNull Observable<Set<ManagedProduct>> getAllOwnedPurchases(); @NonNull Observable<Set<AvailablePurchase>> getAllAvailablePurchases(); @NonNull Observable<Set<InAppPurchase>> getAllAvailablePurchaseSkus(); @NonNull Completable consumePurchase(@NonNull final ConsumablePurchase consumablePurchase); static final int REQUEST_CODE; }