From c85aef0ee2eda1f981ca14ab2a0c255d7f43d149 Mon Sep 17 00:00:00 2001 From: jameswoo-stripe <99316447+jameswoo-stripe@users.noreply.github.com> Date: Mon, 12 Sep 2022 14:17:41 -0700 Subject: [PATCH] Fix issue with custom flow PaymentSheet getting clipped --- CHANGELOG.md | 2 ++ .../com/stripe/android/TestFieldPopulation.kt | 33 +++++++++++++++++++ .../android/test/core/PlaygroundTestDriver.kt | 8 ++++- .../android/test/core/TestParameters.kt | 4 ++- .../PaymentSheetPlaygroundActivity.kt | 4 ++- .../model/PlaygroundCheckoutModel.kt | 3 +- .../PaymentSheetPlaygroundViewModel.kt | 6 ++-- .../paymentsheet/ui/BaseSheetActivity.kt | 4 +++ .../paymentsheet/PaymentSheetActivityTest.kt | 23 +++++++++++++ 9 files changed, 81 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98a513fb1f3..136b1af8f37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ match new brand guidelines. * [FIXED][5480](https://github.com/stripe/stripe-android/pull/5480) `FlowController` now correctly preserves the previously selected payment method for guests. +* [FIXED][5545](https://github.com/stripe/stripe-android/pull/5545) Fix an issue where custom flow + PaymentSheet UI would have the bottom of the form cut off ## 20.11.0 - 2022-08-29 This release adds postal code validation for PaymentSheet and fixed a fileprovider naming bug for Identity. diff --git a/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/TestFieldPopulation.kt b/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/TestFieldPopulation.kt index 1c742c385a8..8aa6fd7c31a 100644 --- a/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/TestFieldPopulation.kt +++ b/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/TestFieldPopulation.kt @@ -6,8 +6,11 @@ import androidx.compose.ui.test.performTextInput import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice +import com.stripe.android.model.PaymentMethod +import com.stripe.android.test.core.AuthorizeAction import com.stripe.android.test.core.Automatic import com.stripe.android.test.core.Billing +import com.stripe.android.test.core.Browser import com.stripe.android.test.core.Currency import com.stripe.android.test.core.Customer import com.stripe.android.test.core.DelayedPMs @@ -90,6 +93,24 @@ class TestFieldPopulation { authorizationAction = null ) + private val bancontact = TestParameters( + lpmRepository.fromCode("bancontact")!!, + Customer.New, + LinkState.Off, + GooglePayState.Off, + Currency.EUR, + IntentType.Pay, + Billing.Off, + shipping = Shipping.Off, + delayed = DelayedPMs.Off, + automatic = Automatic.Off, + saveCheckboxValue = false, + saveForFutureUseCheckboxVisible = false, + useBrowser = Browser.Chrome, + authorizationAction = AuthorizeAction.Authorize, + merchantCountryCode = "GB" + ) + @Ignore("Testing of dropdowns is not yet supported") fun testDropdowns() { @@ -140,6 +161,18 @@ class TestFieldPopulation { } } + @Test + fun testSinglePaymentMethodWithoutGooglePayAndKeyboardInput() { + testDriver.confirmNewOrGuestComplete( + bancontact.copy( + supportedPaymentMethods = listOf(PaymentMethod.Type.Bancontact.code) + ) + ) { + composeTestRule.onNodeWithText("Full name") + .performTextInput("Jenny Rosen") + } + } + companion object { private val lpmRepository = LpmRepository( LpmRepository.LpmRepositoryArguments( diff --git a/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/test/core/PlaygroundTestDriver.kt b/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/test/core/PlaygroundTestDriver.kt index 969bf0ed555..de4d2df9aa5 100644 --- a/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/test/core/PlaygroundTestDriver.kt +++ b/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/test/core/PlaygroundTestDriver.kt @@ -120,7 +120,9 @@ class PlaygroundTestDriver( setup(testParameters) launchComplete() - selectors.paymentSelection.click() + if (testParameters.supportedPaymentMethods.size > 1) { + selectors.paymentSelection.click() + } // This takes a screenshot so that translation strings of placeholders // and labels and design can all be verified @@ -405,6 +407,10 @@ class PlaygroundTestDriver( PaymentSheetPlaygroundActivity.USE_SNAPSHOT_RETURNING_CUSTOMER_EXTRA, testParameters.snapshotReturningCustomer ) + intent.putExtra( + PaymentSheetPlaygroundActivity.SUPPORTED_PAYMENT_METHODS_EXTRA, + testParameters.supportedPaymentMethods.toTypedArray() + ) val scenario = ActivityScenario.launch(intent) scenario.onActivity { activity -> diff --git a/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/test/core/TestParameters.kt b/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/test/core/TestParameters.kt index 13848e10bc3..d8fca971b63 100644 --- a/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/test/core/TestParameters.kt +++ b/paymentsheet-example/src/androidTestDebug/java/com/stripe/android/test/core/TestParameters.kt @@ -1,5 +1,6 @@ package com.stripe.android.test.core +import com.stripe.android.model.PaymentMethodCode import com.stripe.android.paymentsheet.PaymentSheet import com.stripe.android.ui.core.forms.resources.LpmRepository.SupportedPaymentMethod @@ -25,7 +26,8 @@ data class TestParameters( val forceDarkMode: Boolean? = null, val appearance: PaymentSheet.Appearance = PaymentSheet.Appearance(), val snapshotReturningCustomer: Boolean = false, - val merchantCountryCode: String + val merchantCountryCode: String, + val supportedPaymentMethods: List = listOf() ) /** diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/activity/PaymentSheetPlaygroundActivity.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/activity/PaymentSheetPlaygroundActivity.kt index e272962b3df..c0c54c14cf2 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/activity/PaymentSheetPlaygroundActivity.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/activity/PaymentSheetPlaygroundActivity.kt @@ -186,7 +186,8 @@ class PaymentSheetPlaygroundActivity : AppCompatActivity() { linkEnabled, setShippingAddress, setAutomaticPaymentMethods, - backendUrl + backendUrl, + intent.extras?.getStringArray(SUPPORTED_PAYMENT_METHODS_EXTRA)?.toList() ) } } @@ -470,6 +471,7 @@ class PaymentSheetPlaygroundActivity : AppCompatActivity() { const val FORCE_DARK_MODE_EXTRA = "ForceDark" const val APPEARANCE_EXTRA = "Appearance" const val USE_SNAPSHOT_RETURNING_CUSTOMER_EXTRA = "UseSnapshotReturningCustomer" + const val SUPPORTED_PAYMENT_METHODS_EXTRA = "SupportedPaymentMethods" private const val merchantName = "Example, Inc." private const val sharedPreferencesName = "playgroundToggles" diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/model/PlaygroundCheckoutModel.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/model/PlaygroundCheckoutModel.kt index ac0bf6a6606..bbd61c03442 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/model/PlaygroundCheckoutModel.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/model/PlaygroundCheckoutModel.kt @@ -60,7 +60,8 @@ data class CheckoutRequest( val set_shipping_address: Boolean, val automatic_payment_methods: Boolean, val use_link: Boolean, - val merchant_country_code: String + val merchant_country_code: String, + val supported_payment_methods: List? ) @Serializable diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/viewmodel/PaymentSheetPlaygroundViewModel.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/viewmodel/PaymentSheetPlaygroundViewModel.kt index ef623133d0a..99c27b0a06b 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/viewmodel/PaymentSheetPlaygroundViewModel.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/viewmodel/PaymentSheetPlaygroundViewModel.kt @@ -144,7 +144,8 @@ class PaymentSheetPlaygroundViewModel( linkEnabled: Boolean, setShippingAddress: Boolean, setAutomaticPaymentMethod: Boolean, - backendUrl: String + backendUrl: String, + supportedPaymentMethods: List? ) { customerConfig.value = null clientSecret.value = null @@ -158,7 +159,8 @@ class PaymentSheetPlaygroundViewModel( set_shipping_address = setShippingAddress, automatic_payment_methods = setAutomaticPaymentMethod, use_link = linkEnabled, - merchant_country_code = merchantCountry.value + merchant_country_code = merchantCountry.value, + supported_payment_methods = supportedPaymentMethods ) Fuel.post(backendUrl + "checkout") diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/BaseSheetActivity.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/BaseSheetActivity.kt index f80b8334394..c15cfcdcd78 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/BaseSheetActivity.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/BaseSheetActivity.kt @@ -1,5 +1,6 @@ package com.stripe.android.paymentsheet.ui +import android.animation.LayoutTransition import android.content.pm.ActivityInfo import android.content.res.ColorStateList import android.graphics.Insets @@ -98,6 +99,9 @@ internal abstract class BaseSheetActivity : AppCompatActivity() { } } + bottomSheet.layoutTransition.enableTransitionType(LayoutTransition.CHANGING) + fragmentContainerParent.layoutTransition.enableTransitionType(LayoutTransition.CHANGING) + bottomSheetController.setup() bottomSheetController.shouldFinish.observe(this) { shouldFinish -> diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt index 3b2478a44cf..7b65472936d 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt @@ -1,5 +1,6 @@ package com.stripe.android.paymentsheet +import android.animation.LayoutTransition import android.content.Context import androidx.activity.result.ActivityResultLauncher import androidx.arch.core.executor.testing.InstantTaskExecutorRule @@ -963,6 +964,28 @@ internal class PaymentSheetActivityTest { } } + @Test + fun `verify animation is enabled for layout transition changes`() { + val scenario = activityScenario() + scenario.launch(intent).onActivity { activity -> + // wait for bottom sheet to animate in + idleLooper() + + assertThat( + activity.viewBinding.bottomSheet.layoutTransition.isTransitionTypeEnabled( + LayoutTransition.CHANGING + ) + ).isTrue() + + assertThat( + activity.viewBinding.fragmentContainerParent.layoutTransition + .isTransitionTypeEnabled( + LayoutTransition.CHANGING + ) + ).isTrue() + } + } + private fun currentFragment(activity: PaymentSheetActivity) = activity.supportFragmentManager.findFragmentById(activity.viewBinding.fragmentContainer.id)