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));
}
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));
}
Aggregations