diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsActivity.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsActivity.kt index 2e85619934f..07cf4ce3a80 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsActivity.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentOptionsActivity.kt @@ -25,6 +25,7 @@ import com.stripe.android.paymentsheet.ui.AnimationConstants import com.stripe.android.paymentsheet.ui.BaseSheetActivity import com.stripe.android.paymentsheet.ui.PrimaryButton import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel +import java.security.InvalidParameterException /** * An `Activity` for selecting a payment option. @@ -70,13 +71,20 @@ internal class PaymentOptionsActivity : BaseSheetActivity() override val bottomSpacer: View by lazy { viewBinding.bottomSpacer } override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - val starterArgs = this.starterArgs if (starterArgs == null) { finish() return } + try { + starterArgs.config?.validate() + starterArgs.config?.appearance?.parseAppearance() + } catch (e: InvalidParameterException) { + finish() + return + } + + super.onCreate(savedInstanceState) starterArgs.statusBarColor?.let { window.statusBarColor = it diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PrimaryButton.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PrimaryButton.kt index 59181a3c905..75181f8b73a 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PrimaryButton.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PrimaryButton.kt @@ -35,7 +35,8 @@ internal class PrimaryButton @JvmOverloads constructor( attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : FrameLayout(context, attrs, defStyleAttr) { - private var defaultTintList: ColorStateList? = null + @VisibleForTesting + internal var defaultTintList: ColorStateList? = null private var state: State? = null private val animator = PrimaryButtonAnimator(context) @@ -88,8 +89,8 @@ internal class PrimaryButton @JvmOverloads constructor( viewBinding.lockIcon.imageTintList = ColorStateList.valueOf( primaryButtonStyle.getOnBackgroundColor(context) ) - backgroundTintList = tintList defaultTintList = tintList + backgroundTintList = tintList } override fun setBackgroundTintList(tintList: ColorStateList?) { diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsActivityTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsActivityTest.kt index 1a535c6025b..94b9107be60 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsActivityTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentOptionsActivityTest.kt @@ -3,7 +3,10 @@ package com.stripe.android.paymentsheet import android.app.Application import android.content.Context import android.content.Intent +import android.content.res.ColorStateList import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb import androidx.core.os.bundleOf import androidx.core.view.isVisible import androidx.lifecycle.SavedStateHandle @@ -380,6 +383,38 @@ class PaymentOptionsActivityTest { } } + @Test + fun `primary button appearance is set`() { + val scenario = activityScenario() + scenario.launch( + createIntent( + args = PAYMENT_OPTIONS_CONTRACT_ARGS.copy( + config = PaymentSheetFixtures.CONFIG_MINIMUM.copy( + appearance = PaymentSheet.Appearance( + primaryButton = PaymentSheet.PrimaryButton( + colorsLight = PaymentSheet.PrimaryButtonColors( + background = Color.Magenta, + onBackground = Color.Magenta, + border = Color.Magenta + ), + shape = PaymentSheet.PrimaryButtonShape(), + typography = PaymentSheet.PrimaryButtonTypography() + ) + ) + ) + ) + ) + ).use { + idleLooper() + it.onActivity { activity -> + assertThat(activity.viewBinding.continueButton.isVisible).isTrue() + assertThat(activity.viewBinding.continueButton.defaultTintList).isEqualTo( + ColorStateList.valueOf(Color.Magenta.toArgb()) + ) + } + } + } + private fun createIntent( args: PaymentOptionContract.Args = PAYMENT_OPTIONS_CONTRACT_ARGS ): Intent {