Skip to content

Commit

Permalink
Merge pull request #245 from tinkoff-mobile-tech/v.2.13.2
Browse files Browse the repository at this point in the history
V.2.13.2
  • Loading branch information
jQwout authored Apr 26, 2023
2 parents cd8e28e + 30df493 commit b20d36a
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ package ru.tinkoff.acquiring.sdk.exceptions
*
* @author Mariya Chernyadieva
*/
class AcquiringSdkException(throwable: Throwable, paymentId: Long? = null) : RuntimeException(throwable.message, throwable)
class AcquiringSdkException(throwable: Throwable, val paymentId: Long? = null) : RuntimeException(throwable.message, throwable)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.tinkoff.acquiring.sdk.exceptions

/**
*
* Исключение, выбрасываемое при неуспешном открытии какого либо банка по контракту NSPK в
* Cценарии оплаты по СБП
*
* @param throwable - родительская ошибка
* @param message - дополнительное сообщение
* @param deeplink - диплинк для октрытия прилоежния
* @param paymentId - идентификатор платежной сессии
*
* Created by i.golovachev
*/
class NspkOpenException(
throwable: Throwable,
message: String? = null,
val deeplink: String? = null,
val paymentId: Long? = null
) : RuntimeException(message ?: throwable.message, throwable)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ru.tinkoff.acquiring.sdk.responses

import com.google.gson.annotations.SerializedName
import java.io.Serializable

