diff --git a/example-app/src/main/java/com/adyen/checkout/example/extensions/DispatcherExtensions.kt b/example-app/src/main/java/com/adyen/checkout/example/extensions/DispatcherExtensions.kt new file mode 100644 index 0000000000..8848b42ac0 --- /dev/null +++ b/example-app/src/main/java/com/adyen/checkout/example/extensions/DispatcherExtensions.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2024 Adyen N.V. + * + * This file is open source and available under the MIT license. See the LICENSE file for more info. + * + * Created by oscars on 14/11/2024. + */ + +package com.adyen.checkout.example.extensions + +import com.adyen.checkout.core.DispatcherProvider +import kotlinx.coroutines.CoroutineDispatcher + +@Suppress("RestrictedApi") +val IODispatcher: CoroutineDispatcher get() = DispatcherProvider.IO diff --git a/example-app/src/main/java/com/adyen/checkout/example/repositories/RepositoryUtils.kt b/example-app/src/main/java/com/adyen/checkout/example/repositories/RepositoryUtils.kt index 0141a64236..d15abc2a0a 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/repositories/RepositoryUtils.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/repositories/RepositoryUtils.kt @@ -9,12 +9,12 @@ package com.adyen.checkout.example.repositories import android.util.Log -import com.adyen.checkout.core.DispatcherProvider +import com.adyen.checkout.example.extensions.IODispatcher import kotlinx.coroutines.CancellationException import kotlinx.coroutines.withContext -@Suppress("TooGenericExceptionCaught", "RestrictedApi") -internal suspend fun safeApiCall(call: suspend () -> T): T? = withContext(DispatcherProvider.IO) { +@Suppress("TooGenericExceptionCaught") +internal suspend fun safeApiCall(call: suspend () -> T): T? = withContext(IODispatcher) { return@withContext try { call() } catch (e: CancellationException) { diff --git a/example-app/src/main/java/com/adyen/checkout/example/service/ExampleAdvancedDropInService.kt b/example-app/src/main/java/com/adyen/checkout/example/service/ExampleAdvancedDropInService.kt index 1c7e359f9f..e12f1f2754 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/service/ExampleAdvancedDropInService.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/service/ExampleAdvancedDropInService.kt @@ -22,7 +22,6 @@ import com.adyen.checkout.components.core.PaymentComponentState import com.adyen.checkout.components.core.StoredPaymentMethod import com.adyen.checkout.components.core.action.Action import com.adyen.checkout.components.core.paymentmethod.PaymentMethodDetails -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.core.exception.ModelSerializationException import com.adyen.checkout.dropin.AddressLookupDropInServiceResult import com.adyen.checkout.dropin.BalanceDropInServiceResult @@ -33,6 +32,7 @@ import com.adyen.checkout.dropin.FinishedDialog import com.adyen.checkout.dropin.OrderDropInServiceResult import com.adyen.checkout.dropin.RecurringDropInServiceResult import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.extensions.getLogTag import com.adyen.checkout.example.extensions.toStringPretty import com.adyen.checkout.example.repositories.AddressLookupCompletionResult @@ -75,11 +75,10 @@ class ExampleAdvancedDropInService : DropInService() { }.launchIn(this) } - @Suppress("RestrictedApi") override fun onSubmit( state: PaymentComponentState<*>, ) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { Log.d(TAG, "onPaymentsCallRequested") checkPaymentState(state) @@ -125,9 +124,8 @@ class ExampleAdvancedDropInService : DropInService() { // read bundle and handle it } - @Suppress("RestrictedApi") override fun onAdditionalDetails(actionComponentData: ActionComponentData) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { Log.d(TAG, "onDetailsCallRequested") val actionComponentJson = ActionComponentData.SERIALIZER.serialize(actionComponentData) @@ -199,10 +197,9 @@ class ExampleAdvancedDropInService : DropInService() { return OrderResponse.SERIALIZER.deserialize(orderJSON) } - @Suppress("RestrictedApi") private fun fetchPaymentMethods(orderResponse: OrderResponse? = null) { Log.d(TAG, "fetchPaymentMethods") - launch(DispatcherProvider.IO) { + launch(IODispatcher) { val order = orderResponse?.let { Order( pspReference = it.pspReference, @@ -229,9 +226,8 @@ class ExampleAdvancedDropInService : DropInService() { } } - @Suppress("RestrictedApi") override fun onBalanceCheck(paymentComponentState: PaymentComponentState<*>) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { Log.d(TAG, "checkBalance") val amount = paymentComponentState.data.amount val paymentMethod = paymentComponentState.data.paymentMethod @@ -284,9 +280,8 @@ class ExampleAdvancedDropInService : DropInService() { } } - @Suppress("RestrictedApi") override fun onOrderRequest() { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { Log.d(TAG, "createOrder") val paymentRequest = createOrderRequest( @@ -316,9 +311,8 @@ class ExampleAdvancedDropInService : DropInService() { } } - @Suppress("RestrictedApi") override fun onOrderCancel(order: Order, shouldUpdatePaymentMethods: Boolean) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { Log.d(TAG, "cancelOrder") val orderJson = Order.SERIALIZER.serialize(order) val request = createCancelOrderRequest( @@ -355,11 +349,10 @@ class ExampleAdvancedDropInService : DropInService() { } } - @Suppress("RestrictedApi") override fun onRemoveStoredPaymentMethod( storedPaymentMethod: StoredPaymentMethod, ) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { val storedPaymentMethodId = storedPaymentMethod.id.orEmpty() val isSuccessfullyRemoved = paymentsRepository.removeStoredPaymentMethod( storedPaymentMethodId = storedPaymentMethodId, diff --git a/example-app/src/main/java/com/adyen/checkout/example/service/ExampleDropInService.kt b/example-app/src/main/java/com/adyen/checkout/example/service/ExampleDropInService.kt index d5bcd49371..c29433b795 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/service/ExampleDropInService.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/service/ExampleDropInService.kt @@ -15,12 +15,12 @@ import com.adyen.checkout.components.core.PaymentComponentData import com.adyen.checkout.components.core.PaymentComponentState import com.adyen.checkout.components.core.StoredPaymentMethod import com.adyen.checkout.components.core.action.Action -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.dropin.DropInService import com.adyen.checkout.dropin.DropInServiceResult import com.adyen.checkout.dropin.ErrorDialog import com.adyen.checkout.dropin.RecurringDropInServiceResult import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.extensions.getLogTag import com.adyen.checkout.example.extensions.toStringPretty import com.adyen.checkout.example.repositories.PaymentsRepository @@ -43,11 +43,10 @@ class ExampleDropInService : DropInService() { @Inject lateinit var keyValueStorage: KeyValueStorage - @Suppress("RestrictedApi") override fun onSubmit( state: PaymentComponentState<*> ) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { Log.d(TAG, "onPaymentsCallRequested") checkPaymentState(state) @@ -83,9 +82,8 @@ class ExampleDropInService : DropInService() { } } - @Suppress("RestrictedApi") override fun onAdditionalDetails(actionComponentData: ActionComponentData) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { Log.d(TAG, "onDetailsCallRequested") val actionComponentJson = ActionComponentData.SERIALIZER.serialize(actionComponentData) @@ -128,11 +126,10 @@ class ExampleDropInService : DropInService() { return jsonResponse.has("action") } - @Suppress("RestrictedApi") override fun onRemoveStoredPaymentMethod( storedPaymentMethod: StoredPaymentMethod, ) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { val storedPaymentMethodId = storedPaymentMethod.id.orEmpty() val isSuccessfullyRemoved = paymentsRepository.removeStoredPaymentMethod( storedPaymentMethodId = storedPaymentMethodId, diff --git a/example-app/src/main/java/com/adyen/checkout/example/service/ExampleSessionsDropInService.kt b/example-app/src/main/java/com/adyen/checkout/example/service/ExampleSessionsDropInService.kt index 268db5b20a..922214b7a7 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/service/ExampleSessionsDropInService.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/service/ExampleSessionsDropInService.kt @@ -15,11 +15,11 @@ import com.adyen.checkout.components.core.ActionComponentData import com.adyen.checkout.components.core.PaymentComponentData import com.adyen.checkout.components.core.PaymentComponentState import com.adyen.checkout.components.core.action.Action -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.dropin.DropInServiceResult import com.adyen.checkout.dropin.ErrorDialog import com.adyen.checkout.dropin.SessionDropInService import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.extensions.getLogTag import com.adyen.checkout.example.extensions.toStringPretty import com.adyen.checkout.example.repositories.PaymentsRepository @@ -38,7 +38,6 @@ class ExampleSessionsDropInService : SessionDropInService() { @Inject lateinit var keyValueStorage: KeyValueStorage - @Suppress("RestrictedApi") override fun onSubmit( state: PaymentComponentState<*>, ): Boolean { @@ -46,7 +45,7 @@ class ExampleSessionsDropInService : SessionDropInService() { state is BlikComponentState || state is CardComponentState ) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { Log.d(TAG, "onPaymentsCallRequested") // Check out the documentation of this method on the parent DropInService class @@ -74,12 +73,11 @@ class ExampleSessionsDropInService : SessionDropInService() { } } - @Suppress("RestrictedApi") override fun onAdditionalDetails( actionComponentData: ActionComponentData, ): Boolean { return if (isFlowTakenOver) { - launch(DispatcherProvider.IO) { + launch(IODispatcher) { Log.d(TAG, "onDetailsCallRequested") val response = paymentsRepository.makeDetailsRequest( diff --git a/example-app/src/main/java/com/adyen/checkout/example/ui/bacs/BacsViewModel.kt b/example-app/src/main/java/com/adyen/checkout/example/ui/bacs/BacsViewModel.kt index 45ed525d8b..f6e6f5132b 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/ui/bacs/BacsViewModel.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/ui/bacs/BacsViewModel.kt @@ -19,9 +19,9 @@ import com.adyen.checkout.components.core.ComponentCallback import com.adyen.checkout.components.core.ComponentError import com.adyen.checkout.components.core.PaymentComponentData import com.adyen.checkout.components.core.action.Action -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.example.R import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.repositories.PaymentsRepository import com.adyen.checkout.example.service.createPaymentRequest import com.adyen.checkout.example.service.getPaymentMethodRequest @@ -57,8 +57,7 @@ internal class BacsViewModel @Inject constructor( viewModelScope.launch { fetchPaymentMethods() } } - @Suppress("RestrictedApi") - private suspend fun fetchPaymentMethods() = withContext(DispatcherProvider.IO) { + private suspend fun fetchPaymentMethods() = withContext(IODispatcher) { val validationError = if (keyValueStorage.getAmount().currency != CheckoutCurrency.GBP.name) { BacsViewState.Error(R.string.currency_code_error, CheckoutCurrency.GBP.name) } else if (keyValueStorage.getCountry() != Locale.UK.country) { @@ -116,9 +115,8 @@ internal class BacsViewModel @Inject constructor( viewModelScope.launch { _events.emit(BacsEvent.PaymentResult("Failed: ${error.errorMessage}")) } } - @Suppress("RestrictedApi") private fun sendPaymentDetails(actionComponentData: ActionComponentData) { - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val json = ActionComponentData.SERIALIZER.serialize(actionComponentData) handlePaymentResponse(paymentsRepository.makeDetailsRequest(json)) } @@ -147,8 +145,7 @@ internal class BacsViewModel @Inject constructor( val paymentComponentData = PaymentComponentData.SERIALIZER.serialize(data) - @Suppress("RestrictedApi") - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val paymentRequest = createPaymentRequest( paymentComponentData = paymentComponentData, shopperReference = keyValueStorage.getShopperReference(), diff --git a/example-app/src/main/java/com/adyen/checkout/example/ui/blik/BlikViewModel.kt b/example-app/src/main/java/com/adyen/checkout/example/ui/blik/BlikViewModel.kt index 7a18bea928..31931f3a41 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/ui/blik/BlikViewModel.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/ui/blik/BlikViewModel.kt @@ -20,9 +20,9 @@ import com.adyen.checkout.components.core.ComponentError import com.adyen.checkout.components.core.PaymentComponentData import com.adyen.checkout.components.core.action.Action import com.adyen.checkout.components.core.paymentmethod.BlikPaymentMethod -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.example.R import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.repositories.PaymentsRepository import com.adyen.checkout.example.service.createPaymentRequest import com.adyen.checkout.example.service.getPaymentMethodRequest @@ -55,8 +55,7 @@ class BlikViewModel @Inject constructor( viewModelScope.launch { _blikViewState.emit(fetchPaymentMethods()) } } - @Suppress("RestrictedApi") - private suspend fun fetchPaymentMethods(): BlikViewState = withContext(DispatcherProvider.IO) { + private suspend fun fetchPaymentMethods(): BlikViewState = withContext(IODispatcher) { if (keyValueStorage.getAmount().currency != CheckoutCurrency.PLN.name) { return@withContext BlikViewState.Error(R.string.currency_code_error, CheckoutCurrency.PLN.name) } else if (keyValueStorage.getCountry() != POLAND_COUNTRY_CODE) { @@ -139,9 +138,8 @@ class BlikViewModel @Inject constructor( } ?: _events.emit(BlikEvent.PaymentResult("Failed")) } - @Suppress("RestrictedApi") private fun sendPaymentDetails(actionComponentData: ActionComponentData) { - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val json = ActionComponentData.SERIALIZER.serialize(actionComponentData) handlePaymentResponse(paymentsRepository.makeDetailsRequest(json)) } diff --git a/example-app/src/main/java/com/adyen/checkout/example/ui/card/CardViewModel.kt b/example-app/src/main/java/com/adyen/checkout/example/ui/card/CardViewModel.kt index 1670b5a611..4ab7b48b2e 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/ui/card/CardViewModel.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/ui/card/CardViewModel.kt @@ -11,8 +11,8 @@ import com.adyen.checkout.components.core.ComponentError import com.adyen.checkout.components.core.LookupAddress import com.adyen.checkout.components.core.PaymentComponentData import com.adyen.checkout.components.core.action.Action -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.repositories.AddressLookupCompletionResult import com.adyen.checkout.example.repositories.AddressLookupRepository import com.adyen.checkout.example.repositories.PaymentsRepository @@ -56,8 +56,7 @@ internal class CardViewModel @Inject constructor( }.launchIn(viewModelScope) } - @Suppress("RestrictedApi") - private suspend fun fetchPaymentMethods() = withContext(DispatcherProvider.IO) { + private suspend fun fetchPaymentMethods() = withContext(IODispatcher) { val paymentMethodResponse = paymentsRepository.getPaymentMethods( getPaymentMethodRequest( merchantAccount = keyValueStorage.getMerchantAccount(), @@ -129,8 +128,7 @@ internal class CardViewModel @Inject constructor( val paymentComponentData = PaymentComponentData.SERIALIZER.serialize(data) - @Suppress("RestrictedApi") - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val paymentRequest = createPaymentRequest( paymentComponentData = paymentComponentData, shopperReference = keyValueStorage.getShopperReference(), @@ -164,9 +162,8 @@ internal class CardViewModel @Inject constructor( _events.emit(CardEvent.AdditionalAction(action)) } - @Suppress("RestrictedApi") private fun sendPaymentDetails(actionComponentData: ActionComponentData) { - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val json = ActionComponentData.SERIALIZER.serialize(actionComponentData) handlePaymentResponse(paymentsRepository.makeDetailsRequest(json)) } diff --git a/example-app/src/main/java/com/adyen/checkout/example/ui/card/SessionsCardTakenOverViewModel.kt b/example-app/src/main/java/com/adyen/checkout/example/ui/card/SessionsCardTakenOverViewModel.kt index 2d99c29244..7a2dd336e5 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/ui/card/SessionsCardTakenOverViewModel.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/ui/card/SessionsCardTakenOverViewModel.kt @@ -22,8 +22,8 @@ import com.adyen.checkout.components.core.LookupAddress import com.adyen.checkout.components.core.PaymentComponentData import com.adyen.checkout.components.core.PaymentMethodTypes import com.adyen.checkout.components.core.action.Action -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.extensions.getLogTag import com.adyen.checkout.example.repositories.AddressLookupCompletionResult import com.adyen.checkout.example.repositories.AddressLookupRepository @@ -39,7 +39,6 @@ import com.adyen.checkout.sessions.core.SessionComponentCallback import com.adyen.checkout.sessions.core.SessionModel import com.adyen.checkout.sessions.core.SessionPaymentResult import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -50,7 +49,6 @@ import kotlinx.coroutines.launch import org.json.JSONObject import javax.inject.Inject -@OptIn(FlowPreview::class) @Suppress("TooManyFunctions") @HiltViewModel internal class SessionsCardTakenOverViewModel @Inject constructor( @@ -174,13 +172,12 @@ internal class SessionsCardTakenOverViewModel @Inject constructor( return isFlowTakenOver } - @Suppress("RestrictedApi") private fun makePayment(data: PaymentComponentData<*>) { _cardViewState.value = CardViewState.Loading val paymentComponentData = PaymentComponentData.SERIALIZER.serialize(data) - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val paymentRequest = createPaymentRequest( paymentComponentData = paymentComponentData, shopperReference = keyValueStorage.getShopperReference(), @@ -214,9 +211,8 @@ internal class SessionsCardTakenOverViewModel @Inject constructor( _events.emit(CardEvent.AdditionalAction(action)) } - @Suppress("RestrictedApi") private fun sendPaymentDetails(actionComponentData: ActionComponentData) { - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val json = ActionComponentData.SERIALIZER.serialize(actionComponentData) handlePaymentResponse(paymentsRepository.makeDetailsRequest(json)) } diff --git a/example-app/src/main/java/com/adyen/checkout/example/ui/giftcard/GiftCardViewModel.kt b/example-app/src/main/java/com/adyen/checkout/example/ui/giftcard/GiftCardViewModel.kt index b223ef1f1d..453aefb500 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/ui/giftcard/GiftCardViewModel.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/ui/giftcard/GiftCardViewModel.kt @@ -23,9 +23,9 @@ import com.adyen.checkout.components.core.PaymentComponentData import com.adyen.checkout.components.core.PaymentComponentState import com.adyen.checkout.components.core.action.Action import com.adyen.checkout.components.core.paymentmethod.PaymentMethodDetails -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.core.exception.ModelSerializationException import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.extensions.getLogTag import com.adyen.checkout.example.repositories.PaymentsRepository import com.adyen.checkout.example.service.createBalanceRequest @@ -68,8 +68,7 @@ internal class GiftCardViewModel @Inject constructor( viewModelScope.launch { fetchPaymentMethods() } } - @Suppress("RestrictedApi") - private suspend fun fetchPaymentMethods() = withContext(DispatcherProvider.IO) { + private suspend fun fetchPaymentMethods() = withContext(IODispatcher) { val paymentMethodResponse = paymentsRepository.getPaymentMethods( getPaymentMethodRequest( merchantAccount = keyValueStorage.getMerchantAccount(), @@ -113,9 +112,8 @@ internal class GiftCardViewModel @Inject constructor( // no ops override fun onStateChanged(state: GiftCardComponentState) = Unit - @Suppress("RestrictedApi") override fun onBalanceCheck(paymentComponentState: PaymentComponentState<*>) { - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { Log.d(TAG, "checkBalance") val amount = paymentComponentState.data.amount @@ -177,9 +175,8 @@ internal class GiftCardViewModel @Inject constructor( } } - @Suppress("RestrictedApi") override fun onRequestOrder() { - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { Log.d(TAG, "createOrder") val paymentRequest = createOrderRequest( @@ -213,13 +210,12 @@ internal class GiftCardViewModel @Inject constructor( } } - @Suppress("RestrictedApi") private fun makePayment(data: PaymentComponentData<*>) { _giftCardViewStateFlow.value = GiftCardViewState.Loading val paymentComponentData = PaymentComponentData.SERIALIZER.serialize(data) - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val paymentRequest = createPaymentRequest( paymentComponentData = paymentComponentData, shopperReference = keyValueStorage.getShopperReference(), @@ -284,9 +280,8 @@ internal class GiftCardViewModel @Inject constructor( viewModelScope.launch { _events.emit(GiftCardEvent.AdditionalAction(action)) } } - @Suppress("RestrictedApi") private fun sendPaymentDetails(actionComponentData: ActionComponentData) { - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val json = ActionComponentData.SERIALIZER.serialize(actionComponentData) handlePaymentResponse(paymentsRepository.makeDetailsRequest(json)) } diff --git a/example-app/src/main/java/com/adyen/checkout/example/ui/googlepay/GooglePayViewModel.kt b/example-app/src/main/java/com/adyen/checkout/example/ui/googlepay/GooglePayViewModel.kt index 93d280b836..c4d3be339c 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/ui/googlepay/GooglePayViewModel.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/ui/googlepay/GooglePayViewModel.kt @@ -20,9 +20,9 @@ import com.adyen.checkout.components.core.ComponentError import com.adyen.checkout.components.core.PaymentComponentData import com.adyen.checkout.components.core.PaymentMethod import com.adyen.checkout.components.core.action.Action -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.example.R import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.repositories.PaymentsRepository import com.adyen.checkout.example.service.createPaymentRequest import com.adyen.checkout.example.service.getPaymentMethodRequest @@ -67,8 +67,7 @@ internal class GooglePayViewModel @Inject constructor( viewModelScope.launch { fetchPaymentMethods() } } - @Suppress("RestrictedApi") - private suspend fun fetchPaymentMethods() = withContext(DispatcherProvider.IO) { + private suspend fun fetchPaymentMethods() = withContext(IODispatcher) { val paymentMethodResponse = paymentsRepository.getPaymentMethods( getPaymentMethodRequest( merchantAccount = keyValueStorage.getMerchantAccount(), @@ -138,9 +137,8 @@ internal class GooglePayViewModel @Inject constructor( viewModelScope.launch { _events.emit(GooglePayEvent.PaymentResult("Failed: ${error.errorMessage}")) } } - @Suppress("RestrictedApi") private fun sendPaymentDetails(actionComponentData: ActionComponentData) { - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val json = ActionComponentData.SERIALIZER.serialize(actionComponentData) handlePaymentResponse(paymentsRepository.makeDetailsRequest(json)) } @@ -169,8 +167,7 @@ internal class GooglePayViewModel @Inject constructor( val paymentComponentData = PaymentComponentData.SERIALIZER.serialize(data) - @Suppress("RestrictedApi") - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val paymentRequest = createPaymentRequest( paymentComponentData = paymentComponentData, shopperReference = keyValueStorage.getShopperReference(), diff --git a/example-app/src/main/java/com/adyen/checkout/example/ui/googlepay/compose/SessionsGooglePayViewModel.kt b/example-app/src/main/java/com/adyen/checkout/example/ui/googlepay/compose/SessionsGooglePayViewModel.kt index ea6a4c54ed..3939f75ef3 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/ui/googlepay/compose/SessionsGooglePayViewModel.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/ui/googlepay/compose/SessionsGooglePayViewModel.kt @@ -20,8 +20,8 @@ import com.adyen.checkout.components.core.ComponentError import com.adyen.checkout.components.core.PaymentMethod import com.adyen.checkout.components.core.PaymentMethodTypes import com.adyen.checkout.components.core.action.Action -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.extensions.getLogTag import com.adyen.checkout.example.repositories.PaymentsRepository import com.adyen.checkout.example.service.getSessionRequest @@ -71,8 +71,7 @@ internal class SessionsGooglePayViewModel @Inject constructor( viewModelScope.launch { fetchSession() } } - @Suppress("RestrictedApi") - private suspend fun fetchSession() = withContext(DispatcherProvider.IO) { + private suspend fun fetchSession() = withContext(IODispatcher) { val paymentMethodType = PaymentMethodTypes.GOOGLE_PAY val checkoutSession = getSession(paymentMethodType) if (checkoutSession == null) { diff --git a/example-app/src/main/java/com/adyen/checkout/example/ui/instant/InstantViewModel.kt b/example-app/src/main/java/com/adyen/checkout/example/ui/instant/InstantViewModel.kt index 26fd56a436..feed4869bb 100644 --- a/example-app/src/main/java/com/adyen/checkout/example/ui/instant/InstantViewModel.kt +++ b/example-app/src/main/java/com/adyen/checkout/example/ui/instant/InstantViewModel.kt @@ -16,9 +16,9 @@ import com.adyen.checkout.components.core.ComponentCallback import com.adyen.checkout.components.core.ComponentError import com.adyen.checkout.components.core.PaymentComponentData import com.adyen.checkout.components.core.action.Action -import com.adyen.checkout.core.DispatcherProvider import com.adyen.checkout.core.PermissionHandlerCallback import com.adyen.checkout.example.data.storage.KeyValueStorage +import com.adyen.checkout.example.extensions.IODispatcher import com.adyen.checkout.example.repositories.PaymentsRepository import com.adyen.checkout.example.service.createPaymentRequest import com.adyen.checkout.example.service.getPaymentMethodRequest @@ -55,8 +55,7 @@ internal class InstantViewModel @Inject constructor( viewModelScope.launch { fetchPaymentMethods() } } - @Suppress("RestrictedApi") - private suspend fun fetchPaymentMethods() = withContext(DispatcherProvider.IO) { + private suspend fun fetchPaymentMethods() = withContext(IODispatcher) { val paymentMethodResponse = paymentsRepository.getPaymentMethods( getPaymentMethodRequest( merchantAccount = keyValueStorage.getMerchantAccount(), @@ -119,12 +118,11 @@ internal class InstantViewModel @Inject constructor( permissionCallback = null } - @Suppress("RestrictedApi") private fun makePayment(data: PaymentComponentData<*>) { _instantViewState.tryEmit(InstantViewState.Loading) val paymentComponentData = PaymentComponentData.SERIALIZER.serialize(data) - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val paymentRequest = createPaymentRequest( paymentComponentData = paymentComponentData, shopperReference = keyValueStorage.getShopperReference(), @@ -155,9 +153,8 @@ internal class InstantViewModel @Inject constructor( } ?: _events.emit(InstantEvent.PaymentResult("Failed")) } - @Suppress("RestrictedApi") private fun sendPaymentDetails(actionComponentData: ActionComponentData) { - viewModelScope.launch(DispatcherProvider.IO) { + viewModelScope.launch(IODispatcher) { val json = ActionComponentData.SERIALIZER.serialize(actionComponentData) handlePaymentResponse(paymentsRepository.makeDetailsRequest(json)) }