Skip to content

Commit

Permalink
PR feedback from #9287
Browse files Browse the repository at this point in the history
  • Loading branch information
simond-stripe committed Oct 18, 2024
1 parent 50a5783 commit 14dd986
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 46 deletions.
4 changes: 4 additions & 0 deletions connect-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

apply from: configs.androidApplication

apply plugin: 'com.google.devtools.ksp'
Expand Down Expand Up @@ -126,6 +128,8 @@ android {
freeCompilerArgs += [
"-opt-in=kotlinx.coroutines.FlowPreview",
"-Xcontext-receivers",
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:enableStrongSkippingMode=true"
]
if (gradle.ext.isCi) {
kotlinOptions.allWarningsAsErrors = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,12 @@ class EmbeddedComponentService {
}
}

@Serializable
data class FetchClientSecretResponse(
@SerialName("client_secret")
val clientSecret: String
)

@Serializable
data class GetAccountsResponse(
@SerialName("publishable_key")
val publishableKey: String,
@SerialName("available_merchants")
val availableMerchants: List<Merchant>
)

@Serializable
data class Merchant(
@SerialName("merchant_id")
val merchantId: String,
@SerialName("display_name")
val displayName: String
)

suspend fun <T : Any> Request.awaitModel(
serializer: DeserializationStrategy<T>
): Result<T, FuelError> {
val deserializer = object : Deserializable<T> {

override fun deserialize(response: Response): T {
println(response.toString())
val body = response.body().asString("application/json")
return Json.decodeFromString(serializer, body)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.stripe.android.connectsdk.example.networking

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class FetchClientSecretResponse(
@SerialName("client_secret")
val clientSecret: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.stripe.android.connectsdk.example.networking

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class GetAccountsResponse(
@SerialName("publishable_key")
val publishableKey: String,
@SerialName("available_merchants")
val availableMerchants: List<Merchant>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.stripe.android.connectsdk.example.networking

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class Merchant(
@SerialName("merchant_id")
val merchantId: String,
@SerialName("display_name")
val displayName: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ object ApplicationJsonHeaderInterceptor : FoldableRequestInterceptor {
}

object UserAgentHeader : FoldableRequestInterceptor {
private fun getUserAgent(): String {
val androidBrand = Build.BRAND
val androidDevice = Build.MODEL
val osVersion = Build.VERSION.SDK_INT
return buildString {
append("Stripe/ConnectSDKExample")
append(" (Android $androidBrand $androidDevice; (OS Version $osVersion))+")
append(" Version/${StripeSdkVersion.VERSION_NAME}")
private val userAgent: String
get() {
val androidBrand = Build.BRAND
val androidDevice = Build.MODEL
val osVersion = Build.VERSION.SDK_INT
return buildString {
append("Stripe/ConnectSDKExample")
append(" (Android $androidBrand $androidDevice; (OS Version $osVersion))+")
append(" Version/${StripeSdkVersion.VERSION_NAME}")
}
}
}

override fun invoke(next: RequestTransformer): RequestTransformer {
return { request ->
next(request.header("User-Agent", getUserAgent()))
next(request.header("User-Agent", userAgent))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.compose.ui.unit.dp
import com.stripe.android.connectsdk.example.networking.Merchant

@Composable
fun LaunchEmbeddedComponentsScreen(
fun EmbeddedComponentsLauncherScreen(
embeddedComponentName: String,
selectedAccount: Merchant?,
connectSDKAccounts: List<Merchant>,
Expand Down Expand Up @@ -59,7 +59,7 @@ fun LaunchEmbeddedComponentsScreen(
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun AccountSelector(
selectedAccount: Merchant? = null,
selectedAccount: Merchant?,
accounts: List<Merchant>,
onAccountSelected: (Merchant) -> Unit,
) {
Expand Down Expand Up @@ -87,7 +87,7 @@ fun AccountSelector(
expanded = false
}
) {
Text(text = account.displayName,)
Text(text = account.displayName)
}
}
}
Expand All @@ -96,8 +96,8 @@ fun AccountSelector(

@Preview(showBackground = true)
@Composable
fun LaunchEmbeddedComponentsScreenPreviewWithSelectedAccount() {
LaunchEmbeddedComponentsScreen(
private fun LaunchEmbeddedComponentsScreenPreviewWithSelectedAccount() {
EmbeddedComponentsLauncherScreen(
embeddedComponentName = "Payouts",
selectedAccount = Merchant(merchantId = "1", displayName = "Selected Merchant"),
connectSDKAccounts = listOf(
Expand All @@ -112,8 +112,8 @@ fun LaunchEmbeddedComponentsScreenPreviewWithSelectedAccount() {

@Preview(showBackground = true)
@Composable
fun LaunchEmbeddedComponentsScreenPreviewWithNoSelectedAccount() {
LaunchEmbeddedComponentsScreen(
private fun LaunchEmbeddedComponentsScreenPreviewWithNoSelectedAccount() {
EmbeddedComponentsLauncherScreen(
embeddedComponentName = "Payouts",
selectedAccount = null,
connectSDKAccounts = listOf(
Expand All @@ -128,8 +128,8 @@ fun LaunchEmbeddedComponentsScreenPreviewWithNoSelectedAccount() {

@Preview(showBackground = true)
@Composable
fun LaunchEmbeddedComponentsScreenPreviewWithEmptyAccounts() {
LaunchEmbeddedComponentsScreen(
private fun LaunchEmbeddedComponentsScreenPreviewWithEmptyAccounts() {
EmbeddedComponentsLauncherScreen(
embeddedComponentName = "Payouts",
selectedAccount = Merchant(merchantId = "1", displayName = "Selected Merchant"),
connectSDKAccounts = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.stripe.android.connectsdk.PrivateBetaConnectSDK
import com.stripe.android.connectsdk.example.ConnectSdkExampleTheme
import com.stripe.android.connectsdk.example.MainContent
import com.stripe.android.connectsdk.example.R
import com.stripe.android.connectsdk.example.ui.common.LaunchEmbeddedComponentsScreen
import com.stripe.android.connectsdk.example.ui.common.EmbeddedComponentsLauncherScreen

class AccountOnboardingExampleActivity : FragmentActivity() {

Expand All @@ -47,7 +47,7 @@ class AccountOnboardingExampleActivity : FragmentActivity() {
if (isAccountOnboardingVisible) {
AccountOnboardingComponentWrapper(onDismiss = { isAccountOnboardingVisible = false })
} else {
LaunchEmbeddedComponentsScreen(
EmbeddedComponentsLauncherScreen(
embeddedComponentName = stringResource(R.string.account_onboarding),
selectedAccount = accountOnboardingExampleState.selectedAccount,
connectSDKAccounts = accounts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.stripe.android.connectsdk.PrivateBetaConnectSDK
import com.stripe.android.connectsdk.example.ConnectSdkExampleTheme
import com.stripe.android.connectsdk.example.MainContent
import com.stripe.android.connectsdk.example.R
import com.stripe.android.connectsdk.example.ui.common.LaunchEmbeddedComponentsScreen
import com.stripe.android.connectsdk.example.ui.common.EmbeddedComponentsLauncherScreen

class PayoutsExampleActivity : FragmentActivity() {

Expand All @@ -47,7 +47,7 @@ class PayoutsExampleActivity : FragmentActivity() {
if (isPayoutsVisible) {
PayoutsComponentWrapper(onDismiss = { isPayoutsVisible = false })
} else {
LaunchEmbeddedComponentsScreen(
EmbeddedComponentsLauncherScreen(
embeddedComponentName = stringResource(R.string.payouts),
selectedAccount = payoutsExampleState.selectedAccount,
connectSDKAccounts = accounts,
Expand Down

0 comments on commit 14dd986

Please sign in to comment.