-
Notifications
You must be signed in to change notification settings - Fork 995
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
read from customersession setting instead of config #4517
base: master
Are you sure you want to change the base?
Conversation
1 build decreased size, 7 builds had no size change
StripeSize 1.0 (1)
|
Item | Install Size Change |
---|---|
🗑 StripePaymentSheet.PaymentSheetFormFactory.makeCard(cardBrandChoi... | ⬇️ -13.7 kB |
📝 StripePaymentSheet.PaymentSheetFormFactory.makeCard(cardBrandChoi... | ⬆️ 13.0 kB |
🗑 StripePaymentSheet.PaymentSheetFormFactory.makeUSBankAccount(merc... | ⬇️ -8.1 kB |
📝 StripePaymentSheet.PaymentSheetFormFactory.makeUSBankAccount(merc... | ⬆️ 7.4 kB |
📝 StripePaymentSheet.SavedPaymentOptionsViewController.makeViewMode... | ⬆️ 1.7 kB |
StripeIdentitySize 1.0 (1)
com.stripe.StripeIdentitySize
No changes to report
StripeApplePaySize 1.0 (1)
com.stripe.StripeApplePaySize
No changes to report
StripeFinancialConnectionsSize 1.0 (1)
com.stripe.StripeFinancialConnectionsSize
No changes to report
StripeConnectSize 1.0 (1)
com.stripe.StripeConnectSize
No changes to report
🛸 Powered by Emerge Tools
…t for customersheet, fix some tests
…s into joyceqin/MOBILESDK-2666
/// This is an experimental feature that may be removed at any time. | ||
/// If true, users can set a payment method as default and sync their default payment method across web and mobile | ||
/// If false (default), users cannot set default payment methods. | ||
@_spi(AllowsSetAsDefaultPM) public var allowsSetAsDefaultPM = false |
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.
Do a search in the codebase for I see 3 instances that need to be removed/cleaned up. (AllowsSetAsDefaultPM)
@@ -42,6 +42,7 @@ struct CustomerSession: Equatable, Hashable { | |||
return nil | |||
} | |||
let paymentMethodRemoveLast = mobilePaymentElementFeaturesDict["payment_method_remove_last"] as? String ?? "enabled" | |||
let paymentMethodSetAsDefault = mobilePaymentElementFeaturesDict["payment_method_set_as_default"] as? String ?? "disabled" |
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.
Surprised we don't have any tests for this class? If so can we file a run ticket to get some tests created for this class.
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.
Created a ticket: RUN_MOBILESDK-3836
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.
We do have tests. They are in STPElementsSessionTest.swift
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.
Ah I see, it's a child of ElementsSession. Kinda hard to tell it's being tested might still be good to have standalone tests.
} | ||
func testSetAsDefault_disabled() { |
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.
Super nit: Our linter on CI isn't working but let's always have a new line between functions
@@ -262,6 +262,41 @@ class STPElementsSessionTest: XCTestCase { | |||
|
|||
XCTAssertEqual(.legacy, savePaymentMethodConsentBehavior) | |||
} | |||
func testSetAsDefault_enabled() { |
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.
Can we update testDecodedObjectFromAPIResponseMapping to make sure that paymentMethodSetAsDefaultForPaymentSheet defaults to false?
@@ -107,10 +107,10 @@ extension CustomerSessionAdapter { | |||
return stripePaymentMethodId | |||
} | |||
|
|||
func fetchSelectedPaymentOption(for customerId: String, customer: ElementsCustomer? = nil) -> CustomerPaymentOption? { | |||
func fetchSelectedPaymentOption(for customerId: String, elementsSession: STPElementsSession? = nil) -> CustomerPaymentOption? { |
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.
Similarly surprised we don't have tests for this, can you mention this class in the JIRA ticket you create.
@@ -42,7 +42,7 @@ class CustomerSheetDataSource { | |||
await loadFormSpecs() | |||
let customerId = try await customerSessionClientSecret.customerId | |||
let elementSession = try await elementsSessionResult | |||
let paymentOption = customerSessionAdapter.fetchSelectedPaymentOption(for: customerId, customer: elementSession.customer) |
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.
Hm same, this entire file has no tests :(
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.
Not having tests for this class was intentional for most functions in this class as they are just switching on legacy ephemeral keys vs customersession. For loadPaymentMethodInfo
it's debatable whether we want to add tests it seems like we'd end up with a lot of mocked responses so it's unclear how helpful it would be.
@@ -200,7 +200,7 @@ extension PaymentSheet { | |||
params, | |||
with: authenticationContext, | |||
completion: { actionStatus, paymentIntent, error in | |||
if let paymentIntent { | |||
if let paymentIntent, !elementsSession.paymentMethodSetAsDefaultForPaymentSheet { |
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 reads backwards to me, why are we setting default if necessary only if NOT paymentMethodSetAsDefaultForPaymentSheet. Is setDefaultPaymentMethodIfNecessary setting the default in the local storage? If so let's make this more clear there is a difference between where we are saving defaults.
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.
Maybe pass this flag into setDefaultPaymentMethodIfNecessary rather than checking it here? Seems like the wrong place to do it.
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.
Yeah, setDefaultPaymentMethodIfNecessary writes to local storage
@@ -222,7 +222,7 @@ extension PaymentSheet { | |||
setupIntentParams, | |||
with: authenticationContext, | |||
completion: { actionStatus, setupIntent, error in | |||
if let setupIntent { | |||
if let setupIntent, !elementsSession.paymentMethodSetAsDefaultForPaymentSheet { |
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.
Same here
if let paymentOrSetupIntent, !allowsSetAsDefaultPM { | ||
setDefaultPaymentMethodIfNecessary(actionStatus: status, intent: paymentOrSetupIntent, configuration: configuration) |
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.
Same comment here as above
@@ -319,7 +318,7 @@ final class PaymentSheetLoader { | |||
if let customerID = configuration.customer?.id { | |||
var defaultPaymentMethodOption: CustomerPaymentOption? | |||
// if opted in to the "set as default" feature, try to get default payment method from elements session |
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 this comment still true?
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.
Yes, we read from the CustomerSession setting to see if the feature is on, and if so, it tries to get the default payment method from the ElementsSession, but otherwise, it reads from the local storage
…s into joyceqin/MOBILESDK-2666
@@ -211,6 +211,10 @@ extension STPElementsSession { | |||
return customer?.customerSession.mobilePaymentElementComponent.features?.paymentMethodRemoveLast ?? true | |||
} | |||
|
|||
var paymentMethodSetAsDefaultForPaymentSheet: Bool { |
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.
Doesn't need to be in this PR, but we should probably rename xForPaymentSheet to xForMPE
@@ -526,10 +530,10 @@ extension PaymentSheetFormFactory { | |||
) | |||
} | |||
|
|||
func makeUSBankAccount(merchantName: String) -> PaymentMethodElement { | |||
func makeUSBankAccount(merchantName: String, showSetAsDefaultCheckbox: Bool = false) -> PaymentMethodElement { |
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.
There doesn't seem to be a good reason to default to false.
@@ -13,10 +13,10 @@ import StripePayments | |||
import UIKit | |||
|
|||
extension PaymentSheetFormFactory { | |||
func makeCard(cardBrandChoiceEligible: Bool = false) -> PaymentMethodElement { | |||
func makeCard(cardBrandChoiceEligible: Bool = false, showSetAsDefaultCheckbox: Bool = false) -> PaymentMethodElement { |
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 good reason to default showSetAsDefaultCheckbox to false?
if let elementsSession = elementsSession, | ||
let customer = elementsSession.customer, | ||
let features = customer.customerSession.mobilePaymentElementComponent.features, | ||
features.paymentMethodSetAsDefault, | ||
let defaultPaymentMethod = customer.getDefaultOrFirstPaymentMethod() { |
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.
If we go with this pattern, it could be more simply written:
if let elementsSession,
elementsSession.paymentMethodSetAsDefaultForPaymentSheet,
let defaultPaymentMethod = elementsSession.customer?.getDefaultOrFirstPaymentMethod() {
But, taking a step back, have we considered passing in the elementsSession instance into CustomerPaymentOption
so that we can just simply write something like:
CustomerPaymentOption.defaultPaymentMethod(for: customerID, elementsSession: elementsSession, surface: .paymentSheet)
Summary
Reads whether the feature is enabled from ElementsSession.customer.customerSession instead of PaymentSheet/CustomerSheet Configuration
Motivation
MOBILESDK-2666
Testing
Changelog