diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2024-06-19 13:08:30 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2024-06-19 13:08:30 +0200 |
| commit | 121286df1096aa5981c5dbe57155b92a4cb05d8b (patch) | |
| tree | cde86340f45e0bcca147edcc4277e80e937b4a0b /android/lib/billing/src | |
| parent | 88c5d622d797faf99528f79a0907b101fa8f4cae (diff) | |
| parent | 8934d4b62c9e301b5f844204b95f171ccbc7edca (diff) | |
| download | mullvadvpn-121286df1096aa5981c5dbe57155b92a4cb05d8b.tar.xz mullvadvpn-121286df1096aa5981c5dbe57155b92a4cb05d8b.zip | |
Merge branch 'add-schedulers-from-arrow-instead-of-using-our-own-retry-droid-1014'
Diffstat (limited to 'android/lib/billing/src')
| -rw-r--r-- | android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingPaymentRepository.kt | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingPaymentRepository.kt b/android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingPaymentRepository.kt index 8b3ad66171..b526a10032 100644 --- a/android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingPaymentRepository.kt +++ b/android/lib/billing/src/main/kotlin/net/mullvad/mullvadvpn/lib/billing/BillingPaymentRepository.kt @@ -1,6 +1,9 @@ package net.mullvad.mullvadvpn.lib.billing import android.app.Activity +import arrow.core.Either +import arrow.core.raise.either +import arrow.core.raise.ensure import com.android.billingclient.api.BillingClient.BillingResponseCode import com.android.billingclient.api.Purchase import kotlinx.coroutines.flow.Flow @@ -22,6 +25,7 @@ import net.mullvad.mullvadvpn.lib.payment.ProductIds import net.mullvad.mullvadvpn.lib.payment.model.PaymentAvailability import net.mullvad.mullvadvpn.lib.payment.model.ProductId import net.mullvad.mullvadvpn.lib.payment.model.PurchaseResult +import net.mullvad.mullvadvpn.lib.payment.model.VerificationError import net.mullvad.mullvadvpn.lib.payment.model.VerificationResult class BillingPaymentRepository( @@ -129,28 +133,19 @@ class BillingPaymentRepository( } } - override fun verifyPurchases(): Flow<VerificationResult> = flow { - emit(VerificationResult.FetchingUnfinishedPurchases) + override suspend fun verifyPurchases(): Either<VerificationError, VerificationResult> = either { val purchasesResult = billingRepository.queryPurchases() - when (purchasesResult.responseCode()) { - BillingResponseCode.OK -> { - val purchases = purchasesResult.nonPendingPurchases() - if (purchases.isNotEmpty()) { - emit(VerificationResult.VerificationStarted) - emit( - verifyPurchase(purchases.first()) - .fold( - { VerificationResult.Error.VerificationError(null) }, - { VerificationResult.Success } - ) - ) - } else { - emit(VerificationResult.NothingToVerify) - } - } - else -> - emit(VerificationResult.Error.BillingError(purchasesResult.toBillingException())) + ensure(purchasesResult.responseCode() == BillingResponseCode.OK) { + VerificationError.BillingError(purchasesResult.toBillingException()) + } + val purchases = purchasesResult.nonPendingPurchases() + if (purchases.isEmpty()) { + return@either VerificationResult.NothingToVerify } + verifyPurchase(purchases.first()) + .mapLeft { VerificationError.PlayVerificationError } + .map { VerificationResult.Success } + .bind() } private suspend fun initialisePurchase() = playPurchaseRepository.initializePlayPurchase() |
