@stripe/stripe-react-native 0.65.1 → 0.67.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 (107) hide show
  1. package/android/detekt/detekt-baseline.xml +0 -10
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +51 -57
  4. package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementEvent.kt +26 -0
  5. package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementView.kt +129 -16
  6. package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementViewManager.kt +17 -0
  7. package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +4 -0
  8. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +8 -19
  9. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +1 -0
  10. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +89 -31
  11. package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +1 -0
  12. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt +2 -16
  13. package/android/src/main/java/com/reactnativestripesdk/utils/CheckoutMappers.kt +59 -33
  14. package/android/src/main/java/com/reactnativestripesdk/utils/DefaultActivityLifecycleCallbacks.kt +41 -0
  15. package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +11 -6
  16. package/android/src/oldarch/java/com/reactnativestripesdk/NativeOnrampSdkModuleSpec.java +17 -3
  17. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +2 -2
  18. package/android/src/onramp/java/com/reactnativestripesdk/OnrampErrors.kt +145 -0
  19. package/android/src/onramp/java/com/reactnativestripesdk/OnrampMappers.kt +125 -0
  20. package/android/src/onramp/java/com/reactnativestripesdk/OnrampSdkModule.kt +144 -22
  21. package/android/src/test/java/com/reactnativestripesdk/DrawableLoadingTest.kt +6 -2
  22. package/android/src/test/java/com/reactnativestripesdk/OnrampErrorsTest.kt +168 -0
  23. package/android/src/test/java/com/reactnativestripesdk/mappers/OnrampMappersTest.kt +107 -0
  24. package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutMappersTest.kt +39 -30
  25. package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutTestFixtures.java +8 -0
  26. package/ios/CurrencySelectorElementManager.m +7 -0
  27. package/ios/CurrencySelectorElementView.swift +142 -7
  28. package/ios/EmbeddedPaymentElementView.swift +1 -1
  29. package/ios/Mappers+Checkout.swift +251 -107
  30. package/ios/Mappers.swift +97 -7
  31. package/ios/NewArch/StripeCurrencySelectorElementComponentView.mm +14 -0
  32. package/ios/OldArch/StripeSdkEventEmitterCompat.h +1 -0
  33. package/ios/OldArch/StripeSdkEventEmitterCompat.m +6 -0
  34. package/ios/OnrampErrors.swift +132 -0
  35. package/ios/PaymentOptionDisplayData+ReactNative.swift +1 -1
  36. package/ios/PaymentSheetAppearance.swift +1 -1
  37. package/ios/StripeOnrampSdk.mm +19 -0
  38. package/ios/StripeSdk.mm +14 -14
  39. package/ios/StripeSdkEmitter.swift +1 -0
  40. package/ios/StripeSdkImpl+Checkout.swift +66 -31
  41. package/ios/StripeSdkImpl+CustomerSheet.swift +1 -1
  42. package/ios/StripeSdkImpl+Embedded.swift +1 -1
  43. package/ios/StripeSdkImpl+PaymentSheet.swift +1 -1
  44. package/ios/StripeSdkImpl.swift +116 -24
  45. package/lib/commonjs/components/PaymentMethodMessagingElement.js +1 -1
  46. package/lib/commonjs/components/PaymentMethodMessagingElement.js.map +1 -1
  47. package/lib/commonjs/components/StripeProvider.js +1 -1
  48. package/lib/commonjs/components/StripeProvider.js.map +1 -1
  49. package/lib/commonjs/hooks/useCheckout.js +1 -1
  50. package/lib/commonjs/hooks/useCheckout.js.map +1 -1
  51. package/lib/commonjs/hooks/useOnramp.js +1 -1
  52. package/lib/commonjs/hooks/useOnramp.js.map +1 -1
  53. package/lib/commonjs/internal/stripeConfig.js +2 -0
  54. package/lib/commonjs/internal/stripeConfig.js.map +1 -0
  55. package/lib/commonjs/specs/NativeOnrampSdkModule.js.map +1 -1
  56. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  57. package/lib/commonjs/types/Errors.js +1 -1
  58. package/lib/commonjs/types/Errors.js.map +1 -1
  59. package/lib/commonjs/types/Onramp.js +1 -1
  60. package/lib/commonjs/types/Onramp.js.map +1 -1
  61. package/lib/module/components/PaymentMethodMessagingElement.js +1 -1
  62. package/lib/module/components/PaymentMethodMessagingElement.js.map +1 -1
  63. package/lib/module/components/StripeProvider.js +1 -1
  64. package/lib/module/components/StripeProvider.js.map +1 -1
  65. package/lib/module/hooks/useCheckout.js +1 -1
  66. package/lib/module/hooks/useCheckout.js.map +1 -1
  67. package/lib/module/hooks/useOnramp.js +1 -1
  68. package/lib/module/hooks/useOnramp.js.map +1 -1
  69. package/lib/module/internal/stripeConfig.js +2 -0
  70. package/lib/module/internal/stripeConfig.js.map +1 -0
  71. package/lib/module/specs/NativeOnrampSdkModule.js.map +1 -1
  72. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  73. package/lib/module/types/Errors.js +1 -1
  74. package/lib/module/types/Errors.js.map +1 -1
  75. package/lib/module/types/Onramp.js +1 -1
  76. package/lib/module/types/Onramp.js.map +1 -1
  77. package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts +1 -1
  78. package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts.map +1 -1
  79. package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -1
  80. package/lib/typescript/src/hooks/useCheckout.d.ts.map +1 -1
  81. package/lib/typescript/src/hooks/useOnramp.d.ts +32 -10
  82. package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -1
  83. package/lib/typescript/src/internal/stripeConfig.d.ts +3 -0
  84. package/lib/typescript/src/internal/stripeConfig.d.ts.map +1 -0
  85. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts +3 -0
  86. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts.map +1 -1
  87. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +2 -2
  88. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  89. package/lib/typescript/src/types/Checkout.d.ts +266 -92
  90. package/lib/typescript/src/types/Checkout.d.ts.map +1 -1
  91. package/lib/typescript/src/types/Errors.d.ts +0 -5
  92. package/lib/typescript/src/types/Errors.d.ts.map +1 -1
  93. package/lib/typescript/src/types/Onramp.d.ts +168 -9
  94. package/lib/typescript/src/types/Onramp.d.ts.map +1 -1
  95. package/package.json +3 -2
  96. package/src/components/PaymentMethodMessagingElement.tsx +54 -52
  97. package/src/components/StripeProvider.tsx +2 -0
  98. package/src/hooks/useCheckout.tsx +20 -13
  99. package/src/hooks/useOnramp.tsx +139 -12
  100. package/src/internal/stripeConfig.ts +9 -0
  101. package/src/specs/NativeOnrampSdkModule.ts +5 -0
  102. package/src/specs/NativeStripeSdkModule.ts +6 -5
  103. package/src/types/Checkout.ts +289 -93
  104. package/src/types/Errors.ts +0 -6
  105. package/src/types/Onramp.ts +192 -9
  106. package/stripe-react-native.podspec +3 -3
  107. package/ios/CurrencySelectorElementManager.swift +0 -12
