Updated on 2026-08-14
This commit is contained in:
parent
3b6eeb7535
commit
8b677a8e6b
25 changed files with 1149 additions and 17 deletions
|
|
@ -0,0 +1,37 @@
|
|||
package com.tangem.data.pay.converter
|
||||
|
||||
import com.tangem.datasource.api.pay.models.response.CustomerMeResponse
|
||||
import com.tangem.domain.models.account.TangemPayTariffPlan
|
||||
|
||||
internal object TangemPayTariffPlanConverter {
|
||||
|
||||
fun convert(value: CustomerMeResponse.TariffPlan?): TangemPayTariffPlan? {
|
||||
val id = value?.id ?: return null
|
||||
val name = value.name ?: return null
|
||||
return TangemPayTariffPlan(
|
||||
id = id,
|
||||
type = TangemPayTariffPlan.Type.fromString(value.type),
|
||||
name = name,
|
||||
descriptionItems = value.descriptionItems.orEmpty().mapNotNull(::convertDescriptionItem),
|
||||
images = value.images.orEmpty().mapNotNull(::convertImage),
|
||||
)
|
||||
}
|
||||
|
||||
private fun convertDescriptionItem(item: CustomerMeResponse.DescriptionItem): TangemPayTariffPlan.DescriptionItem? {
|
||||
val title = item.title ?: return null
|
||||
return TangemPayTariffPlan.DescriptionItem(
|
||||
section = TangemPayTariffPlan.Section.fromString(item.type),
|
||||
order = item.order ?: 0,
|
||||
title = title,
|
||||
body = item.body.orEmpty(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun convertImage(image: CustomerMeResponse.Image): TangemPayTariffPlan.Image? {
|
||||
val url = image.url ?: return null
|
||||
return TangemPayTariffPlan.Image(
|
||||
type = TangemPayTariffPlan.Image.Type.fromString(image.type),
|
||||
url = url,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -124,8 +124,21 @@ internal interface TangemPayDataModule {
|
|||
@IntoSet
|
||||
fun bindTangemPayUserWalletDataCleaner(impl: TangemPayUserWalletDataCleaner): UserWalletDataCleaner
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindTariffPlanTransitionsRepository(
|
||||
repository: DefaultTariffPlanTransitionsRepository,
|
||||
): TangemPayTariffPlanTransitionsRepository
|
||||
|
||||
companion object {
|
||||
|
||||
@Provides
|
||||
fun provideGetTangemPayTariffPlanTransitionsUseCase(
|
||||
repository: TangemPayTariffPlanTransitionsRepository,
|
||||
): GetTangemPayTariffPlanTransitionsUseCase {
|
||||
return GetTangemPayTariffPlanTransitionsUseCase(repository)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePaymentAccountStatusesStore(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.tangem.data.pay.repository
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.raise.either
|
||||
import com.tangem.data.pay.converter.TangemPayTariffPlanConverter
|
||||
import com.tangem.datasource.api.pay.TangemPayApi
|
||||
import com.tangem.datasource.api.pay.models.response.TariffPlanTransitionResponse
|
||||
import com.tangem.domain.models.account.TangemPayTariffPlanTransition
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.pay.repository.TangemPayTariffPlanTransitionsRepository
|
||||
import com.tangem.domain.visa.error.VisaApiError
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultTariffPlanTransitionsRepository @Inject constructor(
|
||||
private val tangemPayApi: TangemPayApi,
|
||||
private val requestHelper: TangemPayRequestPerformer,
|
||||
) : TangemPayTariffPlanTransitionsRepository {
|
||||
|
||||
override suspend fun getTransitions(
|
||||
userWalletId: UserWalletId,
|
||||
): Either<VisaApiError, List<TangemPayTariffPlanTransition>> = either {
|
||||
val response = requestHelper.performRequest(userWalletId) { authHeader ->
|
||||
tangemPayApi.getTariffPlanTransitions(authHeader = authHeader)
|
||||
}.bind()
|
||||
|
||||
response.result.orEmpty().mapNotNull { it.toDomain() }
|
||||
}
|
||||
|
||||
private fun TariffPlanTransitionResponse.toDomain(): TangemPayTariffPlanTransition? {
|
||||
val plan = TangemPayTariffPlanConverter.convert(tariffPlan) ?: return null
|
||||
return TangemPayTariffPlanTransition(
|
||||
type = TangemPayTariffPlanTransition.Type.fromString(type),
|
||||
plan = plan,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.data.pay.util
|
||||
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.data.pay.converter.TangemPayTariffPlanConverter
|
||||
import com.tangem.datasource.api.pay.models.response.CryptoBalance
|
||||
import com.tangem.datasource.api.pay.models.response.CustomerMeResponse
|
||||
import com.tangem.datasource.api.pay.models.response.FiatBalance
|
||||
|
|
@ -63,21 +64,8 @@ internal object CustomerInfoConverter : Converter<CustomerMeResponse.Result, Cus
|
|||
)
|
||||
}
|
||||
|
||||
private fun CustomerMeResponse.TariffPlan.toDomain(): TangemPayTariffPlan? {
|
||||
val name = name ?: return null
|
||||
return TangemPayTariffPlan(
|
||||
type = TangemPayTariffPlan.Type.fromString(type),
|
||||
name = name,
|
||||
descriptionItems = descriptionItems.orEmpty().map { it.toDomain() },
|
||||
)
|
||||
}
|
||||
|
||||
private fun CustomerMeResponse.DescriptionItem.toDomain() = TangemPayTariffPlan.DescriptionItem(
|
||||
section = TangemPayTariffPlan.Section.fromString(type),
|
||||
order = order ?: 0,
|
||||
title = title.orEmpty(),
|
||||
body = body.orEmpty(),
|
||||
)
|
||||
private fun CustomerMeResponse.TariffPlan.toDomain(): TangemPayTariffPlan? =
|
||||
TangemPayTariffPlanConverter.convert(this)
|
||||
|
||||
private fun CustomerMeResponse.ProductInstance.toDomain(): ProductInstance {
|
||||
val status = status.toDomain()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue