use of com.android.billingclient.api.BillingClient.SkuType in project Android-InAppBilling by LiteKite.
the class BillingManager method queryPurchasesAsync.
/**
* Queries InApp and Subscribed purchase results from Google Play Locally.
*
* @param purchases this list contains all the product purchases made, has InApp and
* Subscription purchased results.
* @param skuType InApp or Subscription.
* @param executeWhenFinished Once the InApp product purchase results are given, then
* subscription based purchase results are queried and results are placed into the {@link
* #myPurchasesResultList}
*/
private void queryPurchasesAsync(final List<Purchase> purchases, @SkuType final String skuType, final Runnable executeWhenFinished) {
PurchasesResponseListener purchasesResponseListener = (billingResult, list) -> {
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
purchases.addAll(list);
if (executeWhenFinished != null) {
executeWhenFinished.run();
}
} else {
MonetizeApp.printLog(TAG, "queryPurchasesAsync() got an error response code: " + billingResult.getResponseCode());
logErrorType(billingResult);
}
if (executeWhenFinished == null) {
processPurchases(purchases);
}
};
executeServiceRequest(() -> myBillingClient.queryPurchasesAsync(skuType, purchasesResponseListener));
}
use of com.android.billingclient.api.BillingClient.SkuType in project Android-InAppBilling by LiteKite.
the class BillingManager method querySkuDetailsAsync.
/**
* Queries SKU Details from Google Play Remote Server of SKU Types (InApp and Subscription).
*
* @param skuResultLMap contains SKU ID and Price Details returned by the sku details query.
* @param params contains list of SKU IDs and SKU Type (InApp or Subscription).
* @param billingType InApp or Subscription.
* @param executeWhenFinished contains query for InApp SKU Details that will be run after
*/
private void querySkuDetailsAsync(Map<String, SkuDetails> skuResultLMap, SkuDetailsParams.Builder params, @SkuType String billingType, Runnable executeWhenFinished) {
final SkuDetailsResponseListener listener = (billingResult, skuDetailsList) -> {
// Process the result.
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
MonetizeApp.printLog(TAG, "Unsuccessful query for type: " + billingType + ". Error code: " + billingResult.getResponseCode());
} else if (skuDetailsList != null && skuDetailsList.size() > 0) {
for (SkuDetails skuDetails : skuDetailsList) {
skuResultLMap.put(skuDetails.getSku(), skuDetails);
}
}
if (executeWhenFinished != null) {
executeWhenFinished.run();
return;
}
if (skuResultLMap.size() == 0) {
MonetizeApp.printLog(TAG, "sku error: " + context.getString(R.string.err_no_sku));
} else {
MonetizeApp.printLog(TAG, "storing sku list locally");
storeSkuDetailsLocally(skuResultLMap);
}
};
// Creating a runnable from the request to use it inside our connection retry policy below
executeServiceRequest(() -> myBillingClient.querySkuDetailsAsync(params.build(), listener));
}
use of com.android.billingclient.api.BillingClient.SkuType in project Android-InAppBilling by LiteKite.
the class BillingManager method queryPurchaseHistoryAsync.
/**
* Queries InApp and Subscribed purchase results from Google Play Remote Server.
*
* @param purchases this list contains all the product purchases made, has InApp and
* Subscription purchased results.
* @param skuType InApp or Subscription.
* @param executeWhenFinished Once the InApp product purchase results are given, then
* subscription based purchase results are queried and results are placed into the {@link
* #myPurchasesResultList}
*/
private void queryPurchaseHistoryAsync(final List<PurchaseHistoryRecord> purchases, @SkuType final String skuType, final Runnable executeWhenFinished) {
PurchaseHistoryResponseListener listener = (billingResult, list) -> {
if (billingResult.getResponseCode() == BillingResponseCode.OK && list != null) {
purchases.addAll(list);
if (executeWhenFinished != null) {
executeWhenFinished.run();
}
} else {
MonetizeApp.printLog(TAG, "queryPurchaseHistoryAsync() got an error response code: " + billingResult.getResponseCode());
logErrorType(billingResult);
}
if (executeWhenFinished == null) {
storePurchaseHistoryRecordsLocally(purchases);
}
};
executeServiceRequest(() -> myBillingClient.queryPurchaseHistoryAsync(skuType, listener));
}
Aggregations