Skip to content

Commit

Permalink
Add purchase verification function to payment repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Sep 13, 2023
1 parent 6fa108f commit 2a0723c
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package net.mullvad.mullvadvpn.payment
import kotlinx.coroutines.flow.singleOrNull
import net.mullvad.mullvadvpn.lib.billing.BillingRepository
import net.mullvad.mullvadvpn.lib.billing.model.BillingProduct
import net.mullvad.mullvadvpn.lib.billing.model.BillingPurchase
import net.mullvad.mullvadvpn.lib.billing.model.PurchaseEvent
import net.mullvad.mullvadvpn.lib.billing.model.PurchaseFlowResult
import net.mullvad.mullvadvpn.lib.billing.model.QueryProductResult
import net.mullvad.mullvadvpn.lib.billing.model.QueryPurchasesResult

class PaymentRepository(
private val billingRepository: BillingRepository,
Expand Down Expand Up @@ -36,7 +38,7 @@ class PaymentRepository(
}
is PurchaseEvent.PurchaseCompleted -> {
// Verify towards api
if (verifyPurchase()) {
if (verifyPurchase(purchaseEvent.purchases.first())) {
PurchaseResult.PurchaseCompleted
} else {
PurchaseResult.VerificationError
Expand All @@ -57,6 +59,13 @@ class PaymentRepository(
}
}

suspend fun verifyPurchases() {
val result = billingRepository.queryPurchases()
if (result is QueryPurchasesResult.PurchaseFound) {
verifyPurchase(result.purchase)
}
}

private suspend fun getBillingProducts(): BillingPaymentAvailability =
when (val result = billingRepository.queryProducts()) {
is QueryProductResult.Ok ->
Expand All @@ -75,7 +84,7 @@ class PaymentRepository(
return "BOOPITOBOP"
}

private fun verifyPurchase(): Boolean {
private fun verifyPurchase(purchase: BillingPurchase): Boolean {
// Placeholder function
return true
}
Expand Down

0 comments on commit 2a0723c

Please sign in to comment.