Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do NOT MERGE] Added a Non functional google Pay Button for demo purpose #25

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ dependencies {
implementation(libs.voyager.navigator)
implementation(libs.voyager.screenModel)
implementation(libs.voyager.transitions)
implementation(libs.compose.pay.button)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
Expand Down
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
<data android:scheme="@string/komoju_consumer_app_scheme" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal class KomojuPaymentViewModel(internal val configuration: KomojuSDK.Conf
amount = deeplinkEntity.amount,
currency = deeplinkEntity.currency,
)

DeeplinkEntity.Verify.BySessionId -> KomojuPaymentRoute.ProcessPayment.ProcessType.Session
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,38 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import cafe.adriel.voyager.core.model.rememberScreenModel
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.google.pay.button.ButtonTheme
import com.google.pay.button.ButtonType
import com.google.pay.button.PayButton
import com.komoju.android.sdk.KomojuSDK
import com.komoju.android.sdk.R
import com.komoju.android.sdk.navigation.paymentResultScreenModel
import com.komoju.android.sdk.ui.composables.ThemedCircularProgressIndicator
import com.komoju.android.sdk.ui.screens.RouterEffect
import com.komoju.android.sdk.ui.screens.payment.composables.PaymentMethodForm
Expand All @@ -32,6 +46,25 @@ import com.komoju.android.sdk.ui.screens.payment.composables.PaymentSheetHandle
import com.komoju.android.sdk.ui.theme.LocalI18nTexts
import kotlinx.parcelize.Parcelize

val allowedPaymentMethods = """
[
{
"type": "CARD",
"parameters": {
"allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],
"allowedCardNetworks": ["AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA"]
},
"tokenizationSpecification": {
"type": "PAYMENT_GATEWAY",
"parameters": {
"gateway": "example",
"gatewayMerchantId": "exampleGatewayMerchantId"
}
}
}
]
""".trimIndent()

@Parcelize
internal data class KomojuPaymentScreen(private val sdkConfiguration: KomojuSDK.Configuration) :
Screen,
Expand All @@ -40,6 +73,7 @@ internal data class KomojuPaymentScreen(private val sdkConfiguration: KomojuSDK.
override fun Content() {
val screenViewModel = rememberScreenModel { KomojuPaymentScreenModel(sdkConfiguration) }
val uiState by screenViewModel.state.collectAsStateWithLifecycle()
val resultScreenModel = LocalNavigator.currentOrThrow.paymentResultScreenModel()
LaunchedEffect(sdkConfiguration.sessionId) {
screenViewModel.init()
}
Expand All @@ -51,6 +85,26 @@ internal data class KomojuPaymentScreen(private val sdkConfiguration: KomojuSDK.
PaymentSheetHandle(LocalI18nTexts.current["PAYMENT_OPTIONS"], onCloseClicked = {
screenViewModel.onCloseClicked()
})
PayButton(
modifier = Modifier
.testTag("payButton")
.fillMaxWidth().padding(12.dp),
onClick = {
resultScreenModel.setResult(KomojuSDK.PaymentResult(isSuccessFul = true))
screenViewModel.onGooglePayButtonClicked()
},
allowedPaymentMethods = allowedPaymentMethods,
theme = ButtonTheme.Dark,
type = ButtonType.Pay,
radius = 8.dp,
)
Row(modifier = Modifier.padding(12.dp), verticalAlignment = Alignment.CenterVertically) {
HorizontalDivider(modifier = Modifier.height(1.dp).weight(1f))
Spacer(modifier = Modifier.width(12.dp))
Text(LocalI18nTexts.current["Or pay using"], fontSize = 12.sp)
Spacer(modifier = Modifier.width(12.dp))
HorizontalDivider(modifier = Modifier.height(1.dp).weight(1f))
}
PaymentMethodsRow(
paymentMethods = uiState.session!!.paymentMethods,
selectedPaymentMethod = uiState.selectedPaymentMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import com.komoju.mobile.sdk.entities.SecureTokenResponse.Status.OK
import com.komoju.mobile.sdk.entities.SecureTokenResponse.Status.SKIPPED
import com.komoju.mobile.sdk.entities.SecureTokenResponse.Status.UNKNOWN
import com.komoju.mobile.sdk.remote.apis.KomojuRemoteApi
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -217,4 +219,12 @@ internal class KomojuPaymentScreenModel(private val config: KomojuSDK.Configurat
fun onCloseClicked() {
mutableRouter.pop()
}

fun onGooglePayButtonClicked() {
mutableState.update { it.copy(isLoading = true) }
screenModelScope.launch {
delay(3.seconds)
mutableRouter.pop()
}
}
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[versions]
agp = "8.7.0"
composePayButton = "1.0.0"
kotlin = "2.0.20"
nexus-publish = "2.0.0"
android-minSdk = "24"
Expand Down Expand Up @@ -28,6 +29,7 @@ kotlinPlugin = "1.8.10"
dokka = "1.9.20"

[libraries]
compose-pay-button = { module = "com.google.pay.button:compose-pay-button", version.ref = "composePayButton" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin", version.ref = "nexus-publish" }
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private val englishTexts = """
"EXPIRY_DATE_ERROR": "Please input the full expiration date",
"CVV_ERROR": "Please input the CVV",
"EMAIL_ERROR": "Please enter a valid email address",
"OR_PAY_USING": "Or pay using",
"": ""
}
""".trimIndent().run {
Expand Down Expand Up @@ -191,6 +192,7 @@ private val japaneseTexts = """
"EXPIRY_DATE_ERROR": "有効期限を入力してください",
"CVV_ERROR": "CVVを入力してください",
"EMAIL_ERROR": "有効なメールアドレスを入力してください",
"OR_PAY_USING": "または、",
"": ""
}
""".trimIndent().run {
Expand Down