Skip to content

Commit

Permalink
Fix issue where us_bank_account is present in payment sheet when fina…
Browse files Browse the repository at this point in the history
…ncial connections sdk is not available (#5215)

* Fix issue where us_bank_account is present in payment sheet when financial connections sdk is not available
  • Loading branch information
jameswoo-stripe committed Jun 28, 2022
1 parent 1d7bace commit 08f7aad
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,9 @@

## X.X.X

### PaymentSheet
* [Fixed][5215](https://github.com/stripe/stripe-android/pull/5215) Fix issue with us_bank_account appearing in payment sheet when Financial Connections SDK is not available

## 20.6.2 - 2022-06-23
This release contains several bug fixes for Payments, reduces the size of StripeCardScan, and adds new `rememberFinancialConnections` features for Financial Connections.

Expand Down
@@ -1,11 +1,15 @@
package com.stripe.android.payments.financialconnections

internal interface IsFinancialConnectionsAvailable {
import androidx.annotation.RestrictTo

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
interface IsFinancialConnectionsAvailable {
operator fun invoke(): Boolean
}

internal class DefaultIsFinancialConnectionsAvailable : IsFinancialConnectionsAvailable {
override fun invoke(): Boolean {
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
class DefaultIsFinancialConnectionsAvailable : IsFinancialConnectionsAvailable {
override operator fun invoke(): Boolean {
return try {
Class.forName("com.stripe.android.financialconnections.FinancialConnectionsSheet")
true
Expand Down
6 changes: 3 additions & 3 deletions payments-ui-core/api/payments-ui-core.api
Expand Up @@ -613,11 +613,11 @@ public final class com/stripe/android/ui/core/forms/resources/LpmRepository$Comp
}

public final class com/stripe/android/ui/core/forms/resources/LpmRepository_Factory : dagger/internal/Factory {
public fun <init> (Ljavax/inject/Provider;)V
public static fun create (Ljavax/inject/Provider;)Lcom/stripe/android/ui/core/forms/resources/LpmRepository_Factory;
public fun <init> (Ljavax/inject/Provider;Ljavax/inject/Provider;)V
public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/ui/core/forms/resources/LpmRepository_Factory;
public fun get ()Lcom/stripe/android/ui/core/forms/resources/LpmRepository;
public synthetic fun get ()Ljava/lang/Object;
public static fun newInstance (Landroid/content/res/Resources;)Lcom/stripe/android/ui/core/forms/resources/LpmRepository;
public static fun newInstance (Landroid/content/res/Resources;Lcom/stripe/android/payments/financialconnections/IsFinancialConnectionsAvailable;)Lcom/stripe/android/ui/core/forms/resources/LpmRepository;
}

public abstract class com/stripe/android/ui/core/forms/resources/injection/ResourceRepositoryModule {
Expand Down
Expand Up @@ -8,6 +8,8 @@ import androidx.annotation.VisibleForTesting
import com.stripe.android.model.ConfirmPaymentIntentParams
import com.stripe.android.model.PaymentMethod
import com.stripe.android.model.PaymentMethodCode
import com.stripe.android.payments.financialconnections.DefaultIsFinancialConnectionsAvailable
import com.stripe.android.payments.financialconnections.IsFinancialConnectionsAvailable
import com.stripe.android.paymentsheet.forms.AffirmRequirement
import com.stripe.android.paymentsheet.forms.AfterpayClearpayRequirement
import com.stripe.android.paymentsheet.forms.AuBecsDebitRequirement
Expand Down Expand Up @@ -42,7 +44,9 @@ import javax.inject.Singleton
@Singleton
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
class LpmRepository @Inject constructor(
resources: Resources?
resources: Resources?,
private val isFinancialConnectionsAvailable: IsFinancialConnectionsAvailable =
DefaultIsFinancialConnectionsAvailable()
) {
private val lpmSerializer: LpmSerializer = LpmSerializer()

Expand All @@ -65,6 +69,12 @@ class LpmRepository @Inject constructor(
val parsedSupportedPaymentMethod = parseLpms(inputStream)
?.filter { exposedPaymentMethods.contains(it.type) }
?.mapNotNull { convertToSupportedPaymentMethod(it) }
?.toMutableList()

parsedSupportedPaymentMethod?.removeAll {
!isFinancialConnectionsAvailable() &&
it.code == PaymentMethod.Type.USBankAccount.code
}

// By mapNotNull we will not accept any LPMs that are not known by the platform.
codeToSupportedPaymentMethod =
Expand Down
Expand Up @@ -3,6 +3,7 @@ package com.stripe.android.ui.core.forms.resources
import android.app.Application
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import com.stripe.android.payments.financialconnections.IsFinancialConnectionsAvailable
import com.stripe.android.paymentsheet.forms.Delayed
import com.stripe.android.ui.core.elements.EmptyFormSpec
import org.junit.Test
Expand All @@ -12,7 +13,12 @@ import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class LpmRepositoryTest {
private val lpmRepository = LpmRepository(
ApplicationProvider.getApplicationContext<Application>().resources
ApplicationProvider.getApplicationContext<Application>().resources,
object : IsFinancialConnectionsAvailable {
override fun invoke(): Boolean {
return true
}
}
)

@Test
Expand Down Expand Up @@ -110,4 +116,43 @@ class LpmRepositoryTest {
lpmRepository.fromCode("sofort")?.requirement?.piRequirements
).contains(Delayed)
}

@Test
fun `Verify that us_bank_account is supported when financial connections sdk available`() {
lpmRepository.initialize(
"""
[
{
"type": "us_bank_account"
}
]
""".trimIndent().byteInputStream()
)

assertThat(lpmRepository.fromCode("us_bank_account")).isNotNull()
}

@Test
fun `Verify that us_bank_account not supported when financial connections sdk not available`() {
val lpmRepository = LpmRepository(
ApplicationProvider.getApplicationContext<Application>().resources,
object : IsFinancialConnectionsAvailable {
override fun invoke(): Boolean {
return false
}
}
)

lpmRepository.initialize(
"""
[
{
"type": "us_bank_account"
}
]
""".trimIndent().byteInputStream()
)

assertThat(lpmRepository.fromCode("us_bank_account")).isNull()
}
}

0 comments on commit 08f7aad

Please sign in to comment.