Skip to content

Commit

Permalink
Fix a bug where cashapp wouldn't launch without the redirect trampoli…
Browse files Browse the repository at this point in the history
…ne. (#7822)
  • Loading branch information
jaynewstrom-stripe authored Jan 25, 2024
1 parent 0a3fdbd commit 5d71352
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion payments-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<ID>LongMethod:PaymentFlowResultProcessor.kt$PaymentFlowResultProcessor$suspend fun processResult( unvalidatedResult: PaymentFlowResult.Unvalidated ): Result&lt;S></ID>
<ID>LongMethod:PaymentIntentJsonParser.kt$PaymentIntentJsonParser$override fun parse(json: JSONObject): PaymentIntent?</ID>
<ID>LongMethod:PaymentMethodJsonParser.kt$PaymentMethodJsonParser$override fun parse(json: JSONObject): PaymentMethod</ID>
<ID>LongMethod:PaymentMethodsActivity.kt$PaymentMethodsActivity$override fun onCreate(savedInstanceState: Bundle?)</ID>
<ID>LongMethod:SourceParamsTest.kt$SourceParamsTest$@Test fun `createKlarna() should create expected params`()</ID>
<ID>LongMethod:StaticCardAccountRangeSourceTest.kt$StaticCardAccountRangeSourceTest$@Test fun `getAccountRange() should return expected AccountRange`()</ID>
<ID>LongMethod:Stripe3ds2ChallengeResultProcessor.kt$DefaultStripe3ds2ChallengeResultProcessor$override suspend fun process( challengeResult: ChallengeResult ): PaymentFlowResult.Unvalidated</ID>
Expand Down Expand Up @@ -206,6 +205,7 @@
<ID>SwallowedException:ActivityUtils.kt$e: IllegalArgumentException</ID>
<ID>SwallowedException:DefaultPaymentAuthenticatorRegistry.kt$e: Exception</ID>
<ID>SwallowedException:PaymentUtils.kt$PaymentUtils$e: ClassCastException</ID>
<ID>SwallowedException:StripeBrowserLauncherActivity.kt$StripeBrowserLauncherActivity$e: ActivityNotFoundException</ID>
<ID>ThrowsCount:StripeApiRepository.kt$StripeApiRepository$@Throws( InvalidRequestException::class, AuthenticationException::class, CardException::class, APIException::class ) private fun handleApiError(response: StripeResponse&lt;String>)</ID>
<ID>TooGenericExceptionCaught:DefaultPaymentAuthenticatorRegistry.kt$e: Exception</ID>
<ID>TooGenericExceptionThrown:DefaultAlipayRepository.kt$DefaultAlipayRepository$throw RuntimeException("Unable to authenticate Payment Intent with Alipay SDK")</ID>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.payments

import android.app.Activity
import android.content.ActivityNotFoundException
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
Expand Down Expand Up @@ -50,10 +51,10 @@ internal class StripeBrowserLauncherActivity : AppCompatActivity() {

val intent = viewModel.createLaunchIntent(args)

if (intent != null) {
try {
launcher.launch(intent)
viewModel.hasLaunched = true
} else {
} catch (e: ActivityNotFoundException) {
finishWithFailure(args)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ internal class StripeBrowserLauncherViewModel(
private val intentChooserTitle: String,
private val resolveErrorMessage: String,
private val savedStateHandle: SavedStateHandle,
private val intentResolver: (Intent) -> Boolean,
) : ViewModel() {

var hasLaunched: Boolean
Expand All @@ -40,7 +39,7 @@ internal class StripeBrowserLauncherViewModel(

fun createLaunchIntent(
args: PaymentBrowserAuthContract.Args
): Intent? {
): Intent {
val url = Uri.parse(args.url)
logBrowserCapabilities()

Expand All @@ -54,13 +53,7 @@ internal class StripeBrowserLauncherViewModel(
}
}

val canResolve = intentResolver(intent)

return if (canResolve) {
Intent.createChooser(intent, intentChooserTitle)
} else {
null
}
return Intent.createChooser(intent, intentChooserTitle)
}

private fun createCustomTabsIntent(
Expand Down Expand Up @@ -147,7 +140,6 @@ internal class StripeBrowserLauncherViewModel(
intentChooserTitle = application.getString(R.string.stripe_verify_your_payment),
resolveErrorMessage = application.getString(R.string.stripe_failure_reason_authentication),
savedStateHandle = savedStateHandle,
intentResolver = { it.resolveActivity(application.packageManager) != null },
) as T
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,11 @@ class StripeBrowserLauncherViewModelTest {
val viewModel = createViewModel()
val launchIntent = viewModel.createLaunchIntent(ARGS)

val browserIntent = requireNotNull(launchIntent?.getParcelableExtra<Intent>(Intent.EXTRA_INTENT))
val browserIntent = requireNotNull(launchIntent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT))

assertThat(browserIntent.action).isEqualTo(Intent.ACTION_VIEW)
assertThat(browserIntent.data).isEqualTo(Uri.parse("https://bank.com"))
assertThat(launchIntent?.getStringExtra(Intent.EXTRA_TITLE)).isEqualTo("Verify your payment")
}

@Test
fun `createLaunchIntent() returns null if intent can't be resolved`() {
val viewModel = createViewModel(canResolveIntent = false)
val launchIntent = viewModel.createLaunchIntent(ARGS)
assertThat(launchIntent).isNull()
assertThat(launchIntent.getStringExtra(Intent.EXTRA_TITLE)).isEqualTo("Verify your payment")
}

@Test
Expand Down Expand Up @@ -105,7 +98,6 @@ class StripeBrowserLauncherViewModelTest {

private fun createViewModel(
browserCapabilities: BrowserCapabilities = BrowserCapabilities.CustomTabs,
canResolveIntent: Boolean = true,
): StripeBrowserLauncherViewModel {
return StripeBrowserLauncherViewModel(
analyticsRequestExecutor = analyticsRequestExecutor,
Expand All @@ -114,7 +106,6 @@ class StripeBrowserLauncherViewModelTest {
intentChooserTitle = "Verify your payment",
resolveErrorMessage = "Unable to resolve things",
savedStateHandle = savedStateHandle,
intentResolver = { canResolveIntent },
)
}

Expand Down

0 comments on commit 5d71352

Please sign in to comment.