com.android.billingclient.api.BillingClient.SkuType Java Examples

The following examples show how to use com.android.billingclient.api.BillingClient.SkuType. 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: BillingPlugin.java    From flutter_billing with Apache License 2.0 6 votes vote down vote up
private void purchase(final String identifier, final Boolean consume, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            int responseCode = billingClient.launchBillingFlow(
                    activity,
                    BillingFlowParams.newBuilder()
                                     .setSku(identifier)
                                     .setType(SkuType.INAPP)
                                     .build());

            if (responseCode == BillingResponse.OK) {
                PurchaseRequest request = new PurchaseRequest(identifier, consume, result);
                pendingPurchaseRequests.add(request);
            } else {
                result.error("ERROR", "Failed to launch billing flow to purchase an item with error " + responseCode, null);
            }
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #2
Source File: MainActivity.java    From FCM-for-Mojo with GNU General Public License v3.0 6 votes vote down vote up
private void showDonateGooglePlay() {
    mBillingClient = BillingClient.newBuilder(this).setListener(this).build();

    mBillingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(@BillingResponse int billingResponseCode) {
            if (billingResponseCode == BillingResponse.OK) {
                // The billing client is ready. You can query purchases here.
                BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                        .setSku("donate_2")
                        .setType(SkuType.INAPP)
                        .build();
                mBillingClient.launchBillingFlow(MainActivity.this, flowParams);
            }
        }

        @Override
        public void onBillingServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }
    });
}
 
Example #3
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 6 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
        final List<String> skuList, final SkuDetailsResponseListener listener) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {
        @Override
        public void run() {
            SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
                    .setSkusList(skuList).setType(itemType).build();
            mBillingClient.querySkuDetailsAsync(skuDetailsParams,
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode,
                                List<SkuDetails> skuDetailsList) {
                            listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                        }
                    });
        }
    };

    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
 
Example #4
Source File: GooglePlayBillingVendor.java    From Cashier with Apache License 2.0 6 votes vote down vote up
@Override
public void getProductDetails(@NonNull Context context, @NonNull final String sku, final boolean isSubscription,
                              @NonNull final ProductDetailsListener listener) {
    throwIfUninitialized();

    api.getSkuDetails(
            isSubscription ? SkuType.SUBS : SkuType.INAPP,
            Collections.singletonList(sku),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    if (responseCode == BillingResponse.OK && skuDetailsList.size() == 1) {
                        logSafely("Successfully got sku details for " + sku + "!");
                        listener.success(
                                GooglePlayBillingProduct.create(skuDetailsList.get(0), isSubscription ? SkuType.SUBS : SkuType.INAPP)
                        );
                    } else {
                        logSafely("Error getting sku details for " + sku + " with code "+responseCode);
                        listener.failure(getDetailsError(responseCode));
                    }
                }
            }
    );
}
 
Example #5
Source File: AcquireFragment.java    From play-billing-codelab with Apache License 2.0 6 votes vote down vote up
/**
 * Executes query for SKU details at the background thread
 */
private void handleManagerAndUiReady() {
    // Start querying for SKUs
    List<String> inAppSkus = mBillingProvider.getBillingManager().getSkus(SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.INAPP, inAppSkus,
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    if (responseCode == BillingResponse.OK
                            && skuDetailsList != null) {
                        for (SkuDetails details : skuDetailsList) {
                            Log.w(TAG, "Got a SKU: " + details);
                        }
                    }
                }
            });
    
    // Show the UI
    displayAnErrorIfNeeded();
}
 
Example #6
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
        final List<String> skuList, final SkuDetailsResponseListener listener) {
    SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
            .setSkusList(skuList).setType(itemType).build();
    mBillingClient.querySkuDetailsAsync(skuDetailsParams,
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode,
                                                 List<SkuDetails> skuDetailsList) {
                    listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                }
            });
}
 
