Search in sources :

Example 1 with PurchaseHistoryRecord

use of com.android.billingclient.api.PurchaseHistoryRecord in project Android-InAppBilling by LiteKite.

the class BillingManager method storePurchaseHistoryRecordsLocally.

/**
 * Stores Purchase Details on local storage.
 *
 * @param purchases list of Purchase Details returned from the queries.
 */
private void storePurchaseHistoryRecordsLocally(List<PurchaseHistoryRecord> purchases) {
    final List<BillingPurchaseDetails> billingPurchaseDetailsList = new ArrayList<>();
    for (PurchaseHistoryRecord purchase : purchases) {
        BillingPurchaseDetails billingPurchaseDetails = new BillingPurchaseDetails();
        billingPurchaseDetails.purchaseToken = purchase.getPurchaseToken();
        billingPurchaseDetails.skuID = purchase.getSkus().stream().findFirst().orElse("");
        billingPurchaseDetails.purchaseTime = purchase.getPurchaseTime();
        billingPurchaseDetailsList.add(billingPurchaseDetails);
    }
    workExecutor.execute(() -> appDatabase.insertPurchaseDetails(billingPurchaseDetailsList));
}
Also used : BillingPurchaseDetails(com.litekite.monetize.room.entity.BillingPurchaseDetails) ArrayList(java.util.ArrayList) PurchaseHistoryRecord(com.android.billingclient.api.PurchaseHistoryRecord)

Example 2 with PurchaseHistoryRecord

use of com.android.billingclient.api.PurchaseHistoryRecord 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));
}
Also used : NetworkManager(com.litekite.monetize.network.NetworkManager) Context(android.content.Context) WorkExecutor(com.litekite.monetize.worker.WorkExecutor) NonNull(androidx.annotation.NonNull) BillingClientStateListener(com.android.billingclient.api.BillingClientStateListener) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) AppDatabase(com.litekite.monetize.room.database.AppDatabase) PurchaseHistoryRecord(com.android.billingclient.api.PurchaseHistoryRecord) MonetizeApp(com.litekite.monetize.app.MonetizeApp) HashMap(java.util.HashMap) CallbackProvider(com.litekite.monetize.base.CallbackProvider) Singleton(javax.inject.Singleton) SkuType(com.android.billingclient.api.BillingClient.SkuType) BillingSkuDetails(com.litekite.monetize.room.entity.BillingSkuDetails) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) R(com.litekite.monetize.R) BillingResult(com.android.billingclient.api.BillingResult) PurchasesUpdatedListener(com.android.billingclient.api.PurchasesUpdatedListener) Map(java.util.Map) ConsumeParams(com.android.billingclient.api.ConsumeParams) PurchasesResponseListener(com.android.billingclient.api.PurchasesResponseListener) AcknowledgePurchaseParams(com.android.billingclient.api.AcknowledgePurchaseParams) SkuDetails(com.android.billingclient.api.SkuDetails) BillingResponseCode(com.android.billingclient.api.BillingClient.BillingResponseCode) ConsumeResponseListener(com.android.billingclient.api.ConsumeResponseListener) Set(java.util.Set) SkuDetailsParams(com.android.billingclient.api.SkuDetailsParams) PurchaseHistoryResponseListener(com.android.billingclient.api.PurchaseHistoryResponseListener) StringRes(androidx.annotation.StringRes) FeatureType(com.android.billingclient.api.BillingClient.FeatureType) Purchase(com.android.billingclient.api.Purchase) List(java.util.List) Nullable(androidx.annotation.Nullable) BillingClient(com.android.billingclient.api.BillingClient) AcknowledgePurchaseResponseListener(com.android.billingclient.api.AcknowledgePurchaseResponseListener) BillingPurchaseDetails(com.litekite.monetize.room.entity.BillingPurchaseDetails) BillingFlowParams(com.android.billingclient.api.BillingFlowParams) Activity(android.app.Activity) PurchaseHistoryResponseListener(com.android.billingclient.api.PurchaseHistoryResponseListener)

Aggregations

PurchaseHistoryRecord (com.android.billingclient.api.PurchaseHistoryRecord)2 BillingPurchaseDetails (com.litekite.monetize.room.entity.BillingPurchaseDetails)2 ArrayList (java.util.ArrayList)2 Activity (android.app.Activity)1 Context (android.content.Context)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 StringRes (androidx.annotation.StringRes)1 AcknowledgePurchaseParams (com.android.billingclient.api.AcknowledgePurchaseParams)1 AcknowledgePurchaseResponseListener (com.android.billingclient.api.AcknowledgePurchaseResponseListener)1 BillingClient (com.android.billingclient.api.BillingClient)1 BillingResponseCode (com.android.billingclient.api.BillingClient.BillingResponseCode)1 FeatureType (com.android.billingclient.api.BillingClient.FeatureType)1 SkuType (com.android.billingclient.api.BillingClient.SkuType)1 BillingClientStateListener (com.android.billingclient.api.BillingClientStateListener)1 BillingFlowParams (com.android.billingclient.api.BillingFlowParams)1 BillingResult (com.android.billingclient.api.BillingResult)1 ConsumeParams (com.android.billingclient.api.ConsumeParams)1 ConsumeResponseListener (com.android.billingclient.api.ConsumeResponseListener)1 Purchase (com.android.billingclient.api.Purchase)1