Java Code Examples for com.android.billingclient.api.Purchase#PurchasesResult

The following examples show how to use com.android.billingclient.api.Purchase#PurchasesResult . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BillingManager.java    From SchoolQuest with GNU General Public License v3.0 6 votes vote down vote up
private void onQueryPurchasesFinished(Purchase.PurchasesResult result) {
    if (mBillingClient == null || result.getResponseCode() != BillingClient.BillingResponse.OK) {
        Log.w(TAG, "Billing client was null or result code (" + result.getResponseCode()
                + ") was bad – quitting");
        return;
    }
    for (Purchase purchase: result.getPurchasesList()) {
        mBillingClient.consumeAsync(purchase.getPurchaseToken(), new ConsumeResponseListener() {
            @Override
            public void onConsumeResponse(int responseCode, String purchaseToken) {
                if (responseCode != BillingClient.BillingResponse.OK) {
                    startServiceConnection(null);
                }
            }
        });
    }
}
 
Example 2
Source File: BillingManager.java    From SchoolQuest with GNU General Public License v3.0 5 votes vote down vote up
private void queryPurchases() {
    Runnable queryToExecute = new Runnable() {
        @Override
        public void run() {
            Purchase.PurchasesResult purchasesResult =
                    mBillingClient.queryPurchases(BillingClient.SkuType.INAPP);
            onQueryPurchasesFinished(purchasesResult);

        }
    };
    executeServiceRequest(queryToExecute);


}
 
Example 3
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private void queryPurchases() {
    Purchase.PurchasesResult result = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
    if (result.getResponseCode() == BillingClient.BillingResponseCode.OK)
        checkPurchases(result.getPurchasesList());
    else
        reportError(result.getBillingResult(), "IAB query purchases");
}
 
Example 4
Source File: DefaultBillingManager.java    From SAI with GNU General Public License v3.0 5 votes vote down vote up
private void loadPurchases() {
    Purchase.PurchasesResult result = mBillingClient.queryPurchases(BillingClient.SkuType.INAPP);
    if (result.getBillingResult().getResponseCode() != BillingClient.BillingResponseCode.OK) {
        Log.w(TAG, String.format("Unable to load purchases, code %d - %s", result.getBillingResult().getResponseCode(), result.getBillingResult().getDebugMessage()));
        return;
    }

    processPurchases(result.getPurchasesList());
}
 
Example 5
Source File: BillingManager.java    From UpdogFarmer with GNU General Public License v3.0 5 votes vote down vote up
private void queryPurchases() {
    final Purchase.PurchasesResult result = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
    final List<Purchase> purchases = result.getPurchasesList();
    if (purchases != null) {
        for (Purchase purchase : purchases) {
            handlePurchase(purchase);
        }
    }
}
 
Example 6
Source File: GooglePlayBillingApi.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public List<Purchase> getPurchases() {
    throwIfUnavailable();

    List<Purchase> allPurchases = new ArrayList<>();

    logSafely("Querying in-app purchases...");
    Purchase.PurchasesResult inAppPurchasesResult = billing.queryPurchases(SkuType.INAPP);

    if (inAppPurchasesResult.getResponseCode() == BillingResponse.OK) {
        List<Purchase> inAppPurchases = inAppPurchasesResult.getPurchasesList();
        logSafely("In-app purchases: " + TextUtils.join(", ", inAppPurchases));
        allPurchases.addAll(inAppPurchases);
        // Check if we support subscriptions and query those purchases as well
        boolean isSubscriptionSupported =
                billing.isFeatureSupported(FeatureType.SUBSCRIPTIONS) == BillingResponse.OK;
        if (isSubscriptionSupported) {
            logSafely("Querying subscription purchases...");
            Purchase.PurchasesResult subscriptionPurchasesResult = billing.queryPurchases(SkuType.SUBS);

            if (subscriptionPurchasesResult.getResponseCode() == BillingResponse.OK) {
                List<Purchase> subscriptionPurchases = subscriptionPurchasesResult.getPurchasesList();
                logSafely("Subscription purchases: " + TextUtils.join(", ", subscriptionPurchases));
                allPurchases.addAll(subscriptionPurchases);
                return allPurchases;
            } else {
                logSafely("Error in querying subscription purchases with code: "
                        + subscriptionPurchasesResult.getResponseCode());
                return allPurchases;
            }
        } else {
            logSafely("Subscriptions are not supported...");
            return allPurchases;
        }
    } else {
        return null;
    }
}
 
Example 7
Source File: GooglePlayBillingApi.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public List<Purchase> getPurchases(String itemType) {
    throwIfUnavailable();

    Purchase.PurchasesResult purchasesResult = billing.queryPurchases(itemType);
    if (purchasesResult.getResponseCode() == BillingResponse.OK) {
        List<Purchase> purchases = purchasesResult.getPurchasesList();
        logSafely(itemType + " purchases: " + TextUtils.join(", ", purchases));
        return purchases;
    }

    return null;
}
 
Example 8
Source File: IAPHelper.java    From rootvalidator with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBillingSetupFinished(int responseCode) {
    Timber.d("onBillingSetupFinished(responseCode=%d)", responseCode);
    if (BillingClient.BillingResponse.OK == responseCode) {
        final Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
        Timber.d("queryPurchases(): code=%d, purchases=%s", purchasesResult.getResponseCode(), purchasesResult.getPurchasesList());
        onPurchasesUpdated(purchasesResult.getResponseCode(), purchasesResult.getPurchasesList());
    }
}
 
Example 9
Source File: GoogleIap.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void queryPurchases() {
    Runnable queryToExecute = () -> {
        Purchase.PurchasesResult result = mBillingClient.queryPurchases(BillingClient.SkuType.INAPP);
        onPurchasesUpdated(result.getBillingResult(), result.getPurchasesList());

        //mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, GoogleIap.this);
    };

    executeServiceRequest(queryToExecute);
}
 
Example 10
Source File: AccelerateDevelop.java    From InviZible with GNU General Public License v3.0 4 votes vote down vote up
private List<Purchase> queryPurchases() {
    Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.INAPP);
    return purchasesResult.getPurchasesList();
}