-
Notifications
You must be signed in to change notification settings - Fork 662
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
Add set as default feature enabled and disabled state to CustomerState #10046
base: master
Are you sure you want to change the base?
Conversation
…ith DefaultPaymentMethodState
@@ -558,29 +557,29 @@ internal class DefaultPaymentElementLoader @Inject constructor( | |||
|
|||
private suspend fun retrieveInitialPaymentSelection( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-worked this function and also withDefaultPaymentMethodOrLastUsedPaymentMethodFirst.
Accessing the defaultPaymentMethodId is a bit more complicated now and the code became hard to read unless I adjusted a bit. The behavior is the same though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth breaking this code out into another object, testing the defaulting logic in isolation, and injecting that object into the loader for use?
defaultPaymentMethodId = null | ||
) | ||
) | ||
assertThat(customerState.permissions.canRemovePaymentMethods).isFalse() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated a few of these tests to only assert on the fields relevant to the test, so that I wouldn't need to update the defaultPaymentMethodId field in as many places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that we can remove
customerId = "cus_1",
ephemeralKeySecret = "ek_1",
from the calls of createElementsSessionCustomer
b/c createElementsSessionCustomer has
customerId: String = "cus_1",
ephemeralKeySecret: String = "ek_1",
As the default values already
defaultPaymentMethodId = null | ||
) | ||
) | ||
assertThat(state.customer?.paymentMethods).isEqualTo(cards) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated a this test and another one below this to only assert on the field relevant to the test, so that I wouldn't need to update the defaultPaymentMethodId field in as many places
Diffuse output:
APK
|
customer.await()?.defaultPaymentMethodId?.let { | ||
customer.await()?.paymentMethods?.firstOrNull { | ||
it.id == customer.await()?.defaultPaymentMethodId | ||
val customer = customerDeferred.await() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a difference between customerDeferred.await()
inside retrieveInitialPaymentSelection
and
retrieveInitialPaymentSelection(
savedSelection = savedSelection,
customer = customer.await(),
isGooglePayReady = isGooglePayReady,
)
} | ||
} | ||
|
||
return primaryPaymentMethodIndex?.let { | ||
val primaryPaymentMethod = get(primaryPaymentMethodIndex) | ||
val primaryPaymentMethod = this.firstOrNull { it.id == primaryPaymentMethodId } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better than what I wrote
Summary
Add set as default feature enabled and disabled state to CustomerState
Motivation
I'm working on replacing the feature flag for the set as default feature with the customer session feature. jira
This is pre-work for that. This consolidates where we are reading the feature flag to be only within CustomerState and then as a next step we can replace the feature flag with the feature enabled/disabled value from the customer session.
Testing
No behavior changes -- all covered by existing tests