/**
* Created by i.golovachev
* Ответ на запрос https://qr.nspk.ru/proxyapp/c2bmembers.json
* представляет список приложений для взаимодействия с СБП
* 182 организации и 181 приложение на момент version - 1.0
*
* @param version - версия справочника
* @param dictionary - список приложений
*/
class NspkC2bResponse(
@SerializedName("version")
val version: String,
@SerializedName("dictionary")
val dictionary: List<NspkAppInfo>,
) : Serializable {

/**
* Информация о приложении банка
*
* @param bankName - наименование организации
* @param logoURL - адресс статического ресурса с логотипом приложения
* @param schema - выделенная схема организации в системе сбп
* @param packageName - наименование пакета приложения организации, если null - приложения не существует или оно удалено
*/
class NspkAppInfo(
@SerializedName("bankName")
val bankName: String,
@SerializedName("logoURL")
val logoURL: String,
@SerializedName("schema")
val schema: String,
@SerializedName("package_name")
val packageName: String?,
) : Serializable
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=2.13.1
VERSION_NAME=2.13.2
VERSION_CODE=21
GROUP=ru.tinkoff.acquiring

Expand Down
5 changes: 5 additions & 0 deletions migration.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.13.2
Новый алгоритм работы со сценарием оплаты СБП
Новый инстанс ошибки `NspkOpenException` - выбрасывается при неуспешном открытии приложения - партнера
по СБП

2.12.0
Изменена версия minSdk всвязи самоподписными сертификатами:
minSdk : `21` -`24`
Expand Down
2 changes: 1 addition & 1 deletion ui/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" android:host="qr.nspk.ru" />
<data android:scheme="*" android:host="qr.nspk.ru" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package ru.tinkoff.acquiring.sdk.models

import ru.tinkoff.acquiring.sdk.AcquiringSdk
import ru.tinkoff.acquiring.sdk.responses.Check3dsVersionResponse
import ru.tinkoff.acquiring.sdk.responses.NspkC2bResponse
import ru.tinkoff.acquiring.sdk.threeds.ThreeDsAppBasedTransaction
import java.io.Serializable

Expand Down Expand Up @@ -61,7 +62,7 @@ class ThreeDsState(val data: ThreeDsData, val transaction: ThreeDsAppBasedTransa
* Состояние открытия приложения (или выбора приложения), зарегистрированного для обработки ссылки
* Системы быстрых платежей, в котором произойдет оплата
*/
class BrowseFpsBankState(val paymentId: Long, val deepLink: String, val banks: Set<Any?>?) : AsdkState()
class BrowseFpsBankState(val paymentId: Long, val deepLink: String, val banksInfo: List<NspkC2bResponse.NspkAppInfo>?) : AsdkState()

/**
* Состояние открытия приложения, зарегистрированного для обработки ссылки Tinkoff Pay.
Expand Down
14 changes: 14 additions & 0 deletions ui/src/main/java/ru/tinkoff/acquiring/sdk/models/BankChooseInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.tinkoff.acquiring.sdk.models


/**
* Created by i.golovachev
*/
class BankChooseInfo(
val appsAndLinks: Map<String, String>
) : java.io.Serializable {

val apps: Set<String> get() = appsAndLinks.keys

fun getDeeplink(packageName: String) : String = appsAndLinks.getValue(packageName)
}
15 changes: 13 additions & 2 deletions ui/src/main/java/ru/tinkoff/acquiring/sdk/models/NspkRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@

package ru.tinkoff.acquiring.sdk.models

import ru.tinkoff.acquiring.sdk.responses.NspkC2bResponse
import ru.tinkoff.acquiring.sdk.utils.NspkClient
import ru.tinkoff.acquiring.sdk.utils.Request
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

/**
* @author Mariya Chernyadieva
*/
internal class NspkRequest: Request<NspkResponse> {
internal class NspkRequest : Request<NspkC2bResponse> {

@Volatile
private var disposed = false
Expand All @@ -35,8 +39,15 @@ internal class NspkRequest: Request<NspkResponse> {
disposed = true
}

override fun execute(onSuccess: (NspkResponse) -> Unit, onFailure: (Exception) -> Unit) {
override fun execute(onSuccess: (NspkC2bResponse) -> Unit, onFailure: (Exception) -> Unit) {
val client = NspkClient()
client.call(this, onSuccess, onFailure)
}

suspend fun execute() = suspendCoroutine<NspkC2bResponse> { ctn ->
execute(
onSuccess = { response -> ctn.resume(response) },
onFailure = { ctn.resumeWithException(it) }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ package ru.tinkoff.acquiring.sdk.models
/**
* @author Mariya Chernyadieva
*/
@Deprecated("use NspkC2bResponse")
internal class NspkResponse(val banks: Set<Any?>)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package ru.tinkoff.acquiring.sdk.models

import ru.tinkoff.acquiring.sdk.responses.NspkC2bResponse
import ru.tinkoff.acquiring.sdk.threeds.ThreeDsAppBasedTransaction

/**
Expand All @@ -31,7 +32,7 @@ internal class FpsBankFormShowedScreenState(val paymentId: Long) : ScreenState()
internal sealed class Screen : ScreenState()
internal object PaymentScreenState : Screen()
internal object FpsScreenState: Screen()
internal class BrowseFpsBankScreenState(val paymentId: Long, val deepLink: String, val banks: Set<Any?>?) : Screen()
internal class BrowseFpsBankScreenState(val paymentId: Long, val deepLink: String, val banks: List<NspkC2bResponse.NspkAppInfo>?) : Screen()
internal class OpenTinkoffPayBankScreenState(val paymentId: Long, val deepLink: String) : Screen()
internal class RejectedCardScreenState(val cardId: String, val rejectedPaymentId: Long) : Screen()
internal class ThreeDsScreenState(val data: ThreeDsData, val transaction: ThreeDsAppBasedTransaction?) : Screen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ package ru.tinkoff.acquiring.sdk.models.result
/**
* @author Mariya Chernyadieva
*/
internal class BankChooseResult(val packageName: String) : AsdkResult
internal class BankChooseResult(val packageName: String, val deeplink: String) : AsdkResult
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ internal constructor(
onSuccess = { response ->
coroutine.call(NspkRequest(),
onSuccess = { nspk ->
sdkState = BrowseFpsBankState(paymentId, response.data!!, nspk.banks)
sdkState = BrowseFpsBankState(paymentId, response.data!!, nspk.dictionary)
sendToListener(PaymentState.BROWSE_SBP_BANK)
},
onFailure = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import ru.tinkoff.acquiring.sdk.R
import ru.tinkoff.acquiring.sdk.models.*
import ru.tinkoff.acquiring.sdk.models.BrowserButtonClickedEvent
import ru.tinkoff.acquiring.sdk.models.ConfirmButtonClickedEvent
import ru.tinkoff.acquiring.sdk.models.OpenBankClickedEvent
Expand All @@ -34,6 +35,7 @@ import ru.tinkoff.acquiring.sdk.models.options.screen.BaseAcquiringOptions
import ru.tinkoff.acquiring.sdk.models.result.BankChooseResult
import ru.tinkoff.acquiring.sdk.ui.fragments.BanksNotFoundFragment
import ru.tinkoff.acquiring.sdk.ui.fragments.BankChooseFragment
import ru.tinkoff.acquiring.sdk.utils.lazyUnsafe
import ru.tinkoff.acquiring.sdk.viewmodel.BaseAcquiringViewModel

/**
Expand All @@ -42,24 +44,26 @@ import ru.tinkoff.acquiring.sdk.viewmodel.BaseAcquiringViewModel
internal class BankChooseActivity: TransparentActivity() {

private lateinit var viewModel: BaseAcquiringViewModel
private val banksInfo: BankChooseInfo by lazyUnsafe {
intent.getSerializableExtra(EXTRA_BANKS) as BankChooseInfo
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val banksList = intent.getStringArrayExtra(EXTRA_BANKS)
initViews(banksList.isNullOrEmpty())
initViews(banksInfo.appsAndLinks.isEmpty())

viewModel = provideViewModel(BaseAcquiringViewModel::class.java) as BaseAcquiringViewModel

if (savedInstanceState == null) {
if (banksList.isNullOrEmpty()) {
if (banksInfo.appsAndLinks.isEmpty()) {
showFragment(BanksNotFoundFragment())
} else {
showFragment(BankChooseFragment.newInstance(banksList.toCollection(arrayListOf())))
showFragment(BankChooseFragment.newInstance(banksInfo.apps.toCollection(arrayListOf())))
}
}

if (banksList.isNullOrEmpty()) {
if (banksInfo.appsAndLinks.isEmpty()) {
prepareToolbar()
val container = findViewById<View>(R.id.acq_activity_fl_container)
container.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
Expand Down Expand Up @@ -89,7 +93,12 @@ internal class BankChooseActivity: TransparentActivity() {
startActivity(browseIntent)
}
is OpenBankClickedEvent -> {
finishWithSuccess(BankChooseResult(screenState.packageName))
finishWithSuccess(
BankChooseResult(
packageName = screenState.packageName,
deeplink = banksInfo.getDeeplink(screenState.packageName)
)
)
}
}
}
Expand All @@ -99,9 +108,9 @@ internal class BankChooseActivity: TransparentActivity() {
private const val EXTRA_BANKS = "extra_banks"
private const val EXTRA_PAYLOAD_LINK = "extra_payload_link"

fun createIntent(context: Context, options: BaseAcquiringOptions, supportedBanks: List<String>, payloadLink: String): Intent {
fun createIntent(context: Context, options: BaseAcquiringOptions, supportedBanks: BankChooseInfo, payloadLink: String): Intent {
val intent = createIntent(context, options, BankChooseActivity::class.java)
intent.putExtra(EXTRA_BANKS, supportedBanks.toTypedArray())
intent.putExtra(EXTRA_BANKS, supportedBanks)
intent.putExtra(EXTRA_PAYLOAD_LINK, payloadLink)
return intent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import ru.tinkoff.acquiring.sdk.models.result.BankChooseResult
import ru.tinkoff.acquiring.sdk.models.result.CardResult
import ru.tinkoff.acquiring.sdk.models.result.PaymentResult
import ru.tinkoff.acquiring.sdk.threeds.ThreeDsSubmitV2Delegate
import ru.tinkoff.acquiring.sdk.ui.activities.PaymentActivity.Companion.EXTRA_SBP_BANK_DEEPLINK
import ru.tinkoff.acquiring.sdk.ui.activities.PaymentActivity.Companion.EXTRA_SBP_BANK_PACKAGE_NAME
import ru.tinkoff.acquiring.sdk.viewmodel.ViewModelProviderFactory
import ru.tinkoff.acquiring.sdk.viewmodel.YandexPaymentViewModel
Expand Down Expand Up @@ -162,7 +163,10 @@ internal open class BaseAcquiringActivity : AppCompatActivity() {
intent.putExtra(TinkoffAcquiring.EXTRA_REBILL_ID, result.rebillId)
}
is CardResult -> intent.putExtra(TinkoffAcquiring.EXTRA_CARD_ID, result.cardId)
is BankChooseResult -> intent.putExtra(EXTRA_SBP_BANK_PACKAGE_NAME, result.packageName)
is BankChooseResult -> with(intent) {
putExtra(EXTRA_SBP_BANK_PACKAGE_NAME, result.packageName)
putExtra(EXTRA_SBP_BANK_DEEPLINK, result.deeplink)
}
}

setResult(Activity.RESULT_OK, intent)
Expand Down
Loading

0 comments on commit b20d36a

Please sign in to comment.