Example #7
Source File: GooglePlayBillingApi.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Override
public int isBillingSupported(@SkuType String itemType) {
    throwIfUnavailable();

    if (SkuType.INAPP.equalsIgnoreCase(itemType) && billing.isReady()) {
        return BillingResponse.OK;
    } else if (SkuType.SUBS.equalsIgnoreCase(itemType)) {
        return billing.isFeatureSupported(FeatureType.SUBSCRIPTIONS);
    }

    return BillingResponse.FEATURE_NOT_SUPPORTED;
}
 
Example #8
Source File: GooglePlayBillingApi.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Override
public void getSkuDetails(@SkuType String itemType, @NonNull List<String> skus,
                          @NonNull SkuDetailsResponseListener listener) {
    throwIfUnavailable();

    logSafely("Query for SKU details with type: " + itemType + " SKUs: " + TextUtils.join(",", skus));

    SkuDetailsParams query = SkuDetailsParams.newBuilder()
            .setSkusList(skus)
            .setType(itemType)
            .build();
    billing.querySkuDetailsAsync(query, listener);
}
 
Example #9
Source File: GooglePlayBillingApi.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Override
public void launchBillingFlow(@NonNull final Activity activity, @NonNull String sku, @SkuType String itemType) {
    throwIfUnavailable();
    logSafely("Launching billing flow for " + sku + " with type " + itemType);

    getSkuDetails(
            itemType,
            Collections.singletonList(sku),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    try {
                        if (responseCode == BillingResponse.OK && skuDetailsList.size() > 0) {
                            BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                                    .setSkuDetails(skuDetailsList.get(0))
                                    .build();

                            // This will call the {@link PurchasesUpdatedListener} specified in {@link #initialize}
                            billing.launchBillingFlow(activity, billingFlowParams);
                        } else {
                            vendor.onPurchasesUpdated(BillingResponse.ERROR, null);
                        }
                    } catch (Exception e) {
                        vendor.onPurchasesUpdated(BillingResponse.ERROR, null);
                    }
                }
            }
    );
}
 
Example #10
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 #11
Source File: GooglePlayBillingProduct.java    From Cashier with Apache License 2.0 5 votes vote down vote up
public static Product create(SkuDetails details, @SkuType String type) {
    return Product.create(
            GooglePlayBillingConstants.VENDOR_PACKAGE,
            details.getSku(),
            details.getPrice(),
            details.getPriceCurrencyCode(),
            details.getTitle(),
            details.getDescription(),
            type.equals(SkuType.SUBS),
            details.getPriceAmountMicros()
    );
}
 
Example #12
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
                                 final List<String> skuList, final SkuDetailsResponseListener listener) {
    SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
            .setSkusList(skuList).setType(itemType).build();
    mBillingClient.querySkuDetailsAsync(skuDetailsParams,
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode,
                                                 List<SkuDetails> skuDetailsList) {
                    listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                }
            });
}
 
Example #13
Source File: AcquireFragment.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
/**
 * Executes query for SKU details at the background thread
 */
private void handleManagerAndUiReady() {
    final List<SkuRowData> inList = new ArrayList<>();
    SkuDetailsResponseListener responseListener = new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(int responseCode,
                                         List<SkuDetails> skuDetailsList) {
            if (responseCode == BillingResponse.OK && skuDetailsList != null) {
                // Repacking the result for an adapter
                for (SkuDetails details : skuDetailsList) {
                    Log.i(TAG, "Found sku: " + details);
                    inList.add(new SkuRowData(details.getSku(), details.getTitle(),
                            details.getPrice(), details.getDescription(),
                            details.getType()));
                }
                if (inList.size() == 0) {
                    displayAnErrorIfNeeded();
                } else {
                    mAdapter.updateData(inList);
                    setWaitScreen(false);
                }
            }
        }
    };

    // Start querying for in-app SKUs
    List<String> skus = mBillingProvider.getBillingManager().getSkus(SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.INAPP, skus, responseListener);
    // Start querying for subscriptions SKUs
    skus = mBillingProvider.getBillingManager().getSkus(SkuType.SUBS);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.SUBS, skus, responseListener);
}
 
