/** 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."); } } }
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 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()); } }