@@ -1,10 +1,12 @@
1
1
  import { EventSubscription, Platform } from 'react-native';
2
2
  import NativeOnrampSdk from '../specs/NativeOnrampSdkModule';
3
- import { Onramp, OnrampError, StripeError } from '../types';
3
+ import { Onramp } from '../types';
4
4
  import type { Address } from '../types';
5
5
  import { useCallback } from 'react';
6
6
  import { addOnrampListener } from '../events';
7
7
  import { CryptoPaymentToken } from '../types/Onramp';
8
+ import { getCurrentPublishableKey } from '../internal/stripeConfig';
9
+ import pjson from '../../package.json';
8
10
 
9
11
  export function requireOnrampModule() {
10
12
  if (NativeOnrampSdk == null) {
@@ -24,6 +26,83 @@ export function requireOnrampModule() {
24
26
  let onCheckoutClientSecretRequestedSubscription: EventSubscription | null =
25
27
  null;
26
28
 
29
+ const legacyAppAttestationUnavailableMessages = [
30
+ 'App attestation is missing or device cannot use native Link.',
31
+ 'Native Link is not available',
32
+ ];
33
+ const cryptoOnrampAppAttestationUnavailableCode = 'app_attestation_unavailable';
34
+
35
+ function isLegacyAppAttestationUnavailableMessage(message?: string): boolean {
36
+ return (
37
+ message != null && legacyAppAttestationUnavailableMessages.includes(message)
38
+ );
39
+ }
40
+
41
+ function publishableKeyMode(): 'live' | 'test' | undefined {
42
+ const publishableKey = getCurrentPublishableKey();
43
+ if (publishableKey?.startsWith('pk_live_')) {
44
+ return 'live';
45
+ }
46
+ if (publishableKey?.startsWith('pk_test_')) {
47
+ return 'test';
48
+ }
49
+ return undefined;
50
+ }
51
+
52
+ // Temporary React Native shim: iOS/Android currently surface this configure/create
53
+ // failure as a legacy SDK-level message instead of a typed rich error. This can be
54
+ // removed once the native SDKs map it themselves, though keeping it is harmless as
55
+ // a compatibility fallback for older native SDK versions.
56
+ function mapLegacyConfigureAppAttestationError(result: {
57
+ error?: Onramp.CryptoOnrampError;
58
+ }): { error?: Onramp.CryptoOnrampError } {
59
+ const error = result.error;
60
+ if (
61
+ error == null ||
62
+ error.onrampErrorType != null ||
63
+ (!isLegacyAppAttestationUnavailableMessage(error.message) &&
64
+ !isLegacyAppAttestationUnavailableMessage(error.localizedMessage))
65
+ ) {
66
+ return result;
67
+ }
68
+
69
+ const userMessage =
70
+ "This app couldn't be verified. Contact the app developer for help.";
71
+ const mode = publishableKeyMode();
72
+
73
+ const context = [
74
+ 'Context:',
75
+ ' operation: configure',
76
+ mode != null ? ` mode: ${mode}` : undefined,
77
+ ].filter((line): line is string => line != null);
78
+ const appAttestationError = {
79
+ ...error,
80
+ message: userMessage,
81
+ localizedMessage: userMessage,
82
+ stripeErrorCode: cryptoOnrampAppAttestationUnavailableCode,
83
+ developerMessage: [
84
+ "App attestation unavailable: this app isn't configured to use Stripe Crypto Onramp.",
85
+ '',
86
+ "This usually means app attestation isn't enabled for this Stripe account, or this app isn't registered as a trusted application. Use your iOS bundle ID or Android package name and contact Stripe to enable app attestation or register the app for this account.",
87
+ '',
88
+ ...context,
89
+ '',
90
+ `Code: ${cryptoOnrampAppAttestationUnavailableCode}`,
91
+ '',
92
+ 'Next step: confirm app attestation is enabled for this Stripe account and that the app identifier is registered as trusted, then call configure again.',
93
+ `SDK: stripe-react-native@${pjson.version}`,
94
+ ].join('\n'),
95
+ userMessage,
96
+ operation: 'configure',
97
+ mode,
98
+ } as unknown as Onramp.CryptoOnrampError;
99
+
100
+ return {
101
+ ...result,
102
+ error: appAttestationError,
103
+ };
104
+ }
105
+
27
106
  /**
28
107
  * useOnramp hook
29
108
  */
@@ -31,8 +110,10 @@ export function useOnramp() {
31
110
  const _configure = useCallback(
32
111
  async (
33
112
  config: Onramp.Configuration
34
- ): Promise<{ error?: StripeError<OnrampError> }> => {
35
- return requireOnrampModule().configureOnramp(config);
113
+ ): Promise<{ error?: Onramp.CryptoOnrampError }> => {
114
+ return mapLegacyConfigureAppAttestationError(
115
+ await requireOnrampModule().configureOnramp(config)
116
+ );
36
117
  },
37
118
  []
38
119
  );
@@ -57,7 +138,7 @@ export function useOnramp() {
57
138
  async (
58
139
  walletAddress: string,
59
140
  network: Onramp.CryptoNetwork
60
- ): Promise<{ error?: StripeError<OnrampError> }> => {
141
+ ): Promise<{ error?: Onramp.CryptoOnrampError }> => {
61
142
  return requireOnrampModule().registerWalletAddress(
62
143
  walletAddress,
63
144
  network
@@ -69,12 +150,31 @@ export function useOnramp() {
69
150
  const _attachKycInfo = useCallback(
70
151
  async (
71
152
  kycInfo: Onramp.KycInfo
72
- ): Promise<{ error?: StripeError<OnrampError> }> => {
153
+ ): Promise<{ error?: Onramp.CryptoOnrampError }> => {
73
154
  return requireOnrampModule().attachKycInfo(kycInfo);
74
155
  },
75
156
  []
76
157
  );
77
158
 
159
+ const _retrieveMissingIdentifiers =
160
+ useCallback(async (): Promise<Onramp.RetrieveMissingIdentifiersResult> => {
161
+ return requireOnrampModule().retrieveMissingIdentifiers();
162
+ }, []);
163
+
164
+ const _submitIdentifiers = useCallback(
165
+ async (
166
+ identifiers: Onramp.ComplianceIdentifier[]
167
+ ): Promise<Onramp.SubmitIdentifiersResult> => {
168
+ return requireOnrampModule().submitIdentifiers(identifiers);
169
+ },
170
+ []
171
+ );
172
+
173
+ const _presentUserAttestation =
174
+ useCallback(async (): Promise<Onramp.UserAttestationResult> => {
175
+ return requireOnrampModule().presentUserAttestation();
176
+ }, []);
177
+
78
178
  const _presentKycInfoVerification = useCallback(
79
179
  async (updatedAddress: Address | null): Promise<Onramp.VerifyKycResult> => {
80
180
  return requireOnrampModule().presentKycInfoVerification(updatedAddress);
@@ -85,7 +185,7 @@ export function useOnramp() {
85
185
  const _authenticateUserWithToken = useCallback(
86
186
  async (
87
187
  linkAuthTokenClientSecret: string
88
- ): Promise<{ error?: StripeError<OnrampError> }> => {
188
+ ): Promise<{ error?: Onramp.CryptoOnrampError }> => {
89
189
  return requireOnrampModule().authenticateUserWithToken(
90
190
  linkAuthTokenClientSecret
91
191
  );
@@ -94,14 +194,14 @@ export function useOnramp() {
94
194
  );
95
195
 
96
196
  const _updatePhoneNumber = useCallback(
97
- async (phone: string): Promise<{ error?: StripeError<OnrampError> }> => {
197
+ async (phone: string): Promise<{ error?: Onramp.CryptoOnrampError }> => {
98
198
  return requireOnrampModule().updatePhoneNumber(phone);
99
199
  },
100
200
  []
101
201
  );
102
202
 
103
203
  const _verifyIdentity = useCallback(async (): Promise<{
104
- error?: StripeError<OnrampError>;
204
+ error?: Onramp.CryptoOnrampError;
105
205
  }> => {
106
206
  return requireOnrampModule().verifyIdentity();
107
207
  }, []);
@@ -149,7 +249,7 @@ export function useOnramp() {
149
249
  async (
150
250
  onrampSessionId: string,
151
251
  provideCheckoutClientSecret: () => Promise<string | null>
152
- ): Promise<{ error?: StripeError<OnrampError> }> => {
252
+ ): Promise<{ error?: Onramp.CryptoOnrampError }> => {
153
253
  onCheckoutClientSecretRequestedSubscription?.remove();
154
254
  onCheckoutClientSecretRequestedSubscription = addOnrampListener(
155
255
  'onCheckoutClientSecretRequested',
@@ -184,13 +284,15 @@ export function useOnramp() {
184
284
  );
185
285
 
186
286
  const _logOut = useCallback(async (): Promise<{
187
- error?: StripeError<OnrampError>;
287
+ error?: Onramp.CryptoOnrampError;
188
288
  }> => {
189
289
  return requireOnrampModule().logout();
190
290
  }, []);
191
291
 
192
- const _isAuthError = (error?: StripeError<OnrampError>): boolean => {
193
- const stripeErrorCode = error?.stripeErrorCode;
292
+ const _isAuthError = (error?: Onramp.CryptoOnrampError): boolean => {
293
+ const stripeErrorCode =
294
+ error?.stripeErrorCode ??
295
+ (error?.onrampErrorType ? error.apiErrorCode : undefined);
194
296
  if (stripeErrorCode == null) {
195
297
  return false;
196
298
  }
@@ -244,6 +346,31 @@ export function useOnramp() {
244
346
  */
245
347
  attachKycInfo: _attachKycInfo,
246
348
 
349
+ /**
350
+ * Retrieves any missing MiCA or CRS/CARF compliance identifiers for the current Link user.
351
+ * Requires an authenticated Link user.
352
+ *
353
+ * @returns Promise that resolves to identifier requirements and alternatives, or error
354
+ */
355
+ retrieveMissingIdentifiers: _retrieveMissingIdentifiers,
356
+
357
+ /**
358
+ * Submits MiCA or CRS/CARF compliance identifiers for the current Link user.
359
+ * Requires an authenticated Link user.
360
+ *
361
+ * @param identifiers The compliance identifiers to submit
362
+ * @returns Promise that resolves to whether collection is complete, any remaining requirements, CARF TIN state, invalid identifiers, or error
363
+ */
364
+ submitIdentifiers: _submitIdentifiers,
365
+
366
+ /**
367
+ * Presents UI for the current Link user to accept user attestation.
368
+ * Requires an authenticated Link user.
369
+ *
370
+ * @returns Promise that resolves to `Confirmed` when accepted, or error
371
+ */
372
+ presentUserAttestation: _presentUserAttestation,
373
+
247
374
  /**
248
375
  * Presents UI to verify KYC information for the current Link user.
249
376
  * Requires the user to be authenticated with prior calls to either `authenticateUserWithToken` or `authorize`,
@@ -0,0 +1,9 @@
1
+ let currentPublishableKey: string | undefined;
2
+
3
+ export function setCurrentPublishableKey(publishableKey: string): void {
4
+ currentPublishableKey = publishableKey;
5
+ }
6
+
7
+ export function getCurrentPublishableKey(): string | undefined {
8
+ return currentPublishableKey;
9
+ }
@@ -19,6 +19,11 @@ export interface Spec extends TurboModule {
19
19
  attachKycInfo(
20
20
  kycInfo: UnsafeObject<Onramp.KycInfo>
21
21
  ): Promise<Onramp.VoidResult>;
22
+ retrieveMissingIdentifiers(): Promise<Onramp.RetrieveMissingIdentifiersResult>;
23
+ submitIdentifiers(
24
+ identifiers: ReadonlyArray<UnsafeObject<Onramp.ComplianceIdentifier>>
25
+ ): Promise<Onramp.SubmitIdentifiersResult>;
26
+ presentUserAttestation(): Promise<Onramp.UserAttestationResult>;
22
27
  presentKycInfoVerification: (
23
28
  updatedAddress: UnsafeObject<Address> | null
24
29
  ) => Promise<Onramp.VerifyKycResult>;
@@ -256,13 +256,14 @@ export interface Spec extends TurboModule {
256
256
  id: string
257
257
  ): Promise<UnsafeObject<Checkout.State>>;
258
258
 
259
- checkoutUpdateTaxId(
260
- sessionKey: string,
261
- type: string,
262
- value: string
259
+ checkoutRunServerUpdateStart(
260
+ sessionKey: string
263
261
  ): Promise<UnsafeObject<Checkout.State>>;
264
262
 
265
- checkoutRefresh(sessionKey: string): Promise<UnsafeObject<Checkout.State>>;
263
+ checkoutRunServerUpdateComplete(
264
+ sessionKey: string,
265
+ error: string | null
266
+ ): Promise<void>;
266
267
 
267
268
  setFinancialConnectionsForceNativeFlow(enabled: boolean): Promise<void>;
268
269