Example #14
Source File: GooglePlayBillingVendor.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void initialized(boolean success) {
    logSafely("Initialized: success = " + success);
    if (!success) {
        logAndDisable("Could not create Google Play Billing instance");
        return;
    }

    try {
        canPurchaseItems =
                api.isBillingSupported(SkuType.INAPP) == BillingResponse.OK;

        canSubscribe =
                api.isBillingSupported(SkuType.SUBS) == BillingResponse.OK;

        available = canPurchaseItems || canSubscribe;
        logSafely("Connected to service and it is " + (available ? "available" : "not available"));
        initializing = false;

        for (InitializationListener listener : initializationListeners) {
            listener.initialized();
        }
        initializationListeners.clear();
    } catch (Exception error) {
        logAndDisable(Log.getStackTraceString(error));
    }
}
 
Example #15
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
        final List<String> skuList, final SkuDetailsResponseListener listener) {
    SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder().setSkusList(skuList)
            .setType(itemType).build();
    mBillingClient.querySkuDetailsAsync(skuDetailsParams,
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                }
            });
}
 
Example #16
Source File: GooglePlayBillingVendor.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void purchase(Activity activity, Product product, String developerPayload, PurchaseListener listener) {
    Preconditions.checkNotNull(activity, "Activity is null.");
    Preconditions.checkNotNull(product, "Product is null.");
    Preconditions.checkNotNull(listener, "Purchase listener is null.");
    throwIfUninitialized();

    if (pendingProduct != null) {
        throw new RuntimeException("Cannot purchase product while another purchase is in progress!");
    }

    // NOTE: Developer payload is not supported with Google Play Billing
    // https://issuetracker.google.com/issues/63381481
    if (developerPayload != null && developerPayload.length() > 0) {
        throw new RuntimeException("Developer payload is not supported in Google Play Billing!");
    }

    this.purchaseListener = listener;
    this.pendingProduct = product;
    logSafely("Launching Google Play Billing flow for " + product.sku());
    try {
        api.launchBillingFlow(activity, product.sku(), product.isSubscription() ? SkuType.SUBS : SkuType.INAPP);
    } catch (Exception e) {
        clearPendingPurchase();
        throw e;
    }
}
 
Example #17
Source File: AcquireFragment.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
/**
 * Executes query for SKU details at the background thread
 */
private void handleManagerAndUiReady() {
    final List<SkuRowData> inList = new ArrayList<>();
    SkuDetailsResponseListener responseListener = new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(int responseCode,
                                         List<SkuDetails> skuDetailsList) {
            if (responseCode == BillingResponse.OK && skuDetailsList != null) {
                // Repacking the result for an adapter
                for (SkuDetails details : skuDetailsList) {
                    Log.i(TAG, "Found sku: " + details);
                    inList.add(new SkuRowData(details.getSku(), details.getTitle(),
                            details.getPrice(), details.getDescription(),
                            details.getType()));
                }
                if (inList.size() == 0) {
                    displayAnErrorIfNeeded();
                } else {
                    mAdapter.updateData(inList);
                    setWaitScreen(false);
                }
            }
        }
    };

    // Start querying for in-app SKUs
    List<String> skus = mBillingProvider.getBillingManager().getSkus(SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.INAPP, skus, responseListener);
    // Start querying for subscriptions SKUs
    skus = mBillingProvider.getBillingManager().getSkus(SkuType.SUBS);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.SUBS, skus, responseListener);
}
 
Example #18
Source File: AcquireFragment.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
/**
 * Executes query for SKU details at the background thread
 */
