Skip to content

Commit

Permalink
Added Support for webMoney
Browse files Browse the repository at this point in the history
  • Loading branch information
AmniX committed Oct 17, 2024
1 parent 18866e4 commit 338a368
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal fun WebMoneyForm(
onValueChange = {
onWebMoneyDisplayDataChange(webMoneyDisplayData.copy(prepaidNumber = it))
},
error = webMoneyDisplayData.prepaidNumberError,
)
Spacer(modifier = Modifier.height(16.dp))
PrimaryButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit 338a368

Please sign in to comment.