public FallingBackInventory(@Nonnull Checkout checkout, @Nonnull Inventory fallbackInventory) { super(checkout); mMainInventory = new CheckoutInventory(checkout); mFallbackInventory = fallbackInventory; }
public void load() { mMainInventory.load(mTask.getRequest(), this); } }
private void loadPurchases(@Nonnull final BillingRequests requests, @Nonnull final Product product) { requests.getAllPurchases(product.id, synchronizedListener(new RequestListener<Purchases>() { @Override public void onSuccess(@Nonnull Purchases purchases) { product.setPurchases(purchases.list); countDown(); } @Override public void onError(int response, @Nonnull Exception e) { countDown(); } })); }
@Test public void testShouldContinueAfterCacheException() throws Exception { populatePurchases(); final CheckoutInventory inventory = new CheckoutInventory(mCheckout); final InventoryTestBase.TestCallback listener = new InventoryTestBase.TestCallback(); mCheckout.start(); inventory.load(mRequest, listener); Tests.waitWhileLoading(inventory); assertTrue(mFailingCache.mExceptionThrown); }
@Test public void testShouldContinueAfterListenerException() throws Exception { populatePurchases(); final Inventory.Request request = Inventory.Request.create() .loadSkus(IN_APP, "in_app_01") .loadSkus(SUBSCRIPTION, "sub_01"); final Checkout checkout = Checkout.forApplication(mBilling); final CrashingCallback listener = new CrashingCallback(); final CheckoutInventory inventory = new CheckoutInventory(checkout); checkout.start(); inventory.load(request, listener); Tests.waitWhileLoading(inventory); Assert.assertTrue(listener.exceptionThrown); }
@Test public void testIsLoadedWithEmptySkusList() throws Exception { populatePurchases(); populateSkus(); final Inventory.Request request = Inventory.Request.create() .loadAllPurchases() .loadSkus(IN_APP, "in_app_01") .loadSkus(SUBSCRIPTION, "sub_01"); final Checkout checkout = Checkout.forApplication(mBilling); final CheckoutInventory inventory = new CheckoutInventory(checkout); final TestCallback listener = new TestCallback(); checkout.start(); inventory.load(request, listener); Tests.waitWhileLoading(inventory); final Inventory.Product app = listener.mProducts.get(IN_APP); Assert.assertTrue(app.getSkus().isEmpty()); Assert.assertFalse(app.getPurchases().isEmpty()); final Inventory.Product sub = listener.mProducts.get(SUBSCRIPTION); Assert.assertTrue(sub.getSkus().isEmpty()); Assert.assertFalse(sub.getPurchases().isEmpty()); }
@Nonnull protected CheckoutInventory newInventory(@Nonnull Checkout checkout) { return new CheckoutInventory(checkout); }
private void loadSkus(@Nonnull BillingRequests requests, @Nonnull final Product product) { final List<String> skuIds = mTask.getRequest().getSkus(product.id); if (skuIds.isEmpty()) { Billing.warning("There are no SKUs for \"" + product.id + "\" product. No SKU information will be loaded"); synchronized (mLock) { countDown(); } return; } requests.getSkus(product.id, skuIds, synchronizedListener(new RequestListener<Skus>() { @Override public void onSuccess(@Nonnull Skus skus) { product.setSkus(skus.list); countDown(); } @Override public void onError(int response, @Nonnull Exception e) { countDown(); } })); } }
/** * Creates an {@link Inventory} object related to this {@link Checkout} instance. The created * {@link Inventory} will use a fall-back {@link Inventory} if it is returned from * {@link Billing.Configuration#getFallbackInventory(Checkout, Executor)} method. * * @return inventory */ @Nonnull public Inventory makeInventory() { Check.isMainThread(); synchronized (mLock) { checkIsNotStopped(); } final Inventory inventory; final Inventory fallbackInventory = mBilling.getConfiguration().getFallbackInventory(this, mOnLoadExecutor); if (fallbackInventory == null) { inventory = new CheckoutInventory(this); } else { inventory = new FallingBackInventory(this, fallbackInventory); } return inventory; }