Skip to content

Commit 07e1cab

Browse files
Fix opening financial accounts in embedded components (#2280)
* Fix financial accounts * Don't show toast messages for warnings or errors
1 parent 0ab336f commit 07e1cab

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,14 +1072,18 @@ class StripeSdkModule(
10721072
promise.resolve(createMissingInitError())
10731073
return
10741074
}
1075+
1076+
// Use connectedAccountId from params if provided, otherwise fall back to global stripeAccountId
1077+
val accountId = getValOr(params, "connectedAccountId", null) ?: stripeAccountId
1078+
10751079
unregisterStripeUIManager(financialConnectionsSheetManager)
10761080
financialConnectionsSheetManager =
10771081
FinancialConnectionsSheetManager(
10781082
reactApplicationContext,
10791083
clientSecret,
10801084
FinancialConnectionsSheetManager.Mode.ForToken,
10811085
publishableKey,
1082-
stripeAccountId,
1086+
accountId,
10831087
).also {
10841088
registerStripeUIManager(it)
10851089
it.present(promise)
@@ -1097,14 +1101,17 @@ class StripeSdkModule(
10971101
return
10981102
}
10991103

1104+
// Use connectedAccountId from params if provided, otherwise fall back to global stripeAccountId
1105+
val accountId = getValOr(params, "connectedAccountId", null) ?: stripeAccountId
1106+
11001107
unregisterStripeUIManager(financialConnectionsSheetManager)
11011108
financialConnectionsSheetManager =
11021109
FinancialConnectionsSheetManager(
11031110
reactApplicationContext,
11041111
clientSecret,
11051112
FinancialConnectionsSheetManager.Mode.ForSession,
11061113
publishableKey,
1107-
stripeAccountId,
1114+
accountId,
11081115
).also {
11091116
registerStripeUIManager(it)
11101117
it.present(promise)

example-stripe-connect/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
import 'expo-router/entry';
2+
import { LogBox } from 'react-native';
3+
4+
LogBox.ignoreAllLogs();

ios/StripeSdkImpl.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,12 +1120,24 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
11201120
self?.emitter?.emitOnFinancialConnectionsEvent(mappedEvent)
11211121
}
11221122

1123+
// Use connectedAccountId from params if provided
1124+
let originalStripeAccount = STPAPIClient.shared.stripeAccount
1125+
if let connectedAccountId = params["connectedAccountId"] as? String {
1126+
STPAPIClient.shared.stripeAccount = connectedAccountId
1127+
}
1128+
1129+
let wrappedResolve: RCTPromiseResolveBlock = { result in
1130+
// Restore original stripeAccount after completion
1131+
STPAPIClient.shared.stripeAccount = originalStripeAccount
1132+
resolve(result)
1133+
}
1134+
11231135
FinancialConnections.presentForToken(
11241136
withClientSecret: clientSecret,
11251137
returnURL: returnURL,
11261138
configuration: configuration,
11271139
onEvent: onEvent,
1128-
resolve: resolve
1140+
resolve: wrappedResolve
11291141
)
11301142
}
11311143

@@ -1154,12 +1166,24 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
11541166
self?.emitter?.emitOnFinancialConnectionsEvent(mappedEvent)
11551167
}
11561168

1169+
// Use connectedAccountId from params if provided
1170+
let originalStripeAccount = STPAPIClient.shared.stripeAccount
1171+
if let connectedAccountId = params["connectedAccountId"] as? String {
1172+
STPAPIClient.shared.stripeAccount = connectedAccountId
1173+
}
1174+
1175+
let wrappedResolve: RCTPromiseResolveBlock = { result in
1176+
// Restore original stripeAccount after completion
1177+
STPAPIClient.shared.stripeAccount = originalStripeAccount
1178+
resolve(result)
1179+
}
1180+
11571181
FinancialConnections.present(
11581182
withClientSecret: clientSecret,
11591183
returnURL: returnURL,
11601184
configuration: configuration,
11611185
onEvent: onEvent,
1162-
resolve: resolve
1186+
resolve: wrappedResolve
11631187
)
11641188
}
11651189

src/connect/EmbeddedComponent.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export function EmbeddedComponent(props: EmbeddedComponentProps) {
370370
connectedAccountId: string;
371371
};
372372

373-
const { clientSecret, id } = messageData;
373+
const { clientSecret, id, connectedAccountId } = messageData;
374374

375375
// Validate client secret
376376
if (!clientSecret || typeof clientSecret !== 'string') {
@@ -420,7 +420,9 @@ export function EmbeddedComponent(props: EmbeddedComponentProps) {
420420
};
421421

422422
// Call native Financial Connections
423-
NativeStripeSdk.collectFinancialConnectionsAccounts(clientSecret, {})
423+
NativeStripeSdk.collectFinancialConnectionsAccounts(clientSecret, {
424+
connectedAccountId,
425+
})
424426
.then(({ session, error }) => {
425427
cleanup();
426428

src/types/FinancialConnections.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export type CollectFinancialConnectionsAccountsParams = {
77
style?: UserInterfaceStyle;
88
/** An optional event listener to receive @type {FinancialConnectionEvent} for specific events during the process of a user connecting their financial accounts. */
99
onEvent?: (event: FinancialConnectionsEvent) => void;
10+
/** Optional connected account ID to use for this Financial Connections session. Used for Stripe Connect embedded components. */
11+
connectedAccountId?: string;
1012
};
1113

1214
export type SessionResult =

0 commit comments

Comments
 (0)