Hide paid tier on devices where the billing API is not available.

This commit is contained in:
Alex Hart 2024-09-19 15:25:26 -03:00 committed by Greyson Parrelli
parent d88265ede6
commit d23ef647d8
2 changed files with 20 additions and 15 deletions

View file

@ -883,10 +883,10 @@ object BackupRepository {
}
suspend fun getAvailableBackupsTypes(availableBackupTiers: List<MessageBackupTier>): List<MessageBackupsType> {
return availableBackupTiers.map { getBackupsType(it) }
return availableBackupTiers.mapNotNull { getBackupsType(it) }
}
suspend fun getBackupsType(tier: MessageBackupTier): MessageBackupsType {
suspend fun getBackupsType(tier: MessageBackupTier): MessageBackupsType? {
return when (tier) {
MessageBackupTier.FREE -> getFreeType()
MessageBackupTier.PAID -> getPaidType()
@ -901,12 +901,12 @@ object BackupRepository {
)
}
private suspend fun getPaidType(): MessageBackupsType {
private suspend fun getPaidType(): MessageBackupsType? {
val config = getSubscriptionsConfiguration()
val product = AppDependencies.billingApi.queryProduct()
val product = AppDependencies.billingApi.queryProduct() ?: return null
return MessageBackupsType.Paid(
pricePerMonth = product!!.price,
pricePerMonth = product.price,
storageAllowanceBytes = config.backupConfiguration.backupLevelConfigurationMap[SubscriptionsConfiguration.BACKUPS_LEVEL]!!.storageAllowanceBytes
)
}

View file

@ -163,6 +163,7 @@ internal class BillingApiImpl(
}
override suspend fun queryProduct(): BillingProduct? {
try {
val products = queryProductsInternal()
val details: ProductDetails? = products.productDetailsList?.firstOrNull { it.productId == billingDependencies.getProductId() }
@ -176,6 +177,10 @@ internal class BillingApiImpl(
return BillingProduct(
price = FiatMoney(BigDecimal.valueOf(pricing.priceAmountMicros, 6), Currency.getInstance(pricing.priceCurrencyCode))
)
} catch (e: BillingError) {
Log.w(TAG, "Failed to query product. Returning null. Error code: ${e.billingResponseCode}", e)
return null
}
}
override suspend fun queryPurchases() {
@ -291,7 +296,7 @@ internal class BillingApiImpl(
billingResponseCode = billingResult.responseCode
)
trySend(State.Failure(billingError))
cancel(CancellationException("Failed to connect to Google Play Billing", billingError))
channel.close()
}
}
})