Updated on 2026-08-14
This commit is contained in:
parent
10584c84a8
commit
096d1e40c9
11 changed files with 79 additions and 53 deletions
|
|
@ -92,8 +92,7 @@ internal class DefaultTangemPayEligibilityManager @Inject constructor(
|
|||
}
|
||||
|
||||
private fun UserWallet.isCompatible(): Boolean = when (this) {
|
||||
is UserWallet.Cold ->
|
||||
scanResponse.card.firmwareVersion >= FirmwareVersion.HDWalletAvailable
|
||||
is UserWallet.Cold -> scanResponse.card.firmwareVersion >= FirmwareVersion.HDWalletAvailable
|
||||
is UserWallet.Hot -> hotWalletId.authType != HotWalletId.AuthType.NoPassword
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,9 +104,9 @@ internal class DefaultPaymentAccountStatusFetcher @Inject constructor(
|
|||
ifRight = { customerInfo ->
|
||||
Timber.tag(TAG).i("proceedWithoutOrder data customerInfo $userWalletId")
|
||||
val status = customerInfo.mapToPaymentAccountStatus()
|
||||
if (status is PaymentAccountStatus.IssuingCard && customerInfo.kycStatus == KycStatus.APPROVED) {
|
||||
// If order id wasn't saved -> start order creation and get customer info
|
||||
if (customerInfo.productInstance == null) {
|
||||
onboardingRepository.createOrder(userWalletId)
|
||||
.onLeft { Timber.tag(TAG).e("createOrder failed: $it") }
|
||||
}
|
||||
status
|
||||
},
|
||||
|
|
@ -128,9 +128,6 @@ internal class DefaultPaymentAccountStatusFetcher @Inject constructor(
|
|||
-> PaymentAccountStatus.IssuingCard(source = StatusSource.ACTUAL)
|
||||
|
||||
OrderStatus.CANCELED -> {
|
||||
// If order was cancelled -> clear previous order from local storage and start order creation
|
||||
onboardingRepository.clearOrderId(userWalletId)
|
||||
onboardingRepository.createOrder(userWalletId)
|
||||
PaymentAccountStatus.Error.CardIssueFailed
|
||||
}
|
||||
OrderStatus.COMPLETED -> {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ internal class DefaultCustomerOrderRepository @Inject constructor(
|
|||
OrderResponse.Result.Status.CANCELED -> OrderStatus.CANCELED
|
||||
}
|
||||
OrderData(
|
||||
customerId = response.result?.customerId.orEmpty(),
|
||||
status = status,
|
||||
withdrawTxHash = response.result?.data?.transactionHash?.ifEmpty { null },
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package com.tangem.data.pay.repository
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.raise.catch
|
||||
import arrow.core.right
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.datasource.api.pay.TangemPayApi
|
||||
import com.tangem.datasource.api.pay.models.request.DeeplinkValidityRequest
|
||||
import com.tangem.datasource.api.pay.models.request.OrderRequest
|
||||
import com.tangem.datasource.api.pay.models.request.SetTangemPayEnabledRequest
|
||||
import com.tangem.datasource.api.pay.models.response.CustomerMeResponse
|
||||
import com.tangem.datasource.api.pay.models.response.OrderResponse
|
||||
import com.tangem.datasource.local.visa.TangemPayCardFrozenStateStore
|
||||
import com.tangem.datasource.local.visa.TangemPayStorage
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
|
|
@ -23,14 +24,11 @@ import com.tangem.domain.tangempay.TangemPayAnalyticsEvents
|
|||
import com.tangem.domain.visa.error.VisaApiError
|
||||
import com.tangem.domain.visa.model.TangemPayCardFrozenState
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val VALID_STATUS = "valid"
|
||||
private const val TAG = "TangemPay: OnboardingRepository"
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
internal class DefaultOnboardingRepository @Inject constructor(
|
||||
|
|
@ -109,25 +107,31 @@ internal class DefaultOnboardingRepository @Inject constructor(
|
|||
return lastFetchedCustomerInfoMap[userWalletId]
|
||||
}
|
||||
|
||||
override suspend fun createOrder(userWalletId: UserWalletId) = withContext(dispatcherProvider.io) {
|
||||
launch {
|
||||
catch(
|
||||
block = {
|
||||
val walletAddress = requestHelper.getCustomerWalletAddress(userWalletId)
|
||||
val response = requestHelper.performRequest(userWalletId) { authHeader ->
|
||||
tangemPayApi.createOrder(authHeader, body = OrderRequest(walletAddress))
|
||||
}.getOrNull()
|
||||
override suspend fun createOrder(userWalletId: UserWalletId): Either<VisaApiError, String> =
|
||||
withContext(dispatcherProvider.io) {
|
||||
val existingOrderId = getOrderId(userWalletId)
|
||||
if (existingOrderId != null) {
|
||||
val orderStatus = requestHelper.performRequest(userWalletId) { authHeader ->
|
||||
tangemPayApi.getOrder(authHeader, existingOrderId)
|
||||
}.map { it.result?.status }.getOrNull()
|
||||
|
||||
val result = requireNotNull(response?.result)
|
||||
val customerWalletAddress = requireNotNull(result.data.customerWalletAddress)
|
||||
tangemPayStorage.storeOrderId(customerWalletAddress, result.id)
|
||||
},
|
||||
catch = {
|
||||
Timber.tag(TAG).e("createOrder: $it")
|
||||
},
|
||||
)
|
||||
if (orderStatus == OrderResponse.Result.Status.NEW ||
|
||||
orderStatus == OrderResponse.Result.Status.PROCESSING
|
||||
) {
|
||||
return@withContext existingOrderId.right()
|
||||
}
|
||||
}
|
||||
|
||||
val walletAddress = requestHelper.getCustomerWalletAddress(userWalletId)
|
||||
requestHelper.performRequest(userWalletId) { authHeader ->
|
||||
val data = OrderRequest.Data(customerWalletAddress = walletAddress)
|
||||
tangemPayApi.createOrder(authHeader, body = OrderRequest(data = data))
|
||||
}.map { response ->
|
||||
val result = requireNotNull(response.result)
|
||||
tangemPayStorage.storeOrderId(walletAddress, result.id)
|
||||
result.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getUserWallet(userWalletId: UserWalletId): UserWallet {
|
||||
return userWalletsListRepository.userWallets.value?.firstOrNull { it.walletId == userWalletId }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue