Skip to content

Commit

Permalink
Add payment repository with query payment types function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Sep 12, 2023
1 parent 80e020d commit 2ff7844
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ dependencies {
implementation(Dependencies.Kotlin.stdlib)
implementation(Dependencies.KotlinX.coroutinesAndroid)

// Billing
implementation(project(Dependencies.Mullvad.billingLib))

// UI tooling
implementation(Dependencies.Compose.uiToolingPreview)
debugImplementation(Dependencies.Compose.uiTooling)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.mullvad.mullvadvpn.repository.payment

import net.mullvad.mullvadvpn.lib.billing.model.BillingException
import net.mullvad.mullvadvpn.lib.billing.model.BillingProduct

sealed interface BillingPaymentAvailability {
data class ProductsAvailable(val products: List<BillingProduct>) : BillingPaymentAvailability

data object ProductsUnavailable : BillingPaymentAvailability

sealed interface Error : BillingPaymentAvailability {
data object BillingUnavailable : BillingPaymentAvailability

data object ServiceUnavailable : BillingPaymentAvailability

data class Other(val exception: BillingException) : BillingPaymentAvailability
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.mullvad.mullvadvpn.repository.payment

data class PaymentAvailability(
val webPaymentAvailable: Boolean,
val billingPaymentAvailability: BillingPaymentAvailability
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.mullvad.mullvadvpn.repository.payment

import net.mullvad.mullvadvpn.lib.billing.BillingRepository
import net.mullvad.mullvadvpn.lib.billing.model.QueryProductResult

class PaymentRepository(
private val billingRepository: BillingRepository,
private val showWebPayment: Boolean
) {
suspend fun queryAvailablePaymentTypes(): PaymentAvailability =
PaymentAvailability(
webPaymentAvailable = showWebPayment,
billingPaymentAvailability = getBillingProducts()
)

private suspend fun getBillingProducts(): BillingPaymentAvailability =
when (val result = billingRepository.queryProducts()) {
is QueryProductResult.Ok ->
BillingPaymentAvailability.ProductsAvailable(products = result.products)
QueryProductResult.ItemUnavailable -> BillingPaymentAvailability.ProductsUnavailable
QueryProductResult.BillingUnavailable ->
BillingPaymentAvailability.Error.BillingUnavailable
QueryProductResult.ServiceUnavailable ->
BillingPaymentAvailability.Error.ServiceUnavailable
is QueryProductResult.Error ->
BillingPaymentAvailability.Error.Other(exception = result.exception)
}

private fun fetchTransactionId(): String {
// Placeholder function
return "BOOPITOBOP"
}
}

0 comments on commit 2ff7844

Please sign in to comment.