@Override public int isGetPurchaseHistorySupported(@Nonnull String product, @Nonnull RequestListener<Object> listener) { Check.isNotEmpty(product); return isBillingSupported(product, Billing.V6, listener); }
@Override public int isPurchaseWithExtraParamsSupported(@Nonnull String product, @Nonnull RequestListener<Object> listener) { Check.isNotEmpty(product); return isBillingSupported(product, Billing.V6, listener); }
@Override public int purchase(@Nonnull String product, @Nonnull String sku, @Nullable String payload, @Nonnull PurchaseFlow purchaseFlow) { Check.isNotEmpty(product); Check.isNotEmpty(sku); return runWhenConnected(new PurchaseRequest(product, sku, payload), wrapListener(purchaseFlow), mTag); }
@Override public int getSkus(@Nonnull String product, @Nonnull List<String> skus, @Nonnull RequestListener<Skus> listener) { Check.isNotEmpty(product); Check.isNotEmpty(skus); return runWhenConnected(new GetSkuDetailsRequest(product, skus), wrapListener(listener), mTag); }
@Override public int purchase(@Nonnull String product, @Nonnull String sku, @Nullable String payload, @Nullable Bundle extraParams, @Nonnull PurchaseFlow purchaseFlow) { Check.isNotEmpty(product); Check.isNotEmpty(sku); return runWhenConnected(new PurchaseRequest(product, sku, payload, extraParams), wrapListener(purchaseFlow), mTag); }
@Override public int changeSubscription(@Nonnull List<String> oldSkus, @Nonnull String newSku, @Nullable String payload, @Nonnull PurchaseFlow purchaseFlow) { Check.isNotEmpty(oldSkus); Check.isNotEmpty(newSku); return runWhenConnected( new ChangePurchaseRequest(ProductTypes.SUBSCRIPTION, oldSkus, newSku, payload), wrapListener(purchaseFlow), mTag); }
/** * Same as {@link #loadSkus(String, List)} with one element in the list. */ @Nonnull public Request loadSkus(@Nonnull String product, @Nonnull String sku) { ProductTypes.checkSupported(product); Check.isNotEmpty(sku); final List<String> list = mSkus.get(product); Check.isTrue(!list.contains(sku), "Adding same SKU is not allowed"); list.add(sku); return this; }
@Override public int getPurchaseHistory(@Nonnull String product, @Nullable String continuationToken, @Nullable Bundle extraParams, @Nonnull RequestListener<Purchases> listener) { Check.isNotEmpty(product); return runWhenConnected(new GetPurchaseHistoryRequest(product, continuationToken, extraParams), wrapListener(listener), mTag); }
@Override public int isBillingSupported(@Nonnull String product, int apiVersion, @Nonnull Bundle extraParams, @Nonnull RequestListener<Object> listener) { Check.isNotEmpty(product); return runWhenConnected(new BillingSupportedRequest(product, apiVersion, extraParams), wrapListener(listener), mTag); }
@Nonnull private List<Purchase> loadPurchases(@Nonnull List<String> skus, @Nonnull SQLiteDatabase db) { Check.isNotEmpty(skus); final List<Purchase> purchases = new ArrayList<>(skus.size()); final String[] columns = {"_id", "state", "productId", "purchaseTime", "developerPayload"}; final String packageName = mContext.getPackageName(); Cursor c = null; try { c = db.query("purchases", columns, "productId in " + makeInClause(skus.size()), skus.toArray(new String[skus.size()]), null, null, null); if (c.moveToFirst()) { do { final String orderId = c.getString(0); final int state = c.getInt(1); final String sku = c.getString(2); final long time = c.getLong(3); final String payload = c.getString(4); final Purchase p = new Purchase(sku, orderId, packageName, time, state, payload, "", false, "", ""); purchases.add(p); } while (c.moveToNext()); } } finally { if (c != null) { c.close(); } } return purchases; } }
@Override public int isBillingSupported(@Nonnull String product, int apiVersion, @Nonnull RequestListener<Object> listener) { Check.isNotEmpty(product); return runWhenConnected(new BillingSupportedRequest(product, apiVersion, null), wrapListener(listener), mTag); }
@Override public int consume(@Nonnull String token, @Nonnull RequestListener<Object> listener) { Check.isNotEmpty(token); return runWhenConnected(new ConsumePurchaseRequest(token), wrapListener(listener), mTag); }
@Override public int getPurchases(@Nonnull final String product, @Nullable final String continuationToken, @Nonnull RequestListener<Purchases> listener) { Check.isNotEmpty(product); return runWhenConnected(new GetPurchasesRequest(product, continuationToken, mConfiguration.getPurchaseVerifier()), wrapListener(listener), mTag); }
@Override public int getWholePurchaseHistory(@Nonnull String product, @Nullable Bundle extraParams, @Nonnull RequestListener<Purchases> listener) { Check.isNotEmpty(product); final GetPurchaseHistoryRequest request = new GetPurchaseHistoryRequest(product, null, extraParams); return runWhenConnected(request, wrapListener(new GetWholePurchaseHistoryListener(request, listener)), mTag); }
@Override public int isPurchased(@Nonnull final String product, @Nonnull final String sku, @Nonnull final RequestListener<Boolean> listener) { Check.isNotEmpty(sku); final IsPurchasedListener isPurchasedListener = new IsPurchasedListener(sku, listener); final GetPurchasesRequest request = new GetPurchasesRequest(product, null, mConfiguration.getPurchaseVerifier()); isPurchasedListener.mRequest = request; return runWhenConnected(request, wrapListener(isPurchasedListener), mTag); }
@Override public int getAllPurchases(@Nonnull String product, @Nonnull RequestListener<Purchases> listener) { Check.isNotEmpty(product); final GetPurchasesRequest request = new GetPurchasesRequest(product, null, mConfiguration.getPurchaseVerifier()); return runWhenConnected(request, wrapListener(new GetAllPurchasesListener(request, listener)), mTag); }
/** * @param context application or activity context. Needed to bind to the in-app billing * service. * @param configuration billing configuration */ public Billing(@Nonnull Context context, @Nonnull Handler handler, @Nonnull Configuration configuration) { if (context instanceof Application) { // mContext.getApplicationContext() might return null for applications as we allow create Billing before // Application#onCreate is called mContext = context; } else { mContext = context.getApplicationContext(); } mMainThread = new MainThread(handler); mConfiguration = new StaticConfiguration(configuration); Check.isNotEmpty(mConfiguration.getPublicKey()); final Cache cache = configuration.getCache(); mCache = new ConcurrentCache(cache == null ? null : new SafeCache(cache)); mPlayStoreBroadcastReceiver = new PlayStoreBroadcastReceiver(mContext, mLock); }