-
Notifications
You must be signed in to change notification settings - Fork 996
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
Set set_as_default_payment_method field using checkbox value #4502
Conversation
…om:stripe/stripe-ios into joyceqin/remove-button-matches-save-button
🚨 New dead code detected in this PR: UIColor+Extensions.swift:34 warning: Property 'textBrand' is unused
UIColor+Extensions.swift:38 warning: Property 'textDisabled' is unused
UIColor+Extensions.swift:42 warning: Property 'textCritical' is unused
UIColor+Extensions.swift:50 warning: Property 'textSuccess' is unused
UIColor+Extensions.swift:70 warning: Property 'borderCritical' is unused
UIColor+Extensions.swift:90 warning: Property 'neutral0' is unused
UIColor+Extensions.swift:114 warning: Property 'neutral300' is unused
UIColor+Extensions.swift:118 warning: Property 'neutral500' is unused
UIColor+Extensions.swift:138 warning: Property 'brand100' is unused
UIColor+Extensions.swift:150 warning: Property 'critical500' is unused
UIColor+Extensions.swift:158 warning: Property 'success100' is unused
UIColor+Extensions.swift:162 warning: Property 'success500' is unused
UIColor+Extensions.swift:182 warning: Function 'dynamic(light:dark:)' is unused
DropdownFieldElement.swift:10 warning: Imported module 'StripeCore' is unused
DropdownFieldElement.swift:267 warning: Parameter 'pickerView' is unused Please remove the dead code before merging. If this is intentional, you can bypass this check by adding the label ℹ️ If this comment appears to be left in error, double check that the flagged code is actually used and/or make sure your branch is up-to-date with |
StripePayments- public var setAsDefaultPM: Foundation.NSNumber?
- public var setAsDefaultPM: Foundation.NSNumber? StripePaymentSheet- case integrationError(nonPIIDebugDescription: Swift.String) If you are adding a new public API consider the following:
If you are modifying or removing a public API:
If you confirm these APIs need to be added/updated and have undergone necessary review, add the label ℹ️ If this comment appears to be left in error, make sure your branch is up-to-date with |
…s into joyceqin/MOBILESDK-2697
) { result, _ in | ||
switch result { | ||
case .completed: | ||
sleep(10) |
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.
For some reason, querying the elementsSession immediately after confirming it, the default payment method returns nil— back end delay in setting it?
…s into joyceqin/MOBILESDK-2697
var setAsDefaultPM: 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.
Can we add a doc comment for what this does?
if configuration.allowsSetAsDefaultPM { | ||
// TODO: update internal default endpoint | ||
} else { | ||
try await customerSheetDataSource.setSelectedPaymentOption(paymentOption: customerPaymentMethodOption) | ||
} |
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 we need this change in this PR? Seems like it doesn't really do much than no-op for allowsSetAsDefaultPM
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 suppose not, I think this was a remnant of when I started implementing it for CustomerSheet but then we decided not to
if let shouldSetAsDefaultPM = shouldSetAsDefaultPM { | ||
params.setAsDefaultPM = NSNumber(value: shouldSetAsDefaultPM) | ||
} |
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 shorten this to params.setAsDefaultPM = NSNumber(value: shouldSetAsDefaultPM ?? false)
, same with in the other spot we do this.
@@ -371,7 +371,8 @@ extension PaymentSheetFormFactory { | |||
isSelectedByDefault: false, | |||
didToggle: didToggle | |||
) | |||
return PaymentMethodElementWrapper(element) { _, params in | |||
return PaymentMethodElementWrapper(element) { checkbox, params in |
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.
Nit: There can be two checkboxes, or at least it seems unclear what checkbox this refers to, can we make it something more specific to what checkbox it is?
@@ -65,6 +65,28 @@ class PaymentSheetAPITest: STPNetworkStubbingTestCase { | |||
return newCardPaymentOption | |||
}() | |||
|
|||
lazy var newCardDefaultPaymentOption: PaymentSheet.PaymentOption = { |
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.
Any way we can DRY up the duplication of code between this and "newCardPaymentOption"?
9277438
to
3bca1bc
Compare
@@ -985,7 +985,7 @@ extension IntentConfirmParams: Equatable { | |||
// Sanity check to make sure when we add new properties, we check them here | |||
let mirror = Mirror(reflecting: lhs) | |||
let propertyCount = mirror.children.count | |||
XCTAssertEqual(propertyCount, 7) | |||
XCTAssertEqual(propertyCount, 8) |
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 possible, I think it'd be valuable to add a test in here like testCard_OnlyCardInfo_WithDefaults or testCard_AllFields_WithDefaults where we set the default checkbox and confirm.
/// `@YES` to set this PaymentIntent’s PaymentMethod as the associated Customer's default | ||
/// This should be a boolean NSNumber, so that it can be `nil` | ||
@objc @_spi(STP) public var setAsDefaultPM: NSNumber? |
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.
Let's update STPSetupIntentConfirmParamsTest with these changes.
@@ -80,6 +80,10 @@ public class STPPaymentIntentParams: NSObject { | |||
/// This should be a boolean NSNumber, so that it can be `nil` | |||
@objc public var savePaymentMethod: NSNumber? | |||
|
|||
/// `@YES` to set this PaymentIntent’s PaymentMethod as the associated Customer's default | |||
/// This should be a boolean NSNumber, so that it can be `nil` | |||
@objc @_spi(STP) public var setAsDefaultPM: NSNumber? |
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.
Let's update STPPaymentIntentParamsTest with these changes
shouldSave: confirmParams.saveForFutureUseCheckboxState == .selected, | ||
shouldSetAsDefaultPM: confirmParams.setAsDefaultPM |
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.
Let's add a test like testDeferredConfirm_valid_new_card_and_save_checkbox_selected for the default PM flow.
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 have a test testDeferredConfirm_valid_new_card_and_save_checkbox_selected_and_set_as_default already
if allowsSetAsDefaultPM { | ||
customerSessionData = [ | ||
"mobile_payment_element": [ | ||
"enabled": true, | ||
"features": ["payment_method_save": "enabled", | ||
"payment_method_remove": "enabled", | ||
], | ||
], | ||
"customer_sheet": [ | ||
"enabled": 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.
shouldn't we set payment_method_set_as_default
to enabled if allowsSetAsDefaultPM
is 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.
Also, please see _testValue on line 61 and see how customerSessionData can be used to pass in the customerSessionData. E.g.:
STPElementsSession._testValue(paymentMethodTypes: ["card"],
customerSessionData: [
"mobile_payment_element": [
"enabled": false,
],
"customer_sheet": [
"enabled": true,
"features": ["payment_method_remove": "enabled"],
],
])
Summary
Added setAsDefault to IntentConfirmParams to set the set_as_default_payment_method flag on the confirm call when checkbox is checked
Motivation
MOBILESDK-2697
MOBILESDK-2699
Testing
Changelog