private void handleManagerAndUiReady() {
    final List<SkuRowData> inList = new ArrayList<>();
    SkuDetailsResponseListener responseListener = new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(int responseCode,
                List<SkuDetails> skuDetailsList) {
            // If we successfully got SKUs, add a header in front of it
            if (responseCode == BillingResponse.OK && skuDetailsList != null) {
                // Repacking the result for an adapter
                for (SkuDetails details : skuDetailsList) {
                    Log.i(TAG, "Found sku: " + details);
                    inList.add(new SkuRowData(details.getSku(), details.getTitle(),
                            details.getPrice(), details.getDescription(),
                            details.getType()));
                }
                if (inList.size() == 0) {
                    displayAnErrorIfNeeded();
                } else {
                    mAdapter.updateData(inList);
                    setWaitScreen(false);
                }
            }
        }
    };

    // Start querying for in-app SKUs
    List<String> skus = mBillingProvider.getBillingManager().getSkus(SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.INAPP, skus, responseListener);
    // Start querying for subscriptions SKUs
    skus = mBillingProvider.getBillingManager().getSkus(SkuType.SUBS);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.SUBS, skus, responseListener);
}
 
Example #19
Source File: MainActivity.java    From PixelWatchFace with GNU General Public License v3.0 5 votes vote down vote up
private void checkPurchases() {
  PurchasesResult purchasesResult = billingClient.queryPurchases(SkuType.INAPP);
  if (purchasesResult.getBillingResult().getResponseCode() == BillingResponseCode.OK) {
    boolean advancedPurchasePresent = false;
    for (Purchase purchase : purchasesResult.getPurchasesList()) {
      handlePurchase(purchase);
      if (purchase.getSku().equals("unlock_weather")){
        advancedPurchasePresent = true;
      }
    }
    if (!advancedPurchasePresent && advanced){
      revokeAdvancedPurchase();
    }
  }
}
 
Example #20
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 5 votes vote down vote up
private void fetchPurchases(final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            List<String> identifiers = new ArrayList<>();

            Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(SkuType.INAPP);
            if (purchasesResult.getResponseCode() == BillingResponse.OK) {
                identifiers.addAll(getIdentifiers(purchasesResult.getPurchasesList()));
            } else {
                Log.w(TAG, "Failed to query purchases for in app products " +
                        "with error " + purchasesResult.getResponseCode());
            }

            purchasesResult = billingClient.queryPurchases(SkuType.SUBS);
            if (purchasesResult.getResponseCode() == BillingResponse.OK) {
                identifiers.addAll(getIdentifiers(purchasesResult.getPurchasesList()));
            } else {
                Log.w(TAG, "Failed to query purchases for in app subscriptions " +
                        "with error " + purchasesResult.getResponseCode());
            }

            result.success(identifiers);
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #21
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 5 votes vote down vote up
private void subscribe(final String identifier, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            int subscriptionSupportResponse = billingClient.isFeatureSupported(FeatureType.SUBSCRIPTIONS);
            if (BillingResponse.OK != subscriptionSupportResponse) {
                result.error("NOT SUPPORTED", "Subscriptions are not supported.", null);
                return;
            }

            int responseCode = billingClient.launchBillingFlow(
                    activity,
                    BillingFlowParams.newBuilder()
                                     .setSku(identifier)
                                     .setType(SkuType.SUBS)
                                     .build());

            if (responseCode == BillingResponse.OK) {
                PurchaseRequest request = new PurchaseRequest(identifier, result);
                pendingPurchaseRequests.add(request);
            } else {
                result.error("ERROR", "Failed to subscribe with error " + responseCode, null);
            }
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #22
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 5 votes vote down vote up
private void fetchProducts(final List<String> identifiers, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            billingClient.querySkuDetailsAsync(
                    SkuDetailsParams.newBuilder()
                                    .setSkusList(identifiers)
                                    .setType(SkuType.INAPP)
                                    .build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                            if (responseCode == BillingResponse.OK) {
                                List<Map<String, Object>> products = getProductsFromSkuDetails(skuDetailsList);
                                result.success(products);
                            } else {
                                result.error("ERROR", "Failed to fetch products!", null);
                            }
                        }
                    });
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #23
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 5 votes vote down vote up
private void fetchSubscriptions(final List<String> identifiers, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            billingClient.querySkuDetailsAsync(
                    SkuDetailsParams.newBuilder()
                                    .setSkusList(identifiers)
                                    .setType(SkuType.SUBS)
                                    .build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                            if (responseCode == BillingResponse.OK) {
                                List<Map<String, Object>> products = getProductsFromSkuDetails(skuDetailsList);
                                result.success(products);
                            } else {
                                result.error("ERROR", "Failed to fetch Subscriptions!", null);
                            }
                        }
                    });
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #24
Source File: GoogleBillingHelper.java    From Augendiagnose with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Handle result of inventory query.
 *
 * @param billingResult  The result flag.
 * @param skuDetailsList The retrieved SKU details.
 * @param isSubscription Flag indicating if this was subscription query.
 * @param listener       The listener called when inventory calls are finished.
 */
