@stripe/stripe-react-native 0.65.1 → 0.66.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 (79) 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 +95 -26
  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/oldarch/java/com/reactnativestripesdk/NativeOnrampSdkModuleSpec.java +17 -3
  16. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +5 -1
  17. package/android/src/onramp/java/com/reactnativestripesdk/OnrampMappers.kt +116 -0
  18. package/android/src/onramp/java/com/reactnativestripesdk/OnrampSdkModule.kt +109 -1
  19. package/android/src/test/java/com/reactnativestripesdk/DrawableLoadingTest.kt +6 -2
  20. package/android/src/test/java/com/reactnativestripesdk/mappers/OnrampMappersTest.kt +107 -0
  21. package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutMappersTest.kt +39 -30
  22. package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutTestFixtures.java +8 -0
  23. package/ios/CurrencySelectorElementManager.m +7 -0
  24. package/ios/CurrencySelectorElementView.swift +142 -7
  25. package/ios/EmbeddedPaymentElementView.swift +1 -1
  26. package/ios/Mappers+Checkout.swift +251 -107
  27. package/ios/Mappers.swift +90 -2
  28. package/ios/NewArch/StripeCurrencySelectorElementComponentView.mm +14 -0
  29. package/ios/OldArch/StripeSdkEventEmitterCompat.h +1 -0
  30. package/ios/OldArch/StripeSdkEventEmitterCompat.m +6 -0
  31. package/ios/PaymentOptionDisplayData+ReactNative.swift +1 -1
  32. package/ios/PaymentSheetAppearance.swift +1 -1
  33. package/ios/StripeOnrampSdk.mm +19 -0
  34. package/ios/StripeSdk.mm +17 -4
  35. package/ios/StripeSdkEmitter.swift +1 -0
  36. package/ios/StripeSdkImpl+Checkout.swift +75 -23
  37. package/ios/StripeSdkImpl+CustomerSheet.swift +1 -1
  38. package/ios/StripeSdkImpl+Embedded.swift +1 -1
  39. package/ios/StripeSdkImpl+PaymentSheet.swift +1 -1
  40. package/ios/StripeSdkImpl.swift +88 -8
  41. package/lib/commonjs/components/PaymentMethodMessagingElement.js +1 -1
  42. package/lib/commonjs/components/PaymentMethodMessagingElement.js.map +1 -1
  43. package/lib/commonjs/hooks/useCheckout.js +1 -1
  44. package/lib/commonjs/hooks/useCheckout.js.map +1 -1
  45. package/lib/commonjs/hooks/useOnramp.js +1 -1
  46. package/lib/commonjs/hooks/useOnramp.js.map +1 -1
  47. package/lib/commonjs/specs/NativeOnrampSdkModule.js.map +1 -1
  48. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  49. package/lib/module/components/PaymentMethodMessagingElement.js +1 -1
  50. package/lib/module/components/PaymentMethodMessagingElement.js.map +1 -1
  51. package/lib/module/hooks/useCheckout.js +1 -1
  52. package/lib/module/hooks/useCheckout.js.map +1 -1
  53. package/lib/module/hooks/useOnramp.js +1 -1
  54. package/lib/module/hooks/useOnramp.js.map +1 -1
  55. package/lib/module/specs/NativeOnrampSdkModule.js.map +1 -1
  56. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  57. package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts +1 -1
  58. package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts.map +1 -1
  59. package/lib/typescript/src/hooks/useCheckout.d.ts.map +1 -1
  60. package/lib/typescript/src/hooks/useOnramp.d.ts +22 -0
  61. package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -1
  62. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts +3 -0
  63. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts.map +1 -1
  64. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +2 -1
  65. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  66. package/lib/typescript/src/types/Checkout.d.ts +266 -84
  67. package/lib/typescript/src/types/Checkout.d.ts.map +1 -1
  68. package/lib/typescript/src/types/Onramp.d.ts +94 -0
  69. package/lib/typescript/src/types/Onramp.d.ts.map +1 -1
  70. package/package.json +3 -2
  71. package/src/components/PaymentMethodMessagingElement.tsx +54 -52
  72. package/src/hooks/useCheckout.tsx +20 -4
  73. package/src/hooks/useOnramp.tsx +44 -0
  74. package/src/specs/NativeOnrampSdkModule.ts +5 -0
  75. package/src/specs/NativeStripeSdkModule.ts +8 -1
  76. package/src/types/Checkout.ts +289 -84
  77. package/src/types/Onramp.ts +109 -0
  78. package/stripe-react-native.podspec +1 -1
  79. package/ios/CurrencySelectorElementManager.swift +0 -12
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useEffect, useRef, useState } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
2
  import {
3
3
  AccessibilityProps,
4
4
  HostComponent,
@@ -50,60 +50,62 @@ export interface Props extends AccessibilityProps {
50
50
  * @returns JSX.Element
51
51
  * @category ReactComponents
52
52
  */
53
- export const PaymentMethodMessagingElement = forwardRef<any, Props>(
54
- ({ appearance, configuration, onStateChange, ...props }) => {
55
- const viewRef =
56
- useRef<React.ComponentRef<HostComponent<NativeProps>>>(null);
53
+ export const PaymentMethodMessagingElement = ({
54
+ appearance,
55
+ configuration,
56
+ onStateChange,
57
+ ...props
58
+ }: Props) => {
59
+ const viewRef = useRef<React.ComponentRef<HostComponent<NativeProps>>>(null);
57
60
 
58
- const [height, setHeight] = useState<number | undefined>();
61
+ const [height, setHeight] = useState<number | undefined>();
59
62
 
60
- useEffect(() => {
61
- // listen for height changes
62
- const sub = addListener(
63
- 'paymentMethodMessagingElementDidUpdateHeight',
64
- ({ height: h }) => {
65
- LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
66
- setHeight(h);
67
- }
68
- );
69
- return () => sub.remove();
70
- });
63
+ useEffect(() => {
64
+ // listen for height changes
65
+ const sub = addListener(
66
+ 'paymentMethodMessagingElementDidUpdateHeight',
67
+ ({ height: h }) => {
68
+ LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
69
+ setHeight(h);
70
+ }
71
+ );
72
+ return () => sub.remove();
73
+ });
71
74
 
72
- useEffect(() => {
73
- // listen for load complete
74
- const sub = addListener(
75
- 'paymentMethodMessagingElementConfigureResult',
76
- ({ status: s }) => {
77
- let state: PaymentMethodMessagingElementState;
75
+ useEffect(() => {
76
+ // listen for load complete
77
+ const sub = addListener(
78
+ 'paymentMethodMessagingElementConfigureResult',
79
+ ({ status: s }) => {
80
+ let state: PaymentMethodMessagingElementState;
78
81
 
79
- if (s === 'loaded') {
80
- state = { status: 'loaded' };
81
- } else if (s === 'loading') {
82
- state = { status: 'loading' };
83
- } else if (s === 'no_content') {
84
- state = { status: 'no_content' };
85
- } else {
86
- state = {
87
- status: 'failed',
88
- error: new Error(
89
- 'Failed to configure payment method messaging element'
90
- ),
91
- };
92
- }
93
- onStateChange?.(state);
82
+ if (s === 'loaded') {
83
+ state = { status: 'loaded' };
84
+ } else if (s === 'loading') {
85
+ state = { status: 'loading' };
86
+ } else if (s === 'no_content') {
87
+ state = { status: 'no_content' };
88
+ } else {
89
+ state = {
90
+ status: 'failed',
91
+ error: new Error(
92
+ 'Failed to configure payment method messaging element'
93
+ ),
94
+ };
94
95
  }
95
- );
96
- return () => sub.remove();
97
- }, [onStateChange]);
98
-
99
- return (
100
- <NativePaymentMethodMessagingElement
101
- appearance={appearance}
102
- style={[{ width: '100%', height: height }]}
103
- configuration={configuration}
104
- {...props}
105
- ref={viewRef}
106
- />
96
+ onStateChange?.(state);
97
+ }
107
98
  );
108
- }
109
- );
99
+ return () => sub.remove();
100
+ }, [onStateChange]);
101
+
102
+ return (
103
+ <NativePaymentMethodMessagingElement
104
+ appearance={appearance}
105
+ style={[{ width: '100%', height: height }]}
106
+ configuration={configuration}
107
+ {...props}
108
+ ref={viewRef}
109
+ />
110
+ );
111
+ };
@@ -165,8 +165,24 @@ export function useCheckout(
165
165
  ),
166
166
  [withLoading]
167
167
  );
168
- const refresh = useCallback<Checkout['refresh']>(
169
- () => withLoading((key) => NativeStripeSdk.checkoutRefresh(key)),
168
+ const runServerUpdate = useCallback<Checkout['runServerUpdate']>(
169
+ (serverUpdate) =>
170
+ withLoading(async (key) => {
171
+ const startPromise = NativeStripeSdk.checkoutRunServerUpdateStart(key);
172
+
173
+ try {
174
+ await serverUpdate();
175
+ await NativeStripeSdk.checkoutRunServerUpdateComplete(key, null);
176
+ } catch (e: any) {
177
+ await NativeStripeSdk.checkoutRunServerUpdateComplete(
178
+ key,
179
+ e.message ?? 'Server update failed'
180
+ );
181
+ throw e;
182
+ }
183
+
184
+ return await startPromise;
185
+ }),
170
186
  [withLoading]
171
187
  );
172
188
 
@@ -189,7 +205,7 @@ export function useCheckout(
189
205
  updateLineItemQuantity,
190
206
  selectShippingOption,
191
207
  updateTaxId,
192
- refresh,
208
+ runServerUpdate,
193
209
  }),
194
210
  [
195
211
  updateShippingAddress,
@@ -199,7 +215,7 @@ export function useCheckout(
199
215
  updateLineItemQuantity,
200
216
  selectShippingOption,
201
217
  updateTaxId,
202
- refresh,
218
+ runServerUpdate,
203
219
  ]
204
220
  );
205
221
 
@@ -75,6 +75,25 @@ export function useOnramp() {
75
75
  []
76
76
  );
77
77
 
78
+ const _retrieveMissingIdentifiers =
79
+ useCallback(async (): Promise<Onramp.RetrieveMissingIdentifiersResult> => {
80
+ return requireOnrampModule().retrieveMissingIdentifiers();
81
+ }, []);
82
+
83
+ const _submitIdentifiers = useCallback(
84
+ async (
85
+ identifiers: Onramp.ComplianceIdentifier[]
86
+ ): Promise<Onramp.SubmitIdentifiersResult> => {
87
+ return requireOnrampModule().submitIdentifiers(identifiers);
88
+ },
89
+ []
90
+ );
91
+
92
+ const _presentCRSCARFDeclaration =
93
+ useCallback(async (): Promise<Onramp.CRSCARFDeclarationResult> => {
94
+ return requireOnrampModule().presentCRSCARFDeclaration();
95
+ }, []);
96
+
78
97
  const _presentKycInfoVerification = useCallback(
79
98
  async (updatedAddress: Address | null): Promise<Onramp.VerifyKycResult> => {
80
99
  return requireOnrampModule().presentKycInfoVerification(updatedAddress);
@@ -244,6 +263,31 @@ export function useOnramp() {
244
263
  */
245
264
  attachKycInfo: _attachKycInfo,
246
265
 
266
+ /**
267
+ * Retrieves any missing MiCA or CRS/CARF compliance identifiers for the current Link user.
268
+ * Requires an authenticated Link user.
269
+ *
270
+ * @returns Promise that resolves to identifier requirements and alternatives, or error
271
+ */
272
+ retrieveMissingIdentifiers: _retrieveMissingIdentifiers,
273
+
274
+ /**
275
+ * Submits MiCA or CRS/CARF compliance identifiers for the current Link user.
276
+ * Requires an authenticated Link user.
277
+ *
278
+ * @param identifiers The compliance identifiers to submit
279
+ * @returns Promise that resolves to whether the submission was valid, any remaining requirements, invalid identifiers, or error
280
+ */
281
+ submitIdentifiers: _submitIdentifiers,
282
+
283
+ /**
284
+ * Presents UI for the current Link user to accept the CRS/CARF declaration.
285
+ * Requires an authenticated Link user.
286
+ *
287
+ * @returns Promise that resolves to `Confirmed` when accepted, or error
288
+ */
289
+ presentCRSCARFDeclaration: _presentCRSCARFDeclaration,
290
+
247
291
  /**
248
292
  * Presents UI to verify KYC information for the current Link user.
249
293
  * Requires the user to be authenticated with prior calls to either `authenticateUserWithToken` or `authorize`,
@@ -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
+ presentCRSCARFDeclaration(): Promise<Onramp.CRSCARFDeclarationResult>;
22
27
  presentKycInfoVerification: (
23
28
  updatedAddress: UnsafeObject<Address> | null
24
29
  ) => Promise<Onramp.VerifyKycResult>;
@@ -262,7 +262,14 @@ export interface Spec extends TurboModule {
262
262
  value: string
263
263
  ): Promise<UnsafeObject<Checkout.State>>;
264
264
 
265
- checkoutRefresh(sessionKey: string): Promise<UnsafeObject<Checkout.State>>;
265
+ checkoutRunServerUpdateStart(
266
+ sessionKey: string
267
+ ): Promise<UnsafeObject<Checkout.State>>;
268
+
269
+ checkoutRunServerUpdateComplete(
270
+ sessionKey: string,
271
+ error: string | null
272
+ ): Promise<void>;
266
273
 
267
274
  setFinancialConnectionsForceNativeFlow(enabled: boolean): Promise<void>;
268
275