Skip to content

Commit

Permalink
1941
Browse files Browse the repository at this point in the history
  • Loading branch information
Velkonost committed Feb 22, 2024
1 parent b15859c commit 7b80586
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import dev.icerock.moko.resources.compose.colorResource
fun AppWebView(
modifier: Modifier = Modifier,
link: String?,
sheetGesturesEnabled: Boolean = true,
sheetState: ModalBottomSheetState
) {

ModalBottomSheetLayout(
sheetState = sheetState,
sheetGesturesEnabled = sheetGesturesEnabled,
sheetShape = RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp),
sheetBackgroundColor = colorResource(resource = SharedR.colors.main_background),
sheetContent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fun AreaDetailContent(
)
}
} else {
Loader(size = 32)
Loader(size = 32.dp)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.rememberLottieComposition
import com.velkonost.getbetter.android.features.subscription.components.OffersSheet
import com.velkonost.getbetter.core.compose.components.AppButton
import com.velkonost.getbetter.core.compose.components.webview.AppWebView
import com.velkonost.getbetter.shared.features.subscription.presentation.SubscriptionViewModel
import com.velkonost.getbetter.shared.features.subscription.presentation.contract.SubscriptionAction
import com.velkonost.getbetter.shared.resources.SharedR
Expand Down Expand Up @@ -77,6 +78,11 @@ fun SubscriptionScreen(
skipHalfExpanded = true,
)

val webViewSheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
skipHalfExpanded = true,
)

LaunchedEffect(Unit) {
scope.launch {
delay(500)
Expand Down Expand Up @@ -250,8 +256,31 @@ fun SubscriptionScreen(
modalSheetState = offersSheetState,
itemClick = {
viewModel.dispatch(SubscriptionAction.SubscriptionItemClick(it))
},
purchaseClick = {
viewModel.dispatch(SubscriptionAction.SubscriptionPurchaseClick)
}
)

AppWebView(
link = state.paymentUrl,
sheetState = webViewSheetState,
sheetGesturesEnabled = false
)

}

LaunchedEffect(state.paymentUrl) {

if (!state.paymentUrl.isNullOrEmpty()) {
scope.launch {
webViewSheetState.show()
}
}

scope.launch {
offersSheetState.hide()
}
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.velkonost.getbetter.android.features.subscription.components

import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand Down Expand Up @@ -39,13 +36,6 @@ import com.velkonost.getbetter.shared.resources.SharedR
import dev.icerock.moko.resources.compose.colorResource
import dev.icerock.moko.resources.compose.painterResource
import dev.icerock.moko.resources.compose.stringResource
import ru.yoomoney.sdk.kassa.payments.Checkout
import ru.yoomoney.sdk.kassa.payments.checkoutParameters.Amount
import ru.yoomoney.sdk.kassa.payments.checkoutParameters.PaymentMethodType
import ru.yoomoney.sdk.kassa.payments.checkoutParameters.PaymentParameters
import ru.yoomoney.sdk.kassa.payments.checkoutParameters.SavePaymentMethod
import java.math.BigDecimal
import java.util.Currency

@OptIn(ExperimentalMaterialApi::class)
@Composable
Expand All @@ -54,14 +44,10 @@ fun OffersSheet(
modalSheetState: ModalBottomSheetState,
items: List<SubscriptionType>,
selectedItem: SubscriptionType,
itemClick: (SubscriptionType) -> Unit
itemClick: (SubscriptionType) -> Unit,
purchaseClick: () -> Unit
) {

val paymentLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) { result: ActivityResult ->
}

val context = LocalContext.current

ModalBottomSheetLayout(
Expand Down Expand Up @@ -110,27 +96,7 @@ fun OffersSheet(
modifier = modifier.padding(top = 32.dp),
labelText = stringResource(resource = SharedR.strings.subscription_confirm),
isLoading = false,
onClick = {
val paymentParameters = PaymentParameters(
amount = Amount(BigDecimal.TEN, Currency.getInstance("RUB")),
title = "Название товара",
subtitle = "Описание товара",
clientApplicationKey = "live_MzMxMjA5lf8FLM_nMtwUESA8dc8wrvO3X4rtmPgTdng", // ключ для клиентских приложений из личного кабинета ЮKassa (https://yookassa.ru/my/api-keys-settings)
shopId = "331209", // идентификатор магазина ЮKassa
paymentMethodTypes = setOf(
PaymentMethodType.BANK_CARD,
PaymentMethodType.SBERBANK,
PaymentMethodType.SBP,
PaymentMethodType.YOO_MONEY
),
savePaymentMethod = SavePaymentMethod.OFF, // флаг выключенного сохранения платежного метода,
authCenterClientId = "ej2j4fcjn0p7va4nqtj28viqn9gn85mb", // идентификатор, полученный при регистрации приложения на сайте https://yookassa.ru
// userPhoneNumber = "+79041234567", // номер телефона пользователя. Используется для автозаполнения поля при оплате через SberPay. Поддерживаемый формат данных: "+7XXXXXXXXXX".
)
val intent =
Checkout.createTokenizeIntent(context, paymentParameters)
paymentLauncher.launch(intent)
}
onClick = purchaseClick
)
Spacer(modifier.weight(1f))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ internal constructor(
}

private fun checkSubscription() {
emit(viewState.value.copy(paymentUrl = null))

launchJob {
checkSubscriptionUseCase() collectAndProcess {
onSuccess { subscription ->
Expand Down

0 comments on commit 7b80586

Please sign in to comment.