Skip to content

Commit 44e7d9c

Browse files
committed
Add convenience init to transform a PaymentSheet.UserInterfaceStyle into ElementsSessionContext.StyleConfig
1 parent f0ee717 commit 44e7d9c

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

StripePaymentSheet/StripePaymentSheet.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
47B19F96CCEA290541E3B988 /* CardSectionElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D03000A6807B09BFD8E6CB1 /* CardSectionElement.swift */; };
138138
48DA2EFE0944E737B0F197B0 /* OHHTTPStubs in Frameworks */ = {isa = PBXBuildFile; productRef = B2AFFAD776D5F21DF837F1BD /* OHHTTPStubs */; };
139139
49803444CD948F1ED28FF021 /* PaymentSheetFormFactory+FormSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD7A1EFF100C589FDFF4D516 /* PaymentSheetFormFactory+FormSpec.swift */; };
140+
49AED8FB2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49AED8FA2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift */; };
140141
49F62EDF394F18E5BB201D53 /* StripePaymentSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AA6166F234C3A2129CBD573 /* StripePaymentSheet.h */; settings = {ATTRIBUTES = (Public, ); }; };
141142
4A1A0A542B824C830A200BE0 /* StubbedBackend.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBF8498CCD12A5190F9267CD /* StubbedBackend.swift */; };
142143
4A8C7B2AFB290567C961DAB0 /* StripePaymentsUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F22354BD25171B8DC2B922D2 /* StripePaymentsUI.framework */; };
@@ -555,6 +556,7 @@
555556
45B6DC9BD9183495E5649369 /* LinkAccountService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkAccountService.swift; sourceTree = "<group>"; };
556557
47C5DB8C01BA7137369C8B4D /* TextFieldElement+Card.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TextFieldElement+Card.swift"; sourceTree = "<group>"; };
557558
492B254E43F3BB9F9CEAEA06 /* PaymentSheetLoaderStubbedTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentSheetLoaderStubbedTest.swift; sourceTree = "<group>"; };
559+
49AED8FA2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ElementsSessionContext+Extensions.swift"; sourceTree = "<group>"; };
558560
4BEFE8C0CFEAE73F9FD736D3 /* STPStringUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPStringUtils.swift; sourceTree = "<group>"; };
559561
4C6AA41454A6757B3E26AE67 /* StripePaymentSheetTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StripePaymentSheetTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
560562
4D595AA033BC84CB4E1C277F /* PaymentSheetFormFactorySnapshotTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentSheetFormFactorySnapshotTest.swift; sourceTree = "<group>"; };
@@ -1225,6 +1227,7 @@
12251227
4DA1B1B7662E177725062922 /* StripePaymentSheet+Exports.swift */,
12261228
70ED08B0F303B7C2334602C3 /* StripePaymentSheetBundleLocator.swift */,
12271229
6103F2BB2BE45990002D67F8 /* SavedPaymentMethodManager.swift */,
1230+
49AED8FA2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift */,
12281231
);
12291232
path = Helpers;
12301233
sourceTree = "<group>";
@@ -2267,6 +2270,7 @@
22672270
B2979A0740F8730FC14DFEC1 /* BottomSheetViewController.swift in Sources */,
22682271
2E4C37C73AD202C8A3DD2E4E /* LoadingViewController.swift in Sources */,
22692272
A8ECBDF889E258F03B86BC2E /* PaymentSheetFlowControllerViewController.swift in Sources */,
2273+
49AED8FB2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift in Sources */,
22702274
247A8FEE5184E5976720599E /* PaymentSheetViewController.swift in Sources */,
22712275
6B31B9BA2B90FCE60064E210 /* CustomerSession.swift in Sources */,
22722276
4DDECA1F7EC6B624C00D549E /* PollingViewController.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// ElementsSessionContext+Extensions.swift
3+
// StripePaymentSheet
4+
//
5+
// Created by Mat Schmid on 2025-01-30.
6+
//
7+
8+
@_spi(STP) import StripeCore
9+
10+
extension ElementsSessionContext.StyleConfig {
11+
/// Convenience init to transform a `PaymentSheet.UserInterfaceStyle` into `ElementsSessionContext.StyleConfig`.
12+
init(from style: PaymentSheet.UserInterfaceStyle) {
13+
switch style {
14+
case .automatic: self = .automatic
15+
case .alwaysLight: self = .alwaysLight
16+
case .alwaysDark: self = .alwaysDark
17+
}
18+
}
19+
}

StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Link/LinkPaymentController.swift

+1-8
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,7 @@ import UIKit
314314
)
315315
)
316316

317-
let styleConfig: ElementsSessionContext.StyleConfig = {
318-
switch configuration.style {
319-
case .automatic: return .automatic
320-
case .alwaysLight: return .alwaysLight
321-
case .alwaysDark: return .alwaysDark
322-
}
323-
}()
324-
317+
let styleConfig = ElementsSessionContext.StyleConfig(from: configuration.style)
325318
return ElementsSessionContext(
326319
amount: mode.amount,
327320
currency: mode.currency,

StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/PaymentMethodFormViewController.swift

+1-7
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,7 @@ extension PaymentMethodFormViewController {
275275
)
276276
let linkMode = elementsSession.linkSettings?.linkMode
277277
let billingDetails = instantDebitsFormElement?.billingDetails
278-
let styleConfig: ElementsSessionContext.StyleConfig = {
279-
switch configuration.style {
280-
case .automatic: return .automatic
281-
case .alwaysLight: return .alwaysLight
282-
case .alwaysDark: return .alwaysDark
283-
}
284-
}()
278+
let styleConfig = ElementsSessionContext.StyleConfig(from: configuration.style)
285279

286280
return ElementsSessionContext(
287281
amount: intent.amount,

0 commit comments

Comments
 (0)