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

Set set_as_default_payment_method field using checkbox value #4502

Merged
merged 39 commits into from
Jan 30, 2025

Conversation

joyceqin-stripe
Copy link
Collaborator

@joyceqin-stripe joyceqin-stripe commented Jan 23, 2025

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

Copy link

github-actions bot commented Jan 23, 2025

🚨 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 skip dead code check to this PR.

ℹ️ 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 master.

Copy link

github-actions bot commented Jan 24, 2025

⚠️ Public API changes detected:

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:

  • Do these APIs need to be public or can they be protected with @_spi(STP)?
  • If these APIs need to be public, assess whether they require an API review.

If you are modifying or removing a public API:

  • Does this require a breaking version change?
  • Do these changes require API review?

If you confirm these APIs need to be added/updated and have undergone necessary review, add the label modifies public API to this PR to acknowledge and bypass this check.

ℹ️ If this comment appears to be left in error, make sure your branch is up-to-date with master.

@joyceqin-stripe joyceqin-stripe marked this pull request as ready for review January 28, 2025 20:47
@joyceqin-stripe joyceqin-stripe requested review from a team as code owners January 28, 2025 20:47
) { result, _ in
switch result {
case .completed:
sleep(10)
Copy link
Collaborator Author

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?

Comment on lines +48 to +49
var setAsDefaultPM: Bool?

Copy link
Collaborator

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?

Comment on lines 723 to 727
if configuration.allowsSetAsDefaultPM {
// TODO: update internal default endpoint
} else {
try await customerSheetDataSource.setSelectedPaymentOption(paymentOption: customerPaymentMethodOption)
}
Copy link
Collaborator

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

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 suppose not, I think this was a remnant of when I started implementing it for CustomerSheet but then we decided not to

Comment on lines 640 to 642
if let shouldSetAsDefaultPM = shouldSetAsDefaultPM {
params.setAsDefaultPM = NSNumber(value: shouldSetAsDefaultPM)
}
Copy link
Collaborator

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

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 = {
Copy link
Collaborator

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"?

@joyceqin-stripe joyceqin-stripe force-pushed the joyceqin/MOBILESDK-2697 branch 2 times, most recently from 9277438 to 3bca1bc Compare January 29, 2025 20:35
@@ -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)
Copy link
Collaborator

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.

Comment on lines +54 to +56
/// `@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?
Copy link
Collaborator

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?
Copy link
Collaborator

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

Comment on lines +193 to +194
shouldSave: confirmParams.saveForFutureUseCheckboxState == .selected,
shouldSetAsDefaultPM: confirmParams.setAsDefaultPM
Copy link
Collaborator

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.

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 have a test testDeferredConfirm_valid_new_card_and_save_checkbox_selected_and_set_as_default already

@joyceqin-stripe joyceqin-stripe merged commit e6d488d into master Jan 30, 2025
6 checks passed
@joyceqin-stripe joyceqin-stripe deleted the joyceqin/MOBILESDK-2697 branch January 30, 2025 22:49
Comment on lines +165 to +177
if allowsSetAsDefaultPM {
customerSessionData = [
"mobile_payment_element": [
"enabled": true,
"features": ["payment_method_save": "enabled",
"payment_method_remove": "enabled",
],
],
"customer_sheet": [
"enabled": false,
]
]
}
Copy link
Collaborator

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?

Copy link
Collaborator

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"],
                                                           ],
                                                       ])

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.

3 participants