@stripe/stripe-react-native 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +3 -0
  3. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  4. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  5. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  6. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  7. package/android/.gradle/8.9/gc.properties +0 -0
  8. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  9. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  10. package/android/.gradle/vcs-1/gc.properties +0 -0
  11. package/android/.project +11 -0
  12. package/android/.settings/org.eclipse.buildship.core.prefs +3 -3
  13. package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt +21 -0
  14. package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +20 -0
  15. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +114 -35
  16. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +50 -0
  17. package/ios/FinancialConnections.swift +14 -2
  18. package/ios/Mappers.swift +23 -0
  19. package/ios/PaymentMethodFactory.swift +31 -29
  20. package/ios/StripeSdk.swift +50 -19
  21. package/lib/commonjs/NativeStripeSdk.js.map +1 -1
  22. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  23. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  24. package/lib/commonjs/components/AddressSheet.js +1 -1
  25. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  26. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  27. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  28. package/lib/commonjs/components/CardField.js +1 -1
  29. package/lib/commonjs/components/CardField.js.map +1 -1
  30. package/lib/commonjs/components/CardForm.js +1 -1
  31. package/lib/commonjs/components/CardForm.js.map +1 -1
  32. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  33. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  34. package/lib/commonjs/components/StripeContainer.js +1 -1
  35. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  36. package/lib/commonjs/functions.js +1 -1
  37. package/lib/commonjs/functions.js.map +1 -1
  38. package/lib/commonjs/hooks/useFinancialConnectionsSheet.js +1 -1
  39. package/lib/commonjs/hooks/useFinancialConnectionsSheet.js.map +1 -1
  40. package/lib/commonjs/hooks/useStripe.js +1 -1
  41. package/lib/commonjs/hooks/useStripe.js.map +1 -1
  42. package/lib/commonjs/types/FinancialConnections.js +1 -1
  43. package/lib/commonjs/types/FinancialConnections.js.map +1 -1
  44. package/lib/commonjs/types/PaymentIntent.js.map +1 -1
  45. package/lib/commonjs/types/PaymentMethod.js.map +1 -1
  46. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  47. package/lib/module/NativeStripeSdk.js.map +1 -1
  48. package/lib/module/components/AddToWalletButton.js +1 -1
  49. package/lib/module/components/AddToWalletButton.js.map +1 -1
  50. package/lib/module/components/AddressSheet.js +1 -1
  51. package/lib/module/components/AddressSheet.js.map +1 -1
  52. package/lib/module/components/AuBECSDebitForm.js +1 -1
  53. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  54. package/lib/module/components/CardField.js +1 -1
  55. package/lib/module/components/CardField.js.map +1 -1
  56. package/lib/module/components/CardForm.js +1 -1
  57. package/lib/module/components/CardForm.js.map +1 -1
  58. package/lib/module/components/PlatformPayButton.js +1 -1
  59. package/lib/module/components/PlatformPayButton.js.map +1 -1
  60. package/lib/module/components/StripeContainer.js +1 -1
  61. package/lib/module/components/StripeContainer.js.map +1 -1
  62. package/lib/module/functions.js +1 -1
  63. package/lib/module/functions.js.map +1 -1
  64. package/lib/module/hooks/useFinancialConnectionsSheet.js +1 -1
  65. package/lib/module/hooks/useFinancialConnectionsSheet.js.map +1 -1
  66. package/lib/module/hooks/useStripe.js +1 -1
  67. package/lib/module/hooks/useStripe.js.map +1 -1
  68. package/lib/module/types/FinancialConnections.js +1 -1
  69. package/lib/module/types/FinancialConnections.js.map +1 -1
  70. package/lib/module/types/PaymentIntent.js.map +1 -1
  71. package/lib/module/types/PaymentMethod.js.map +1 -1
  72. package/lib/module/types/PaymentSheet.js.map +1 -1
  73. package/lib/typescript/src/NativeStripeSdk.d.ts +1 -1
  74. package/lib/typescript/src/functions.d.ts +6 -2
  75. package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts +4 -2
  76. package/lib/typescript/src/hooks/useStripe.d.ts +2 -2
  77. package/lib/typescript/src/types/FinancialConnections.d.ts +64 -0
  78. package/lib/typescript/src/types/PaymentIntent.d.ts +26 -0
  79. package/lib/typescript/src/types/PaymentMethod.d.ts +7 -0
  80. package/lib/typescript/src/types/PaymentSheet.d.ts +1 -1
  81. package/package.json +3 -4
  82. package/src/NativeStripeSdk.tsx +1 -1
  83. package/src/functions.ts +57 -2
  84. package/src/hooks/useFinancialConnectionsSheet.tsx +12 -4
  85. package/src/hooks/useStripe.tsx +10 -4
  86. package/src/types/FinancialConnections.ts +69 -0
  87. package/src/types/PaymentIntent.ts +30 -1
  88. package/src/types/PaymentMethod.ts +8 -0
  89. package/src/types/PaymentSheet.ts +1 -1
  90. package/stripe-react-native.podspec +1 -1
@@ -58,12 +58,16 @@ export declare type MandateData = {
58
58
  };
59
59
  };
60
60
  };
61
+ declare type MetaData = {
62
+ [key: string]: string;
63
+ };
61
64
  export declare type CardParams = {
62
65
  paymentMethodType: 'Card';
63
66
  paymentMethodData?: {
64
67
  token?: string;
65
68
  billingDetails?: BillingDetails;
66
69
  mandateData?: MandateData;
70
+ metadata?: MetaData;
67
71
  };
68
72
  } | {
69
73
  paymentMethodType: 'Card';
@@ -72,6 +76,7 @@ export declare type CardParams = {
72
76
  cvc?: string;
73
77
  billingDetails?: BillingDetails;
74
78
  mandateData?: MandateData;
79
+ metadata?: MetaData;
75
80
  };
76
81
  };
77
82
  export interface IdealParams {
@@ -80,6 +85,7 @@ export interface IdealParams {
80
85
  bankName?: string;
81
86
  billingDetails?: BillingDetails;
82
87
  mandateData?: MandateData;
88
+ metadata?: MetaData;
83
89
  };
84
90
  }
85
91
  export interface FPXParams {
@@ -87,12 +93,14 @@ export interface FPXParams {
87
93
  paymentMethodData?: {
88
94
  testOfflineBank?: boolean;
89
95
  mandateData?: MandateData;
96
+ metadata?: MetaData;
90
97
  };
91
98
  }
92
99
  export interface AlipayParams {
93
100
  paymentMethodType: 'Alipay';
94
101
  paymentMethodData?: {
95
102
  mandateData?: MandateData;
103
+ metadata?: MetaData;
96
104
  };
97
105
  }
98
106
  export interface OxxoParams {
@@ -100,6 +108,7 @@ export interface OxxoParams {
100
108
  paymentMethodData: {
101
109
  billingDetails: BillingDetails;
102
110
  mandateData?: MandateData;
111
+ metadata?: MetaData;
103
112
  };
104
113
  }
105
114
  export interface SofortParams {
@@ -108,6 +117,7 @@ export interface SofortParams {
108
117
  country: string;
109
118
  billingDetails: BillingDetails;
110
119
  mandateData?: MandateData;
120
+ metadata?: MetaData;
111
121
  };
112
122
  }
113
123
  export interface GrabPayParams {
@@ -115,6 +125,7 @@ export interface GrabPayParams {
115
125
  paymentMethodData?: {
116
126
  billingDetails?: BillingDetails;
117
127
  mandateData?: MandateData;
128
+ metadata?: MetaData;
118
129
  };
119
130
  }
120
131
  export interface BancontactParams {
@@ -122,6 +133,7 @@ export interface BancontactParams {
122
133
  paymentMethodData: {
123
134
  billingDetails: BillingDetails;
124
135
  mandateData?: MandateData;
136
+ metadata?: MetaData;
125
137
  };
126
138
  }
127
139
  export interface SepaParams {
@@ -130,6 +142,7 @@ export interface SepaParams {
130
142
  iban: string;
131
143
  billingDetails: BillingDetails;
132
144
  mandateData?: MandateData;
145
+ metadata?: MetaData;
133
146
  };
134
147
  }
135
148
  export interface GiropayParams {
@@ -137,6 +150,7 @@ export interface GiropayParams {
137
150
  paymentMethodData: {
138
151
  billingDetails: BillingDetails;
139
152
  mandateData?: MandateData;
153
+ metadata?: MetaData;
140
154
  };
141
155
  }
142
156
  export interface AfterpayClearpayParams {
@@ -145,6 +159,7 @@ export interface AfterpayClearpayParams {
145
159
  shippingDetails: BillingDetails;
146
160
  billingDetails: BillingDetails;
147
161
  mandateData?: MandateData;
162
+ metadata?: MetaData;
148
163
  };
149
164
  }
150
165
  export declare type KlarnaParams = {
@@ -155,6 +170,7 @@ export declare type KlarnaParams = {
155
170
  } & BillingDetails;
156
171
  shippingDetails?: BillingDetails;
157
172
  mandateData?: MandateData;
173
+ metadata?: MetaData;
158
174
  };
159
175
  };
160
176
  export interface EpsParams {
@@ -162,6 +178,7 @@ export interface EpsParams {
162
178
  paymentMethodData: {
163
179
  billingDetails: BillingDetails;
164
180
  mandateData?: MandateData;
181
+ metadata?: MetaData;
165
182
  };
166
183
  }
167
184
  export interface P24Params {
@@ -169,6 +186,7 @@ export interface P24Params {
169
186
  paymentMethodData: {
170
187
  billingDetails: BillingDetails;
171
188
  mandateData?: MandateData;
189
+ metadata?: MetaData;
172
190
  };
173
191
  }
174
192
  export interface WeChatPayParams {
@@ -177,6 +195,7 @@ export interface WeChatPayParams {
177
195
  appId: string;
178
196
  billingDetails?: BillingDetails;
179
197
  mandateData?: MandateData;
198
+ metadata?: MetaData;
180
199
  };
181
200
  }
182
201
  export interface AuBecsDebitParams {
@@ -193,6 +212,7 @@ export declare type AffirmParams = {
193
212
  shippingDetails?: BillingDetails;
194
213
  billingDetails?: BillingDetails;
195
214
  mandateData?: MandateData;
215
+ metadata?: MetaData;
196
216
  };
197
217
  };
198
218
  /**
@@ -210,6 +230,7 @@ export declare type USBankAccountParams = {
210
230
  /** Defaults to Checking */
211
231
  accountType?: BankAcccountType;
212
232
  mandateData?: MandateData;
233
+ metadata?: MetaData;
213
234
  };
214
235
  };
215
236
  export declare type PayPalParams = {
@@ -217,6 +238,7 @@ export declare type PayPalParams = {
217
238
  paymentMethodData?: {
218
239
  billingDetails?: BillingDetails;
219
240
  mandateData?: MandateData;
241
+ metadata?: MetaData;
220
242
  };
221
243
  };
222
244
  export declare type CashAppParams = {
@@ -224,6 +246,7 @@ export declare type CashAppParams = {
224
246
  paymentMethodData?: {
225
247
  billingDetails?: BillingDetails;
226
248
  mandateData?: MandateData;
249
+ metadata?: MetaData;
227
250
  };
228
251
  };
229
252
  export declare type RevolutPayParams = {
@@ -231,6 +254,7 @@ export declare type RevolutPayParams = {
231
254
  paymentMethodData?: {
232
255
  billingDetails?: BillingDetails;
233
256
  mandateData?: MandateData;
257
+ metadata?: MetaData;
234
258
  };
235
259
  };
236
260
  export declare type CollectBankAccountParams = {
@@ -241,5 +265,7 @@ export declare type CollectBankAccountParams = {
241
265
  email?: string;
242
266
  };
243
267
  mandateData?: MandateData;
268
+ metadata?: MetaData;
244
269
  };
245
270
  };
271
+ export {};
@@ -2,6 +2,7 @@ import type { FormDetails } from './components/AuBECSDebitFormComponent';
2
2
  import type { CardBrand, BankAcccountHolderType, BankAcccountType } from './Token';
3
3
  import type { FutureUsage } from './PaymentIntent';
4
4
  import type { Address, BillingDetails } from './Common';
5
+ import type { FinancialConnectionsEvent } from './FinancialConnections';
5
6
  export interface Result {
6
7
  id: string;
7
8
  liveMode: boolean;
@@ -234,4 +235,10 @@ export declare type CollectBankAccountParams = {
234
235
  email?: string;
235
236
  };
236
237
  };
238
+ /** An optional event listener to receive @type {FinancialConnectionEvent} for specific events during the process of a user connecting their financial accounts. */
239
+ onEvent?: (event: FinancialConnectionsEvent) => void;
240
+ };
241
+ export declare type CollectBankAccountTokenParams = {
242
+ /** An optional event listener to receive @type {FinancialConnectionEvent} for specific events during the process of a user connecting their financial accounts. */
243
+ onEvent?: (event: FinancialConnectionsEvent) => void;
237
244
  };
@@ -4,7 +4,7 @@ import type { ButtonType, RecurringPaymentRequest, AutomaticReloadPaymentRequest
4
4
  import type { FutureUsage } from './PaymentIntent';
5
5
  import type { Result } from './PaymentMethod';
6
6
  import type { StripeError } from './Errors';
7
- declare type SetupParamsBase = IntentParams & {
7
+ export declare type SetupParamsBase = IntentParams & {
8
8
  /** Your customer-facing business name. On Android, this is required and cannot be an empty string. */
9
9
  merchantDisplayName: string;
10
10
  /** The identifier of the Stripe Customer object. See https://stripe.com/docs/api/customers/object#customer_object-id */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/stripe-react-native",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "author": "Stripe",
5
5
  "description": "Stripe SDK for React Native",
6
6
  "main": "lib/commonjs/index",
@@ -20,7 +20,7 @@
20
20
  "bootstrap": "yarn example && yarn && yarn pods",
21
21
  "bootstrap-no-pods": "yarn example && yarn",
22
22
  "docs": "yarn typedoc ./src/index.tsx --out ./docs/api-reference --tsconfig ./tsconfig.json --readme none --sort source-order",
23
- "run-example-ios": "cd example;react-native run-ios --configuration Release --simulator \"iPhone 15\"",
23
+ "run-example-ios": "cd example;react-native run-ios --configuration Release --simulator \"iPhone 15 (17.2)\"",
24
24
  "run-example-android": "cd example;react-native run-android --variant=release",
25
25
  "test:e2e:ios": "bash ./scripts/run-maestro-tests ios",
26
26
  "test:e2e:android": "bash ./scripts/run-maestro-tests android",
@@ -148,6 +148,5 @@
148
148
  },
149
149
  "resolutions": {
150
150
  "simple-plist": "1.3.1"
151
- },
152
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
151
+ }
153
152
  }
@@ -84,7 +84,7 @@ type NativeStripeSdkType = {
84
84
  collectBankAccount(
85
85
  isPaymentIntent: boolean,
86
86
  clientSecret: string,
87
- params: PaymentMethod.CollectBankAccountParams
87
+ params: Omit<PaymentMethod.CollectBankAccountParams, 'onEvent'>
88
88
  ): Promise<ConfirmSetupIntentResult | ConfirmPaymentResult>;
89
89
  getConstants(): { API_VERSIONS: { CORE: string; ISSUING: string } };
90
90
  canAddCardToWallet(
package/src/functions.ts CHANGED
@@ -38,6 +38,8 @@ import {
38
38
  NativeModules,
39
39
  EmitterSubscription,
40
40
  } from 'react-native';
41
+ import type { CollectFinancialConnectionsAccountsParams } from './types/FinancialConnections';
42
+ import type { CollectBankAccountTokenParams } from './types/PaymentMethod';
41
43
 
42
44
  export const createPaymentMethod = async (
43
45
  params: PaymentMethod.CreateParams,
@@ -356,6 +358,7 @@ export const verifyMicrodepositsForSetup = async (
356
358
  const eventEmitter = new NativeEventEmitter(NativeModules.StripeSdk);
357
359
  let confirmHandlerCallback: EmitterSubscription | null = null;
358
360
  let orderTrackingCallbackListener: EmitterSubscription | null = null;
361
+ let financialConnectionsEventListener: EmitterSubscription | null = null;
359
362
 
360
363
  export const initPaymentSheet = async (
361
364
  params: PaymentSheet.SetupParams
@@ -468,6 +471,15 @@ export const collectBankAccountForPayment = async (
468
471
  clientSecret: string,
469
472
  params: PaymentMethod.CollectBankAccountParams
470
473
  ): Promise<CollectBankAccountForPaymentResult> => {
474
+ financialConnectionsEventListener?.remove();
475
+
476
+ if (params.onEvent) {
477
+ financialConnectionsEventListener = eventEmitter.addListener(
478
+ 'onFinancialConnectionsEvent',
479
+ params.onEvent
480
+ );
481
+ }
482
+
471
483
  try {
472
484
  const { paymentIntent, error } = (await NativeStripeSdk.collectBankAccount(
473
485
  true,
@@ -475,6 +487,8 @@ export const collectBankAccountForPayment = async (
475
487
  params
476
488
  )) as CollectBankAccountForPaymentResult;
477
489
 
490
+ financialConnectionsEventListener?.remove();
491
+
478
492
  if (error) {
479
493
  return {
480
494
  error,
@@ -484,6 +498,7 @@ export const collectBankAccountForPayment = async (
484
498
  paymentIntent: paymentIntent!,
485
499
  };
486
500
  } catch (error: any) {
501
+ financialConnectionsEventListener?.remove();
487
502
  return {
488
503
  error: createError(error),
489
504
  };
@@ -494,6 +509,15 @@ export const collectBankAccountForSetup = async (
494
509
  clientSecret: string,
495
510
  params: PaymentMethod.CollectBankAccountParams
496
511
  ): Promise<CollectBankAccountForSetupResult> => {
512
+ financialConnectionsEventListener?.remove();
513
+
514
+ if (params.onEvent) {
515
+ financialConnectionsEventListener = eventEmitter.addListener(
516
+ 'onFinancialConnectionsEvent',
517
+ params.onEvent
518
+ );
519
+ }
520
+
497
521
  try {
498
522
  const { setupIntent, error } = (await NativeStripeSdk.collectBankAccount(
499
523
  false,
@@ -501,6 +525,8 @@ export const collectBankAccountForSetup = async (
501
525
  params
502
526
  )) as CollectBankAccountForSetupResult;
503
527
 
528
+ financialConnectionsEventListener?.remove();
529
+
504
530
  if (error) {
505
531
  return {
506
532
  error,
@@ -510,6 +536,7 @@ export const collectBankAccountForSetup = async (
510
536
  setupIntent: setupIntent!,
511
537
  };
512
538
  } catch (error: any) {
539
+ financialConnectionsEventListener?.remove();
513
540
  return {
514
541
  error: createError(error),
515
542
  };
@@ -520,15 +547,28 @@ export const collectBankAccountForSetup = async (
520
547
  * Use collectBankAccountToken in the [Add a Financial Connections Account to a US Custom Connect](https://stripe.com/docs/financial-connections/connect-payouts) account flow.
521
548
  * When called, it will load the Authentication Flow, an on-page modal UI which allows your user to securely link their external financial account for payouts.
522
549
  * @param {string} clientSecret The client_secret of the [Financial Connections Session](https://stripe.com/docs/api/financial_connections/session).
550
+ * @param {CollectBankAccountTokenParams} params Optional parameters.
523
551
  * @returns A promise that resolves to an object containing either `session` and `token` fields, or an error field.
524
552
  */
525
553
  export const collectBankAccountToken = async (
526
- clientSecret: string
554
+ clientSecret: string,
555
+ params: CollectBankAccountTokenParams = {}
527
556
  ): Promise<FinancialConnections.TokenResult> => {
557
+ financialConnectionsEventListener?.remove();
558
+
559
+ if (params.onEvent) {
560
+ financialConnectionsEventListener = eventEmitter.addListener(
561
+ 'onFinancialConnectionsEvent',
562
+ params.onEvent
563
+ );
564
+ }
565
+
528
566
  try {
529
567
  const { session, token, error } =
530
568
  await NativeStripeSdk.collectBankAccountToken(clientSecret);
531
569
 
570
+ financialConnectionsEventListener?.remove();
571
+
532
572
  if (error) {
533
573
  return {
534
574
  error,
@@ -539,6 +579,7 @@ export const collectBankAccountToken = async (
539
579
  token: token!,
540
580
  };
541
581
  } catch (error: any) {
582
+ financialConnectionsEventListener?.remove();
542
583
  return {
543
584
  error: createError(error),
544
585
  };
@@ -549,15 +590,28 @@ export const collectBankAccountToken = async (
549
590
  * Use collectFinancialConnectionsAccounts in the [Collect an account to build data-powered products](https://stripe.com/docs/financial-connections/other-data-powered-products) flow.
550
591
  * When called, it will load the Authentication Flow, an on-page modal UI which allows your user to securely link their external financial account.
551
592
  * @param {string} clientSecret The client_secret of the [Financial Connections Session](https://stripe.com/docs/api/financial_connections/session).
593
+ * @param {CollectFinancialConnectionsAccountsParams} params Optional parameters.
552
594
  * @returns A promise that resolves to an object containing either a `session` field, or an error field.
553
595
  */
554
596
  export const collectFinancialConnectionsAccounts = async (
555
- clientSecret: string
597
+ clientSecret: string,
598
+ params: CollectFinancialConnectionsAccountsParams = {}
556
599
  ): Promise<FinancialConnections.SessionResult> => {
600
+ financialConnectionsEventListener?.remove();
601
+
602
+ if (params.onEvent) {
603
+ financialConnectionsEventListener = eventEmitter.addListener(
604
+ 'onFinancialConnectionsEvent',
605
+ params.onEvent
606
+ );
607
+ }
608
+
557
609
  try {
558
610
  const { session, error } =
559
611
  await NativeStripeSdk.collectFinancialConnectionsAccounts(clientSecret);
560
612
 
613
+ financialConnectionsEventListener?.remove();
614
+
561
615
  if (error) {
562
616
  return {
563
617
  error,
@@ -567,6 +621,7 @@ export const collectFinancialConnectionsAccounts = async (
567
621
  session: session!,
568
622
  };
569
623
  } catch (error: any) {
624
+ financialConnectionsEventListener?.remove();
570
625
  return {
571
626
  error: createError(error),
572
627
  };
@@ -1,5 +1,7 @@
1
1
  import { useState, useCallback } from 'react';
2
2
  import { useStripe } from './useStripe';
3
+ import type { CollectFinancialConnectionsAccountsParams } from 'src/types/FinancialConnections';
4
+ import type { CollectBankAccountTokenParams } from 'src/types/PaymentMethod';
3
5
 
4
6
  /**
5
7
  * React hook for accessing functions on the Financial Connections sheet.
@@ -13,9 +15,9 @@ export function useFinancialConnectionsSheet() {
13
15
  useStripe();
14
16
 
15
17
  const _collectBankAccountToken = useCallback(
16
- async (clientSecret: string) => {
18
+ async (clientSecret: string, params?: CollectBankAccountTokenParams) => {
17
19
  setLoading(true);
18
- const result = await collectBankAccountToken(clientSecret);
20
+ const result = await collectBankAccountToken(clientSecret, params);
19
21
  setLoading(false);
20
22
  return result;
21
23
  },
@@ -23,9 +25,15 @@ export function useFinancialConnectionsSheet() {
23
25
  );
24
26
 
25
27
  const _collectFinancialConnectionsAccounts = useCallback(
26
- async (clientSecret: string) => {
28
+ async (
29
+ clientSecret: string,
30
+ params?: CollectFinancialConnectionsAccountsParams
31
+ ) => {
27
32
  setLoading(true);
28
- const result = await collectFinancialConnectionsAccounts(clientSecret);
33
+ const result = await collectFinancialConnectionsAccounts(
34
+ clientSecret,
35
+ params
36
+ );
29
37
  setLoading(false);
30
38
  return result;
31
39
  },
@@ -60,6 +60,8 @@ import {
60
60
  updatePlatformPaySheet,
61
61
  openPlatformPaySetup,
62
62
  } from '../functions';
63
+ import type { CollectBankAccountTokenParams } from 'src/types/PaymentMethod';
64
+ import type { CollectFinancialConnectionsAccountsParams } from 'src/types/FinancialConnections';
63
65
 
64
66
  /**
65
67
  * useStripe hook
@@ -225,17 +227,21 @@ export function useStripe() {
225
227
  );
226
228
 
227
229
  const _collectBankAccountToken = useCallback(
228
- async (clientSecret: string): Promise<FinancialConnections.TokenResult> => {
229
- return collectBankAccountToken(clientSecret);
230
+ async (
231
+ clientSecret: string,
232
+ params?: CollectBankAccountTokenParams
233
+ ): Promise<FinancialConnections.TokenResult> => {
234
+ return collectBankAccountToken(clientSecret, params);
230
235
  },
231
236
  []
232
237
  );
233
238
 
234
239
  const _collectFinancialConnectionsAccounts = useCallback(
235
240
  async (
236
- clientSecret: string
241
+ clientSecret: string,
242
+ params?: CollectFinancialConnectionsAccountsParams
237
243
  ): Promise<FinancialConnections.SessionResult> => {
238
- return collectFinancialConnectionsAccounts(clientSecret);
244
+ return collectFinancialConnectionsAccounts(clientSecret, params);
239
245
  },
240
246
  []
241
247
  );
@@ -1,6 +1,11 @@
1
1
  import type { BankAccount } from './Token';
2
2
  import type { StripeError } from './Errors';
3
3
 
4
+ export type CollectFinancialConnectionsAccountsParams = {
5
+ /** An optional event listener to receive @type {FinancialConnectionEvent} for specific events during the process of a user connecting their financial accounts. */
6
+ onEvent?: (event: FinancialConnectionsEvent) => void;
7
+ };
8
+
4
9
  export type SessionResult =
5
10
  | {
6
11
  /** The updated Financial Connections Session object. */
@@ -124,3 +129,67 @@ export enum FinancialConnectionsSheetError {
124
129
  Failed = 'Failed',
125
130
  Canceled = 'Canceled',
126
131
  }
132
+
133
+ export type FinancialConnectionsEvent = {
134
+ /** The event's name. Represents the type of event that has occurred during the Financial Connections process. */
135
+ name: FinancialConnectionsEventName;
136
+ /** Event-associated metadata. Provides further detail related to the occurred event. */
137
+ metadata: FinancialConnectionsEventMetadata;
138
+ };
139
+
140
+ export enum FinancialConnectionsEventName {
141
+ /** Invoked when the sheet successfully opens. */
142
+ Open = 'open',
143
+ /** Invoked when the manual entry flow is initiated. */
144
+ ManualEntryInitiated = 'manual_entry_initiated',
145
+ /** Invoked when "Agree and continue" is selected on the consent pane. */
146
+ ConsentAcquired = 'consent_acquired',
147
+ /** Invoked when the search bar is selected, the user inputs search terms, and receives an API response. */
148
+ SearchInitiated = 'search_initiated',
149
+ /** Invoked when an institution is selected, either from featured institutions or search results. */
150
+ InstitutionSelected = 'institution_selected',
151
+ /** Invoked when the authorization is successfully completed. */
152
+ InstitutionAuthorized = 'institution_authorized',
153
+ /** Invoked when accounts are selected and "confirm" is selected. */
154
+ AccountsSelected = 'accounts_selected',
155
+ /** Invoked when the flow is completed and selected accounts are correctly connected to the payment instrument. */
156
+ Success = 'success',
157
+ /** Invoked when an error is encountered. Refer to error codes for more details. */
158
+ Error = 'error',
159
+ /** Invoked when the flow is cancelled, typically by the user pressing the "X" button. */
160
+ Cancel = 'cancel',
161
+ /** Invoked when the modal is launched in an external browser. After this event, no other events will be sent until the completion of the browser session. */
162
+ FlowLaunchedInBrowser = 'flow_launched_in_browser',
163
+ }
164
+
165
+ export type FinancialConnectionsEventMetadata = {
166
+ /** A Boolean value that indicates if the user completed the process through the manual entry flow. */
167
+ manualEntry?: boolean;
168
+ /** A String value containing the name of the institution that the user selected. */
169
+ institutionName?: string;
170
+ /** An ErrorCode value representing the type of error that occurred. */
171
+ errorCode?: FinancialConnectionsEventErrorCode;
172
+ };
173
+
174
+ export enum FinancialConnectionsEventErrorCode {
175
+ /** The system could not retrieve account numbers for selected accounts. */
176
+ AccountNumbersUnavailable = 'account_numbers_unavailable',
177
+ /** The system could not retrieve accounts for the selected institution. */
178
+ AccountsUnavailable = 'accounts_unavailable',
179
+ /** For payment flows, no debitable account was available at the selected institution. */
180
+ NoDebitableAccount = 'no_debitable_account',
181
+ /** Authorization with the selected institution has failed. */
182
+ AuthorizationFailed = 'authorization_failed',
183
+ /** The selected institution is down for expected maintenance. */
184
+ InstitutionUnavailablePlanned = 'institution_unavailable_planned',
185
+ /** The selected institution is unexpectedly down. */
186
+ InstitutionUnavailableUnplanned = 'institution_unavailable_unplanned',
187
+ /** A timeout occurred while communicating with our partner or downstream institutions. */
188
+ InstitutionTimeout = 'institution_timeout',
189
+ /** An unexpected error occurred, either in an API call or on the client-side. */
190
+ UnexpectedError = 'unexpected_error',
191
+ /** The client secret that powers the session has expired. */
192
+ SessionExpired = 'session_expired',
193
+ /** The hCaptcha challenge failed. */
194
+ FailedBotDetection = 'failed_bot_detection',
195
+ }