diff --git a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentScreenModel.kt b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentScreenModel.kt index d44e220..1322604 100644 --- a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentScreenModel.kt +++ b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentScreenModel.kt @@ -216,10 +216,27 @@ internal class KomojuPaymentScreenModel(private val config: KomojuSDK.Configurat is PaymentMethod.Paidy -> state.value.paidyDisplayData.validate() is PaymentMethod.NetCash -> state.value.netCashDisplayData.validate() is PaymentMethod.BitCash -> state.value.bitCashDisplayData.validate() + is PaymentMethod.WebMoney -> state.value.webMoneyDisplayData.validate() is PaymentMethod.OffSitePayment -> true // No input required for Offsite payment else -> false } + private fun WebMoneyDisplayData.validate(): Boolean{ + val prepaidNumberError = when { + prepaidNumber.isBlank() -> "The entered prepaid number cannot be empty" + prepaidNumber.length != 16 -> "The entered prepaid number is not valid" + else -> null + } + mutableState.update { + it.copy( + webMoneyDisplayData = it.webMoneyDisplayData.copy( + prepaidNumberError = prepaidNumberError, + ), + ) + } + return prepaidNumberError == null + } + private fun BitCashDisplayData.validate(): Boolean { val idError = when { bitCashId.isBlank() -> "The entered net cash id cannot be empty" @@ -349,7 +366,10 @@ internal class KomojuPaymentScreenModel(private val config: KomojuSDK.Configurat phoneNumber = state.value.paidyDisplayData.phoneNumber, ) is PaymentMethod.PayEasy -> TODO() - is PaymentMethod.WebMoney -> TODO() + is PaymentMethod.WebMoney -> PaymentRequest.WebMoney( + paymentMethod = this, + prepaidNumber = state.value.webMoneyDisplayData.prepaidNumber, + ) is PaymentMethod.OffSitePayment -> PaymentRequest.OffSitePaymentRequest(this) } diff --git a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentUIState.kt b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentUIState.kt index 89c411c..ba53c56 100644 --- a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentUIState.kt +++ b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentUIState.kt @@ -55,7 +55,7 @@ internal data class BitCashDisplayData(val bitCashId: String = String.empty, val internal data class NetCashDisplayData(val netCashId: String = String.empty, val netCashError: String? = null) -internal data class WebMoneyDisplayData(val prepaidNumber: String = String.empty) +internal data class WebMoneyDisplayData(val prepaidNumber: String = String.empty, val prepaidNumberError: String? = null) internal data class PaidyDisplayData( val fullName: String = String.empty, diff --git a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/WebMoneyForm.kt b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/WebMoneyForm.kt index 0f29bbe..56b1dcd 100644 --- a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/WebMoneyForm.kt +++ b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/WebMoneyForm.kt @@ -38,6 +38,7 @@ internal fun WebMoneyForm( onValueChange = { onWebMoneyDisplayDataChange(webMoneyDisplayData.copy(prepaidNumber = it)) }, + error = webMoneyDisplayData.prepaidNumberError, ) Spacer(modifier = Modifier.height(16.dp)) PrimaryButton( diff --git a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/entities/PaymentRequest.kt b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/entities/PaymentRequest.kt index e124d3e..23f3459 100644 --- a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/entities/PaymentRequest.kt +++ b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/entities/PaymentRequest.kt @@ -10,4 +10,5 @@ sealed interface PaymentRequest { data class OffSitePaymentRequest(override val paymentMethod: PaymentMethod.OffSitePayment) : PaymentRequest data class NetCash(override val paymentMethod: PaymentMethod.NetCash, val netCashId: String) : PaymentRequest data class BitCash(override val paymentMethod: PaymentMethod.BitCash, val bitCashId: String) : PaymentRequest + data class WebMoney(override val paymentMethod: PaymentMethod.WebMoney, val prepaidNumber: String) : PaymentRequest } diff --git a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/dtos/PaymentRequestDto.kt b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/dtos/PaymentRequestDto.kt index 461a285..68f357e 100644 --- a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/dtos/PaymentRequestDto.kt +++ b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/dtos/PaymentRequestDto.kt @@ -42,6 +42,13 @@ internal data class PaymentRequestDto(@SerialName("payment_details") val payment prepaidNumber = paymentRequest.bitCashId, ), ) + + is PaymentRequest.WebMoney -> PaymentRequestDto( + paymentDetails = PaymentDetails( + type = "bit_cash", + prepaidNumber = paymentRequest.prepaidNumber, + ), + ) } } diff --git a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/mappers/PaymentMapper.kt b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/mappers/PaymentMapper.kt index ff39912..f9f14ca 100644 --- a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/mappers/PaymentMapper.kt +++ b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/mappers/PaymentMapper.kt @@ -38,7 +38,7 @@ internal object PaymentMapper { type = type.orEmpty(), ) - "net_cash", "bit_cash" -> Payment.Completed( + "net_cash", "bit_cash", "web_money" -> Payment.Completed( amount = payment.amount.orEmpty(), currency = payment.currency.orEmpty(), status = PaymentStatus.fromString(payment.status.orEmpty()),