Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add payment verification to Connect Screen #5487

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ val uiModule = module {
viewModel {
ChangelogViewModel(get(), BuildConfig.VERSION_CODE, BuildConfig.ALWAYS_SHOW_CHANGELOG)
}
viewModel { ConnectViewModel(get(), get(), get(), get(), get(), get()) }
viewModel { ConnectViewModel(get(), get(), get(), get(), get(), get(), get()) }
viewModel { DeviceListViewModel(get(), get()) }
viewModel { DeviceRevokedViewModel(get(), get()) }
viewModel { LoginViewModel(get(), get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface PaymentUseCase {

suspend fun resetPurchaseResult()

suspend fun verifyPurchases()
suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit = {})
}

class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : PaymentUseCase {
Expand All @@ -42,11 +42,12 @@ class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : Pay
_purchaseResult.emit(null)
}

override suspend fun verifyPurchases() {
override suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit) {
paymentRepository.verifyPurchases().collect {
if (it == VerificationResult.Success) {
// Update the payment availability after a successful verification.
queryPaymentAvailability()
onSuccessfulVerification()
}
}
}
Expand All @@ -68,7 +69,7 @@ class EmptyPaymentUseCase : PaymentUseCase {
// No op
}

override suspend fun verifyPurchases() {
override suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit) {
// No op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionState
import net.mullvad.mullvadvpn.ui.serviceconnection.authTokenCache
import net.mullvad.mullvadvpn.ui.serviceconnection.connectionProxy
import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase
import net.mullvad.mullvadvpn.usecase.PaymentUseCase
import net.mullvad.mullvadvpn.usecase.RelayListUseCase
import net.mullvad.mullvadvpn.util.callbackFlowFromNotifier
import net.mullvad.mullvadvpn.util.combine
Expand All @@ -49,7 +50,8 @@ class ConnectViewModel(
private val deviceRepository: DeviceRepository,
private val inAppNotificationController: InAppNotificationController,
private val newDeviceNotificationUseCase: NewDeviceNotificationUseCase,
private val relayListUseCase: RelayListUseCase
private val relayListUseCase: RelayListUseCase,
private val paymentUseCase: PaymentUseCase
) : ViewModel() {
private val _uiSideEffect = MutableSharedFlow<UiSideEffect>(extraBufferCapacity = 1)
val uiSideEffect = _uiSideEffect.asSharedFlow()
Expand Down Expand Up @@ -137,6 +139,9 @@ class ConnectViewModel(
// The create account cache is no longer needed as we have successfully reached the connect
// screen
accountRepository.clearCreatedAccountCache()
viewModelScope.launch {
paymentUseCase.verifyPurchases { accountRepository.fetchAccountExpiry() }
}
}

private fun LocationInfoCache.locationCallbackFlow() = callbackFlow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionState
import net.mullvad.mullvadvpn.ui.serviceconnection.authTokenCache
import net.mullvad.mullvadvpn.ui.serviceconnection.connectionProxy
import net.mullvad.mullvadvpn.usecase.PaymentUseCase
import net.mullvad.mullvadvpn.usecase.RelayListUseCase
import net.mullvad.mullvadvpn.util.appVersionCallbackFlow
import net.mullvad.talpid.tunnel.ErrorState
Expand Down Expand Up @@ -89,6 +90,9 @@ class ConnectViewModelTest {
// Relay list use case
private val mockRelayListUseCase: RelayListUseCase = mockk()

// Payment use case
private val mockPaymentUseCase: PaymentUseCase = mockk(relaxed = true)

// Captures
private val locationSlot = slot<((GeoIpLocation?) -> Unit)>()

Expand Down Expand Up @@ -139,7 +143,8 @@ class ConnectViewModelTest {
deviceRepository = mockDeviceRepository,
inAppNotificationController = mockInAppNotificationController,
relayListUseCase = mockRelayListUseCase,
newDeviceNotificationUseCase = mockk()
newDeviceNotificationUseCase = mockk(),
paymentUseCase = mockPaymentUseCase
)
}

Expand Down
Loading