Auto commit (MindMachine) Thu Apr 16 08:01:01 PM CDT 2026
This commit is contained in:
@@ -54,36 +54,36 @@ class BillingManager(
|
|||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var isConnecting = false
|
private var isConnecting = false
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
log("BillingManager.start() - isReady=${billingClient.isReady}, isConnecting=$isConnecting")
|
log("BillingManager.start() - isReady=${billingClient.isReady}, isConnecting=$isConnecting")
|
||||||
|
|
||||||
if (billingClient.isReady) {
|
if (billingClient.isReady) {
|
||||||
log("Billing client already ready")
|
log("Billing client already ready")
|
||||||
refresh()
|
refresh()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isConnecting) {
|
if (isConnecting) {
|
||||||
log("Billing client connection already in progress")
|
log("Billing client connection already in progress")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isConnecting = true
|
isConnecting = true
|
||||||
log("Calling startConnection()")
|
log("Calling startConnection()")
|
||||||
|
|
||||||
billingClient.startConnection(object : BillingClientStateListener {
|
billingClient.startConnection(object : BillingClientStateListener {
|
||||||
override fun onBillingSetupFinished(result: BillingResult) {
|
override fun onBillingSetupFinished(result: BillingResult) {
|
||||||
isConnecting = false
|
isConnecting = false
|
||||||
log("Billing setup finished: ${result.responseCode} ${result.debugMessage}")
|
log("Billing setup finished: ${result.responseCode} ${result.debugMessage}")
|
||||||
|
|
||||||
if (result.responseCode == BillingClient.BillingResponseCode.OK) {
|
if (result.responseCode == BillingClient.BillingResponseCode.OK) {
|
||||||
refresh()
|
refresh()
|
||||||
} else {
|
} else {
|
||||||
logError("Billing setup failed: ${result.responseCode} ${result.debugMessage}")
|
logError("Billing setup failed: ${result.responseCode} ${result.debugMessage}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBillingServiceDisconnected() {
|
override fun onBillingServiceDisconnected() {
|
||||||
isConnecting = false
|
isConnecting = false
|
||||||
log("Billing service disconnected")
|
log("Billing service disconnected")
|
||||||
@@ -150,55 +150,55 @@ class BillingManager(
|
|||||||
log("Billing client not ready")
|
log("Billing client not ready")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val featureResult = billingClient.isFeatureSupported(BillingClient.FeatureType.PRODUCT_DETAILS)
|
val featureResult = billingClient.isFeatureSupported(BillingClient.FeatureType.PRODUCT_DETAILS)
|
||||||
log("PRODUCT_DETAILS support: ${featureResult.responseCode} ${featureResult.debugMessage}")
|
log("PRODUCT_DETAILS support: ${featureResult.responseCode} ${featureResult.debugMessage}")
|
||||||
if (featureResult.responseCode != BillingClient.BillingResponseCode.OK) {
|
if (featureResult.responseCode != BillingClient.BillingResponseCode.OK) {
|
||||||
logError("PRODUCT_DETAILS feature not supported")
|
logError("PRODUCT_DETAILS feature not supported")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
queryProductDetailsForType(
|
queryProductDetailsForType(
|
||||||
productType = BillingClient.ProductType.SUBS,
|
productType = BillingClient.ProductType.SUBS,
|
||||||
productIds = listOf(BillingProducts.SUB_REMOVE_ADS_MONTHLY)
|
productIds = listOf(BillingProducts.SUB_REMOVE_ADS_MONTHLY)
|
||||||
)
|
)
|
||||||
|
|
||||||
queryProductDetailsForType(
|
queryProductDetailsForType(
|
||||||
productType = BillingClient.ProductType.INAPP,
|
productType = BillingClient.ProductType.INAPP,
|
||||||
productIds = listOf(BillingProducts.INAPP_REMOVE_ADS_FOREVER)
|
productIds = listOf(BillingProducts.INAPP_REMOVE_ADS_FOREVER)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun queryProductDetailsForType(
|
private fun queryProductDetailsForType(
|
||||||
productType: String,
|
productType: String,
|
||||||
productIds: List<String>
|
productIds: List<String>
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
log("Querying $productType product details for $productIds")
|
log("Querying $productType product details for $productIds")
|
||||||
|
|
||||||
val products = productIds.map { productId ->
|
val products = productIds.map { productId ->
|
||||||
QueryProductDetailsParams.Product.newBuilder()
|
QueryProductDetailsParams.Product.newBuilder()
|
||||||
.setProductId(productId)
|
.setProductId(productId)
|
||||||
.setProductType(productType)
|
.setProductType(productType)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
val params = QueryProductDetailsParams.newBuilder()
|
val params = QueryProductDetailsParams.newBuilder()
|
||||||
.setProductList(products)
|
.setProductList(products)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
billingClient.queryProductDetailsAsync(params) { result, queryResult ->
|
billingClient.queryProductDetailsAsync(params) { billingResult, queryResult ->
|
||||||
log("queryProductDetailsAsync($productType) result: ${result.responseCode} ${result.debugMessage}")
|
log("queryProductDetailsAsync($productType) result: ${billingResult.responseCode} ${billingResult.debugMessage}")
|
||||||
|
|
||||||
val detailsList = queryResult.productDetailsList
|
val detailsList = queryResult.productDetailsList
|
||||||
log("Fetched $productType products: ${detailsList.map { it.productId }}")
|
log("Fetched $productType products: ${detailsList?.map { it.productId } ?: emptyList()}")
|
||||||
|
|
||||||
if (queryResult.unfetchedProductList.isNotEmpty()) {
|
if (queryResult.unfetchedProductList.isNotEmpty()) {
|
||||||
logError("Unfetched $productType products: ${queryResult.unfetchedProductList}")
|
logError("Unfetched $productType products: ${queryResult.unfetchedProductList}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.responseCode == BillingClient.BillingResponseCode.OK) {
|
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
|
||||||
_productDetails.value = _productDetails.value + detailsList.associateBy { it.productId }
|
_productDetails.value = _productDetails.value + (detailsList?.associateBy { it.productId } ?: emptyMap())
|
||||||
log("Product details cache now has: ${_productDetails.value.keys}")
|
log("Product details cache now has: ${_productDetails.value.keys}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,23 +214,29 @@ class BillingManager(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val listener = PurchasesResponseListener { result, purchases ->
|
billingClient.queryPurchasesAsync(
|
||||||
if (result.responseCode == BillingClient.BillingResponseCode.OK) {
|
QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.SUBS).build()
|
||||||
log("Query purchases returned ${purchases.size} items")
|
) { billingResult, queryResult ->
|
||||||
|
val purchases = queryResult.purchasesList
|
||||||
|
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
|
||||||
|
log("Query SUBS purchases returned ${purchases.size} items")
|
||||||
handlePurchases(purchases)
|
handlePurchases(purchases)
|
||||||
} else {
|
} else {
|
||||||
logError("Query purchases failed: ${result.responseCode} ${result.debugMessage}")
|
logError("Query SUBS purchases failed: ${billingResult.responseCode} ${billingResult.debugMessage}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
billingClient.queryPurchasesAsync(
|
billingClient.queryPurchasesAsync(
|
||||||
QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.SUBS).build(),
|
QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build()
|
||||||
listener
|
) { billingResult, queryResult ->
|
||||||
)
|
val purchases = queryResult.purchasesList
|
||||||
billingClient.queryPurchasesAsync(
|
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
|
||||||
QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build(),
|
log("Query INAPP purchases returned ${purchases.size} items")
|
||||||
listener
|
handlePurchases(purchases)
|
||||||
)
|
} else {
|
||||||
|
logError("Query INAPP purchases failed: ${billingResult.responseCode} ${billingResult.debugMessage}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handlePurchases(purchases: List<Purchase>) {
|
private fun handlePurchases(purchases: List<Purchase>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user