@stripe/stripe-react-native 0.57.3 → 0.59.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 (233) hide show
  1. package/android/build.gradle +2 -0
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/AndroidManifest.xml +27 -1
  4. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +0 -3
  5. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +7 -3
  6. package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +8 -0
  7. package/android/src/main/java/com/reactnativestripesdk/NavigationBarView.kt +12 -1
  8. package/android/src/main/java/com/reactnativestripesdk/PaymentElementConfig.kt +26 -0
  9. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodMessagingElementConfig.kt +147 -0
  10. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodMessagingElementView.kt +164 -0
  11. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodMessagingElementViewManager.kt +65 -0
  12. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +1 -1
  13. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +60 -31
  14. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +17 -5
  15. package/android/src/main/java/com/reactnativestripesdk/StripeConnectDeepLinkInterceptorActivity.kt +77 -0
  16. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +334 -24
  17. package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +1 -0
  18. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt +3 -0
  19. package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +8 -0
  20. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +0 -2
  21. package/android/src/main/res/xml/file_paths.xml +4 -0
  22. package/android/src/oldarch/java/com/facebook/react/viewmanagers/PaymentMethodMessagingElementViewManagerDelegate.java +36 -0
  23. package/android/src/oldarch/java/com/facebook/react/viewmanagers/PaymentMethodMessagingElementViewManagerInterface.java +18 -0
  24. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +20 -0
  25. package/android/src/test/java/com/reactnativestripesdk/PaymentElementConfigTest.kt +175 -1
  26. package/android/src/test/java/com/reactnativestripesdk/PaymentMethodMessagingElementConfigTest.kt +543 -0
  27. package/android/src/test/java/com/reactnativestripesdk/PaymentSheetManagerTest.kt +70 -0
  28. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingView.swift +13 -19
  29. package/ios/CustomerSheet/CustomerSheetUtils.swift +4 -0
  30. package/ios/OldArch/StripeSdkEventEmitterCompat.h +2 -0
  31. package/ios/OldArch/StripeSdkEventEmitterCompat.m +13 -1
  32. package/ios/PaymentMethodMessagingElementConfig.swift +116 -0
  33. package/ios/PaymentMethodMessagingElementHandler.m +9 -0
  34. package/ios/PaymentMethodMessagingElementView.swift +139 -0
  35. package/ios/StripeSdk.mm +40 -0
  36. package/ios/StripeSdkEmitter.swift +2 -0
  37. package/ios/StripeSdkImpl+CustomerSheet.swift +1 -0
  38. package/ios/StripeSdkImpl+Embedded.swift +8 -1
  39. package/ios/StripeSdkImpl+PaymentSheet.swift +44 -1
  40. package/ios/StripeSdkImpl.swift +158 -2
  41. package/jest/mock.js +26 -0
  42. package/jest/setup.js +30 -0
  43. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  44. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  45. package/lib/commonjs/components/AddressSheet.js +1 -1
  46. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  47. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  48. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  49. package/lib/commonjs/components/CardField.js +1 -1
  50. package/lib/commonjs/components/CardField.js.map +1 -1
  51. package/lib/commonjs/components/CardForm.js +1 -1
  52. package/lib/commonjs/components/CardForm.js.map +1 -1
  53. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  54. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  55. package/lib/commonjs/components/StripeContainer.js +1 -1
  56. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  57. package/lib/commonjs/connect/Components.js +1 -1
  58. package/lib/commonjs/connect/Components.js.map +1 -1
  59. package/lib/commonjs/connect/ConnectComponentsProvider.js +1 -1
  60. package/lib/commonjs/connect/ConnectComponentsProvider.js.map +1 -1
  61. package/lib/commonjs/connect/EmbeddedComponent.js +10 -5
  62. package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -1
  63. package/lib/commonjs/connect/ModalCloseButton.js +1 -1
  64. package/lib/commonjs/connect/ModalCloseButton.js.map +1 -1
  65. package/lib/commonjs/connect/NavigationBar.js +1 -1
  66. package/lib/commonjs/connect/NavigationBar.js.map +1 -1
  67. package/lib/commonjs/connect/analytics/AnalyticsClient.js +2 -0
  68. package/lib/commonjs/connect/analytics/AnalyticsClient.js.map +1 -0
  69. package/lib/commonjs/connect/analytics/ComponentAnalyticsClient.js +2 -0
  70. package/lib/commonjs/connect/analytics/ComponentAnalyticsClient.js.map +1 -0
  71. package/lib/commonjs/connect/analytics/events.js +2 -0
  72. package/lib/commonjs/connect/analytics/events.js.map +1 -0
  73. package/lib/commonjs/connect/testUtils.js +2 -0
  74. package/lib/commonjs/connect/testUtils.js.map +1 -0
  75. package/lib/commonjs/events.js.map +1 -1
  76. package/lib/commonjs/functions.js +1 -1
  77. package/lib/commonjs/functions.js.map +1 -1
  78. package/lib/commonjs/helpers.js +1 -1
  79. package/lib/commonjs/hooks/useStripe.js +1 -1
  80. package/lib/commonjs/hooks/useStripe.js.map +1 -1
  81. package/lib/commonjs/specs/NativeAddToWalletButton.js +1 -1
  82. package/lib/commonjs/specs/NativeAddressSheet.js +1 -1
  83. package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
  84. package/lib/commonjs/specs/NativeAuBECSDebitForm.js +1 -1
  85. package/lib/commonjs/specs/NativeCardField.js +1 -1
  86. package/lib/commonjs/specs/NativeCardField.js.map +1 -1
  87. package/lib/commonjs/specs/NativeCardForm.js +1 -1
  88. package/lib/commonjs/specs/NativeCardForm.js.map +1 -1
  89. package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js +1 -1
  90. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +1 -1
  91. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -1
  92. package/lib/commonjs/specs/NativeGooglePayButton.js +1 -1
  93. package/lib/commonjs/specs/NativeNavigationBar.js +1 -1
  94. package/lib/commonjs/specs/NativePaymentMethodMessagingElement.js +2 -0
  95. package/lib/commonjs/specs/NativePaymentMethodMessagingElement.js.map +1 -0
  96. package/lib/commonjs/specs/NativeStripeContainer.js +1 -1
  97. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  98. package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
  99. package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
  100. package/lib/commonjs/types/Errors.js +1 -1
  101. package/lib/commonjs/types/Errors.js.map +1 -1
  102. package/lib/commonjs/types/FinancialConnections.js.map +1 -1
  103. package/lib/commonjs/types/PaymentSheet.js +1 -1
  104. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  105. package/lib/commonjs/types/components/PaymentMethodMessagingElementComponent.js +2 -0
  106. package/lib/commonjs/types/components/PaymentMethodMessagingElementComponent.js.map +1 -0
  107. package/lib/commonjs/types/index.js.map +1 -1
  108. package/lib/module/components/AddToWalletButton.js +1 -1
  109. package/lib/module/components/AddToWalletButton.js.map +1 -1
  110. package/lib/module/components/AddressSheet.js +1 -1
  111. package/lib/module/components/AddressSheet.js.map +1 -1
  112. package/lib/module/components/AuBECSDebitForm.js +1 -1
  113. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  114. package/lib/module/components/CardField.js +1 -1
  115. package/lib/module/components/CardField.js.map +1 -1
  116. package/lib/module/components/CardForm.js +1 -1
  117. package/lib/module/components/CardForm.js.map +1 -1
  118. package/lib/module/components/PlatformPayButton.js +1 -1
  119. package/lib/module/components/PlatformPayButton.js.map +1 -1
  120. package/lib/module/components/StripeContainer.js +1 -1
  121. package/lib/module/components/StripeContainer.js.map +1 -1
  122. package/lib/module/connect/Components.js +1 -1
  123. package/lib/module/connect/Components.js.map +1 -1
  124. package/lib/module/connect/ConnectComponentsProvider.js +1 -1
  125. package/lib/module/connect/ConnectComponentsProvider.js.map +1 -1
  126. package/lib/module/connect/EmbeddedComponent.js +10 -5
  127. package/lib/module/connect/EmbeddedComponent.js.map +1 -1
  128. package/lib/module/connect/ModalCloseButton.js +1 -1
  129. package/lib/module/connect/ModalCloseButton.js.map +1 -1
  130. package/lib/module/connect/NavigationBar.js +1 -1
  131. package/lib/module/connect/NavigationBar.js.map +1 -1
  132. package/lib/module/connect/analytics/AnalyticsClient.js +2 -0
  133. package/lib/module/connect/analytics/AnalyticsClient.js.map +1 -0
  134. package/lib/module/connect/analytics/ComponentAnalyticsClient.js +2 -0
  135. package/lib/module/connect/analytics/ComponentAnalyticsClient.js.map +1 -0
  136. package/lib/module/connect/analytics/events.js +2 -0
  137. package/lib/module/connect/analytics/events.js.map +1 -0
  138. package/lib/module/connect/testUtils.js +2 -0
  139. package/lib/module/connect/testUtils.js.map +1 -0
  140. package/lib/module/events.js.map +1 -1
  141. package/lib/module/functions.js +1 -1
  142. package/lib/module/functions.js.map +1 -1
  143. package/lib/module/helpers.js +1 -1
  144. package/lib/module/hooks/useStripe.js +1 -1
  145. package/lib/module/hooks/useStripe.js.map +1 -1
  146. package/lib/module/specs/NativeAddToWalletButton.js +1 -1
  147. package/lib/module/specs/NativeAddressSheet.js +1 -1
  148. package/lib/module/specs/NativeApplePayButton.js +1 -1
  149. package/lib/module/specs/NativeAuBECSDebitForm.js +1 -1
  150. package/lib/module/specs/NativeCardField.js +1 -1
  151. package/lib/module/specs/NativeCardField.js.map +1 -1
  152. package/lib/module/specs/NativeCardForm.js +1 -1
  153. package/lib/module/specs/NativeCardForm.js.map +1 -1
  154. package/lib/module/specs/NativeConnectAccountOnboardingView.js +1 -1
  155. package/lib/module/specs/NativeEmbeddedPaymentElement.js +1 -1
  156. package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -1
  157. package/lib/module/specs/NativeGooglePayButton.js +1 -1
  158. package/lib/module/specs/NativeNavigationBar.js +1 -1
  159. package/lib/module/specs/NativePaymentMethodMessagingElement.js +2 -0
  160. package/lib/module/specs/NativePaymentMethodMessagingElement.js.map +1 -0
  161. package/lib/module/specs/NativeStripeContainer.js +1 -1
  162. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  163. package/lib/module/types/EmbeddedPaymentElement.js +1 -1
  164. package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
  165. package/lib/module/types/Errors.js +1 -1
  166. package/lib/module/types/Errors.js.map +1 -1
  167. package/lib/module/types/FinancialConnections.js.map +1 -1
  168. package/lib/module/types/PaymentSheet.js +1 -1
  169. package/lib/module/types/PaymentSheet.js.map +1 -1
  170. package/lib/module/types/components/PaymentMethodMessagingElementComponent.js +2 -0
  171. package/lib/module/types/components/PaymentMethodMessagingElementComponent.js.map +1 -0
  172. package/lib/module/types/index.js.map +1 -1
  173. package/lib/typescript/src/connect/Components.d.ts +91 -0
  174. package/lib/typescript/src/connect/Components.d.ts.map +1 -1
  175. package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts +61 -0
  176. package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts.map +1 -1
  177. package/lib/typescript/src/connect/EmbeddedComponent.d.ts.map +1 -1
  178. package/lib/typescript/src/connect/analytics/AnalyticsClient.d.ts +32 -0
  179. package/lib/typescript/src/connect/analytics/AnalyticsClient.d.ts.map +1 -0
  180. package/lib/typescript/src/connect/analytics/ComponentAnalyticsClient.d.ts +94 -0
  181. package/lib/typescript/src/connect/analytics/ComponentAnalyticsClient.d.ts.map +1 -0
  182. package/lib/typescript/src/connect/analytics/events.d.ts +215 -0
  183. package/lib/typescript/src/connect/analytics/events.d.ts.map +1 -0
  184. package/lib/typescript/src/connect/connectTypes.d.ts +5 -1
  185. package/lib/typescript/src/connect/connectTypes.d.ts.map +1 -1
  186. package/lib/typescript/src/connect/testUtils.d.ts +45 -0
  187. package/lib/typescript/src/connect/testUtils.d.ts.map +1 -0
  188. package/lib/typescript/src/events.d.ts +2 -0
  189. package/lib/typescript/src/events.d.ts.map +1 -1
  190. package/lib/typescript/src/functions.d.ts +13 -1
  191. package/lib/typescript/src/functions.d.ts.map +1 -1
  192. package/lib/typescript/src/hooks/useStripe.d.ts +2 -1
  193. package/lib/typescript/src/hooks/useStripe.d.ts.map +1 -1
  194. package/lib/typescript/src/specs/NativePaymentMethodMessagingElement.d.ts +16 -0
  195. package/lib/typescript/src/specs/NativePaymentMethodMessagingElement.d.ts.map +1 -0
  196. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +16 -1
  197. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  198. package/lib/typescript/src/types/CustomerSheet.d.ts +5 -0
  199. package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -1
  200. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts +11 -1
  201. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -1
  202. package/lib/typescript/src/types/Errors.d.ts +4 -0
  203. package/lib/typescript/src/types/Errors.d.ts.map +1 -1
  204. package/lib/typescript/src/types/FinancialConnections.d.ts +2 -0
  205. package/lib/typescript/src/types/FinancialConnections.d.ts.map +1 -1
  206. package/lib/typescript/src/types/PaymentSheet.d.ts +35 -0
  207. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
  208. package/lib/typescript/src/types/components/PaymentMethodMessagingElementComponent.d.ts +69 -0
  209. package/lib/typescript/src/types/components/PaymentMethodMessagingElementComponent.d.ts.map +1 -0
  210. package/lib/typescript/src/types/index.d.ts +8 -1
  211. package/lib/typescript/src/types/index.d.ts.map +1 -1
  212. package/package.json +4 -1
  213. package/src/connect/Components.tsx +109 -11
  214. package/src/connect/ConnectComponentsProvider.tsx +69 -2
  215. package/src/connect/EmbeddedComponent.tsx +458 -23
  216. package/src/connect/analytics/AnalyticsClient.ts +75 -0
  217. package/src/connect/analytics/ComponentAnalyticsClient.ts +315 -0
  218. package/src/connect/analytics/events.ts +253 -0
  219. package/src/connect/connectTypes.ts +5 -1
  220. package/src/connect/testUtils.ts +37 -0
  221. package/src/events.ts +2 -0
  222. package/src/functions.ts +10 -0
  223. package/src/hooks/useStripe.tsx +8 -0
  224. package/src/specs/NativePaymentMethodMessagingElement.ts +25 -0
  225. package/src/specs/NativeStripeSdkModule.ts +21 -1
  226. package/src/types/CustomerSheet.ts +5 -0
  227. package/src/types/EmbeddedPaymentElement.tsx +11 -1
  228. package/src/types/Errors.ts +5 -0
  229. package/src/types/FinancialConnections.ts +2 -0
  230. package/src/types/PaymentSheet.ts +38 -1
  231. package/src/types/components/PaymentMethodMessagingElementComponent.tsx +74 -0
  232. package/src/types/index.ts +11 -0
  233. package/stripe-react-native.podspec +1 -1
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Analytics HTTP client for sending events to Stripe backend
3
+ * Matches the Swift iOS SDK's AnalyticsClientV2 user agent format
4
+ */
5
+
6
+ import { Platform } from 'react-native';
7
+ import type { AnalyticsPayload } from './events';
8
+
9
+ const ANALYTICS_URL = 'https://r.stripe.com/0';
10
+ const CLIENT_ID = 'mobile_connect_sdk';
11
+ const ORIGIN = 'stripe-connect-react-native';
12
+
13
+ /**
14
+ * System information for analytics
15
+ */
16
+ export interface SystemInfo {
17
+ sdkVersion: string;
18
+ osVersion: string;
19
+ deviceType: string;
20
+ appName: string;
21
+ appVersion: string;
22
+ }
23
+
24
+ /**
25
+ * Analytics client for sending events to Stripe backend
26
+ */
27
+ export class AnalyticsClient {
28
+ private systemInfo: SystemInfo;
29
+
30
+ constructor(systemInfo: SystemInfo) {
31
+ this.systemInfo = systemInfo;
32
+ }
33
+
34
+ /**
35
+ * Send an analytics event to the Stripe backend
36
+ * Silently fails if network request fails - analytics should never break app functionality
37
+ */
38
+ async sendEvent(payload: AnalyticsPayload): Promise<void> {
39
+ try {
40
+ const fullPayload = {
41
+ ...payload,
42
+ client_id: CLIENT_ID,
43
+ origin: ORIGIN,
44
+ sdk_platform: Platform.OS as 'ios' | 'android',
45
+ sdk_version: this.systemInfo.sdkVersion,
46
+ os_version: this.systemInfo.osVersion,
47
+ device_type: this.systemInfo.deviceType,
48
+ app_name: this.systemInfo.appName,
49
+ app_version: this.systemInfo.appVersion,
50
+ };
51
+
52
+ await fetch(ANALYTICS_URL, {
53
+ method: 'POST',
54
+ headers: {
55
+ 'Content-Type': 'application/json',
56
+ 'User-Agent': this.buildUserAgent(),
57
+ },
58
+ body: JSON.stringify(fullPayload),
59
+ });
60
+ } catch (error) {
61
+ // Silently fail - analytics should never break app functionality
62
+ if (__DEV__) {
63
+ console.warn('[StripeConnect] Analytics event failed:', error);
64
+ }
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Build user agent string for analytics requests
70
+ */
71
+ private buildUserAgent(): string {
72
+ const platform = Platform.OS; // 'ios' or 'android'
73
+ return `Stripe/v1 ${platform}/${this.systemInfo.sdkVersion}`;
74
+ }
75
+ }
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Component Analytics Client for tracking Connect component events
3
+ * Matches the Swift iOS SDK's ComponentAnalyticsClient implementation
4
+ */
5
+
6
+ import { AnalyticsClient } from './AnalyticsClient';
7
+ import {
8
+ EVENT_NAMES,
9
+ type AnalyticsPayload,
10
+ type CommonAnalyticsFields,
11
+ type ConnectAnalyticsEvent,
12
+ } from './events';
13
+
14
+ /**
15
+ * Configuration for ComponentAnalyticsClient
16
+ */
17
+ export interface ComponentAnalyticsConfig {
18
+ publishableKey?: string;
19
+ platformId?: string;
20
+ merchantId?: string;
21
+ livemode?: boolean;
22
+ component: string;
23
+ }
24
+
25
+ /**
26
+ * Generates a UUID v4
27
+ */
28
+ function generateUUID(): string {
29
+ /* eslint-disable no-bitwise */
30
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
31
+ const r = (Math.random() * 16) | 0;
32
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
33
+ return v.toString(16);
34
+ });
35
+ /* eslint-enable no-bitwise */
36
+ }
37
+
38
+ /**
39
+ * Component Analytics Client for tracking lifecycle, web view, and error events
40
+ */
41
+ export class ComponentAnalyticsClient {
42
+ private analyticsClient: AnalyticsClient;
43
+ private config: ComponentAnalyticsConfig;
44
+ private componentInstance: string;
45
+ private pageViewId?: string;
46
+ private loadStart: number;
47
+ private componentFirstViewedTime?: number;
48
+ private loggedPageLoaded: boolean = false;
49
+ private loggedComponentLoaded: boolean = false;
50
+
51
+ constructor(
52
+ analyticsClient: AnalyticsClient,
53
+ config: ComponentAnalyticsConfig
54
+ ) {
55
+ this.analyticsClient = analyticsClient;
56
+ this.config = config;
57
+ this.componentInstance = generateUUID();
58
+ this.loadStart = Date.now();
59
+ }
60
+
61
+ /**
62
+ * Build common fields for all events
63
+ */
64
+ private buildCommonFields(): CommonAnalyticsFields {
65
+ return {
66
+ event_id: generateUUID(),
67
+ created: Date.now(),
68
+ client_id: 'mobile_connect_sdk',
69
+ origin: 'stripe-connect-react-native',
70
+ sdk_platform: 'ios' as 'ios' | 'android',
71
+ sdk_version: '',
72
+ os_version: '',
73
+ device_type: '',
74
+ app_name: '',
75
+ app_version: '',
76
+ publishable_key: this.config.publishableKey,
77
+ platform_id: this.config.platformId,
78
+ merchant_id: this.config.merchantId,
79
+ livemode: this.config.livemode,
80
+ component: this.config.component,
81
+ component_instance: this.componentInstance,
82
+ };
83
+ }
84
+
85
+ /**
86
+ * Send an analytics event
87
+ */
88
+ private async log(event: ConnectAnalyticsEvent): Promise<void> {
89
+ const payload: AnalyticsPayload = {
90
+ ...this.buildCommonFields(),
91
+ ...event,
92
+ };
93
+
94
+ await this.analyticsClient.sendEvent(payload);
95
+ }
96
+
97
+ /**
98
+ * Log component created event
99
+ */
100
+ logComponentCreated(): void {
101
+ this.log({
102
+ event_name: EVENT_NAMES.COMPONENT_CREATED,
103
+ });
104
+ }
105
+
106
+ /**
107
+ * Log component viewed event (first time component becomes visible)
108
+ */
109
+ logComponentViewed(): void {
110
+ if (this.componentFirstViewedTime) {
111
+ return;
112
+ }
113
+
114
+ this.componentFirstViewedTime = Date.now();
115
+ this.log({
116
+ event_name: EVENT_NAMES.COMPONENT_VIEWED,
117
+ });
118
+ }
119
+
120
+ /**
121
+ * Log web page loaded event
122
+ */
123
+ logComponentWebPageLoaded(pageViewId?: string): void {
124
+ if (this.loggedPageLoaded) {
125
+ return;
126
+ }
127
+
128
+ this.loggedPageLoaded = true;
129
+ if (pageViewId) {
130
+ this.pageViewId = pageViewId;
131
+ }
132
+
133
+ const timeToLoad = (Date.now() - this.loadStart) / 1000;
134
+
135
+ this.log({
136
+ event_name: EVENT_NAMES.COMPONENT_WEB_PAGE_LOADED,
137
+ event_metadata: {
138
+ time_to_load: timeToLoad,
139
+ },
140
+ time_to_load: timeToLoad,
141
+ });
142
+ }
143
+
144
+ /**
145
+ * Log component loaded event (Connect JS fully initialized)
146
+ */
147
+ logComponentLoaded(): void {
148
+ if (this.loggedComponentLoaded) {
149
+ return;
150
+ }
151
+
152
+ this.loggedComponentLoaded = true;
153
+
154
+ const timeToLoad = (Date.now() - this.loadStart) / 1000;
155
+ const perceivedTimeToLoad = this.componentFirstViewedTime
156
+ ? (Date.now() - this.componentFirstViewedTime) / 1000
157
+ : undefined;
158
+
159
+ this.log({
160
+ event_name: EVENT_NAMES.COMPONENT_WEB_COMPONENT_LOADED,
161
+ event_metadata: {
162
+ page_view_id: this.pageViewId,
163
+ time_to_load: timeToLoad,
164
+ perceived_time_to_load: perceivedTimeToLoad,
165
+ },
166
+ page_view_id: this.pageViewId,
167
+ time_to_load: timeToLoad,
168
+ perceived_time_to_load: perceivedTimeToLoad,
169
+ });
170
+ }
171
+
172
+ /**
173
+ * Log page load error
174
+ */
175
+ logPageLoadError(error: Error, url?: string): void {
176
+ this.log({
177
+ event_name: EVENT_NAMES.COMPONENT_WEB_ERROR_PAGE_LOAD,
178
+ event_metadata: {
179
+ error_message: error.message,
180
+ error_domain: error.name,
181
+ url,
182
+ },
183
+ error_message: error.message,
184
+ error_domain: error.name,
185
+ url,
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Log unexpected navigation error
191
+ */
192
+ logUnexpectedNavigation(url?: string): void {
193
+ this.log({
194
+ event_name: EVENT_NAMES.COMPONENT_WEB_ERROR_UNEXPECTED_NAVIGATION,
195
+ event_metadata: {
196
+ url,
197
+ },
198
+ url,
199
+ });
200
+ }
201
+
202
+ /**
203
+ * Log unexpected load error type
204
+ */
205
+ logUnexpectedLoadErrorType(errorType: string): void {
206
+ this.log({
207
+ event_name: EVENT_NAMES.COMPONENT_WEB_ERROR_UNEXPECTED_LOAD_ERROR_TYPE,
208
+ event_metadata: {
209
+ error_type: errorType,
210
+ },
211
+ error_type: errorType,
212
+ });
213
+ }
214
+
215
+ /**
216
+ * Log unrecognized setter function warning
217
+ */
218
+ logUnrecognizedSetter(setterName: string): void {
219
+ this.log({
220
+ event_name: EVENT_NAMES.COMPONENT_WEB_WARN_UNRECOGNIZED_SETTER,
221
+ event_metadata: {
222
+ setter_name: setterName,
223
+ },
224
+ setter_name: setterName,
225
+ });
226
+ }
227
+
228
+ /**
229
+ * Log message deserialization error
230
+ */
231
+ logDeserializeMessageError(messageName: string, error: Error): void {
232
+ this.log({
233
+ event_name: EVENT_NAMES.COMPONENT_WEB_ERROR_DESERIALIZE_MESSAGE,
234
+ event_metadata: {
235
+ message_name: messageName,
236
+ error_message: error.message,
237
+ },
238
+ message_name: messageName,
239
+ error_message: error.message,
240
+ });
241
+ }
242
+
243
+ /**
244
+ * Log authenticated web view opened
245
+ */
246
+ logAuthenticatedWebViewOpened(id: string): void {
247
+ this.log({
248
+ event_name: EVENT_NAMES.COMPONENT_AUTHENTICATED_WEB_OPENED,
249
+ event_metadata: {
250
+ id,
251
+ },
252
+ id,
253
+ });
254
+ }
255
+
256
+ /**
257
+ * Log authenticated web view canceled
258
+ */
259
+ logAuthenticatedWebViewCanceled(id: string): void {
260
+ this.log({
261
+ event_name: EVENT_NAMES.COMPONENT_AUTHENTICATED_WEB_CANCELED,
262
+ event_metadata: {
263
+ id,
264
+ },
265
+ id,
266
+ });
267
+ }
268
+
269
+ /**
270
+ * Log authenticated web view redirected
271
+ */
272
+ logAuthenticatedWebViewRedirected(id: string): void {
273
+ this.log({
274
+ event_name: EVENT_NAMES.COMPONENT_AUTHENTICATED_WEB_REDIRECTED,
275
+ event_metadata: {
276
+ id,
277
+ },
278
+ id,
279
+ });
280
+ }
281
+
282
+ /**
283
+ * Log authenticated web view error
284
+ */
285
+ logAuthenticatedWebViewError(id: string, error: Error): void {
286
+ this.log({
287
+ event_name: EVENT_NAMES.COMPONENT_AUTHENTICATED_WEB_ERROR,
288
+ event_metadata: {
289
+ id,
290
+ error_message: error.message,
291
+ },
292
+ id,
293
+ error_message: error.message,
294
+ });
295
+ }
296
+
297
+ /**
298
+ * Log client error (catch-all for mobile client errors)
299
+ */
300
+ logClientError(error: Error, file?: string, line?: number): void {
301
+ this.log({
302
+ event_name: EVENT_NAMES.CLIENT_ERROR,
303
+ event_metadata: {
304
+ error_message: error.message,
305
+ error_domain: error.name,
306
+ file,
307
+ line,
308
+ },
309
+ error_message: error.message,
310
+ error_domain: error.name,
311
+ file,
312
+ line,
313
+ });
314
+ }
315
+ }
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Analytics event types for Connect components
3
+ * Matches the Swift iOS SDK implementation
4
+ */
5
+
6
+ /**
7
+ * Event names matching Swift SDK
8
+ */
9
+ export const EVENT_NAMES = {
10
+ COMPONENT_CREATED: 'component.created',
11
+ COMPONENT_VIEWED: 'component.viewed',
12
+ COMPONENT_WEB_PAGE_LOADED: 'component.web.page_loaded',
13
+ COMPONENT_WEB_COMPONENT_LOADED: 'component.web.component_loaded',
14
+ COMPONENT_WEB_ERROR_PAGE_LOAD: 'component.web.error.page_load',
15
+ COMPONENT_WEB_ERROR_UNEXPECTED_NAVIGATION:
16
+ 'component.web.error.unexpected_navigation',
17
+ COMPONENT_WEB_ERROR_UNEXPECTED_LOAD_ERROR_TYPE:
18
+ 'component.web.error.unexpected_load_error_type',
19
+ COMPONENT_WEB_WARN_UNRECOGNIZED_SETTER:
20
+ 'component.web.warn.unrecognized_setter_function',
21
+ COMPONENT_WEB_ERROR_DESERIALIZE_MESSAGE:
22
+ 'component.web.error.deserialize_message',
23
+ COMPONENT_AUTHENTICATED_WEB_OPENED: 'component.authenticated_web.opened',
24
+ COMPONENT_AUTHENTICATED_WEB_CANCELED: 'component.authenticated_web.canceled',
25
+ COMPONENT_AUTHENTICATED_WEB_REDIRECTED:
26
+ 'component.authenticated_web.redirected',
27
+ COMPONENT_AUTHENTICATED_WEB_ERROR: 'component.authenticated_web.error',
28
+ CLIENT_ERROR: 'client_error',
29
+ } as const;
30
+
31
+ /**
32
+ * Common fields included in all analytics events
33
+ */
34
+ export interface CommonAnalyticsFields {
35
+ event_id: string;
36
+ created: number;
37
+ client_id: string;
38
+ origin: string;
39
+ sdk_platform: 'ios' | 'android';
40
+ sdk_version: string;
41
+ os_version: string;
42
+ device_type: string;
43
+ app_name: string;
44
+ app_version: string;
45
+ publishable_key?: string;
46
+ platform_id?: string;
47
+ merchant_id?: string;
48
+ livemode?: boolean;
49
+ component: string;
50
+ component_instance: string;
51
+ }
52
+
53
+ /**
54
+ * Base analytics event structure
55
+ */
56
+ export interface AnalyticsEvent {
57
+ event_name: string;
58
+ event_metadata?: Record<string, any>;
59
+ }
60
+
61
+ /**
62
+ * Component created event
63
+ */
64
+ export interface ComponentCreatedEvent extends AnalyticsEvent {
65
+ event_name: typeof EVENT_NAMES.COMPONENT_CREATED;
66
+ }
67
+
68
+ /**
69
+ * Component viewed event (first time component becomes visible)
70
+ */
71
+ export interface ComponentViewedEvent extends AnalyticsEvent {
72
+ event_name: typeof EVENT_NAMES.COMPONENT_VIEWED;
73
+ }
74
+
75
+ /**
76
+ * Web page loaded event (HTML page finished loading)
77
+ */
78
+ export interface ComponentWebPageLoadedEvent extends AnalyticsEvent {
79
+ event_name: typeof EVENT_NAMES.COMPONENT_WEB_PAGE_LOADED;
80
+ event_metadata: {
81
+ time_to_load: number;
82
+ };
83
+ time_to_load: number;
84
+ }
85
+
86
+ /**
87
+ * Component loaded event (Connect JS fully initialized)
88
+ */
89
+ export interface ComponentWebComponentLoadedEvent extends AnalyticsEvent {
90
+ event_name: typeof EVENT_NAMES.COMPONENT_WEB_COMPONENT_LOADED;
91
+ event_metadata: {
92
+ page_view_id?: string;
93
+ time_to_load: number;
94
+ perceived_time_to_load?: number;
95
+ };
96
+ page_view_id?: string;
97
+ time_to_load: number;
98
+ perceived_time_to_load?: number;
99
+ }
100
+
101
+ /**
102
+ * Page load error event
103
+ */
104
+ export interface PageLoadErrorEvent extends AnalyticsEvent {
105
+ event_name: typeof EVENT_NAMES.COMPONENT_WEB_ERROR_PAGE_LOAD;
106
+ event_metadata: {
107
+ error_message: string;
108
+ error_domain?: string;
109
+ error_code?: string;
110
+ url?: string;
111
+ };
112
+ error_message: string;
113
+ error_domain?: string;
114
+ error_code?: string;
115
+ url?: string;
116
+ }
117
+
118
+ /**
119
+ * Unexpected navigation error event
120
+ */
121
+ export interface UnexpectedNavigationEvent extends AnalyticsEvent {
122
+ event_name: typeof EVENT_NAMES.COMPONENT_WEB_ERROR_UNEXPECTED_NAVIGATION;
123
+ event_metadata: {
124
+ url?: string;
125
+ };
126
+ url?: string;
127
+ }
128
+
129
+ /**
130
+ * Unexpected load error type event
131
+ */
132
+ export interface UnexpectedLoadErrorTypeEvent extends AnalyticsEvent {
133
+ event_name: typeof EVENT_NAMES.COMPONENT_WEB_ERROR_UNEXPECTED_LOAD_ERROR_TYPE;
134
+ event_metadata: {
135
+ error_type: string;
136
+ };
137
+ error_type: string;
138
+ }
139
+
140
+ /**
141
+ * Unrecognized setter function warning event
142
+ */
143
+ export interface UnrecognizedSetterEvent extends AnalyticsEvent {
144
+ event_name: typeof EVENT_NAMES.COMPONENT_WEB_WARN_UNRECOGNIZED_SETTER;
145
+ event_metadata: {
146
+ setter_name: string;
147
+ };
148
+ setter_name: string;
149
+ }
150
+
151
+ /**
152
+ * Message deserialization error event
153
+ */
154
+ export interface DeserializeMessageErrorEvent extends AnalyticsEvent {
155
+ event_name: typeof EVENT_NAMES.COMPONENT_WEB_ERROR_DESERIALIZE_MESSAGE;
156
+ event_metadata: {
157
+ message_name: string;
158
+ error_message: string;
159
+ };
160
+ message_name: string;
161
+ error_message: string;
162
+ }
163
+
164
+ /**
165
+ * Authenticated web view opened event
166
+ */
167
+ export interface AuthenticatedWebViewOpenedEvent extends AnalyticsEvent {
168
+ event_name: typeof EVENT_NAMES.COMPONENT_AUTHENTICATED_WEB_OPENED;
169
+ event_metadata: {
170
+ id: string;
171
+ };
172
+ id: string;
173
+ }
174
+
175
+ /**
176
+ * Authenticated web view canceled event
177
+ */
178
+ export interface AuthenticatedWebViewCanceledEvent extends AnalyticsEvent {
179
+ event_name: typeof EVENT_NAMES.COMPONENT_AUTHENTICATED_WEB_CANCELED;
180
+ event_metadata: {
181
+ id: string;
182
+ };
183
+ id: string;
184
+ }
185
+
186
+ /**
187
+ * Authenticated web view redirected event
188
+ */
189
+ export interface AuthenticatedWebViewRedirectedEvent extends AnalyticsEvent {
190
+ event_name: typeof EVENT_NAMES.COMPONENT_AUTHENTICATED_WEB_REDIRECTED;
191
+ event_metadata: {
192
+ id: string;
193
+ };
194
+ id: string;
195
+ }
196
+
197
+ /**
198
+ * Authenticated web view error event
199
+ */
200
+ export interface AuthenticatedWebViewErrorEvent extends AnalyticsEvent {
201
+ event_name: typeof EVENT_NAMES.COMPONENT_AUTHENTICATED_WEB_ERROR;
202
+ event_metadata: {
203
+ id: string;
204
+ error_message: string;
205
+ };
206
+ id: string;
207
+ error_message: string;
208
+ }
209
+
210
+ /**
211
+ * Client error event (catch-all for mobile client errors)
212
+ */
213
+ export interface ClientErrorEvent extends AnalyticsEvent {
214
+ event_name: typeof EVENT_NAMES.CLIENT_ERROR;
215
+ event_metadata: {
216
+ error_message: string;
217
+ error_domain?: string;
218
+ error_code?: string;
219
+ file?: string;
220
+ line?: number;
221
+ };
222
+ error_message: string;
223
+ error_domain?: string;
224
+ error_code?: string;
225
+ file?: string;
226
+ line?: number;
227
+ }
228
+
229
+ /**
230
+ * Union type of all possible analytics events
231
+ */
232
+ export type ConnectAnalyticsEvent =
233
+ | ComponentCreatedEvent
234
+ | ComponentViewedEvent
235
+ | ComponentWebPageLoadedEvent
236
+ | ComponentWebComponentLoadedEvent
237
+ | PageLoadErrorEvent
238
+ | UnexpectedNavigationEvent
239
+ | UnexpectedLoadErrorTypeEvent
240
+ | UnrecognizedSetterEvent
241
+ | DeserializeMessageErrorEvent
242
+ | AuthenticatedWebViewOpenedEvent
243
+ | AuthenticatedWebViewCanceledEvent
244
+ | AuthenticatedWebViewRedirectedEvent
245
+ | AuthenticatedWebViewErrorEvent
246
+ | ClientErrorEvent;
247
+
248
+ /**
249
+ * Full analytics payload sent to backend
250
+ */
251
+ export interface AnalyticsPayload
252
+ extends CommonAnalyticsFields,
253
+ AnalyticsEvent {}
@@ -42,7 +42,11 @@ export type EmbeddedErrorType =
42
42
  /**
43
43
  * API errors covering any other type of problem (e.g., a temporary problem with Stripe's servers), and are extremely uncommon.
44
44
  */
45
- | 'api_error';
45
+ | 'api_error'
46
+ /**
47
+ * Failure to render the component, typically caused by browser extensions or network issues
48
+ */
49
+ | 'render_error';
46
50
 
47
51
  export type Status =
48
52
  | 'blocked'
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Shared test utilities for Connect component tests
3
+ */
4
+
5
+ /**
6
+ * Mock constants returned by NativeStripeSdkModule.getConstants()
7
+ * Used to mock the native module in tests
8
+ */
9
+ export const mockNativeConstants = {
10
+ API_VERSIONS: {
11
+ CORE: '2024-12-15',
12
+ ISSUING: '2024-12-15',
13
+ },
14
+ SYSTEM_INFO: {
15
+ sdkVersion: '1.0.0',
16
+ osVersion: '18.0',
17
+ deviceType: 'iPhone14,5',
18
+ appName: 'TestApp',
19
+ appVersion: '1.0.0',
20
+ },
21
+ };
22
+
23
+ /**
24
+ * Creates a mock for NativeStripeSdkModule with standard test constants
25
+ * NOTE: Prefixed with 'mock' to be allowed in jest.mock() factory functions
26
+ * @param additionalMethods - Optional additional methods to include in the mock
27
+ * @returns Mock module configuration
28
+ */
29
+ export const mockCreateNativeStripeSdkMock = (
30
+ additionalMethods: Record<string, any> = {}
31
+ ) => ({
32
+ __esModule: true,
33
+ default: {
34
+ getConstants: jest.fn(() => mockNativeConstants),
35
+ ...additionalMethods,
36
+ },
37
+ });
package/src/events.ts CHANGED
@@ -64,6 +64,8 @@ type Events = {
64
64
  embeddedPaymentElementLoadingFailed: EventEmitter<UnsafeObject<any>>;
65
65
  embeddedPaymentElementUpdateComplete: EventEmitter<UnsafeObject<any>>;
66
66
  onCustomPaymentMethodConfirmHandlerCallback: EventEmitter<UnsafeObject<any>>;
67
+ paymentMethodMessagingElementDidUpdateHeight: EventEmitter<UnsafeObject<any>>;
68
+ paymentMethodMessagingElementConfigureResult: EventEmitter<UnsafeObject<any>>;
67
69
  };
68
70
 
69
71
  export function addListener<EventT extends keyof Events>(