diff --git a/CHANGELOG.md b/CHANGELOG.md index 445293fd4c9..fd4fca6c6fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ `PaymentSheet`, that clears any persisted authentication state. * [FIXED][5388](https://github.com/stripe/stripe-android/pull/5388) Fixed issue with Appearance API not working with `FlowController` +* [FIXED][5399](https://github.com/stripe/stripe-android/pull/5399) Bank Account Payments that pass + stripeAccountId for connected accounts will now succeed. + +### CollectBankAccountLauncher +* [FIXED][5399](https://github.com/stripe/stripe-android/pull/5399) CollectBankAccountLauncher now + accepts stripeAccountId for Connect merchants. ## 20.8.0 - 2022-08-01 diff --git a/payments-core/api/payments-core.api b/payments-core/api/payments-core.api index 4b890c476e7..82d78557c48 100644 --- a/payments-core/api/payments-core.api +++ b/payments-core/api/payments-core.api @@ -6470,8 +6470,8 @@ public final class com/stripe/android/payments/bankaccount/CollectBankAccountCon public abstract interface class com/stripe/android/payments/bankaccount/CollectBankAccountLauncher { public static final field Companion Lcom/stripe/android/payments/bankaccount/CollectBankAccountLauncher$Companion; - public abstract fun presentWithPaymentIntent (Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/payments/bankaccount/CollectBankAccountConfiguration;)V - public abstract fun presentWithSetupIntent (Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/payments/bankaccount/CollectBankAccountConfiguration;)V + public abstract fun presentWithPaymentIntent (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/payments/bankaccount/CollectBankAccountConfiguration;)V + public abstract fun presentWithSetupIntent (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/payments/bankaccount/CollectBankAccountConfiguration;)V } public final class com/stripe/android/payments/bankaccount/CollectBankAccountLauncher$Companion { @@ -6479,6 +6479,11 @@ public final class com/stripe/android/payments/bankaccount/CollectBankAccountLau public final fun create (Landroidx/fragment/app/Fragment;Lkotlin/jvm/functions/Function1;)Lcom/stripe/android/payments/bankaccount/CollectBankAccountLauncher; } +public final class com/stripe/android/payments/bankaccount/CollectBankAccountLauncher$DefaultImpls { + public static synthetic fun presentWithPaymentIntent$default (Lcom/stripe/android/payments/bankaccount/CollectBankAccountLauncher;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/payments/bankaccount/CollectBankAccountConfiguration;ILjava/lang/Object;)V + public static synthetic fun presentWithSetupIntent$default (Lcom/stripe/android/payments/bankaccount/CollectBankAccountLauncher;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/payments/bankaccount/CollectBankAccountConfiguration;ILjava/lang/Object;)V +} + public final class com/stripe/android/payments/bankaccount/di/CollectBankAccountModule_ProvidePublishableKeyFactory : dagger/internal/Factory { public fun (Ljavax/inject/Provider;)V public static fun create (Ljavax/inject/Provider;)Lcom/stripe/android/payments/bankaccount/di/CollectBankAccountModule_ProvidePublishableKeyFactory; diff --git a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/CollectBankAccountLauncher.kt b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/CollectBankAccountLauncher.kt index 34e2796bd15..dd763fd5fac 100644 --- a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/CollectBankAccountLauncher.kt +++ b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/CollectBankAccountLauncher.kt @@ -17,12 +17,14 @@ interface CollectBankAccountLauncher { fun presentWithPaymentIntent( publishableKey: String, + stripeAccountId: String? = null, clientSecret: String, configuration: CollectBankAccountConfiguration ) fun presentWithSetupIntent( publishableKey: String, + stripeAccountId: String? = null, clientSecret: String, configuration: CollectBankAccountConfiguration ) @@ -70,12 +72,14 @@ internal class StripeCollectBankAccountLauncher constructor( override fun presentWithPaymentIntent( publishableKey: String, + stripeAccountId: String?, clientSecret: String, configuration: CollectBankAccountConfiguration ) { hostActivityLauncher.launch( CollectBankAccountContract.Args.ForPaymentIntent( publishableKey = publishableKey, + stripeAccountId = stripeAccountId, clientSecret = clientSecret, configuration = configuration, attachToIntent = true @@ -85,12 +89,14 @@ internal class StripeCollectBankAccountLauncher constructor( override fun presentWithSetupIntent( publishableKey: String, + stripeAccountId: String?, clientSecret: String, configuration: CollectBankAccountConfiguration ) { hostActivityLauncher.launch( CollectBankAccountContract.Args.ForSetupIntent( publishableKey = publishableKey, + stripeAccountId = stripeAccountId, clientSecret = clientSecret, configuration = configuration, attachToIntent = true diff --git a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/domain/AttachFinancialConnectionsSession.kt b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/domain/AttachFinancialConnectionsSession.kt index 6a82d45d682..2173e1b1445 100644 --- a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/domain/AttachFinancialConnectionsSession.kt +++ b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/domain/AttachFinancialConnectionsSession.kt @@ -19,13 +19,17 @@ internal class AttachFinancialConnectionsSession @Inject constructor( suspend fun forPaymentIntent( publishableKey: String, linkedAccountSessionId: String, - clientSecret: String + clientSecret: String, + stripeAccountId: String? ): Result = kotlin.runCatching { stripeRepository.attachFinancialConnectionsSessionToPaymentIntent( financialConnectionsSessionId = linkedAccountSessionId, clientSecret = clientSecret, paymentIntentId = PaymentIntent.ClientSecret(clientSecret).paymentIntentId, - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options( + apiKey = publishableKey, + stripeAccount = stripeAccountId + ) ) }.mapCatching { it ?: throw InternalError("Error attaching session to PaymentIntent") } @@ -38,13 +42,17 @@ internal class AttachFinancialConnectionsSession @Inject constructor( suspend fun forSetupIntent( publishableKey: String, linkedAccountSessionId: String, - clientSecret: String + clientSecret: String, + stripeAccountId: String? ): Result = kotlin.runCatching { stripeRepository.attachFinancialConnectionsSessionToSetupIntent( financialConnectionsSessionId = linkedAccountSessionId, clientSecret = clientSecret, setupIntentId = SetupIntent.ClientSecret(clientSecret).setupIntentId, - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options( + apiKey = publishableKey, + stripeAccount = stripeAccountId + ) ) }.mapCatching { it ?: throw InternalError("Error attaching session to SetupIntent") } } diff --git a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/domain/CreateFinancialConnectionsSession.kt b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/domain/CreateFinancialConnectionsSession.kt index e17b8ce8c70..6de536ab43a 100644 --- a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/domain/CreateFinancialConnectionsSession.kt +++ b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/domain/CreateFinancialConnectionsSession.kt @@ -9,7 +9,7 @@ import com.stripe.android.networking.StripeRepository import javax.inject.Inject internal class CreateFinancialConnectionsSession @Inject constructor( - private val stripeRepository: StripeRepository + private val stripeRepository: StripeRepository, ) { /** @@ -19,7 +19,8 @@ internal class CreateFinancialConnectionsSession @Inject constructor( publishableKey: String, clientSecret: String, customerName: String, - customerEmail: String? + customerEmail: String?, + stripeAccountId: String? ): Result = kotlin.runCatching { stripeRepository.createPaymentIntentFinancialConnectionsSession( paymentIntentId = PaymentIntent.ClientSecret(clientSecret).paymentIntentId, @@ -28,7 +29,10 @@ internal class CreateFinancialConnectionsSession @Inject constructor( customerName = customerName, customerEmailAddress = customerEmail ), - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options( + publishableKey, + stripeAccountId + ) ) }.mapCatching { it ?: throw InternalError("Error creating session for PaymentIntent") } @@ -39,7 +43,8 @@ internal class CreateFinancialConnectionsSession @Inject constructor( publishableKey: String, clientSecret: String, customerName: String, - customerEmail: String? + customerEmail: String?, + stripeAccountId: String? ): Result = kotlin.runCatching { stripeRepository.createSetupIntentFinancialConnectionsSession( setupIntentId = SetupIntent.ClientSecret(clientSecret).setupIntentId, @@ -48,7 +53,10 @@ internal class CreateFinancialConnectionsSession @Inject constructor( customerName = customerName, customerEmailAddress = customerEmail ), - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options( + publishableKey, + stripeAccountId + ) ) }.mapCatching { it ?: throw InternalError("Error creating session for SetupIntent") } } diff --git a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/navigation/CollectBankAccountContract.kt b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/navigation/CollectBankAccountContract.kt index 1264ad998e6..7874540e4e5 100644 --- a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/navigation/CollectBankAccountContract.kt +++ b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/navigation/CollectBankAccountContract.kt @@ -40,6 +40,7 @@ class CollectBankAccountContract : @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) sealed class Args( open val publishableKey: String, + open val stripeAccountId: String?, open val clientSecret: String, open val configuration: CollectBankAccountConfiguration, open val attachToIntent: Boolean @@ -48,21 +49,35 @@ class CollectBankAccountContract : @Parcelize @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - data class ForPaymentIntent constructor( + data class ForPaymentIntent( override val publishableKey: String, + override val stripeAccountId: String?, override val clientSecret: String, override val configuration: CollectBankAccountConfiguration, override val attachToIntent: Boolean - ) : Args(publishableKey, clientSecret, configuration, attachToIntent) + ) : Args( + publishableKey = publishableKey, + stripeAccountId = stripeAccountId, + clientSecret = clientSecret, + configuration = configuration, + attachToIntent = attachToIntent + ) @Parcelize @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - data class ForSetupIntent constructor( + data class ForSetupIntent( override val publishableKey: String, + override val stripeAccountId: String?, override val clientSecret: String, override val configuration: CollectBankAccountConfiguration, override val attachToIntent: Boolean - ) : Args(publishableKey, clientSecret, configuration, attachToIntent) + ) : Args( + publishableKey = publishableKey, + stripeAccountId = stripeAccountId, + clientSecret = clientSecret, + configuration = configuration, + attachToIntent = attachToIntent + ) companion object { fun fromIntent(intent: Intent): Args? { diff --git a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/ui/CollectBankAccountViewModel.kt b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/ui/CollectBankAccountViewModel.kt index a34045ded97..17f551eabc4 100644 --- a/payments-core/src/main/java/com/stripe/android/payments/bankaccount/ui/CollectBankAccountViewModel.kt +++ b/payments-core/src/main/java/com/stripe/android/payments/bankaccount/ui/CollectBankAccountViewModel.kt @@ -60,12 +60,14 @@ internal class CollectBankAccountViewModel @Inject constructor( is CollectBankAccountConfiguration.USBankAccount -> when (args) { is ForPaymentIntent -> createFinancialConnectionsSession.forPaymentIntent( publishableKey = args.publishableKey, + stripeAccountId = args.stripeAccountId, clientSecret = args.clientSecret, customerName = configuration.name, customerEmail = configuration.email ) is ForSetupIntent -> createFinancialConnectionsSession.forSetupIntent( publishableKey = args.publishableKey, + stripeAccountId = args.stripeAccountId, clientSecret = args.clientSecret, customerName = configuration.name, customerEmail = configuration.email @@ -133,11 +135,13 @@ internal class CollectBankAccountViewModel @Inject constructor( when (args) { is ForPaymentIntent -> attachFinancialConnectionsSession.forPaymentIntent( publishableKey = args.publishableKey, + stripeAccountId = args.stripeAccountId, clientSecret = args.clientSecret, linkedAccountSessionId = financialConnectionsSession.id ) is ForSetupIntent -> attachFinancialConnectionsSession.forSetupIntent( publishableKey = args.publishableKey, + stripeAccountId = args.stripeAccountId, clientSecret = args.clientSecret, linkedAccountSessionId = financialConnectionsSession.id ) diff --git a/payments-core/src/test/java/com/stripe/android/payments/bankaccount/StripeCollectBankAccountLauncherTest.kt b/payments-core/src/test/java/com/stripe/android/payments/bankaccount/StripeCollectBankAccountLauncherTest.kt index c429a73fe4d..c794e665b4e 100644 --- a/payments-core/src/test/java/com/stripe/android/payments/bankaccount/StripeCollectBankAccountLauncherTest.kt +++ b/payments-core/src/test/java/com/stripe/android/payments/bankaccount/StripeCollectBankAccountLauncherTest.kt @@ -19,14 +19,16 @@ class StripeCollectBankAccountLauncherTest { @Test fun `presentWithPaymentIntent - launches CollectBankAccountActivity with correct arguments`() { launcher.presentWithPaymentIntent( - PUBLISHABLE_KEY, - CLIENT_SECRET, - CONFIGURATION + publishableKey = PUBLISHABLE_KEY, + clientSecret = CLIENT_SECRET, + stripeAccountId = STRIPE_ACCOUNT_ID, + configuration = CONFIGURATION ) verify(mockHostActivityLauncher).launch( CollectBankAccountContract.Args.ForPaymentIntent( publishableKey = PUBLISHABLE_KEY, + stripeAccountId = STRIPE_ACCOUNT_ID, clientSecret = CLIENT_SECRET, configuration = CONFIGURATION, attachToIntent = true @@ -37,14 +39,16 @@ class StripeCollectBankAccountLauncherTest { @Test fun `presentWithSetupIntent - launches CollectBankAccountActivity with correct arguments`() { launcher.presentWithSetupIntent( - PUBLISHABLE_KEY, - CLIENT_SECRET, - CONFIGURATION + publishableKey = PUBLISHABLE_KEY, + stripeAccountId = STRIPE_ACCOUNT_ID, + clientSecret = CLIENT_SECRET, + configuration = CONFIGURATION ) verify(mockHostActivityLauncher).launch( CollectBankAccountContract.Args.ForSetupIntent( publishableKey = PUBLISHABLE_KEY, + stripeAccountId = STRIPE_ACCOUNT_ID, clientSecret = CLIENT_SECRET, configuration = CONFIGURATION, attachToIntent = true @@ -55,6 +59,7 @@ class StripeCollectBankAccountLauncherTest { companion object { private const val CLIENT_SECRET = "client_secret" private const val PUBLISHABLE_KEY = "publishableKey" + private const val STRIPE_ACCOUNT_ID = "stripe_account_id" private val CONFIGURATION = CollectBankAccountConfiguration.USBankAccount( name = "Carlos", email = null diff --git a/payments-core/src/test/java/com/stripe/android/payments/bankaccount/domain/AttachFinancialConnectionsSessionTest.kt b/payments-core/src/test/java/com/stripe/android/payments/bankaccount/domain/AttachFinancialConnectionsSessionTest.kt index 5a8d77dd35a..4e2d70731ee 100644 --- a/payments-core/src/test/java/com/stripe/android/payments/bankaccount/domain/AttachFinancialConnectionsSessionTest.kt +++ b/payments-core/src/test/java/com/stripe/android/payments/bankaccount/domain/AttachFinancialConnectionsSessionTest.kt @@ -22,12 +22,14 @@ class AttachFinancialConnectionsSessionTest { private val stripeRepository = mock() private val attachFinancialConnectionsSession = AttachFinancialConnectionsSession(stripeRepository) + private val publishableKey = "publishable_key" + private val linkedAccountSessionId = "session_id" + private val stripeAccountId = "stripe_account_id" + @Test fun `forPaymentIntent - given repository succeeds, linkedSession attached and paymentIntent returned`() { runTest { // Given - val publishableKey = "publishable_key" - val linkedAccountSessionId = "session_id" val clientSecret = "pi_1234_secret_5678" val paymentIntent = mock { on { this.clientSecret } doReturn clientSecret @@ -36,9 +38,10 @@ class AttachFinancialConnectionsSessionTest { // When val result: Result = attachFinancialConnectionsSession.forPaymentIntent( - publishableKey, - linkedAccountSessionId, - clientSecret + publishableKey = publishableKey, + linkedAccountSessionId = linkedAccountSessionId, + clientSecret = clientSecret, + stripeAccountId = stripeAccountId ) // Then @@ -46,7 +49,7 @@ class AttachFinancialConnectionsSessionTest { clientSecret = clientSecret, paymentIntentId = "pi_1234", financialConnectionsSessionId = linkedAccountSessionId, - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options(publishableKey, stripeAccountId) ) assertThat((result)).isEqualTo(Result.success(paymentIntent)) } @@ -56,16 +59,15 @@ class AttachFinancialConnectionsSessionTest { fun `forPaymentIntent - given repository returns null, results in internal error failure`() { runTest { // Given - val publishableKey = "publishable_key" - val linkedAccountSessionId = "session_id" val clientSecret = "pi_1234_secret_5678" givenAttachPaymentIntentReturns { null } // When val result: Result = attachFinancialConnectionsSession.forPaymentIntent( - publishableKey, - linkedAccountSessionId, - clientSecret + publishableKey = publishableKey, + linkedAccountSessionId = linkedAccountSessionId, + clientSecret = clientSecret, + stripeAccountId = stripeAccountId ) // Then @@ -73,7 +75,7 @@ class AttachFinancialConnectionsSessionTest { clientSecret = clientSecret, paymentIntentId = "pi_1234", financialConnectionsSessionId = linkedAccountSessionId, - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options(publishableKey, stripeAccountId) ) assertThat(result.exceptionOrNull()!!).isInstanceOf(InternalError::class.java) } @@ -83,17 +85,16 @@ class AttachFinancialConnectionsSessionTest { fun `forPaymentIntent - given repository throws exception, results in internal error failure`() { runTest { // Given - val publishableKey = "publishable_key" - val linkedAccountSessionId = "session_id" val clientSecret = "pi_1234_secret_5678" val expectedException = APIException() givenAttachPaymentIntentReturns { throw expectedException } // When val result: Result = attachFinancialConnectionsSession.forPaymentIntent( - publishableKey, - linkedAccountSessionId, - clientSecret + publishableKey = publishableKey, + linkedAccountSessionId = linkedAccountSessionId, + clientSecret = clientSecret, + stripeAccountId = stripeAccountId ) // Then @@ -101,7 +102,7 @@ class AttachFinancialConnectionsSessionTest { clientSecret = clientSecret, paymentIntentId = "pi_1234", financialConnectionsSessionId = linkedAccountSessionId, - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options(publishableKey, stripeAccountId) ) assertThat(result.exceptionOrNull()!!).isEqualTo(expectedException) } @@ -111,8 +112,6 @@ class AttachFinancialConnectionsSessionTest { fun `forPaymentIntent - given wrong secret, results in internal error failure`() { runTest { // Given - val publishableKey = "publishable_key" - val linkedAccountSessionId = "session_id" val clientSecret = "wrong_secret" val paymentIntent = mock() givenAttachPaymentIntentReturns { paymentIntent } @@ -121,7 +120,8 @@ class AttachFinancialConnectionsSessionTest { val result: Result = attachFinancialConnectionsSession.forPaymentIntent( publishableKey, linkedAccountSessionId, - clientSecret + clientSecret, + stripeAccountId ) // Then @@ -133,8 +133,6 @@ class AttachFinancialConnectionsSessionTest { fun `forSetupIntent - given repository succeeds, linkedSession attached and setupIntent returned`() { runTest { // Given - val publishableKey = "publishable_key" - val linkedAccountSessionId = "session_id" val clientSecret = "seti_1234_secret_5678" val setupIntent = mock { on { this.clientSecret } doReturn clientSecret @@ -145,7 +143,8 @@ class AttachFinancialConnectionsSessionTest { val result: Result = attachFinancialConnectionsSession.forSetupIntent( publishableKey, linkedAccountSessionId, - clientSecret + clientSecret, + stripeAccountId ) // Then @@ -153,7 +152,7 @@ class AttachFinancialConnectionsSessionTest { clientSecret = clientSecret, setupIntentId = "seti_1234", financialConnectionsSessionId = linkedAccountSessionId, - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options(publishableKey, stripeAccountId) ) assertThat((result)).isEqualTo(Result.success(setupIntent)) } @@ -163,8 +162,6 @@ class AttachFinancialConnectionsSessionTest { fun `forSetupIntent - given repository returns null, results in internal error failure`() { runTest { // Given - val publishableKey = "publishable_key" - val linkedAccountSessionId = "session_id" val clientSecret = "seti_1234_secret_5678" givenAttachSetupIntentReturns { null } @@ -172,7 +169,8 @@ class AttachFinancialConnectionsSessionTest { val setupIntent: Result = attachFinancialConnectionsSession.forSetupIntent( publishableKey, linkedAccountSessionId, - clientSecret + clientSecret, + stripeAccountId ) // Then @@ -180,7 +178,7 @@ class AttachFinancialConnectionsSessionTest { clientSecret = clientSecret, setupIntentId = "seti_1234", financialConnectionsSessionId = linkedAccountSessionId, - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options(publishableKey, stripeAccountId) ) assertThat(setupIntent.exceptionOrNull()!!).isInstanceOf(InternalError::class.java) } @@ -190,8 +188,6 @@ class AttachFinancialConnectionsSessionTest { fun `forSetupIntent - given repository throws exception, results in internal error failure`() { runTest { // Given - val publishableKey = "publishable_key" - val linkedAccountSessionId = "session_id" val clientSecret = "seti_1234_secret_5678" val expectedException = APIException() givenAttachSetupIntentReturns { throw expectedException } @@ -200,7 +196,8 @@ class AttachFinancialConnectionsSessionTest { val setupIntent: Result = attachFinancialConnectionsSession.forSetupIntent( publishableKey, linkedAccountSessionId, - clientSecret + clientSecret, + stripeAccountId ) // Then @@ -208,7 +205,7 @@ class AttachFinancialConnectionsSessionTest { clientSecret = clientSecret, setupIntentId = "seti_1234", financialConnectionsSessionId = linkedAccountSessionId, - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options(publishableKey, stripeAccountId) ) assertThat(setupIntent.exceptionOrNull()!!).isEqualTo(expectedException) } @@ -228,7 +225,8 @@ class AttachFinancialConnectionsSessionTest { val setupIntent: Result = attachFinancialConnectionsSession.forSetupIntent( publishableKey, linkedAccountSessionId, - clientSecret + clientSecret, + stripeAccountId ) // Then diff --git a/payments-core/src/test/java/com/stripe/android/payments/bankaccount/domain/CreateFinancialConnectionsSessionTest.kt b/payments-core/src/test/java/com/stripe/android/payments/bankaccount/domain/CreateFinancialConnectionsSessionTest.kt index 6827e63abca..96761bd6a7a 100644 --- a/payments-core/src/test/java/com/stripe/android/payments/bankaccount/domain/CreateFinancialConnectionsSessionTest.kt +++ b/payments-core/src/test/java/com/stripe/android/payments/bankaccount/domain/CreateFinancialConnectionsSessionTest.kt @@ -41,7 +41,8 @@ class CreateFinancialConnectionsSessionTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = customerName, - customerEmail = null + customerEmail = null, + stripeAccountId = null ) // Then @@ -72,7 +73,8 @@ class CreateFinancialConnectionsSessionTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = customerName, - customerEmail = null + customerEmail = null, + stripeAccountId = null ) // Then @@ -106,7 +108,8 @@ class CreateFinancialConnectionsSessionTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = customerName, - customerEmail = null + customerEmail = null, + stripeAccountId = null ) // Then @@ -137,7 +140,8 @@ class CreateFinancialConnectionsSessionTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = customerName, - customerEmail = null + customerEmail = null, + stripeAccountId = null ) // Then @@ -151,6 +155,7 @@ class CreateFinancialConnectionsSessionTest { // Given val publishableKey = "publishable_key" val clientSecret = "seti_1234_secret_5678" + val stripeAccountId = "accountId" givenCreateSessionWithSetupIntentReturns { linkedAccountSession } // When @@ -159,7 +164,8 @@ class CreateFinancialConnectionsSessionTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = customerName, - customerEmail = null + customerEmail = null, + stripeAccountId = stripeAccountId ) // Then @@ -170,7 +176,10 @@ class CreateFinancialConnectionsSessionTest { customerName, null ), - requestOptions = ApiRequest.Options(publishableKey) + requestOptions = ApiRequest.Options( + apiKey = publishableKey, + stripeAccount = stripeAccountId + ) ) assertThat((paymentIntent)).isEqualTo(Result.success(linkedAccountSession)) } @@ -190,7 +199,8 @@ class CreateFinancialConnectionsSessionTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = customerName, - customerEmail = null + customerEmail = null, + stripeAccountId = null ) // Then @@ -223,7 +233,8 @@ class CreateFinancialConnectionsSessionTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = customerName, - customerEmail = null + customerEmail = null, + stripeAccountId = null ) // Then @@ -254,7 +265,8 @@ class CreateFinancialConnectionsSessionTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = customerName, - customerEmail = null + customerEmail = null, + stripeAccountId = null ) // Then diff --git a/payments-core/src/test/java/com/stripe/android/payments/bankaccount/ui/CollectBankAccountViewModelTest.kt b/payments-core/src/test/java/com/stripe/android/payments/bankaccount/ui/CollectBankAccountViewModelTest.kt index 964d8b5f283..7b62d73b760 100644 --- a/payments-core/src/test/java/com/stripe/android/payments/bankaccount/ui/CollectBankAccountViewModelTest.kt +++ b/payments-core/src/test/java/com/stripe/android/payments/bankaccount/ui/CollectBankAccountViewModelTest.kt @@ -44,6 +44,7 @@ class CollectBankAccountViewModelTest { private val retrieveStripeIntent: RetrieveStripeIntent = mock() private val publishableKey = "publishable_key" + private val stripeAccountId = "stripe_account_id" private val clientSecret = "client_secret" private val name = "name" private val email = "email" @@ -115,7 +116,12 @@ class CollectBankAccountViewModelTest { // Then cancelAndConsumeRemainingEvents() - verify(attachFinancialConnectionsSession, never()).forPaymentIntent(any(), any(), any()) + verify(attachFinancialConnectionsSession, never()).forPaymentIntent( + any(), + any(), + any(), + any() + ) } } @@ -135,7 +141,12 @@ class CollectBankAccountViewModelTest { // Then cancelAndConsumeRemainingEvents() - verify(attachFinancialConnectionsSession, never()).forSetupIntent(any(), any(), any()) + verify(attachFinancialConnectionsSession, never()).forSetupIntent( + any(), + any(), + any(), + any() + ) } } @@ -241,7 +252,8 @@ class CollectBankAccountViewModelTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = name, - customerEmail = email + customerEmail = email, + stripeAccountId = stripeAccountId ) }.doReturn(result) } @@ -254,8 +266,9 @@ class CollectBankAccountViewModelTest { onBlocking { forPaymentIntent( publishableKey = publishableKey, + linkedAccountSessionId = linkedAccountSessionId, clientSecret = clientSecret, - linkedAccountSessionId = linkedAccountSessionId + stripeAccountId = stripeAccountId ) }.doReturn(result) } @@ -268,8 +281,9 @@ class CollectBankAccountViewModelTest { onBlocking { forSetupIntent( publishableKey = publishableKey, + linkedAccountSessionId = linkedAccountSessionId, clientSecret = clientSecret, - linkedAccountSessionId = linkedAccountSessionId + stripeAccountId = stripeAccountId ) }.doReturn(result) } @@ -284,7 +298,8 @@ class CollectBankAccountViewModelTest { publishableKey = publishableKey, clientSecret = clientSecret, customerName = name, - customerEmail = email + customerEmail = email, + stripeAccountId = stripeAccountId ) }.doReturn(result) } @@ -321,6 +336,7 @@ class CollectBankAccountViewModelTest { ): ForPaymentIntent { return ForPaymentIntent( publishableKey = publishableKey, + stripeAccountId = stripeAccountId, clientSecret = clientSecret, configuration = CollectBankAccountConfiguration.USBankAccount( name, @@ -335,6 +351,7 @@ class CollectBankAccountViewModelTest { ): ForSetupIntent { return ForSetupIntent( publishableKey = publishableKey, + stripeAccountId = stripeAccountId, clientSecret = clientSecret, configuration = CollectBankAccountConfiguration.USBankAccount( name, diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/CollectBankAccountForPaymentSheetLauncher.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/CollectBankAccountForPaymentSheetLauncher.kt index 63e67bd827c..3a0decbdcdd 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/CollectBankAccountForPaymentSheetLauncher.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/CollectBankAccountForPaymentSheetLauncher.kt @@ -14,12 +14,14 @@ internal class CollectBankAccountForPaymentSheetLauncher( override fun presentWithPaymentIntent( publishableKey: String, + stripeAccountId: String?, clientSecret: String, configuration: CollectBankAccountConfiguration ) { hostActivityLauncher.launch( CollectBankAccountContract.Args.ForPaymentIntent( publishableKey = publishableKey, + stripeAccountId = stripeAccountId, clientSecret = clientSecret, configuration = configuration, attachToIntent = false @@ -29,12 +31,14 @@ internal class CollectBankAccountForPaymentSheetLauncher( override fun presentWithSetupIntent( publishableKey: String, + stripeAccountId: String?, clientSecret: String, configuration: CollectBankAccountConfiguration ) { hostActivityLauncher.launch( CollectBankAccountContract.Args.ForSetupIntent( publishableKey = publishableKey, + stripeAccountId = stripeAccountId, clientSecret = clientSecret, configuration = configuration, attachToIntent = false diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModel.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModel.kt index 87bd235995c..bd0e3c6aefe 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModel.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModel.kt @@ -298,9 +298,10 @@ internal class USBankAccountFormViewModel @Inject internal constructor( when (clientSecret) { is PaymentIntentClientSecret -> { collectBankAccountLauncher?.presentWithPaymentIntent( - lazyPaymentConfig.get().publishableKey, - clientSecret.value, - CollectBankAccountConfiguration.USBankAccount( + publishableKey = lazyPaymentConfig.get().publishableKey, + stripeAccountId = lazyPaymentConfig.get().stripeAccountId, + clientSecret = clientSecret.value, + configuration = CollectBankAccountConfiguration.USBankAccount( name.value, email.value ) @@ -308,9 +309,10 @@ internal class USBankAccountFormViewModel @Inject internal constructor( } is SetupIntentClientSecret -> { collectBankAccountLauncher?.presentWithSetupIntent( - lazyPaymentConfig.get().publishableKey, - clientSecret.value, - CollectBankAccountConfiguration.USBankAccount( + publishableKey = lazyPaymentConfig.get().publishableKey, + stripeAccountId = lazyPaymentConfig.get().stripeAccountId, + clientSecret = clientSecret.value, + configuration = CollectBankAccountConfiguration.USBankAccount( name.value, email.value ) diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/CollectBankAccountForPaymentSheetLauncherTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/CollectBankAccountForPaymentSheetLauncherTest.kt index 2f202834564..2dea55edeff 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/CollectBankAccountForPaymentSheetLauncherTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/CollectBankAccountForPaymentSheetLauncherTest.kt @@ -20,14 +20,16 @@ class CollectBankAccountForPaymentSheetLauncherTest { @Test fun `presentWithPaymentIntent - launches CollectBankAccountActivity with correct arguments`() { launcher.presentWithPaymentIntent( - PUBLISHABLE_KEY, - CLIENT_SECRET, - CONFIGURATION + publishableKey = PUBLISHABLE_KEY, + stripeAccountId = STRIPE_ACCOUNT_ID, + clientSecret = CLIENT_SECRET, + configuration = CONFIGURATION ) verify(mockHostActivityLauncher).launch( CollectBankAccountContract.Args.ForPaymentIntent( publishableKey = PUBLISHABLE_KEY, + stripeAccountId = STRIPE_ACCOUNT_ID, clientSecret = CLIENT_SECRET, configuration = CONFIGURATION, attachToIntent = false @@ -38,14 +40,16 @@ class CollectBankAccountForPaymentSheetLauncherTest { @Test fun `presentWithSetupIntent - launches CollectBankAccountActivity with correct arguments`() { launcher.presentWithSetupIntent( - PUBLISHABLE_KEY, - CLIENT_SECRET, - CONFIGURATION + publishableKey = PUBLISHABLE_KEY, + stripeAccountId = STRIPE_ACCOUNT_ID, + clientSecret = CLIENT_SECRET, + configuration = CONFIGURATION ) verify(mockHostActivityLauncher).launch( CollectBankAccountContract.Args.ForSetupIntent( publishableKey = PUBLISHABLE_KEY, + stripeAccountId = STRIPE_ACCOUNT_ID, clientSecret = CLIENT_SECRET, configuration = CONFIGURATION, attachToIntent = false @@ -56,6 +60,7 @@ class CollectBankAccountForPaymentSheetLauncherTest { companion object { private const val CLIENT_SECRET = "client_secret" private const val PUBLISHABLE_KEY = "publishableKey" + private const val STRIPE_ACCOUNT_ID = "stripe_account_id" private val CONFIGURATION = CollectBankAccountConfiguration.USBankAccount( name = "Carlos", email = null diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt index 1f044e854e1..fd5e0e8cbf8 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/paymentdatacollection/ach/USBankAccountFormViewModelTest.kt @@ -1,6 +1,5 @@ package com.stripe.android.paymentsheet.paymentdatacollection.ach -import android.app.Application import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import androidx.test.core.app.ApplicationProvider @@ -21,7 +20,6 @@ import com.stripe.android.paymentsheet.model.PaymentIntentClientSecret import com.stripe.android.paymentsheet.model.PaymentSelection import com.stripe.android.paymentsheet.paymentdatacollection.FormFragmentArguments import com.stripe.android.ui.core.Amount -import com.stripe.android.ui.core.forms.resources.LpmRepository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.stateIn @@ -42,11 +40,6 @@ import kotlin.test.Test @ExperimentalCoroutinesApi @RunWith(RobolectricTestRunner::class) class USBankAccountFormViewModelTest { - private val lpmRepository = - LpmRepository(LpmRepository.LpmRepositoryArguments(ApplicationProvider.getApplicationContext().resources)).apply { - this.forceUpdate(listOf(PaymentMethod.Type.Card.code, PaymentMethod.Type.USBankAccount.code), null) - } - private val usBankAccount = lpmRepository.fromCode(PaymentMethod.Type.USBankAccount.code)!! private val defaultArgs = USBankAccountFormViewModel.Args( formArgs = FormFragmentArguments( @@ -128,7 +121,7 @@ class USBankAccountFormViewModelTest { viewModel.handlePrimaryButtonClick(currentScreenState as USBankAccountFormScreenState.NameAndEmailCollection) - verify(collectBankAccountLauncher).presentWithPaymentIntent(any(), any(), any()) + verify(collectBankAccountLauncher).presentWithPaymentIntent(any(), any(), any(), any()) } @Test @@ -222,7 +215,7 @@ class USBankAccountFormViewModelTest { viewModel.handlePrimaryButtonClick(currentScreenState as USBankAccountFormScreenState.NameAndEmailCollection) - verify(collectBankAccountLauncher).presentWithPaymentIntent(any(), any(), any()) + verify(collectBankAccountLauncher).presentWithPaymentIntent(any(), any(), any(), any()) } @Test @@ -299,7 +292,10 @@ class USBankAccountFormViewModelTest { private fun createViewModel( args: USBankAccountFormViewModel.Args = defaultArgs ): USBankAccountFormViewModel { - val paymentConfiguration = PaymentConfiguration(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY) + val paymentConfiguration = PaymentConfiguration( + ApiKeyFixtures.FAKE_PUBLISHABLE_KEY, + STRIPE_ACCOUNT_ID + ) return USBankAccountFormViewModel( args = args, application = ApplicationProvider.getApplicationContext(), @@ -366,5 +362,6 @@ class USBankAccountFormViewModelTest { const val MERCHANT_NAME = "merchantName" const val CUSTOMER_NAME = "Jenny Rose" const val CUSTOMER_EMAIL = "email@email.com" + const val STRIPE_ACCOUNT_ID = "stripe_account_id" } }