Skip to content

Commit

Permalink
Merge pull request #172 from Tinkoff/MC-7844-scopes-refactoring
Browse files Browse the repository at this point in the history
Mc 7844 scopes refactoring
  • Loading branch information
jQwout authored Dec 29, 2022
2 parents f048298 + 3b04f32 commit 4952a9a
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 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 All @@ -43,6 +42,7 @@ import ru.tinkoff.acquiring.sdk.ui.activities.NotificationPaymentActivity
import ru.tinkoff.acquiring.sdk.ui.activities.PaymentActivity
import ru.tinkoff.acquiring.sdk.ui.activities.QrCodeActivity
import ru.tinkoff.acquiring.sdk.ui.activities.SavedCardsActivity
import kotlin.coroutines.suspendCoroutine

/**
* Точка входа для взаимодействия с Acquiring SDK
Expand Down Expand Up @@ -209,30 +209,29 @@ 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 mainScope = this
val result = sdk.tinkoffPayStatus().performSuspendRequest()
withContext(Dispatchers.Main) {
result.fold(onSuccess = onSuccess, onFailure = { onFailure?.invoke(it) })
mainScope.cancel()
}
}
}

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

val onFailureOrThrow = onFailure ?: { throw it }

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

val mainScope = this
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) })
mainScope.cancel()
}
}
}
Expand Down

0 comments on commit 4952a9a

Please sign in to comment.