@Override public void onReady(@Nonnull BillingRequests requests) { final PurchaseFlow flow = mCheckout.createOneShotPurchaseFlow(new PurchaseListener()); requests.changeSubscription(new ArrayList<>(old), sku, null, flow); } });
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { mCheckout.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data); }
@Nonnull public static ActivityCheckout forActivity(@Nonnull Activity activity, @Nonnull Billing billing) { return new ActivityCheckout(activity, billing); }
@Test public void testOneShotPurchaseFlowShouldBeRemovedOnError() throws Exception { RequestListener l = mock(RequestListener.class); mCheckout.createOneShotPurchaseFlow(l); mCheckout.onActivityResult(ActivityCheckout.DEFAULT_REQUEST_CODE, Activity.RESULT_CANCELED, null); verify(l).onError(eq(NULL_INTENT), any(Exception.class)); verifyPurchaseFlowDoesntExist(); }
@Test public void testShouldCreateOneShotPurchaseFlow() throws Exception { mCheckout.createOneShotPurchaseFlow(101, mock(RequestListener.class)); assertNotNull(mCheckout.getPurchaseFlow(101)); }
@Test public void testDestroyShouldRemovePurchaseFlow() throws Exception { mCheckout.createPurchaseFlow(102, mock(RequestListener.class)); mCheckout.destroyPurchaseFlow(102); verifyPurchaseFlowDoesntExist(102); }
@Test public void testShouldCreatePurchaseFlow() throws Exception { mCheckout.createPurchaseFlow(100, mock(RequestListener.class)); assertNotNull(mCheckout.getPurchaseFlow(100)); }
@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()); }
@Override protected void onDestroy() { mCheckout.stop(); super.onDestroy(); }
private void purchase(Sku sku) { final RequestListener<Purchase> listener = makeRequestListener(); mCheckout.startPurchaseFlow(sku, null, listener); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_static); ButterKnife.bind(this); mBuy.setOnClickListener(this); mSkus.setAdapter(new ArrayAdapter<>(this, R.layout.support_simple_spinner_dropdown_item, new String[]{"android.test.purchased", "android.test.canceled", "android.test.refunded", "android.test.item_unavailable"})); mSkus.setSelection(0); Billing.setLogger(Billing.newMainThreadLogger(new BillingLogger(mConsole))); final Billing billing = CheckoutApplication.get(this).getBilling(); mCheckout = Checkout.forActivity(this, billing); mCheckout.start(); }
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); } } }); }
private void verifyPurchaseFlowDoesntExist() { try { mCheckout.getPurchaseFlow(); fail(); } catch (IllegalArgumentException e) { // ok } }
@Test public void testOneShotPurchaseFlowShouldBeRemovedOnSuccess() throws Exception { final PurchaseVerifier verifier = mock(PurchaseVerifier.class); Tests.mockVerifier(verifier, true); mBilling.setPurchaseVerifier(verifier); final RequestListener l = mock(RequestListener.class); mCheckout.createOneShotPurchaseFlow(l); mCheckout.onActivityResult(ActivityCheckout.DEFAULT_REQUEST_CODE, Activity.RESULT_OK, newOkIntent()); verify(l).onSuccess(anyObject()); verifyPurchaseFlowDoesntExist(); }
@Test public void testDestroyShouldCancelPurchaseFlow() throws Exception { final CancellableRequestListener l = mock(CancellableRequestListener.class); mCheckout.createPurchaseFlow(l); mCheckout.destroyPurchaseFlow(); verify(l).cancel(); }
@Test public void testShouldCreateDefaultPurchaseFlow() throws Exception { mCheckout.createPurchaseFlow(mock(RequestListener.class)); assertNotNull(mCheckout.getPurchaseFlow()); }
@Override protected void onDestroy() { mCheckout.stop(); super.onDestroy(); }
private void purchase(Sku sku) { mCheckout.startPurchaseFlow(sku, null, new PurchaseListener()); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_skus); ButterKnife.bind(this); final Adapter adapter = new Adapter(); mInventoryCallback = new InventoryCallback(adapter); mRecycler.setLayoutManager(new LinearLayoutManager(this)); mRecycler.setAdapter(adapter); final Billing billing = CheckoutApplication.get(this).getBilling(); mCheckout = Checkout.forActivity(this, billing); mCheckout.start(); reloadInventory(); }
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); }