mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-04 10:19:18 +02:00
Update billing library
This commit is contained in:
parent
5c6b028c59
commit
e7687fd511
4 changed files with 15 additions and 13 deletions
|
@ -203,8 +203,8 @@ dependencies {
|
||||||
implementation 'com.squareup.okhttp3:okhttp-tls:4.9.0'
|
implementation 'com.squareup.okhttp3:okhttp-tls:4.9.0'
|
||||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
|
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
|
||||||
|
|
||||||
googleApiImplementation "com.android.billingclient:billing:3.0.3"
|
googleApiImplementation "com.android.billingclient:billing:4.0.0"
|
||||||
googleApiImplementation "com.android.billingclient:billing-ktx:3.0.3"
|
googleApiImplementation "com.android.billingclient:billing-ktx:4.0.0"
|
||||||
|
|
||||||
implementation('io.socket:socket.io-client:1.0.0') {
|
implementation('io.socket:socket.io-client:1.0.0') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
|
|
|
@ -137,11 +137,11 @@ class ActivityPurchaseModel(application: Application): AndroidViewModel(applicat
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun queryPurchases() = initAndUseClient { client ->
|
suspend fun queryPurchases() = initAndUseClient { client ->
|
||||||
val response = client.queryPurchases(BillingClient.SkuType.INAPP)
|
val response = client.queryPurchasesAsync(BillingClient.SkuType.INAPP)
|
||||||
|
|
||||||
response.billingResult.assertSuccess()
|
response.billingResult.assertSuccess()
|
||||||
|
|
||||||
response.purchasesList!!.filter {
|
response.purchasesList.filter {
|
||||||
it.purchaseState == Purchase.PurchaseState.PURCHASED
|
it.purchaseState == Purchase.PurchaseState.PURCHASED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,11 +151,11 @@ class ActivityPurchaseModel(application: Application): AndroidViewModel(applicat
|
||||||
isWorkingInternal.setTemporarily(true).use {
|
isWorkingInternal.setTemporarily(true).use {
|
||||||
try {
|
try {
|
||||||
initAndUseClient { client ->
|
initAndUseClient { client ->
|
||||||
val result = client.queryPurchases(BillingClient.SkuType.INAPP)
|
val result = client.queryPurchasesAsync(BillingClient.SkuType.INAPP)
|
||||||
|
|
||||||
result.billingResult.assertSuccess()
|
result.billingResult.assertSuccess()
|
||||||
|
|
||||||
for (purchase in result.purchasesList!!) {
|
for (purchase in result.purchasesList) {
|
||||||
handlePurchase(purchase, client)
|
handlePurchase(purchase, client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,9 @@ class ActivityPurchaseModel(application: Application): AndroidViewModel(applicat
|
||||||
Log.d(LOG_TAG, "handlePurchase($purchase)")
|
Log.d(LOG_TAG, "handlePurchase($purchase)")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PurchaseIds.SAL_SKUS.contains(purchase.sku)) {
|
val sku = purchase.skus.single()
|
||||||
|
|
||||||
|
if (PurchaseIds.SAL_SKUS.contains(sku)) {
|
||||||
// just acknowledge
|
// just acknowledge
|
||||||
|
|
||||||
billingClient.acknowledgePurchase(
|
billingClient.acknowledgePurchase(
|
||||||
|
@ -227,7 +229,7 @@ class ActivityPurchaseModel(application: Application): AndroidViewModel(applicat
|
||||||
.setPurchaseToken(purchase.purchaseToken)
|
.setPurchaseToken(purchase.purchaseToken)
|
||||||
.build()
|
.build()
|
||||||
).assertSuccess()
|
).assertSuccess()
|
||||||
} else if (PurchaseIds.BUY_SKUS.contains(purchase.sku)) {
|
} else if (PurchaseIds.BUY_SKUS.contains(sku)) {
|
||||||
// send and consume
|
// send and consume
|
||||||
|
|
||||||
val server = logic.serverLogic.getServerConfigCoroutine()
|
val server = logic.serverLogic.getServerConfigCoroutine()
|
||||||
|
@ -251,7 +253,7 @@ class ActivityPurchaseModel(application: Application): AndroidViewModel(applicat
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Log.d(LOG_TAG, "don't know how to handle ${purchase.sku}")
|
Log.d(LOG_TAG, "don't know how to handle $sku")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ class StayAwesomeModel(application: Application): AndroidViewModel(application)
|
||||||
id = skuId,
|
id = skuId,
|
||||||
title = sku?.description ?: skuId,
|
title = sku?.description ?: skuId,
|
||||||
price = sku?.price ?: "???",
|
price = sku?.price ?: "???",
|
||||||
bought = purchases.find { it.sku == skuId } != null
|
bought = purchases.find { purchase -> purchase.skus.find { sku -> sku == skuId } != null } != null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -32,7 +32,7 @@ object BillingClient {
|
||||||
fun launchBillingFlow(activity: Activity, params: BillingFlowParams) = BillingResult
|
fun launchBillingFlow(activity: Activity, params: BillingFlowParams) = BillingResult
|
||||||
fun acknowledgePurchase(params: AcknowledgePurchaseParams) = BillingResult
|
fun acknowledgePurchase(params: AcknowledgePurchaseParams) = BillingResult
|
||||||
fun consumePurchase(params: ConsumeParams) = BillingResult
|
fun consumePurchase(params: ConsumeParams) = BillingResult
|
||||||
fun queryPurchases(type: String) = QueryPurchasesResult
|
suspend fun queryPurchasesAsync(type: String) = QueryPurchasesResult
|
||||||
|
|
||||||
object BillingResponseCode {
|
object BillingResponseCode {
|
||||||
const val OK = 0
|
const val OK = 0
|
||||||
|
@ -74,7 +74,7 @@ object SkuDetailsParams {
|
||||||
object Purchase {
|
object Purchase {
|
||||||
const val purchaseState = PurchaseState.PURCHASED
|
const val purchaseState = PurchaseState.PURCHASED
|
||||||
const val isAcknowledged = true
|
const val isAcknowledged = true
|
||||||
const val sku = ""
|
val skus = listOf("")
|
||||||
const val purchaseToken = ""
|
const val purchaseToken = ""
|
||||||
const val originalJson = ""
|
const val originalJson = ""
|
||||||
const val signature = ""
|
const val signature = ""
|
||||||
|
@ -113,7 +113,7 @@ object BillingFlowParams {
|
||||||
|
|
||||||
object QueryPurchasesResult {
|
object QueryPurchasesResult {
|
||||||
val billingResult = BillingResult
|
val billingResult = BillingResult
|
||||||
val purchasesList: List<Purchase>? = emptyList()
|
val purchasesList: List<Purchase> = emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
data class QuerySkuDetailsResult(val billingResult: BillingResult, val details: List<SkuDetails>?) {
|
data class QuerySkuDetailsResult(val billingResult: BillingResult, val details: List<SkuDetails>?) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue