Skip to content

Commit

Permalink
defaultPaymentMethodId to savedPaymentMethodSelectionId (#9931)
Browse files Browse the repository at this point in the history
* defaultPaymentMethodId to savedPaymentMethodSelectionId

* FakeElementsSessionRepository
  • Loading branch information
tianzhao-stripe authored Jan 17, 2025
1 parent 3a0e9e3 commit bc1d1ac
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sealed interface ElementsSessionParams : Parcelable {
val customerSessionClientSecret: String?
val locale: String?
val expandFields: List<String>
val defaultPaymentMethodId: String?
val savedPaymentMethodSelectionId: String?
val externalPaymentMethods: List<String>

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
Expand All @@ -23,7 +23,7 @@ sealed interface ElementsSessionParams : Parcelable {
override val clientSecret: String,
override val locale: String? = Locale.getDefault().toLanguageTag(),
override val customerSessionClientSecret: String? = null,
override val defaultPaymentMethodId: String? = null,
override val savedPaymentMethodSelectionId: String? = null,
override val externalPaymentMethods: List<String>,
) : ElementsSessionParams {

Expand All @@ -40,7 +40,7 @@ sealed interface ElementsSessionParams : Parcelable {
override val clientSecret: String,
override val locale: String? = Locale.getDefault().toLanguageTag(),
override val customerSessionClientSecret: String? = null,
override val defaultPaymentMethodId: String? = null,
override val savedPaymentMethodSelectionId: String? = null,
override val externalPaymentMethods: List<String>,
) : ElementsSessionParams {

Expand All @@ -57,7 +57,7 @@ sealed interface ElementsSessionParams : Parcelable {
override val locale: String? = Locale.getDefault().toLanguageTag(),
val deferredIntentParams: DeferredIntentParams,
override val externalPaymentMethods: List<String>,
override val defaultPaymentMethodId: String? = null,
override val savedPaymentMethodSelectionId: String? = null,
override val customerSessionClientSecret: String? = null,
) : ElementsSessionParams {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ class StripeApiRepository @JvmOverloads internal constructor(
params.locale.let { this["locale"] = it }
params.customerSessionClientSecret?.let { this["customer_session_client_secret"] = it }
params.externalPaymentMethods.takeIf { it.isNotEmpty() }?.let { this["external_payment_methods"] = it }
params.defaultPaymentMethodId?.let { this["client_default_payment_method"] = it }
params.savedPaymentMethodSelectionId?.let { this["client_default_payment_method"] = it }
(params as? ElementsSessionParams.DeferredIntentType)?.let { type ->
this.putAll(type.deferredIntentParams.toQueryParams())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,7 @@ internal class StripeApiRepositoryTest {
params = ElementsSessionParams.PaymentIntentType(
clientSecret = "client_secret",
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = "pm_123",
savedPaymentMethodSelectionId = "pm_123",
),
options = DEFAULT_OPTIONS,
)
Expand Down Expand Up @@ -2601,7 +2601,7 @@ internal class StripeApiRepositoryTest {
create().retrieveElementsSession(
params = ElementsSessionParams.PaymentIntentType(
clientSecret = "client_secret",
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
externalPaymentMethods = emptyList(),
),
options = DEFAULT_OPTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal class CustomerAdapterDataSource @Inject constructor(
initializationMode,
customer = null,
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
).onSuccess {
errorReporter.report(
errorEvent = ErrorReporter.SuccessEvent.CUSTOMER_SHEET_ELEMENTS_SESSION_LOAD_SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal class DefaultCustomerSessionElementsSessionManager @Inject constructor(
paymentMethodTypes = intentConfiguration.paymentMethodTypes,
)
),
defaultPaymentMethodId = savedSelection?.id,
savedPaymentMethodSelectionId = savedSelection?.id,
customer = PaymentSheet.CustomerConfiguration.createWithCustomerSession(
id = customerSessionClientSecret.customerId,
clientSecret = customerSessionClientSecret.clientSecret,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal interface ElementsSessionRepository {
initializationMode: PaymentElementLoader.InitializationMode,
customer: PaymentSheet.CustomerConfiguration?,
externalPaymentMethods: List<String>,
defaultPaymentMethodId: String?,
savedPaymentMethodSelectionId: String?,
): Result<ElementsSession>
}

Expand All @@ -50,12 +50,12 @@ internal class RealElementsSessionRepository @Inject constructor(
initializationMode: PaymentElementLoader.InitializationMode,
customer: PaymentSheet.CustomerConfiguration?,
externalPaymentMethods: List<String>,
defaultPaymentMethodId: String?,
savedPaymentMethodSelectionId: String?,
): Result<ElementsSession> {
val params = initializationMode.toElementsSessionParams(
customer = customer,
externalPaymentMethods = externalPaymentMethods,
defaultPaymentMethodId = defaultPaymentMethodId,
savedPaymentMethodSelectionId = savedPaymentMethodSelectionId,
)

val elementsSession = stripeRepository.retrieveElementsSession(
Expand Down Expand Up @@ -113,7 +113,7 @@ private fun StripeIntent.withoutWeChatPay(): StripeIntent {
internal fun PaymentElementLoader.InitializationMode.toElementsSessionParams(
customer: PaymentSheet.CustomerConfiguration?,
externalPaymentMethods: List<String>,
defaultPaymentMethodId: String?,
savedPaymentMethodSelectionId: String?,
): ElementsSessionParams {
val customerSessionClientSecret = customer?.toElementSessionParam()

Expand All @@ -123,7 +123,7 @@ internal fun PaymentElementLoader.InitializationMode.toElementsSessionParams(
clientSecret = clientSecret,
customerSessionClientSecret = customerSessionClientSecret,
externalPaymentMethods = externalPaymentMethods,
defaultPaymentMethodId = defaultPaymentMethodId,
savedPaymentMethodSelectionId = savedPaymentMethodSelectionId,
)
}

Expand All @@ -132,7 +132,7 @@ internal fun PaymentElementLoader.InitializationMode.toElementsSessionParams(
clientSecret = clientSecret,
customerSessionClientSecret = customerSessionClientSecret,
externalPaymentMethods = externalPaymentMethods,
defaultPaymentMethodId = defaultPaymentMethodId,
savedPaymentMethodSelectionId = savedPaymentMethodSelectionId,
)
}

Expand All @@ -141,7 +141,7 @@ internal fun PaymentElementLoader.InitializationMode.toElementsSessionParams(
deferredIntentParams = intentConfiguration.toDeferredIntentParams(),
externalPaymentMethods = externalPaymentMethods,
customerSessionClientSecret = customerSessionClientSecret,
defaultPaymentMethodId = defaultPaymentMethodId,
savedPaymentMethodSelectionId = savedPaymentMethodSelectionId,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ internal class DefaultPaymentElementLoader @Inject constructor(
initializationMode = initializationMode,
customer = configuration.customer,
externalPaymentMethods = configuration.externalPaymentMethods,
defaultPaymentMethodId = savedPaymentMethodSelection?.id,
savedPaymentMethodSelectionId = savedPaymentMethodSelection?.id,
).getOrThrow()

val customerInfo = createCustomerInfo(
Expand Down Expand Up @@ -233,13 +233,13 @@ internal class DefaultPaymentElementLoader @Inject constructor(
initializationMode: PaymentElementLoader.InitializationMode,
customer: PaymentSheet.CustomerConfiguration?,
externalPaymentMethods: List<String>,
defaultPaymentMethodId: String?,
savedPaymentMethodSelectionId: String?,
): Result<ElementsSession> {
return elementsSessionRepository.get(
initializationMode = initializationMode,
customer = customer,
externalPaymentMethods = externalPaymentMethods,
defaultPaymentMethodId = defaultPaymentMethodId
savedPaymentMethodSelectionId = savedPaymentMethodSelectionId
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DefaultCustomerSessionElementsSessionManagerTest {

val lastParams = elementsSessionRepository.lastParams

assertThat(lastParams?.defaultPaymentMethodId).isEqualTo("pm_123")
assertThat(lastParams?.savedPaymentMethodSelectionId).isEqualTo("pm_123")
assertThat(lastParams?.externalPaymentMethods).isEmpty()

val initializationMode = lastParams?.initializationMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal class ElementsSessionRepositoryTest {
),
customer = null,
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
).getOrThrow()
}

Expand Down Expand Up @@ -82,7 +82,7 @@ internal class ElementsSessionRepositoryTest {
),
customer = null,
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
).getOrThrow()
}

Expand All @@ -108,7 +108,7 @@ internal class ElementsSessionRepositoryTest {
),
customer = null,
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
).getOrThrow()
}

Expand Down Expand Up @@ -140,7 +140,7 @@ internal class ElementsSessionRepositoryTest {
),
customer = null,
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
).getOrThrow()

val argumentCaptor: KArgumentCaptor<ElementsSessionParams> = argumentCaptor()
Expand Down Expand Up @@ -177,7 +177,7 @@ internal class ElementsSessionRepositoryTest {
),
customer = null,
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
)

assertThat(session.isSuccess).isTrue()
Expand Down Expand Up @@ -210,7 +210,7 @@ internal class ElementsSessionRepositoryTest {
),
customer = null,
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
)

assertThat(session.isSuccess).isTrue()
Expand Down Expand Up @@ -246,7 +246,7 @@ internal class ElementsSessionRepositoryTest {
clientSecret = "customer_session_client_secret"
),
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
)

verify(stripeRepository).retrieveElementsSession(
Expand All @@ -255,7 +255,7 @@ internal class ElementsSessionRepositoryTest {
clientSecret = "client_secret",
customerSessionClientSecret = "customer_session_client_secret",
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = null,
savedPaymentMethodSelectionId = null,
)
),
options = any()
Expand Down Expand Up @@ -287,15 +287,15 @@ internal class ElementsSessionRepositoryTest {
),
customer = null,
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = "pm_123",
savedPaymentMethodSelectionId = "pm_123",
)

verify(stripeRepository).retrieveElementsSession(
params = eq(
ElementsSessionParams.PaymentIntentType(
clientSecret = "client_secret",
externalPaymentMethods = emptyList(),
defaultPaymentMethodId = "pm_123",
savedPaymentMethodSelectionId = "pm_123",
)
),
options = any()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@ internal class DefaultPaymentElementLoaderTest {
initializedViaCompose = false,
)

assertThat(repository.lastParams?.defaultPaymentMethodId)
assertThat(repository.lastParams?.savedPaymentMethodSelectionId)
.isEqualTo("pm_1234321")
}

Expand Down Expand Up @@ -1950,7 +1950,7 @@ internal class DefaultPaymentElementLoaderTest {
initializedViaCompose = false,
)

assertThat(repository.lastParams?.defaultPaymentMethodId).isNull()
assertThat(repository.lastParams?.savedPaymentMethodSelectionId).isNull()
}

@Test
Expand Down Expand Up @@ -1999,7 +1999,7 @@ internal class DefaultPaymentElementLoaderTest {
initializedViaCompose = false,
)

assertThat(repository.lastParams?.defaultPaymentMethodId).isNull()
assertThat(repository.lastParams?.savedPaymentMethodSelectionId).isNull()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class FakeElementsSessionRepository(
val initializationMode: PaymentElementLoader.InitializationMode,
val customer: PaymentSheet.CustomerConfiguration?,
val externalPaymentMethods: List<String>,
val defaultPaymentMethodId: String?
val savedPaymentMethodSelectionId: String?
)

var lastParams: Params? = null
Expand All @@ -29,13 +29,13 @@ internal class FakeElementsSessionRepository(
initializationMode: PaymentElementLoader.InitializationMode,
customer: PaymentSheet.CustomerConfiguration?,
externalPaymentMethods: List<String>,
defaultPaymentMethodId: String?,
savedPaymentMethodSelectionId: String?,
): Result<ElementsSession> {
lastParams = Params(
initializationMode = initializationMode,
customer = customer,
externalPaymentMethods = externalPaymentMethods,
defaultPaymentMethodId = defaultPaymentMethodId,
savedPaymentMethodSelectionId = savedPaymentMethodSelectionId,
)
return if (error != null) {
Result.failure(error)
Expand Down

0 comments on commit bc1d1ac

Please sign in to comment.