Created
September 5, 2019 16:28
-
-
Save isaidamier/044bb4714d73d8a258361314d44d0f6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun queryPurchasesAsync() { | |
val purchasesResult = HashSet<Purchase>() | |
var result = playStoreBillingClient.queryPurchases(BillingClient.SkuType.INAPP) | |
if(nullOrEmpty(result)) { | |
queryPurchaseHistoryAsync() | |
} else { | |
result?.purchasesList?.let { purchasesResult.addAll(it) } | |
} | |
} | |
private fun queryPurchaseHistoryAsync() { | |
playStoreBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.SUBS) { | |
billingResult, purchasesList -> | |
when (billingResult.responseCode) { | |
BillingClient.BillingResponseCode.OK -> { | |
if(purchasesList.isNotEmpty()) { | |
purchasesList.forEach { | |
if(it.purchaseTime < oneDayOld()) { | |
processPurchase(it.sku, it.purchaseToken) | |
} | |
} | |
} | |
} | |
else -> { | |
//do nothing. Someone else will connect it through retry policy. | |
//May choose to send to server though | |
Log.d(LOG_TAG, billingResult.debugMessage) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment