/** Returns information about a product provided by the purchase manager. * * Note, you should set autoFetchInformation to true in {@link PurchaseSystem#install} to true to make this method work for all * PurchaseManager implementations * * @return {@link Information#UNAVAILABLE} if the product is not available or information was not previously fetched */ public static Information getInformation(String identifier) { if (hasManager()) { return manager.getInformation(identifier); } else { throw new RuntimeException("No purchase manager was found."); } } }
/** Disposes the purchase manager if there was one. */ public static void dispose () { if (manager != null) { manager.dispose(); manager = null; } }
/** Returns true if the purchase system is installed and ready to go. */ public static boolean installed () { if (hasManager()) { return manager.installed(); } else { return false; } }
/** Returns the store name or null for none. */ public static String storeName () { if (hasManager()) { return manager.storeName(); } else { return null; } }
/** Executes a purchase. */ public static void purchase (String identifier) { if (hasManager()) { manager.purchase(identifier); } else { throw new RuntimeException("No purchase manager was found."); } }
/** Asks to restore previous purchases. Results are returned to the observer. */ public static void purchaseRestore () { if (hasManager()) { manager.purchaseRestore(); } else { throw new RuntimeException("No purchase manager was found."); } }
/** Installs a purchase observer. * * @param autoFetchInformation tells PurchaseManager to automatically fetch offer details on setup to make * {@link PurchaseSystem#getInformation(String)} work properly **/ public static void install (PurchaseObserver observer, PurchaseManagerConfig config, boolean autoFetchInformation) { if (hasManager()) { manager.install(observer, config, autoFetchInformation); } else { observer.handleInstallError(new RuntimeException("No purchase manager was available.")); } }
private void setInformationFields(Transaction transaction, String productId) { Information information = purchaseManager.getInformation(productId); Integer priceInCents = information.getPriceInCents(); transaction.setPurchaseCost(priceInCents == null ? 0 : priceInCents); transaction.setPurchaseCostCurrency(information.getPriceCurrencyCode()); }
@Test public void shouldDisposeManagerOnAppRestart() throws Exception { PurchaseSystem.onAppRestarted(); verify(purchaseManager).dispose(); } }
@Test public void shouldCreateTransactionForInformationWithoutPriceInCents() throws Exception { Information information = informationFullEditionEntitlementNoPriceInCents(); when(purchaseManager.getInformation(PRODUCT_IDENTIFIER_FULL_EDITION)).thenReturn(information); Transaction transaction = converter.convertToTransaction(activityResultPurchaseFullEditionSuccess()); assertEquals(0, transaction.getPurchaseCost()); assertEquals(INAPP_DATA_SIGNATURE_ACTIVITY_RESULT_SUCCESS, transaction.getTransactionDataSignature()); } }