Skip to content

Commit

Permalink
MC-7844 - scopes refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jQwout committed Dec 29, 2022
1 parent f048298 commit 954b03c
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions ui/src/main/java/ru/tinkoff/acquiring/sdk/TinkoffAcquiring.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.fragment.app.Fragment
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import ru.tinkoff.acquiring.sdk.localization.LocalizationSource
import ru.tinkoff.acquiring.sdk.models.*
import ru.tinkoff.acquiring.sdk.models.options.FeaturesOptions
Expand All @@ -33,6 +31,7 @@ import ru.tinkoff.acquiring.sdk.models.paysources.CardData
import ru.tinkoff.acquiring.sdk.models.paysources.GooglePay
import ru.tinkoff.acquiring.sdk.payment.PaymentProcess
import ru.tinkoff.acquiring.sdk.requests.performSuspendRequest
import ru.tinkoff.acquiring.sdk.responses.GetTerminalPayMethodsResponse
import ru.tinkoff.acquiring.sdk.responses.TerminalInfo
import ru.tinkoff.acquiring.sdk.responses.TinkoffPayStatusResponse
import ru.tinkoff.acquiring.sdk.threeds.ThreeDsHelper
Expand Down Expand Up @@ -209,30 +208,27 @@ class TinkoffAcquiring(
onFailure: ((Throwable) -> Unit)? = null
) {
CoroutineScope(Dispatchers.IO).launch {
sdk.tinkoffPayStatus().execute({
launch(Dispatchers.Main) { onSuccess(it) }
}, {
launch(Dispatchers.Main) { onFailure?.invoke(it) }
})
val result = sdk.tinkoffPayStatus().performSuspendRequest()
withContext(Dispatchers.Main) {
result.fold(onSuccess = onSuccess, onFailure = { onFailure?.invoke(it) })
cancel()
}
}
}

/**
* Проверка доступных спосбов оплаты
*/
fun checkTerminalInfo(onSuccess: (TerminalInfo?) -> Unit,
onFailure: ((Throwable) -> Unit)? = null) {

val onFailureOrThrow = onFailure ?: { throw it }

onFailure: ((Throwable) -> Unit)? = null
) {
CoroutineScope(Dispatchers.IO).launch {

val result = sdk.getTerminalPayMethods()
.performSuspendRequest()
.map { it.terminalInfo }

launch(Dispatchers.Main) {
result.fold(onSuccess, onFailureOrThrow)
withContext(Dispatchers.Main) {
result.fold(onSuccess = onSuccess, onFailure = { onFailure?.invoke(it) })
cancel()
}
}
}
Expand Down

0 comments on commit 954b03c

Please sign in to comment.