private void onSkuDetailsResponse(final BillingResult billingResult, final List<SkuDetails> skuDetailsList, final boolean isSubscription,
								  final OnInventoryFinishedListener listener) {
	Log.d(TAG, "Query inventory finished - " + billingResult.getResponseCode() + " - " + isSubscription);

	if (billingResult.getResponseCode() != BillingResponseCode.OK) {
		Log.e(TAG, "Failed to query inventory: " + billingResult.getDebugMessage());
		return;
	}

	Log.d(TAG, "Query inventory was successful.");

	Map<String, Purchase> purchaseMap = new HashMap<>();
	List<SkuPurchase> skuPurchases = new ArrayList<>();

	PurchasesResult purchasesResult = mBillingClient.queryPurchases(isSubscription ? SkuType.SUBS : SkuType.INAPP);
	if (purchasesResult.getResponseCode() != BillingResponseCode.OK) {
		Log.e(TAG, "Failed to query purchases: " + purchasesResult.getBillingResult().getDebugMessage());
		return;
	}
	for (Purchase purchase : purchasesResult.getPurchasesList()) {
		if (purchase.getPackageName().equals(mContext.getPackageName())) {
			purchaseMap.put(purchase.getSku(), purchase);
			if (purchase.getPurchaseState() == PurchaseState.PURCHASED) {
				doAcknowledgePurchaseIfRequired(purchase);
				mIsPremium = true;
			}
		}
	}

	for (SkuDetails skuDetails : skuDetailsList) {
		if (purchaseMap.containsKey(skuDetails.getSku())) {
			skuPurchases.add(new SkuPurchase(skuDetails, purchaseMap.get(skuDetails.getSku())));
		}
		else {
			skuPurchases.add(new SkuPurchase(skuDetails));
		}
	}

	synchronized (this) {
		if (isSubscription) {
			mSubscriptionSkus = skuPurchases;
		}
		else {
			mInAppSkus = skuPurchases;
		}

		if (listener != null && mSubscriptionSkus != null && mInAppSkus != null) {
			listener.handleProducts(mInAppSkus, mSubscriptionSkus);
		}
	}
}
 
Example #25
Source File: AbstractGooglePlayBillingApi.java    From Cashier with Apache License 2.0 4 votes vote down vote up
@Nullable
public abstract List<Purchase> getPurchases(@SkuType String itemType);
 
Example #26
Source File: AbstractGooglePlayBillingApi.java    From Cashier with Apache License 2.0 4 votes vote down vote up
public abstract void getSkuDetails(@SkuType String itemType, @NonNull List<String> skus,
@NonNull SkuDetailsResponseListener listener);
 
Example #27
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 4 votes vote down vote up
public List<String> getSkus(@SkuType String type) {
    return SKUS.get(type);
}
 
Example #28
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 4 votes vote down vote up
public List<String> getSkus(@SkuType String type) {
    return SKUS.get(type);
}
 
Example #29
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 4 votes vote down vote up
public List<String> getSkus(@SkuType String type) {
    return SKUS.get(type);
}
 
Example #30
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 4 votes vote down vote up
public List<String> getSkus(@SkuType String type) {
    return SKUS.get(type);
}