InAppBillingV3Vendor implements Vendor { @Override public void purchase(Activity activity, Product product, String developerPayload, PurchaseListener listener) { if (activity == null || product == null || listener == null) { throw new IllegalArgumentException("Activity, product, or listener is null"); } throwIfUninitialized(); if (!canPurchase(product)) { throw new IllegalArgumentException("Cannot purchase given product!" + product.toString()); } log("Constructing buy intent..."); final String type = product.isSubscription() ? PRODUCT_TYPE_SUBSCRIPTION : PRODUCT_TYPE_ITEM; try { if (developerPayload == null) { this.developerPayload = UUID.randomUUID().toString(); } else { this.developerPayload = developerPayload; } final Bundle buyBundle = api.getBuyIntent(product.sku(), type, developerPayload); final int response = getResponseCode(buyBundle); if (response != BILLING_RESPONSE_RESULT_OK) { log("Couldn't purchase product! code:" + response); listener.failure(product, purchaseError(response)); return; } final PendingIntent pendingIntent = buyBundle.getParcelable(RESPONSE_BUY_INTENT); if (pendingIntent == null) { log("Received no pending intent!"); listener.failure(product, purchaseError(response)); return; } log("Launching buy intent for " + product.sku()); this.purchaseListener = listener; pendingProduct = product; requestCode = new Random().nextInt(1024); activity.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(), 0, 0, 0); } catch (RemoteException | IntentSender.SendIntentException e) { log("Failed to launch purchase!\n" + Log.getStackTraceString(e)); listener.failure(product, purchaseError(BILLING_RESPONSE_RESULT_ERROR)); } } InAppBillingV3Vendor();  InAppBillingV3Vendor(String publicKey64);  InAppBillingV3Vendor(AbstractInAppBillingV3API api);  InAppBillingV3Vendor(AbstractInAppBillingV3API api, @Nullable String publicKey64); @Override String id(); @Override void initialize(Context context, InitializationListener listener); @Override void dispose(Context context); @Override boolean available(); @Override boolean canPurchase(Product product); @Override void purchase(Activity activity, Product product, String developerPayload,
                       PurchaseListener listener); @Override void consume(Context context, Purchase purchase, ConsumeListener listener); @Override void getInventory(Context context, Collection<String> inappSkus, Collection<String> subSkus,
                           InventoryListener listener); @Override void getProductDetails(Context context, String sku, boolean isSubscription,
                                ProductDetailsListener listener); @Override void setLogger(@Nullable Logger logger); @Override boolean onActivityResult(int requestCode, int resultCode, Intent data); @Override Product getProductFrom(JSONObject json); @Override Purchase getPurchaseFrom(JSONObject json);  }
@Test(expected = IllegalArgumentException.class) public void purchaseRequiresActivity() throws RemoteException { InAppBillingV3Vendor vendor = new InAppBillingV3Vendor(api, null); vendor.purchase(null, mock(Product.class), null, mock(PurchaseListener.class)); }
@Test(expected = IllegalArgumentException.class) public void purchaseRequiresProduct() throws RemoteException { InAppBillingV3Vendor vendor = new InAppBillingV3Vendor(api, null); vendor.purchase(mock(Activity.class), null, null, mock(PurchaseListener.class)); }
@Test(expected = IllegalArgumentException.class) public void purchaseRequiresListener() throws RemoteException { InAppBillingV3Vendor vendor = new InAppBillingV3Vendor(api, null); vendor.purchase(mock(Activity.class), mock(Product.class), null, null); }
@Test(expected = IllegalStateException.class) public void purchaseRequiresInitialization() throws RemoteException { InAppBillingV3Vendor vendor = new InAppBillingV3Vendor(api, null); vendor.purchase(mock(Activity.class), mock(Product.class), null, mock(PurchaseListener.class)); }