Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BANKCON-4898 CollectBankAccountLauncher not using stripeAccountId #5399

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions payments-core/api/payments-core.api
Expand Up @@ -6470,15 +6470,20 @@ 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 {
public final fun create (Landroidx/activity/ComponentActivity;Lkotlin/jvm/functions/Function1;)Lcom/stripe/android/payments/bankaccount/CollectBankAccountLauncher;
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 <init> (Ljavax/inject/Provider;)V
public static fun create (Ljavax/inject/Provider;)Lcom/stripe/android/payments/bankaccount/di/CollectBankAccountModule_ProvidePublishableKeyFactory;
Expand Down
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Expand Up @@ -19,13 +19,17 @@ internal class AttachFinancialConnectionsSession @Inject constructor(
suspend fun forPaymentIntent(
publishableKey: String,
linkedAccountSessionId: String,
clientSecret: String
clientSecret: String,
stripeAccountId: String?
): Result<PaymentIntent> = 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") }

Expand All @@ -38,13 +42,17 @@ internal class AttachFinancialConnectionsSession @Inject constructor(
suspend fun forSetupIntent(
publishableKey: String,
linkedAccountSessionId: String,
clientSecret: String
clientSecret: String,
stripeAccountId: String?
): Result<SetupIntent> = 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") }
}
Expand Up @@ -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,
) {

/**
Expand All @@ -19,7 +19,8 @@ internal class CreateFinancialConnectionsSession @Inject constructor(
publishableKey: String,
clientSecret: String,
customerName: String,
customerEmail: String?
customerEmail: String?,
stripeAccountId: String?
): Result<FinancialConnectionsSession> = kotlin.runCatching {
stripeRepository.createPaymentIntentFinancialConnectionsSession(
paymentIntentId = PaymentIntent.ClientSecret(clientSecret).paymentIntentId,
Expand All @@ -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") }

Expand All @@ -39,7 +43,8 @@ internal class CreateFinancialConnectionsSession @Inject constructor(
publishableKey: String,
clientSecret: String,
customerName: String,
customerEmail: String?
customerEmail: String?,
stripeAccountId: String?
): Result<FinancialConnectionsSession> = kotlin.runCatching {
stripeRepository.createSetupIntentFinancialConnectionsSession(
setupIntentId = SetupIntent.ClientSecret(clientSecret).setupIntentId,
Expand All @@ -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") }
}
Expand Up @@ -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
Expand All @@ -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? {
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down