-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add payment repository with query payment types function
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...p/src/main/kotlin/net/mullvad/mullvadvpn/repository/payment/BillingPaymentAvailability.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/payment/PaymentAvailability.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
33 changes: 33 additions & 0 deletions
33
android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/payment/PaymentRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |