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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7bc9d63
set remove button height to match save button
joyceqin-stripe Jan 21, 2025
66255c3
Merge branch 'master' into joyceqin/remove-button-matches-save-button
joyceqin-stripe Jan 21, 2025
0955579
separated RemoveButton into own class
joyceqin-stripe Jan 22, 2025
2d27f68
Merge branch 'master' into joyceqin/remove-button-matches-save-button
joyceqin-stripe Jan 22, 2025
dd1ddb1
Merge branch 'joyceqin/remove-button-matches-save-button' of github.c…
joyceqin-stripe Jan 22, 2025
fdf24e5
remove dead code
joyceqin-stripe Jan 22, 2025
0615150
use parameter
joyceqin-stripe Jan 22, 2025
ae0cafd
client-side set_as_default_payment_method
joyceqin-stripe Jan 23, 2025
26401fe
Merge branch 'master' into joyceqin/MOBILESDK-2697
joyceqin-stripe Jan 23, 2025
d7cbfdf
always set set_as_default_payment_method param to a value
joyceqin-stripe Jan 23, 2025
3b33102
remove unused code
joyceqin-stripe Jan 24, 2025
dad8ae7
remove extra arguments
joyceqin-stripe Jan 24, 2025
ddbeea9
removed more unused code
joyceqin-stripe Jan 24, 2025
af21c85
set as default checkbox on new pm in customersheet
joyceqin-stripe Jan 24, 2025
48f02d2
remove checkbox from customersheet until we know better how to proceed
joyceqin-stripe Jan 24, 2025
bcc1ff7
revert customersheet changes
joyceqin-stripe Jan 27, 2025
549aaef
revert change
joyceqin-stripe Jan 27, 2025
b7e62a7
Merge branch 'master' into joyceqin/MOBILESDK-2697
joyceqin-stripe Jan 27, 2025
4e762cb
attempt at test
joyceqin-stripe Jan 28, 2025
e00ee59
test network stubs
joyceqin-stripe Jan 28, 2025
041f865
changed property number in test
joyceqin-stripe Jan 28, 2025
9aa4e8b
Merge branch 'master' into joyceqin/MOBILESDK-2697
joyceqin-stripe Jan 28, 2025
f28ac9f
revert test timeout
joyceqin-stripe Jan 28, 2025
2e33889
Merge branch 'joyceqin/MOBILESDK-2697' of github.com:stripe/stripe-io…
joyceqin-stripe Jan 28, 2025
030ca74
tests
joyceqin-stripe Jan 28, 2025
2b75dcc
fix build?
joyceqin-stripe Jan 28, 2025
53ae9a8
deferred paymentintent test attempt
joyceqin-stripe Jan 28, 2025
c606817
add timeout to deferred paymentintent test
joyceqin-stripe Jan 28, 2025
222bdf1
Merge branch 'master' into joyceqin/MOBILESDK-2697
joyceqin-stripe Jan 28, 2025
4aaa0ef
fix network stubs?
joyceqin-stripe Jan 29, 2025
168ed36
lower timeout
joyceqin-stripe Jan 29, 2025
855f7e1
Merge branch 'joyceqin/MOBILESDK-2697' of github.com:stripe/stripe-io…
joyceqin-stripe Jan 29, 2025
a9d9db1
clean up
joyceqin-stripe Jan 29, 2025
3bca1bc
Merge branch 'master' into joyceqin/MOBILESDK-2697
joyceqin-stripe Jan 29, 2025
3e7c01a
revert params.setAsDefaultPM
joyceqin-stripe Jan 29, 2025
07182b9
Merge branch 'master' into joyceqin/MOBILESDK-2697
joyceqin-stripe Jan 29, 2025
1846b90
Merge branch 'master' into joyceqin/MOBILESDK-2697
joyceqin-stripe Jan 30, 2025
145ff3a
added tests
joyceqin-stripe Jan 30, 2025
66bc395
return test api_key to ek
joyceqin-stripe Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Stripe/StripeiOSTests/STPPaymentIntentParamsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class STPPaymentIntentParamsTest: XCTestCase {
XCTAssertNil(params.perform(NSSelectorFromString("saveSourceToCustomer")))
XCTAssertNil(params.savePaymentMethod)
XCTAssertNil(params.returnURL)
XCTAssertNil(params.setAsDefaultPM)
XCTAssertNil(params.setupFutureUsage)
XCTAssertNil(params.useStripeSDK)
XCTAssertNil(params.mandateData)
Expand Down Expand Up @@ -141,6 +142,7 @@ class STPPaymentIntentParamsTest: XCTestCase {
params.paymentMethodId = "test_payment_method_id"
params.savePaymentMethod = NSNumber(value: true)
params.returnURL = "fake://testing_only"
params.setAsDefaultPM = NSNumber(value: true)
params.setupFutureUsage = STPPaymentIntentSetupFutureUsage(
rawValue: Int(truncating: NSNumber(value: 1))
)
Expand Down Expand Up @@ -172,6 +174,7 @@ class STPPaymentIntentParamsTest: XCTestCase {
XCTAssertEqual(params.setupFutureUsage, STPPaymentIntentSetupFutureUsage.none)
XCTAssertEqual(params.savePaymentMethod, paramsCopy.savePaymentMethod)
XCTAssertEqual(params.returnURL, paramsCopy.returnURL)
XCTAssertEqual(params.setAsDefaultPM, paramsCopy.setAsDefaultPM)
XCTAssertEqual(params.useStripeSDK, paramsCopy.useStripeSDK)
XCTAssertEqual(params.paymentMethodOptions, paramsCopy.paymentMethodOptions)
XCTAssertEqual(
Expand Down
3 changes: 3 additions & 0 deletions Stripe/StripeiOSTests/STPSetupIntentConfirmParamsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class STPSetupIntentConfirmParamsTest: XCTestCase {
XCTAssertEqual(params.additionalAPIParameters.count, 0)
XCTAssertNil(params.paymentMethodID)
XCTAssertNil(params.returnURL)
XCTAssertNil(params.setAsDefaultPM)
XCTAssertNil(params.useStripeSDK)
XCTAssertNil(params.mandateData)
}
Expand Down Expand Up @@ -94,6 +95,7 @@ class STPSetupIntentConfirmParamsTest: XCTestCase {
params.paymentMethodParams = STPPaymentMethodParams()
params.paymentMethodID = "test_payment_method_id"
params.returnURL = "fake://testing_only"
params.setAsDefaultPM = NSNumber(value: true)
params.useStripeSDK = NSNumber(value: true)
params.mandateData = STPMandateDataParams(
customerAcceptance: STPMandateCustomerAcceptanceParams(
Expand All @@ -114,6 +116,7 @@ class STPSetupIntentConfirmParamsTest: XCTestCase {
XCTAssertEqual(params.mandateData, paramsCopy.mandateData)

XCTAssertEqual(params.returnURL, paramsCopy.returnURL)
XCTAssertEqual(params.setAsDefaultPM, paramsCopy.setAsDefaultPM)
XCTAssertEqual(params.useStripeSDK, paramsCopy.useStripeSDK)
XCTAssertEqual(
params.additionalAPIParameters as NSDictionary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ final class IntentConfirmParams {
}
}

/// True if the customer opts to save their payment method as their default payment method.
var setAsDefaultPM: Bool?

Comment on lines +49 to +50
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?

func makeIcon(updateImageHandler: DownloadManager.UpdateImageHandler?) -> UIImage {
if let bankName = (financialConnectionsLinkedBank?.bankName ?? instantDebitsLinkedBank?.bankName) {
return PaymentSheetImageLibrary.bankIcon(for: PaymentSheetImageLibrary.bankIconCode(for: bankName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ extension PaymentSheet {
confirmPaymentMethodType: .new(
params: confirmParams.paymentMethodParams,
paymentOptions: confirmParams.confirmPaymentMethodOptions,
shouldSave: confirmParams.saveForFutureUseCheckboxState == .selected
shouldSave: confirmParams.saveForFutureUseCheckboxState == .selected,
shouldSetAsDefaultPM: confirmParams.setAsDefaultPM
Comment on lines +193 to +194
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

),
paymentIntent: paymentIntent,
configuration: configuration
Expand All @@ -211,7 +212,8 @@ extension PaymentSheet {
confirmPaymentMethodType: .new(
params: confirmParams.paymentMethodParams,
paymentOptions: confirmParams.confirmPaymentMethodOptions,
shouldSave: false
shouldSave: false,
shouldSetAsDefaultPM: confirmParams.setAsDefaultPM
),
setupIntent: setupIntent,
configuration: configuration
Expand All @@ -232,7 +234,8 @@ extension PaymentSheet {
confirmType: .new(
params: confirmParams.paymentMethodParams,
paymentOptions: confirmParams.confirmPaymentMethodOptions,
shouldSave: confirmParams.saveForFutureUseCheckboxState == .selected
shouldSave: confirmParams.saveForFutureUseCheckboxState == .selected,
shouldSetAsDefaultPM: confirmParams.setAsDefaultPM
),
configuration: configuration,
intentConfig: intentConfig,
Expand Down Expand Up @@ -570,7 +573,9 @@ extension PaymentSheet {
intent.isSetupFutureUsageSet,
let paymentMethod = intent.paymentMethod,
// Can it appear in the list of saved PMs?
PaymentSheet.supportedSavedPaymentMethods.contains(paymentMethod.type)
PaymentSheet.supportedSavedPaymentMethods.contains(paymentMethod.type),
// Should we be writing to local storage?
!configuration.allowsSetAsDefaultPM
else {
return
}
Expand All @@ -592,12 +597,12 @@ extension PaymentSheet {
enum ConfirmPaymentMethodType {
case saved(STPPaymentMethod, paymentOptions: STPConfirmPaymentMethodOptions?)
/// - paymentMethod: Pass this if you created a PaymentMethod already (e.g. for the deferred flow).
case new(params: STPPaymentMethodParams, paymentOptions: STPConfirmPaymentMethodOptions, paymentMethod: STPPaymentMethod? = nil, shouldSave: Bool)
case new(params: STPPaymentMethodParams, paymentOptions: STPConfirmPaymentMethodOptions, paymentMethod: STPPaymentMethod? = nil, shouldSave: Bool, shouldSetAsDefaultPM: Bool? = nil)
var shouldSave: Bool {
switch self {
case .saved:
return false
case .new(_, _, _, let shouldSave):
case .new(_, _, _, let shouldSave, _):
return shouldSave
}
}
Expand All @@ -619,7 +624,7 @@ extension PaymentSheet {
params = STPPaymentIntentParams(clientSecret: paymentIntent.clientSecret, paymentMethodType: paymentMethod.type)
params.paymentMethodOptions = paymentMethodOptions
params.paymentMethodId = paymentMethod.stripeId
case let .new(paymentMethodParams, paymentMethodoptions, paymentMethod, _shouldSave):
case let .new(paymentMethodParams, paymentMethodoptions, paymentMethod, _shouldSave, shouldSetAsDefaultPM):
shouldSave = _shouldSave
if let paymentMethod = paymentMethod {
paymentMethodType = paymentMethod.type
Expand All @@ -632,7 +637,9 @@ extension PaymentSheet {
params.paymentMethodOptions = paymentMethodoptions
paymentMethodType = paymentMethodParams.type
}

if let shouldSetAsDefaultPM {
params.setAsDefaultPM = NSNumber(value: shouldSetAsDefaultPM)
}
let requiresMandateData: [STPPaymentMethodType] = [.payPal, .cashApp, .revolutPay, .amazonPay, .klarna]
if requiresMandateData.contains(paymentMethodType) && paymentIntent.setupFutureUsage == .offSession
{
Expand All @@ -652,7 +659,6 @@ extension PaymentSheet {
params.paymentMethodOptions = paymentOptions
params.returnURL = configuration.returnURL
params.shipping = makeShippingParams(for: paymentIntent, configuration: configuration)

return params
}

Expand All @@ -671,7 +677,7 @@ extension PaymentSheet {
)
params.paymentMethodID = paymentMethod.stripeId

case let .new(paymentMethodParams, _, paymentMethod, _):
case let .new(paymentMethodParams, _, paymentMethod, _, shouldSetAsDefaultPM):
if let paymentMethod {
params = STPSetupIntentConfirmParams(
clientSecret: setupIntent.clientSecret,
Expand All @@ -682,6 +688,9 @@ extension PaymentSheet {
params = STPSetupIntentConfirmParams(clientSecret: setupIntent.clientSecret)
params.paymentMethodParams = paymentMethodParams
}
if let shouldSetAsDefaultPM {
params.setAsDefaultPM = NSNumber(value: shouldSetAsDefaultPM)
}
// Paypal & revolut requires mandate_data if setting up
if params.paymentMethodType == .payPal || params.paymentMethodType == .revolutPay {
params.mandateData = .makeWithInferredValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension PaymentSheet {
switch confirmType {
case let .saved(savedPaymentMethod, _):
paymentMethod = savedPaymentMethod
case let .new(params, paymentOptions, newPaymentMethod, shouldSave):
case let .new(params, paymentOptions, newPaymentMethod, shouldSave, shouldSetAsDefaultPM):
if let newPaymentMethod {
let errorAnalytic = ErrorAnalytic(event: .unexpectedPaymentSheetConfirmationError,
error: PaymentSheetError.unexpectedNewPaymentMethod,
Expand All @@ -37,7 +37,7 @@ extension PaymentSheet {
}
stpAssert(newPaymentMethod == nil)
paymentMethod = try await configuration.apiClient.createPaymentMethod(with: params, additionalPaymentUserAgentValues: makeDeferredPaymentUserAgentValue(intentConfiguration: intentConfig))
confirmType = .new(params: params, paymentOptions: paymentOptions, paymentMethod: paymentMethod, shouldSave: shouldSave)
confirmType = .new(params: params, paymentOptions: paymentOptions, paymentMethod: paymentMethod, shouldSave: shouldSave, shouldSetAsDefaultPM: shouldSetAsDefaultPM)
}

// 2. Get Intent client secret from merchant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ extension PaymentSheetFormFactory {
isSelectedByDefault: false,
didToggle: didToggle
)
return PaymentMethodElementWrapper(element) { _, params in
return PaymentMethodElementWrapper(element) { defaultCheckbox, params in
params.setAsDefaultPM = defaultCheckbox.isSelected
return params
}
}
Expand Down
Loading
Loading