Skip to content

Commit

Permalink
[Do NOT MERGE] Added a Non functional google Pay Button for demo purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
AmniX committed Oct 3, 2024
1 parent 6538bad commit 2f53c87
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
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 @@ -36,6 +36,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,22 +6,33 @@ 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 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.ui.composables.ThemedCircularProgressIndicator
Expand All @@ -32,6 +43,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 @@ -51,6 +81,23 @@ 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 = 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.6.1"
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

0 comments on commit 2f53c87

Please sign in to comment.