Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

amk-stripe
Copy link
Collaborator

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

  • Added tests
  • Modified tests
  • Manually verified

No behavior changes -- all covered by existing tests

@@ -558,29 +557,29 @@ internal class DefaultPaymentElementLoader @Inject constructor(

private suspend fun retrieveInitialPaymentSelection(
Copy link
Collaborator Author

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

Copy link
Collaborator

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()
Copy link
Collaborator Author

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

Copy link
Contributor

@tianzhao-stripe tianzhao-stripe Jan 31, 2025

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)
Copy link
Collaborator Author

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

Copy link
Contributor

Diffuse output:

OLD: identity-example-release-base.apk (signature: V1, V2)
NEW: identity-example-release-pr.apk (signature: V1, V2)

          │          compressed          │         uncompressed         
          ├───────────┬───────────┬──────┼───────────┬───────────┬──────
 APK      │ old       │ new       │ diff │ old       │ new       │ diff 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
      dex │     2 MiB │     2 MiB │  0 B │   4.1 MiB │   4.1 MiB │  0 B 
     arsc │     1 MiB │     1 MiB │  0 B │     1 MiB │     1 MiB │  0 B 
 manifest │   2.3 KiB │   2.3 KiB │  0 B │     8 KiB │     8 KiB │  0 B 
      res │ 302.6 KiB │ 302.6 KiB │  0 B │ 456.7 KiB │ 456.7 KiB │  0 B 
   native │   6.2 MiB │   6.2 MiB │  0 B │  15.8 MiB │  15.8 MiB │  0 B 
    asset │   7.1 KiB │   7.1 KiB │  0 B │   6.9 KiB │   6.9 KiB │  0 B 
    other │  90.4 KiB │  90.4 KiB │ +5 B │ 170.7 KiB │ 170.7 KiB │  0 B 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
    total │   9.6 MiB │   9.6 MiB │ +5 B │  21.5 MiB │  21.5 MiB │  0 B 

 DEX     │ old   │ new   │ diff      
─────────┼───────┼───────┼───────────
   files │     1 │     1 │ 0         
 strings │ 19975 │ 19975 │ 0 (+0 -0) 
   types │  6193 │  6193 │ 0 (+0 -0) 
 classes │  4985 │  4985 │ 0 (+0 -0) 
 methods │ 29820 │ 29820 │ 0 (+0 -0) 
  fields │ 17538 │ 17538 │ 0 (+0 -0) 

 ARSC    │ old  │ new  │ diff 
─────────┼──────┼──────┼──────
 configs │  164 │  164 │  0   
 entries │ 3624 │ 3624 │  0
APK
   compressed    │  uncompressed   │                     
──────────┬──────┼──────────┬──────┤                     
 size     │ diff │ size     │ diff │ path                
──────────┼──────┼──────────┼──────┼─────────────────────
 28.5 KiB │ +6 B │ 63.1 KiB │  0 B │ ∆ META-INF/CERT.SF  
  1.2 KiB │ -1 B │  1.2 KiB │  0 B │ ∆ META-INF/CERT.RSA 
──────────┼──────┼──────────┼──────┼─────────────────────
 29.7 KiB │ +5 B │ 64.3 KiB │  0 B │ (total)

@amk-stripe amk-stripe marked this pull request as ready for review January 31, 2025 00:54
@amk-stripe amk-stripe requested review from a team as code owners January 31, 2025 00:54
customer.await()?.defaultPaymentMethodId?.let {
customer.await()?.paymentMethods?.firstOrNull {
it.id == customer.await()?.defaultPaymentMethodId
val customer = customerDeferred.await()
Copy link
Contributor

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 }
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants