Start re-work of play billing checkout flow.

This commit is contained in:
Alex Hart
2024-09-18 12:28:11 -03:00
committed by Greyson Parrelli
parent b340097f9c
commit 48bd57c56a
37 changed files with 807 additions and 1111 deletions

View File

@@ -6,13 +6,22 @@
package org.signal.core.util.billing
import android.app.Activity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
/**
* Variant interface for the BillingApi.
*/
interface BillingApi {
/**
* Listenable stream of billing purchase results. It's up to the user
* to call queryPurchases after subscription.
*/
fun getBillingPurchaseResults(): Flow<BillingPurchaseResult> = emptyFlow()
fun isApiAvailable(): Boolean = false
suspend fun queryProducts() = Unit
suspend fun queryProduct(): BillingProduct? = null
/**
* Queries the user's current purchases. This enqueues a check and will

View File

@@ -0,0 +1,15 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.signal.core.util.billing
import org.signal.core.util.money.FiatMoney
/**
* Represents a purchasable product from the Google Play Billing API
*/
data class BillingProduct(
val price: FiatMoney
)

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.signal.core.util.billing
/**
* Sealed class hierarchy representing the different success
* and error states of google play billing purchases.
*/
sealed interface BillingPurchaseResult {
data class Success(
val purchaseToken: String,
val isAcknowledged: Boolean,
val purchaseTime: Long
) : BillingPurchaseResult
data object UserCancelled : BillingPurchaseResult
data object None : BillingPurchaseResult
data object TryAgainLater : BillingPurchaseResult
data object AlreadySubscribed : BillingPurchaseResult
data object FeatureNotSupported : BillingPurchaseResult
data object GenericError : BillingPurchaseResult
data object NetworkError : BillingPurchaseResult
data object BillingUnavailable : BillingPurchaseResult
}