From 24799458328e8b02f1dd45ac4781b58d2548144b Mon Sep 17 00:00:00 2001 From: amnix Date: Wed, 9 Oct 2024 16:30:06 +0900 Subject: [PATCH] Added RakutenPay Support --- .../sdk/ui/screens/payment/KomojuPaymentScreenModel.kt | 4 +++- .../kotlin/com/komoju/mobile/sdk/entities/Payment.kt | 2 ++ .../com/komoju/mobile/sdk/entities/PaymentRequest.kt | 1 + .../com/komoju/mobile/sdk/remote/dtos/PaymentRequestDto.kt | 6 ++++++ .../com/komoju/mobile/sdk/remote/mappers/PaymentMapper.kt | 7 +++++++ 5 files changed, 19 insertions(+), 1 deletion(-) 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 de5a474..07c02f1 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 @@ -129,6 +129,7 @@ internal class KomojuPaymentScreenModel(private val config: KomojuSDK.Configurat when (this) { is Payment.Konbini -> mutableRouter.value = Router.Replace(KomojuPaymentRoute.KonbiniAwaitingPayment(config, payment = this)) is Payment.PayPay -> mutableRouter.value = Router.Handle(url = redirectURL) + is Payment.RakutenPay -> mutableRouter.value = Router.Handle(url = redirectURL) else -> Unit } } @@ -137,6 +138,7 @@ internal class KomojuPaymentScreenModel(private val config: KomojuSDK.Configurat is PaymentMethod.CreditCard -> state.value.creditCardDisplayData.validate() is PaymentMethod.Konbini -> state.value.konbiniDisplayData.validate(state.value.commonDisplayData) is PaymentMethod.PayPay -> true // No input required + is PaymentMethod.RakutenPay -> true // No input required else -> false } @@ -210,7 +212,7 @@ internal class KomojuPaymentScreenModel(private val config: KomojuSDK.Configurat is PaymentMethod.Paidy -> TODO() is PaymentMethod.PayEasy -> TODO() is PaymentMethod.PayPay -> PaymentRequest.PayPay(paymentMethod = this) - is PaymentMethod.RakutenPay -> TODO() + is PaymentMethod.RakutenPay -> PaymentRequest.RakutenPay(paymentMethod = this) is PaymentMethod.WebMoney -> TODO() } diff --git a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/entities/Payment.kt b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/entities/Payment.kt index 10abbe0..cb63a61 100644 --- a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/entities/Payment.kt +++ b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/entities/Payment.kt @@ -21,6 +21,8 @@ sealed interface Payment { data class CreditCard(override val status: PaymentStatus, override val amount: String, override val currency: String) : Payment + data class RakutenPay(override val status: PaymentStatus, override val amount: String, override val currency: String, val redirectURL: String) : Payment + data class Error(val code: String, val message: String, override val amount: String, override val currency: String) : Payment { override val status: PaymentStatus = PaymentStatus.EXPIRED } 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 9db8146..f44f60b 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 @@ -8,4 +8,5 @@ sealed interface PaymentRequest { data class Konbini(override val paymentMethod: PaymentMethod.Konbini, val konbiniBrand: KonbiniBrand, val email: String) : PaymentRequest data class PayPay(override val paymentMethod: PaymentMethod.PayPay) : PaymentRequest + data class RakutenPay(override val paymentMethod: PaymentMethod.RakutenPay) : 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 93f68ea..0b9d9f1 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 @@ -20,6 +20,12 @@ internal data class PaymentRequestDto(@SerialName("payment_details") val payment type = "paypay", ), ) + + is PaymentRequest.RakutenPay -> PaymentRequestDto( + paymentDetails = PaymentDetails( + type = "rakutenpay", + ), + ) } } 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 a7d203a..b282bb5 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 @@ -36,6 +36,13 @@ internal object PaymentMapper { status = PaymentStatus.fromString(payment.status.orEmpty()), ) + "rakutenpay" -> Payment.RakutenPay( + amount = payment.amount.orEmpty(), + currency = payment.currency.orEmpty(), + redirectURL = payment.paymentDetails.redirectUrl.orEmpty(), + status = PaymentStatus.fromString(payment.status.orEmpty()), + ) + else -> error("Invalid payment type") } }