@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ButterKnife.bind(this, view); mItem.setText(AD_FREE); mBuyConsume.setOnClickListener(this); mCheckout.loadInventory(Inventory.Request.create().loadAllPurchases(), new InventoryCallback()); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_banner); ButterKnife.bind(this); mAd.setOnClickListener(this); final Billing billing = CheckoutApplication.get(this).getBilling(); mCheckout = Checkout.forActivity(this, billing); mCheckout.start(); mCheckout.loadInventory(Inventory.Request.create().loadAllPurchases(), new InventoryCallback()); }
@Test public void testShouldLoadPurchasesWhenProductsBecameSupported() throws Exception { when(mService.isBillingSupported(eq(3), anyString(), eq(IN_APP))).thenReturn(BILLING_UNAVAILABLE); when(mService.isBillingSupported(eq(3), anyString(), eq(SUBSCRIPTION))).thenReturn(BILLING_UNAVAILABLE); when(mService.getPurchases(anyInt(), anyString(), anyString(), isNull(String.class))).thenReturn(newPurchasesBundle(0, false)); mCheckout.start(); final AwaitingCallback c1 = new AwaitingCallback(); mCheckout.loadInventory(Inventory.Request.create().loadAllPurchases(), c1); c1.waitWhileLoading(); assertFalse(c1.mProducts.get(IN_APP).supported); assertFalse(c1.mProducts.get(SUBSCRIPTION).supported); assertTrue(c1.mProducts.get(IN_APP).getPurchases().isEmpty()); when(mService.isBillingSupported(eq(3), anyString(), eq(IN_APP))).thenReturn(OK); when(mService.isBillingSupported(eq(3), anyString(), eq(SUBSCRIPTION))).thenReturn(OK); final AwaitingCallback c2 = new AwaitingCallback(); mCheckout.loadInventory(Inventory.Request.create().loadAllPurchases(), c2); c2.waitWhileLoading(); assertTrue(c2.mProducts.get(IN_APP).supported); assertTrue(c2.mProducts.get(SUBSCRIPTION).supported); assertTrue(c2.mProducts.get(IN_APP).getPurchases().size() == 1); }
@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()); }
@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 testShouldLoadSeveralTasksAsynchronously() throws Exception { populatePurchases(); populateSkus(); mCheckout.start(); final CountingCallback c = new CountingCallback(); mInventory.load(Inventory.Request.create().loadPurchases(IN_APP), c); mInventory.load(Inventory.Request.create().loadPurchases(SUBSCRIPTION), c); mInventory.load(Inventory.Request.create().loadSkus(SUBSCRIPTION, asList("sub1", "sub2", "sub3", "sub4")), c); mInventory.load(Inventory.Request.create().loadSkus(IN_APP, asList("1", "2", "3", "4", "6")), c); mInventory.load(mRequest, c); Tests.waitWhileLoading(mInventory); assertEquals(5, c.mCount); }
private void reloadInventory() { final Inventory.Request request = Inventory.Request.create(); request.loadPurchases(SUBSCRIPTION); request.loadSkus(SUBSCRIPTION, SKUS); mCheckout.loadInventory(request, new Inventory.Callback() { @Override public void onLoaded(@Nonnull Inventory.Products products) { for (Inventory.Callback callback : mInventoryCallbacks) { callback.onLoaded(products); } } }); }
@Test public void testShouldLoadSkus() throws Exception { populateSkus(); mCheckout.start(); final TestCallback c1 = new TestCallback(); mInventory.load(Inventory.Request.create().loadSkus(SUBSCRIPTION, asList("subX", "sub2", "sub3")), c1); final TestCallback c2 = new TestCallback(); mInventory.load(Inventory.Request.create().loadSkus(IN_APP, asList("1", "2", "5")), c2); Tests.waitWhileLoading(mInventory); assertEquals(0, c1.mProducts.get(SUBSCRIPTION).getSkus().size()); assertEquals(2, c2.mProducts.get(IN_APP).getSkus().size()); }
private void reloadInventory() { final Inventory.Request request = Inventory.Request.create(); // load purchase info request.loadAllPurchases(); // load SKU details request.loadSkus(ProductTypes.IN_APP, getInAppSkus()); mCheckout.loadInventory(request, mInventoryCallback); }
@Test public void testShouldLoadSkus() throws Exception { populateSkus(); mCheckout.start(); final TestCallback c1 = new TestCallback(); mInventory.load(Inventory.Request.create().loadSkus(SUBSCRIPTION, asList("subX", "sub2", "sub3")), c1); final TestCallback c2 = new TestCallback(); mInventory.load(Inventory.Request.create().loadSkus(IN_APP, asList("1", "2", "5")), c2); Tests.waitWhileLoading(mInventory); assertEquals(2, c1.mProducts.get(SUBSCRIPTION).getSkus().size()); assertEquals(2, c2.mProducts.get(IN_APP).getSkus().size()); }
@Before public void setUp() throws Exception { mFailingCache = new FailingCache(); mBilling = newBilling(); mRequest = Inventory.Request.create() .loadAllPurchases() .loadSkus(IN_APP, asList("1", "2", "3", "4", "6")) .loadSkus(SUBSCRIPTION, asList("sub1", "sub2", "sub3", "sub4")); mCheckout = Checkout.forApplication(mBilling); }
@Before public void setUp() throws Exception { mBilling = newBilling(); mRequest = Inventory.Request.create() .loadAllPurchases() .loadSkus(IN_APP, asList("1", "2", "3", "4", "6")) .loadSkus(SUBSCRIPTION, asList("sub1", "sub2", "sub3", "sub4")); mCheckout = Checkout.forApplication(mBilling); mInventory = newInventory(mCheckout); }
@Before public void setUp() throws Exception { final Billing billing = Tests.newBilling(); billing.setMainThread(sameThreadExecutor()); mRequest = Inventory.Request.create().loadSkus(IN_APP, asList("sku_0", "sku_1", "sku_2", "sku_3", "sku_4", "sku_6")).loadAllPurchases(); mCheckout = Checkout.forApplication(billing); mDb = new BillingDB(RuntimeEnvironment.application); }