Skip to content

Commit 378fed9

Browse files
Add paymentMethodType to PaymentOption for FlowController. (#10940)
1 parent 9c852c8 commit 378fed9

File tree

11 files changed

+53
-9
lines changed

11 files changed

+53
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [ADDED][10935](https://github.com/stripe/stripe-android/pull/10935) Add `formInsetValues` method to `PaymentSheet.Appearance.Builder`.
77
* [ADDED][10831](https://github.com/stripe/stripe-android/pull/10831) Added `RowSelectionBehavior` API to Embedded Payment Element
88
* [DEPRECATED][10833](https://github.com/stripe/stripe-android/pull/10833) Deprecated PaymentSheet/FlowController constructors, create methods, and Compose remember functions in favor of new Builder pattern APIs.
9+
* [ADDED][10940](https://github.com/stripe/stripe-android/pull/10940) Add `paymentMethodType` to `PaymentOption` for use with `PaymentSheet.FlowController`.
910

1011
## 21.17.0 - 2025-06-09
1112

paymentsheet/api/paymentsheet.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,10 +2953,12 @@ public final class com/stripe/android/paymentsheet/model/PaymentOption {
29532953
public fun <init> (ILjava/lang/String;)V
29542954
public final fun component1 ()I
29552955
public final fun component2 ()Ljava/lang/String;
2956+
public final fun component3 ()Ljava/lang/String;
29562957
public fun equals (Ljava/lang/Object;)Z
29572958
public final fun getDrawableResourceId ()I
29582959
public final fun getIconPainter (Landroidx/compose/runtime/Composer;I)Landroidx/compose/ui/graphics/painter/Painter;
29592960
public final fun getLabel ()Ljava/lang/String;
2961+
public final fun getPaymentMethodType ()Ljava/lang/String;
29602962
public final fun getShippingDetails ()Lcom/stripe/android/paymentsheet/addresselement/AddressDetails;
29612963
public fun hashCode ()I
29622964
public final fun icon ()Landroid/graphics/drawable/Drawable;

paymentsheet/src/androidTest/java/com/stripe/android/paymentsheet/DefaultPaymentMethodsFlowControllerConfirmationTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ internal class DefaultPaymentMethodsFlowControllerConfirmationTest {
150150
page.clickPrimaryButton()
151151
composeTestRule.waitForIdle()
152152

153-
assertThat(testContext.configureCallbackTurbine.awaitItem()?.label).endsWith(paymentMethodType.getLast4())
153+
val paymentOption = testContext.configureCallbackTurbine.awaitItem()
154+
assertThat(paymentOption?.label).endsWith(paymentMethodType.getLast4())
155+
assertThat(paymentOption?.paymentMethodType).isEqualTo(paymentMethodType.type.code)
154156

155157
composeTestRule.waitForIdle()
156158

paymentsheet/src/androidTest/java/com/stripe/android/paymentsheet/FlowControllerTest.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ internal class FlowControllerTest {
187187
page.fillOutCardDetails()
188188

189189
page.clickPrimaryButton()
190-
assertThat(testContext.configureCallbackTurbine.awaitItem()?.label).endsWith("4242")
190+
val paymentOption = testContext.configureCallbackTurbine.awaitItem()
191+
assertThat(paymentOption?.label).endsWith("4242")
192+
assertThat(paymentOption?.paymentMethodType).isEqualTo("card")
191193
composeTestRule.waitForIdle()
192194

193195
testContext.flowController.presentPaymentOptions()
@@ -233,14 +235,18 @@ internal class FlowControllerTest {
233235
page.assertLpmSelected("cashapp")
234236

235237
page.clickPrimaryButton()
236-
assertThat(testContext.configureCallbackTurbine.awaitItem()?.label).endsWith("Cash App Pay")
238+
val paymentOption1 = testContext.configureCallbackTurbine.awaitItem()
239+
assertThat(paymentOption1?.label).endsWith("Cash App Pay")
240+
assertThat(paymentOption1?.paymentMethodType).isEqualTo("cashapp")
237241
composeTestRule.waitForIdle()
238242

239243
testContext.flowController.presentPaymentOptions()
240244

241245
page.assertLpmSelected("cashapp")
242246
page.clickPrimaryButton()
243-
assertThat(testContext.configureCallbackTurbine.awaitItem()?.label).endsWith("Cash App Pay")
247+
val paymentOption2 = testContext.configureCallbackTurbine.awaitItem()
248+
assertThat(paymentOption2?.label).endsWith("Cash App Pay")
249+
assertThat(paymentOption2?.paymentMethodType).isEqualTo("cashapp")
244250

245251
testContext.markTestSucceeded()
246252
}
@@ -831,7 +837,9 @@ internal class FlowControllerTest {
831837
.and(hasText("4242", substring = true))
832838
).performClick()
833839

834-
assertThat(testContext.configureCallbackTurbine.awaitItem()?.label).endsWith("4242")
840+
val paymentOption = testContext.configureCallbackTurbine.awaitItem()
841+
assertThat(paymentOption?.label).endsWith("4242")
842+
assertThat(paymentOption?.paymentMethodType).isEqualTo("card")
835843

836844
page.fillCvcRecollection("123")
837845

@@ -911,7 +919,9 @@ internal class FlowControllerTest {
911919

912920
testContext.configureCallbackTurbine.expectNoEvents()
913921
page.clickPrimaryButton()
914-
assertThat(testContext.configureCallbackTurbine.awaitItem()?.label).endsWith("4242")
922+
val paymentOption = testContext.configureCallbackTurbine.awaitItem()
923+
assertThat(paymentOption?.label).endsWith("4242")
924+
assertThat(paymentOption?.paymentMethodType).isEqualTo("card")
915925
testContext.markTestSucceeded()
916926
}
917927

paymentsheet/src/androidTest/java/com/stripe/android/paymentsheet/GooglePayTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ internal class GooglePayTest {
148148

149149
if (context is ProductIntegrationTestRunnerContext.WithFlowController) {
150150
runTest {
151-
val label = context.context.configureCallbackTurbine.awaitItem()?.label
152-
assertThat(label).isEqualTo("Google Pay")
151+
val paymentOption = context.context.configureCallbackTurbine.awaitItem()
152+
assertThat(paymentOption?.label).isEqualTo("Google Pay")
153+
assertThat(paymentOption?.paymentMethodType).isEqualTo("google_pay")
153154
}
154155

155156
context.confirm()

paymentsheet/src/main/java/com/stripe/android/paymentelement/EmbeddedPaymentElement.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class EmbeddedPaymentElement @Inject internal constructor(
518518
* - If this is a Stripe payment method, see
519519
* https://stripe.com/docs/api/payment_methods/object#payment_method_object-type for possible values.
520520
* - If this is an external payment method, see
521-
* https://stripe.com/docs/payments/external-payment-methods?platform=ios#available-external-payment-methods
521+
* https://docs.stripe.com/payments/mobile/external-payment-methods?platform=android
522522
* for possible values.
523523
* - If this is Google Pay, the value is "google_pay".
524524
*/

paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/PaymentOption.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ data class PaymentOption internal constructor(
2424
* For example, "···· 4242" for a Visa ending in 4242.
2525
*/
2626
val label: String,
27+
/**
28+
* A string representation of the customer's desired payment method:
29+
* - If this is a Stripe payment method, see
30+
* https://stripe.com/docs/api/payment_methods/object#payment_method_object-type for possible values.
31+
* - If this is an external payment method, see
32+
* https://docs.stripe.com/payments/mobile/external-payment-methods?platform=android
33+
* for possible values.
34+
* - If this is Google Pay, the value is "google_pay".
35+
*/
36+
val paymentMethodType: String,
2737
private val _shippingDetails: AddressDetails?,
2838

2939
private val imageLoader: suspend () -> Drawable,
@@ -44,6 +54,7 @@ data class PaymentOption internal constructor(
4454
) : this(
4555
drawableResourceId = drawableResourceId,
4656
label = label,
57+
paymentMethodType = "unsupportedInitializationType",
4758
_shippingDetails = null,
4859
imageLoader = errorImageLoader,
4960
)

paymentsheet/src/main/java/com/stripe/android/paymentsheet/model/PaymentOptionFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal class PaymentOptionFactory @Inject constructor(
1313
return PaymentOption(
1414
drawableResourceId = selection.drawableResourceId,
1515
label = selection.label.resolve(context),
16+
paymentMethodType = selection.paymentMethodType,
1617
_shippingDetails = selection.shippingDetails,
1718
imageLoader = {
1819
iconLoader.load(

paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class CustomerSheetTest {
123123

124124
assertThat(paymentMethodSelection.paymentMethod)
125125
.isEqualTo(CARD_PAYMENT_METHOD.copy(id = "pm_1"))
126+
assertThat(paymentMethodSelection.paymentOption.paymentMethodType)
127+
.isEqualTo("card")
126128
assertThat(paymentMethodSelection.paymentOption.label)
127129
.isEqualTo("···· 4242")
128130
}

paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ internal class DefaultFlowControllerTest {
441441
val paymentOption = flowController.getPaymentOption()
442442
assertThat(paymentOption?.drawableResourceId).isEqualTo(R.drawable.stripe_ic_paymentsheet_card_visa_ref)
443443
assertThat(paymentOption?.label).isEqualTo("···· $last4")
444+
assertThat(paymentOption?.paymentMethodType).isEqualTo("card")
444445
}
445446

446447
@Test
@@ -463,6 +464,7 @@ internal class DefaultFlowControllerTest {
463464
val paymentOption = flowController.getPaymentOption()
464465
assertThat(paymentOption?.drawableResourceId).isEqualTo(R.drawable.stripe_ic_paymentsheet_card_visa_ref)
465466
assertThat(paymentOption?.label).isEqualTo("···· $last4")
467+
assertThat(paymentOption?.paymentMethodType).isEqualTo("card")
466468

467469
// Simulate a real FlowControllerInitializer that fetches the payment methods for the new
468470
// customer, who doesn't have any saved payment methods
@@ -659,6 +661,7 @@ internal class DefaultFlowControllerTest {
659661
val paymentOption = flowController.getPaymentOption()
660662
assertThat(paymentOption?.drawableResourceId).isEqualTo(R.drawable.stripe_ic_paymentsheet_card_visa_ref)
661663
assertThat(paymentOption?.label).isEqualTo("···· 4242")
664+
assertThat(paymentOption?.paymentMethodType).isEqualTo("card")
662665
}
663666

664667
@Test
@@ -688,6 +691,7 @@ internal class DefaultFlowControllerTest {
688691
val paymentOption = flowController.getPaymentOption()
689692
assertThat(paymentOption?.drawableResourceId).isEqualTo(R.drawable.stripe_google_pay_mark)
690693
assertThat(paymentOption?.label).isEqualTo("Google Pay")
694+
assertThat(paymentOption?.paymentMethodType).isEqualTo("google_pay")
691695
}
692696

693697
@Test
@@ -782,6 +786,7 @@ internal class DefaultFlowControllerTest {
782786
val paymentOption = flowController.getPaymentOption()
783787
assertThat(paymentOption?.drawableResourceId).isEqualTo(R.drawable.stripe_google_pay_mark)
784788
assertThat(paymentOption?.label).isEqualTo("Google Pay")
789+
assertThat(paymentOption?.paymentMethodType).isEqualTo("google_pay")
785790
}
786791

787792
@Test

0 commit comments

Comments
 (0)