Skip to content

Commit 26a345b

Browse files
committed
Fix ios Build
1 parent b71e289 commit 26a345b

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

ios/StripeSdkImpl+Checkout.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Nick Porter on 4/29/26.
66
//
77

8+
import Combine
89
import Foundation
910
@_spi(CheckoutSessionsPreview) import StripePaymentSheet
1011

@@ -13,6 +14,28 @@ extension StripeSdkImpl {
1314
Mappers.mapFromCheckoutState(checkout.state)
1415
}
1516

17+
/// Forwards every `Checkout` state change to JS. We listen on `$state`
18+
/// instead of `CheckoutDelegate` since the delegate misses the loading
19+
/// transitions, but `$state` fires on every assignment.
20+
@MainActor
21+
internal func observeCheckoutState(
22+
_ checkout: Checkout,
23+
sessionKey: String
24+
) {
25+
checkoutStateCancellables[sessionKey]?.cancel()
26+
27+
checkoutStateCancellables[sessionKey] = checkout.$state
28+
// JS already has the initial state from `initCheckoutSession`.
29+
.dropFirst()
30+
.receive(on: DispatchQueue.main)
31+
.sink { [weak self] state in
32+
self?.emitter?.emitCheckoutSessionDidChangeState([
33+
"sessionKey": sessionKey,
34+
"state": Mappers.mapFromCheckoutState(state),
35+
])
36+
}
37+
}
38+
1639
@objc(initCheckoutSession:configuration:resolver:rejecter:)
1740
public func initCheckoutSession(
1841
clientSecret: String,
@@ -36,6 +59,7 @@ extension StripeSdkImpl {
3659
let sessionKey = UUID().uuidString
3760

3861
self.checkoutInstances[sessionKey] = checkout
62+
self.observeCheckoutState(checkout, sessionKey: sessionKey)
3963

4064
resolve([
4165
"sessionKey": sessionKey,

ios/StripeSdkImpl.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AuthenticationServices
2+
import Combine
23
import Foundation
34
import PassKit
45
@_spi(DashboardOnly) @_spi(STP) import Stripe
@@ -69,6 +70,8 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
6970
internal var paymentSheet: PaymentSheet?
7071
internal var paymentSheetFlowController: PaymentSheet.FlowController?
7172
internal var checkoutInstances: [String: Checkout] = [:]
73+
/// One Combine subscription per active `Checkout`, keyed by `sessionKey`.
74+
internal var checkoutStateCancellables: [String: AnyCancellable] = [:]
7275
var paymentSheetIntentCreationCallback: ((Result<String, Error>) -> Void)?
7376
var paymentSheetConfirmationTokenIntentCreationCallback: ((Result<String, Error>) -> Void)?
7477

0 commit comments

Comments
 (0)