From 7cc708433b51d05946e444b52ca8edd5f420f0d6 Mon Sep 17 00:00:00 2001 From: Aman tonk Date: Thu, 17 Oct 2024 10:20:17 +0900 Subject: [PATCH] Added back LinePay, Because Why not :) (#51) --- .../ui/screens/payment/KomojuPaymentScreen.kt | 2 ++ .../payment/composables/CreditCardForm.kt | 3 --- .../payment/composables/OffSitePayForm.kt | 3 +++ .../payment/composables/PaymentMethodsRow.kt | 2 ++ .../main/res/drawable/komoju_ic_linepay.xml | 15 +++++++++++++++ .../sdk/remote/mappers/PaymentMapper.kt | 19 ++++++------------- .../sdk/remote/mappers/SessionMapper.kt | 19 +++++++------------ .../mobile/sdk/types/OffSitePaymentType.kt | 8 ++++++++ 8 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 android/src/main/res/drawable/komoju_ic_linepay.xml diff --git a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentScreen.kt b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentScreen.kt index 25f5a68..60f864a 100644 --- a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentScreen.kt +++ b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/KomojuPaymentScreen.kt @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll @@ -69,6 +70,7 @@ internal data class KomojuPaymentScreen(private val sdkConfiguration: KomojuSDK. selectedPaymentMethod = uiState.selectedPaymentMethod, onSelected = screenViewModel::onNewPaymentMethodSelected, ) + Spacer(modifier = Modifier.height(8.dp)) uiState.selectedPaymentMethod?.let { paymentMethod -> PaymentMethodForm( paymentMethod = paymentMethod, diff --git a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/CreditCardForm.kt b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/CreditCardForm.kt index 957489e..215ac98 100644 --- a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/CreditCardForm.kt +++ b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/CreditCardForm.kt @@ -25,7 +25,6 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment -import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.onGloballyPositioned @@ -58,7 +57,6 @@ import com.komoju.android.sdk.utils.CreditCardUtils.makeExpirationFilter import com.komoju.android.sdk.utils.testID import com.komoju.mobile.sdk.entities.PaymentMethod -@OptIn(ExperimentalComposeUiApi::class) @Composable internal fun CreditCardForm( creditCard: PaymentMethod.CreditCard, @@ -76,7 +74,6 @@ internal fun CreditCardForm( } val dividerColor = if (creditCardDisplayData.creditCardError == null) Gray200 else Red600 Column { - Spacer(modifier = Modifier.height(8.dp)) TextField( creditCardDisplayData.fullNameOnCard, titleKey = "CARD_HOLDER_NAME", diff --git a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/OffSitePayForm.kt b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/OffSitePayForm.kt index 7ab9866..bb026bd 100644 --- a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/OffSitePayForm.kt +++ b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/OffSitePayForm.kt @@ -39,6 +39,7 @@ internal fun OffSitePayForm(paymentMethod: PaymentMethod.OffSitePayment, onPayBu OffSitePaymentType.MER_PAY -> "PAYMENT_VIA_MER_PAY" OffSitePaymentType.PAY_PAY -> "PAYMENT_VIA_PAY_PAY" OffSitePaymentType.RAKUTEN_PAY -> "PAYMENT_VIA_RAKUTEN" + OffSitePaymentType.LINE_PAY -> "PAYMENT_VIA_LINE_PAY" else -> null } } @@ -50,6 +51,7 @@ internal fun OffSitePayForm(paymentMethod: PaymentMethod.OffSitePayment, onPayBu OffSitePaymentType.MER_PAY -> "MER_PAY_REDIRECT_MESSAGE" OffSitePaymentType.PAY_PAY -> "PAY_PAY_REDIRECT_MESSAGE" OffSitePaymentType.RAKUTEN_PAY -> "RAKUTEN_REDIRECT_MESSAGE" + OffSitePaymentType.LINE_PAY -> "LINE_PAY_REDIRECT_MESSAGE" else -> null } } @@ -61,6 +63,7 @@ internal fun OffSitePayForm(paymentMethod: PaymentMethod.OffSitePayment, onPayBu OffSitePaymentType.MER_PAY -> "CONTINUE_TO_MER_PAY" OffSitePaymentType.PAY_PAY -> "CONTINUE_TO_PAY_PAY" OffSitePaymentType.RAKUTEN_PAY -> "CONTINUE_TO_RAKUTEN" + OffSitePaymentType.LINE_PAY -> "CONTINUE_TO_LINE_PAY" else -> null } } diff --git a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/PaymentMethodsRow.kt b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/PaymentMethodsRow.kt index 1771f55..50a9c9a 100644 --- a/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/PaymentMethodsRow.kt +++ b/android/src/main/java/com/komoju/android/sdk/ui/screens/payment/composables/PaymentMethodsRow.kt @@ -65,6 +65,8 @@ private val PaymentMethod.displayIcon OffSitePaymentType.MER_PAY -> R.drawable.komoju_ic_merpay OffSitePaymentType.PAY_PAY -> R.drawable.komoju_ic_paypay OffSitePaymentType.RAKUTEN_PAY -> R.drawable.komoju_ic_rakuten_pay + OffSitePaymentType.LINE_PAY -> R.drawable.komoju_ic_linepay + OffSitePaymentType.UNKNOWN -> R.drawable.komoju_ic_credit_card } is PaymentMethod.BankTransfer -> R.drawable.komoju_ic_bank_transfer is PaymentMethod.BitCash -> R.drawable.komoju_ic_bitcash diff --git a/android/src/main/res/drawable/komoju_ic_linepay.xml b/android/src/main/res/drawable/komoju_ic_linepay.xml new file mode 100644 index 0000000..4526151 --- /dev/null +++ b/android/src/main/res/drawable/komoju_ic_linepay.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file 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 0d2fae0..0a29215 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 @@ -29,20 +29,13 @@ internal object PaymentMapper { currency = payment.currency.orEmpty(), status = PaymentStatus.fromString(payment.status.orEmpty()), ) - - OffSitePaymentType.RAKUTEN_PAY.id, - OffSitePaymentType.AU_PAY.id, - OffSitePaymentType.ALI_PAY.id, - OffSitePaymentType.MER_PAY.id, - OffSitePaymentType.PAY_PAY.id, - -> Payment.OffSitePayment( - amount = payment.amount.orEmpty(), - currency = payment.currency.orEmpty(), - redirectURL = payment.paymentDetails.redirectUrl.orEmpty(), - status = PaymentStatus.fromString(payment.status.orEmpty()), - type = type, + in OffSitePaymentType.supportedTypes -> Payment.OffSitePayment( + amount = payment?.amount.orEmpty(), + currency = payment?.currency.orEmpty(), + redirectURL = payment?.paymentDetails?.redirectUrl.orEmpty(), + status = PaymentStatus.fromString(payment?.status.orEmpty()), + type = type.orEmpty(), ) - else -> error("Invalid payment type") } } diff --git a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/mappers/SessionMapper.kt b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/mappers/SessionMapper.kt index 3597f8b..3cdb4f2 100644 --- a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/mappers/SessionMapper.kt +++ b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/remote/mappers/SessionMapper.kt @@ -48,19 +48,14 @@ internal object SessionMapper { }.orEmpty(), ) - OffSitePaymentType.PAY_PAY.id, - OffSitePaymentType.MER_PAY.id, - OffSitePaymentType.ALI_PAY.id, - OffSitePaymentType.AU_PAY.id, - OffSitePaymentType.RAKUTEN_PAY.id, - -> PaymentMethod.OffSitePayment( - hashedGateway = paymentMethod.hashedGateway.orEmpty(), - exchangeRate = paymentMethod.exchangeRate ?: 1.0, - currency = paymentMethod.currency.orEmpty(), + in OffSitePaymentType.supportedTypes -> PaymentMethod.OffSitePayment( + hashedGateway = paymentMethod?.hashedGateway.orEmpty(), + exchangeRate = paymentMethod?.exchangeRate ?: 1.0, + currency = paymentMethod?.currency.orEmpty(), amount = (response.amount ?: 0).toString(), - additionalFields = paymentMethod.additionalFields?.filterNotNull().orEmpty(), - displayName = i18nTexts[paymentMethodType], - type = OffSitePaymentType.entries.first { it.id == paymentMethodType }, + additionalFields = paymentMethod?.additionalFields?.filterNotNull().orEmpty(), + displayName = i18nTexts[paymentMethodType.toString()], + type = OffSitePaymentType.fromId(paymentMethodType.orEmpty()), ) "bank_transfer" -> PaymentMethod.BankTransfer( diff --git a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/types/OffSitePaymentType.kt b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/types/OffSitePaymentType.kt index 249be8e..6f8f332 100644 --- a/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/types/OffSitePaymentType.kt +++ b/shared/src/commonMain/kotlin/com/komoju/mobile/sdk/types/OffSitePaymentType.kt @@ -6,4 +6,12 @@ enum class OffSitePaymentType(val id: String) { MER_PAY("merpay"), PAY_PAY("paypay"), RAKUTEN_PAY("rakutenpay"), + LINE_PAY("linepay"), + UNKNOWN(""), + ; + + companion object { + val supportedTypes = entries.map { it.id } + fun fromId(id: String): OffSitePaymentType = entries.find { it.id == id } ?: UNKNOWN + } }