Skip to content

Commit 9970737

Browse files
committed
Added Generic to LinkController.PaymentMethodType
- Added `Generic` LinkPaymentMethodFilter - `PaymentMethodPreview` now returns `Generic` for `Generic` types
1 parent b9e99ab commit 9970737

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

paymentsheet/src/main/java/com/stripe/android/link/LinkController.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ class LinkController @Inject internal constructor(
757757
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
758758
enum class PaymentMethodType {
759759
Card,
760-
BankAccount
760+
BankAccount,
761+
Generic
761762
}
762763

763764
/**

paymentsheet/src/main/java/com/stripe/android/link/LinkControllerInteractor.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ internal class LinkControllerInteractor @Inject constructor(
234234
LinkController.PaymentMethodType.Card -> {
235235
config.billingDetailsCollectionConfiguration.name
236236
}
237+
LinkController.PaymentMethodType.Generic -> {
238+
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
239+
}
237240
}
238241

239242
val billingDetailsCollectionConfiguration = config.billingDetailsCollectionConfiguration
@@ -735,7 +738,7 @@ internal fun ConsumerPaymentDetails.PaymentDetails.toPreview(
735738
LinkController.PaymentMethodType.BankAccount
736739
}
737740
is ConsumerPaymentDetails.Generic -> {
738-
LinkController.PaymentMethodType.Card
741+
LinkController.PaymentMethodType.Generic
739742
}
740743
}
741744

@@ -803,4 +806,5 @@ private fun LinkController.PaymentMethodType.toFilter(): LinkPaymentMethodFilter
803806
when (this) {
804807
LinkController.PaymentMethodType.Card -> LinkPaymentMethodFilter.Card
805808
LinkController.PaymentMethodType.BankAccount -> LinkPaymentMethodFilter.BankAccount
809+
LinkController.PaymentMethodType.Generic -> LinkPaymentMethodFilter.Generic
806810
}

paymentsheet/src/main/java/com/stripe/android/link/LinkPaymentMethodFilter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import com.stripe.android.model.ConsumerPaymentDetails
44

55
internal enum class LinkPaymentMethodFilter {
66
Card,
7-
BankAccount;
7+
BankAccount,
8+
Generic;
89

910
operator fun invoke(details: ConsumerPaymentDetails.PaymentDetails): Boolean {
1011
return when (details) {
1112
is ConsumerPaymentDetails.BankAccount -> this == BankAccount
1213
is ConsumerPaymentDetails.Card -> this == Card
14+
is ConsumerPaymentDetails.Generic -> this == Generic
1315
else -> false
1416
}
1517
}

paymentsheet/src/test/java/com/stripe/android/link/LinkControllerInteractorTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,23 @@ class LinkControllerInteractorTest {
537537
.isEqualTo(PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always)
538538
}
539539

540+
@Test
541+
fun `onPresentPaymentMethods() with Generic payment method uses automatic name collection`() = runTest {
542+
val interactor = createInteractor()
543+
configure(interactor)
544+
545+
val launcher = FakeActivityResultLauncher<LinkActivityContract.Args>()
546+
interactor.presentPaymentMethods(
547+
launcher = launcher,
548+
email = null,
549+
paymentMethodType = LinkController.PaymentMethodType.Generic
550+
)
551+
552+
val collectionConfig = launcher.calls.awaitItem().input.configuration.billingDetailsCollectionConfiguration
553+
assertThat(collectionConfig.name)
554+
.isEqualTo(PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic)
555+
}
556+
540557
@Test
541558
fun `onLinkActivityResult() with PaymentMethodObtained result does nothing`() = runTest {
542559
val interactor = createInteractor()

paymentsheet/src/test/java/com/stripe/android/link/ui/wallet/AddPaymentMethodOptionsTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ class AddPaymentMethodOptionsTest {
9191
)
9292
}
9393

94+
@Test
95+
fun `values returns empty when Generic filter applied`() {
96+
val options = createOptions(paymentMethodFilter = LinkPaymentMethodFilter.Generic)
97+
98+
assertThat(options.values).isEmpty()
99+
}
100+
94101
@Test
95102
fun `values handles empty funding sources with card fallback`() {
96103
val options = createOptions(fundingSources = emptyList())

0 commit comments

Comments
 (0)