diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-11-16 00:56:10 +0100 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-11-16 09:34:26 +0100 |
| commit | ae7471c50a653133aae6472199d7b0d16ad2a145 (patch) | |
| tree | 20488d174aae09caee907ac20960e26146b1aa9f /android/lib/payment/src | |
| parent | 5c5c2a95d676648ffbd953b5f9e8587a8a80bf66 (diff) | |
| download | mullvadvpn-ae7471c50a653133aae6472199d7b0d16ad2a145.tar.xz mullvadvpn-ae7471c50a653133aae6472199d7b0d16ad2a145.zip | |
Add payment module and billing payment repository
Diffstat (limited to 'android/lib/payment/src')
10 files changed, 127 insertions, 0 deletions
diff --git a/android/lib/payment/src/main/AndroidManifest.xml b/android/lib/payment/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..b2d3ea1235 --- /dev/null +++ b/android/lib/payment/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" /> diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/PaymentRepository.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/PaymentRepository.kt new file mode 100644 index 0000000000..73fd0c061d --- /dev/null +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/PaymentRepository.kt @@ -0,0 +1,20 @@ +package net.mullvad.mullvadvpn.lib.payment + +import android.app.Activity +import kotlinx.coroutines.flow.Flow +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.VerificationResult + +interface PaymentRepository { + + fun purchaseProduct( + productId: ProductId, + activityProvider: () -> Activity + ): Flow<PurchaseResult> + + fun verifyPurchases(): Flow<VerificationResult> + + fun queryPaymentAvailability(): Flow<PaymentAvailability> +} diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/ProductIds.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/ProductIds.kt new file mode 100644 index 0000000000..8754968891 --- /dev/null +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/ProductIds.kt @@ -0,0 +1,5 @@ +package net.mullvad.mullvadvpn.lib.payment + +object ProductIds { + const val OneMonth = "one_month" +} diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PaymentAvailability.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PaymentAvailability.kt new file mode 100644 index 0000000000..cee2800677 --- /dev/null +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PaymentAvailability.kt @@ -0,0 +1,26 @@ +package net.mullvad.mullvadvpn.lib.payment.model + +sealed interface PaymentAvailability { + data object Loading : PaymentAvailability + + data class ProductsAvailable(val products: List<PaymentProduct>) : PaymentAvailability + + data object ProductsUnavailable : PaymentAvailability + + data object NoProductsFounds : PaymentAvailability + + sealed interface Error: PaymentAvailability { + data object BillingUnavailable : Error + + data object ServiceUnavailable : Error + + data object FeatureNotSupported : Error + + data object DeveloperError : Error + + data object ItemUnavailable : Error + + data class Other(val exception: Throwable) : + Error + } +} diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PaymentProduct.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PaymentProduct.kt new file mode 100644 index 0000000000..8945453d37 --- /dev/null +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PaymentProduct.kt @@ -0,0 +1,7 @@ +package net.mullvad.mullvadvpn.lib.payment.model + +data class PaymentProduct( + val productId: ProductId, + val price: ProductPrice, + val status: PaymentStatus? +) diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PaymentStatus.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PaymentStatus.kt new file mode 100644 index 0000000000..37574249a6 --- /dev/null +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PaymentStatus.kt @@ -0,0 +1,6 @@ +package net.mullvad.mullvadvpn.lib.payment.model + +enum class PaymentStatus { + PENDING, + VERIFICATION_IN_PROGRESS +} diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/ProductId.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/ProductId.kt new file mode 100644 index 0000000000..49a367f7c2 --- /dev/null +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/ProductId.kt @@ -0,0 +1,4 @@ +package net.mullvad.mullvadvpn.lib.payment.model + +@JvmInline +value class ProductId(val value: String) diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/ProductPrice.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/ProductPrice.kt new file mode 100644 index 0000000000..4939eac3a5 --- /dev/null +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/ProductPrice.kt @@ -0,0 +1,4 @@ +package net.mullvad.mullvadvpn.lib.payment.model + +@JvmInline +value class ProductPrice(val value: String) diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PurchaseResult.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PurchaseResult.kt new file mode 100644 index 0000000000..f5b89bffe6 --- /dev/null +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/PurchaseResult.kt @@ -0,0 +1,34 @@ +package net.mullvad.mullvadvpn.lib.payment.model + +sealed interface PurchaseResult { + data object FetchingProducts : PurchaseResult + + data object FetchingObfuscationId : PurchaseResult + + data object BillingFlowStarted : PurchaseResult + + data object VerificationStarted : PurchaseResult + + sealed interface Completed : PurchaseResult { + data object Success : Completed + + data object Cancelled : Completed + + // This ends our part of the purchase flow. The rest is handled by Google and the api. + data object Pending : Completed + } + + sealed interface Error : PurchaseResult { + data class NoProductFound(val productId: ProductId) : Error + + data class FetchProductsError(val productId: ProductId, val exception: Throwable?) : Error + + data class TransactionIdError(val productId: ProductId, val exception: Throwable?) : Error + + data class BillingError(val exception: Throwable?) : Error + + data class VerificationError(val exception: Throwable?) : Error + } + + fun isTerminatingState(): Boolean = this is Completed || this is Error +} diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/VerificationResult.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/VerificationResult.kt new file mode 100644 index 0000000000..725ea0af68 --- /dev/null +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/model/VerificationResult.kt @@ -0,0 +1,19 @@ +package net.mullvad.mullvadvpn.lib.payment.model + +sealed interface VerificationResult { + data object FetchingUnfinishedPurchases : VerificationResult + + data object VerificationStarted : VerificationResult + + // No verification was needed as there is no purchases to verify + data object NothingToVerify : VerificationResult + + data object Success : VerificationResult + + // Generic error, add more cases as needed + sealed interface Error : VerificationResult { + data class BillingError(val exception: Throwable?) : Error + + data class VerificationError(val exception: Throwable?) : Error + } +} |
