diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundActivity.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundActivity.kt index 2ffc8db3487..3661559dce2 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundActivity.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundActivity.kt @@ -48,6 +48,7 @@ import com.stripe.android.customersheet.ExperimentalCustomerSheetApi import com.stripe.android.customersheet.rememberCustomerSheet import com.stripe.android.paymentsheet.PaymentSheet import com.stripe.android.paymentsheet.example.R +import com.stripe.android.paymentsheet.example.samples.ui.customersheet.playground.CustomerSheetPlaygroundViewAction.UpdateMerchantCountryCode import com.stripe.android.paymentsheet.example.samples.ui.shared.MultiToggleButton import com.stripe.android.paymentsheet.example.samples.ui.shared.PaymentSheetExampleTheme import com.stripe.android.paymentsheet.example.utils.rememberDrawablePainter @@ -535,6 +536,23 @@ class CustomerSheetPlaygroundActivity : AppCompatActivity() { } ) } + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 2.dp) + ) { + Text( + text = "Merchant Country", + color = MaterialTheme.colors.onBackground, + ) + MultiToggleButton( + currentSelection = configurationState.merchantCountry, + toggleStates = listOf("US", "FR"), + onToggleChange = { viewActionHandler(UpdateMerchantCountryCode(it)) }, + ) + } } } diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundConfigurationState.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundConfigurationState.kt index cca8990d3c9..c02fb3a6864 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundConfigurationState.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundConfigurationState.kt @@ -10,5 +10,11 @@ data class CustomerSheetPlaygroundConfigurationState( val attachDefaultBillingAddress: Boolean = true, val achEnabled: Boolean = true, val billingCollectionConfiguration: PaymentSheet.BillingDetailsCollectionConfiguration = - PaymentSheet.BillingDetailsCollectionConfiguration() -) + PaymentSheet.BillingDetailsCollectionConfiguration(), + val merchantCountry: String = "US", + val currency: String = "usd", +) { + + val customerId: String + get() = if (isExistingCustomer) "returning" else "new" +} diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewAction.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewAction.kt index b1ca3121789..65f584c448f 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewAction.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewAction.kt @@ -11,4 +11,5 @@ sealed class CustomerSheetPlaygroundViewAction { data class UpdateBillingEmailCollection(val value: String) : CustomerSheetPlaygroundViewAction() data class UpdateBillingPhoneCollection(val value: String) : CustomerSheetPlaygroundViewAction() data class UpdateBillingAddressCollection(val value: String) : CustomerSheetPlaygroundViewAction() + data class UpdateMerchantCountryCode(val code: String) : CustomerSheetPlaygroundViewAction() } diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewModel.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewModel.kt index bd11cab0bdc..8decce888ff 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewModel.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/customersheet/playground/CustomerSheetPlaygroundViewModel.kt @@ -147,19 +147,19 @@ class CustomerSheetPlaygroundViewModel( ) init { - viewModelScope.launch { + viewModelScope.launch(Dispatchers.IO) { fetchClientSecret() } } private suspend fun fetchClientSecret( - customerId: String = "returning" + customerId: String = configurationState.value.customerId, ): Result { val request = PlaygroundCustomerSheetRequest( customerId = customerId, mode = "payment", - merchantCountryCode = "US", - currency = "usd", + merchantCountryCode = configurationState.value.merchantCountry, + currency = configurationState.value.currency, ) val requestBody = Json.encodeToString( @@ -240,6 +240,9 @@ class CustomerSheetPlaygroundViewModel( updateBillingNameCollection(viewAction.value) is CustomerSheetPlaygroundViewAction.UpdateBillingPhoneCollection -> updateBillingPhoneCollection(viewAction.value) + is CustomerSheetPlaygroundViewAction.UpdateMerchantCountryCode -> { + updateMerchantCountry(viewAction.code) + } } } @@ -301,14 +304,8 @@ class CustomerSheetPlaygroundViewModel( ) } - viewModelScope.launch { - fetchClientSecret( - if (configurationState.value.isExistingCustomer) { - "returning" - } else { - "new" - } - ) + viewModelScope.launch(Dispatchers.IO) { + fetchClientSecret() } } @@ -389,6 +386,21 @@ class CustomerSheetPlaygroundViewModel( } } + private fun updateMerchantCountry(code: String) { + val currency = if (code == "FR") "eur" else "usd" + + updateConfiguration { + it.copy( + merchantCountry = code, + currency = currency, + ) + } + + viewModelScope.launch(Dispatchers.IO) { + fetchClientSecret() + } + } + private inline fun updateViewState(transform: (T) -> T) { (_viewState.value as? T)?.let { _viewState.update {