@stripe/stripe-react-native 0.29.0 → 0.30.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 (45) hide show
  1. package/CHANGELOG.md +84 -71
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +35 -8
  4. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +13 -1
  5. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +8 -1
  6. package/ios/Mappers.swift +1 -0
  7. package/ios/StripeSdk.m +7 -0
  8. package/ios/StripeSdk.swift +32 -0
  9. package/jest/mock.js +4 -0
  10. package/lib/commonjs/NativeStripeSdk.js.map +1 -1
  11. package/lib/commonjs/functions.js +1 -1
  12. package/lib/commonjs/functions.js.map +1 -1
  13. package/lib/commonjs/hooks/useFinancialConnectionsSheet.js +1 -1
  14. package/lib/commonjs/hooks/useFinancialConnectionsSheet.js.map +1 -1
  15. package/lib/commonjs/hooks/usePaymentSheet.js +1 -1
  16. package/lib/commonjs/hooks/usePaymentSheet.js.map +1 -1
  17. package/lib/commonjs/hooks/useStripe.js +1 -1
  18. package/lib/commonjs/hooks/useStripe.js.map +1 -1
  19. package/lib/commonjs/types/PushProvisioning.js.map +1 -1
  20. package/lib/commonjs/types/index.js.map +1 -1
  21. package/lib/module/NativeStripeSdk.js.map +1 -1
  22. package/lib/module/functions.js +1 -1
  23. package/lib/module/functions.js.map +1 -1
  24. package/lib/module/hooks/useFinancialConnectionsSheet.js +1 -1
  25. package/lib/module/hooks/useFinancialConnectionsSheet.js.map +1 -1
  26. package/lib/module/hooks/usePaymentSheet.js +1 -1
  27. package/lib/module/hooks/usePaymentSheet.js.map +1 -1
  28. package/lib/module/hooks/useStripe.js +1 -1
  29. package/lib/module/hooks/useStripe.js.map +1 -1
  30. package/lib/module/types/PushProvisioning.js.map +1 -1
  31. package/lib/module/types/index.js.map +1 -1
  32. package/lib/typescript/src/NativeStripeSdk.d.ts +2 -1
  33. package/lib/typescript/src/functions.d.ts +8 -1
  34. package/lib/typescript/src/hooks/useStripe.d.ts +2 -1
  35. package/lib/typescript/src/types/PushProvisioning.d.ts +9 -1
  36. package/lib/typescript/src/types/index.d.ts +7 -0
  37. package/package.json +1 -1
  38. package/src/NativeStripeSdk.tsx +5 -0
  39. package/src/functions.ts +36 -0
  40. package/src/hooks/useFinancialConnectionsSheet.tsx +19 -13
  41. package/src/hooks/usePaymentSheet.tsx +25 -18
  42. package/src/hooks/useStripe.tsx +13 -0
  43. package/src/types/PushProvisioning.ts +9 -1
  44. package/src/types/index.ts +10 -0
  45. package/stripe-react-native.podspec +1 -1
@@ -1,8 +1,9 @@
1
- import type { PaymentMethod, PaymentIntent, PlatformPay, PaymentSheet, SetupIntent, InitialiseParams, CreatePaymentMethodResult, RetrievePaymentIntentResult, RetrieveSetupIntentResult, ConfirmPaymentResult, HandleNextActionResult, ConfirmSetupIntentResult, CreateTokenForCVCUpdateResult, InitPaymentSheetResult, PresentPaymentSheetResult, ConfirmPaymentSheetPaymentResult, CreateTokenResult, OpenApplePaySetupResult, Token, VerifyMicrodepositsParams, IsCardInWalletResult, CanAddCardToWalletParams, CanAddCardToWalletResult, FinancialConnections } from './types';
1
+ import type { PaymentMethod, PaymentIntent, PlatformPay, PaymentSheet, SetupIntent, InitialiseParams, CreatePaymentMethodResult, RetrievePaymentIntentResult, RetrieveSetupIntentResult, ConfirmPaymentResult, HandleNextActionResult, HandleNextActionForSetupResult, ConfirmSetupIntentResult, CreateTokenForCVCUpdateResult, InitPaymentSheetResult, PresentPaymentSheetResult, ConfirmPaymentSheetPaymentResult, CreateTokenResult, OpenApplePaySetupResult, Token, VerifyMicrodepositsParams, IsCardInWalletResult, CanAddCardToWalletParams, CanAddCardToWalletResult, FinancialConnections } from './types';
2
2
  declare type NativeStripeSdkType = {
3
3
  initialise(params: InitialiseParams): Promise<void>;
4
4
  createPaymentMethod(params: PaymentMethod.CreateParams, options: PaymentMethod.CreateOptions): Promise<CreatePaymentMethodResult>;
5
5
  handleNextAction(paymentIntentClientSecret: string, returnURL?: string | null): Promise<HandleNextActionResult>;
6
+ handleNextActionForSetup(setupIntentClientSecret: string, returnURL?: string | null): Promise<HandleNextActionForSetupResult>;
6
7
  confirmPayment(paymentIntentClientSecret: string, params?: PaymentIntent.ConfirmParams, options?: PaymentIntent.ConfirmOptions): Promise<ConfirmPaymentResult>;
7
8
  confirmSetupIntent(paymentIntentClientSecret: string, params: SetupIntent.ConfirmParams, options: SetupIntent.ConfirmOptions): Promise<ConfirmSetupIntentResult>;
8
9
  retrievePaymentIntent(clientSecret: string): Promise<RetrievePaymentIntentResult>;
@@ -1,4 +1,4 @@
1
- import type { PlatformPayError, ConfirmPaymentResult, ConfirmPaymentSheetPaymentResult, SetupIntent, PaymentIntent, ConfirmSetupIntentResult, CreatePaymentMethodResult, CreateTokenForCVCUpdateResult, CreateTokenResult, HandleNextActionResult, InitPaymentSheetResult, PaymentMethod, PaymentSheet, PresentPaymentSheetResult, RetrievePaymentIntentResult, RetrieveSetupIntentResult, StripeError, Token, VerifyMicrodepositsParams, VerifyMicrodepositsForPaymentResult, VerifyMicrodepositsForSetupResult, CollectBankAccountForPaymentResult, CollectBankAccountForSetupResult, IsCardInWalletResult, CanAddCardToWalletParams, CanAddCardToWalletResult, FinancialConnections, PlatformPay } from './types';
1
+ import type { PlatformPayError, ConfirmPaymentResult, ConfirmPaymentSheetPaymentResult, SetupIntent, PaymentIntent, ConfirmSetupIntentResult, CreatePaymentMethodResult, CreateTokenForCVCUpdateResult, CreateTokenResult, HandleNextActionResult, HandleNextActionForSetupResult, InitPaymentSheetResult, PaymentMethod, PaymentSheet, PresentPaymentSheetResult, RetrievePaymentIntentResult, RetrieveSetupIntentResult, StripeError, Token, VerifyMicrodepositsParams, VerifyMicrodepositsForPaymentResult, VerifyMicrodepositsForSetupResult, CollectBankAccountForPaymentResult, CollectBankAccountForSetupResult, IsCardInWalletResult, CanAddCardToWalletParams, CanAddCardToWalletResult, FinancialConnections, PlatformPay } from './types';
2
2
  export declare const createPaymentMethod: (params: PaymentMethod.CreateParams, options?: PaymentMethod.CreateOptions) => Promise<CreatePaymentMethodResult>;
3
3
  export declare const createToken: (params: Token.CreateParams) => Promise<CreateTokenResult>;
4
4
  export declare const retrievePaymentIntent: (clientSecret: string) => Promise<RetrievePaymentIntentResult>;
@@ -19,6 +19,13 @@ export declare const confirmPayment: (paymentIntentClientSecret: string, params?
19
19
  * @param {string=} returnURL An optional return URL so the Stripe SDK can redirect back to your app after authentication. This should match the `return_url` you specified during PaymentIntent confirmation.
20
20
  * */
21
21
  export declare const handleNextAction: (paymentIntentClientSecret: string, returnURL?: string | undefined) => Promise<HandleNextActionResult>;
22
+ /** Handles any nextAction required to authenticate the SetupIntent.
23
+ * Call this method if you are confirming the SetupIntent on your backend and get a status of requires_action.
24
+ *
25
+ * @param {string} setupIntentClientSecret The client secret associated with the SetupIntent.
26
+ * @param {string=} returnURL An optional return URL so the Stripe SDK can redirect back to your app after authentication. This should match the `return_url` you specified during PaymentIntent confirmation.
27
+ * */
28
+ export declare const handleNextActionForSetup: (setupIntentClientSecret: string, returnURL?: string | undefined) => Promise<HandleNextActionForSetupResult>;
22
29
  export declare const confirmSetupIntent: (paymentIntentClientSecret: string, params: SetupIntent.ConfirmParams, options?: SetupIntent.ConfirmOptions) => Promise<ConfirmSetupIntentResult>;
23
30
  export declare const createTokenForCVCUpdate: (cvc: string) => Promise<CreateTokenForCVCUpdateResult>;
24
31
  /**
@@ -1,4 +1,4 @@
1
- import type { PaymentMethod, PaymentIntent, PaymentSheet, CreatePaymentMethodResult, RetrievePaymentIntentResult, RetrieveSetupIntentResult, ConfirmPaymentResult, HandleNextActionResult, ConfirmSetupIntentResult, CreateTokenForCVCUpdateResult, StripeError, InitPaymentSheetResult, PresentPaymentSheetResult, ConfirmPaymentSheetPaymentResult, SetupIntent, CreateTokenResult, Token, VerifyMicrodepositsParams, VerifyMicrodepositsForPaymentResult, VerifyMicrodepositsForSetupResult, CollectBankAccountForSetupResult, CollectBankAccountForPaymentResult, CanAddCardToWalletParams, CanAddCardToWalletResult, FinancialConnections, PlatformPay, PlatformPayError } from '../types';
1
+ import type { PaymentMethod, PaymentIntent, PaymentSheet, CreatePaymentMethodResult, RetrievePaymentIntentResult, RetrieveSetupIntentResult, ConfirmPaymentResult, HandleNextActionResult, HandleNextActionForSetupResult, ConfirmSetupIntentResult, CreateTokenForCVCUpdateResult, StripeError, InitPaymentSheetResult, PresentPaymentSheetResult, ConfirmPaymentSheetPaymentResult, SetupIntent, CreateTokenResult, Token, VerifyMicrodepositsParams, VerifyMicrodepositsForPaymentResult, VerifyMicrodepositsForSetupResult, CollectBankAccountForSetupResult, CollectBankAccountForPaymentResult, CanAddCardToWalletParams, CanAddCardToWalletResult, FinancialConnections, PlatformPay, PlatformPayError } from '../types';
2
2
  /**
3
3
  * useStripe hook
4
4
  */
@@ -8,6 +8,7 @@ export declare function useStripe(): {
8
8
  confirmPayment: (paymentIntentClientSecret: string, data?: PaymentIntent.ConfirmParams | undefined, options?: PaymentIntent.ConfirmOptions) => Promise<ConfirmPaymentResult>;
9
9
  createPaymentMethod: (data: PaymentMethod.CreateParams, options?: PaymentMethod.CreateOptions) => Promise<CreatePaymentMethodResult>;
10
10
  handleNextAction: (paymentIntentClientSecret: string, returnURL?: string | undefined) => Promise<HandleNextActionResult>;
11
+ handleNextActionForSetup: (setupIntentClientSecret: string, returnURL?: string | undefined) => Promise<HandleNextActionForSetupResult>;
11
12
  confirmSetupIntent: (paymentIntentClientSecret: string, data: SetupIntent.ConfirmParams, options?: SetupIntent.ConfirmOptions) => Promise<ConfirmSetupIntentResult>;
12
13
  createTokenForCVCUpdate: (cvc: string) => Promise<CreateTokenForCVCUpdateResult>;
13
14
  handleURLCallback: (url: string) => Promise<boolean>;
@@ -1,11 +1,19 @@
1
1
  import type { StripeError, GooglePayError } from './Errors';
2
2
  export declare type GooglePayCardToken = {
3
+ /** The token reference ID. */
3
4
  id: string;
4
- cardLastFour: string;
5
+ /** Last four digits of the FPAN */
6
+ fpanLastFour: string;
7
+ /** Last four digits of the DPAN */
8
+ dpanLastFour: string;
5
9
  network: number;
6
10
  serviceProvider: number;
11
+ /** The name of the issuer. */
7
12
  issuer: string;
13
+ /** The GooglePayCardTokenStatus. */
8
14
  status: GooglePayCardTokenStatus;
15
+ /** Deprecated. Use fpanLastFour or dpanLastFour. */
16
+ cardLastFour: string;
9
17
  };
10
18
  export declare enum GooglePayCardTokenStatus {
11
19
  /** */
@@ -62,6 +62,13 @@ export declare type HandleNextActionResult = {
62
62
  paymentIntent?: undefined;
63
63
  error: StripeError<CardActionError>;
64
64
  };
65
+ export declare type HandleNextActionForSetupResult = {
66
+ setupIntent: SetupIntent.Result;
67
+ error?: undefined;
68
+ } | {
69
+ setupIntent?: undefined;
70
+ error: StripeError<CardActionError>;
71
+ };
65
72
  export declare type ConfirmSetupIntentResult = {
66
73
  setupIntent: SetupIntent.Result;
67
74
  error?: undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/stripe-react-native",
3
- "version": "0.29.0",
3
+ "version": "0.30.0",
4
4
  "author": "Stripe",
5
5
  "description": "Stripe SDK for React Native",
6
6
  "main": "lib/commonjs/index",
@@ -11,6 +11,7 @@ import type {
11
11
  RetrieveSetupIntentResult,
12
12
  ConfirmPaymentResult,
13
13
  HandleNextActionResult,
14
+ HandleNextActionForSetupResult,
14
15
  ConfirmSetupIntentResult,
15
16
  CreateTokenForCVCUpdateResult,
16
17
  InitPaymentSheetResult,
@@ -36,6 +37,10 @@ type NativeStripeSdkType = {
36
37
  paymentIntentClientSecret: string,
37
38
  returnURL?: string | null
38
39
  ): Promise<HandleNextActionResult>;
40
+ handleNextActionForSetup(
41
+ setupIntentClientSecret: string,
42
+ returnURL?: string | null
43
+ ): Promise<HandleNextActionForSetupResult>;
39
44
  confirmPayment(
40
45
  paymentIntentClientSecret: string,
41
46
  params?: PaymentIntent.ConfirmParams,
package/src/functions.ts CHANGED
@@ -12,6 +12,7 @@ import type {
12
12
  CreateTokenForCVCUpdateResult,
13
13
  CreateTokenResult,
14
14
  HandleNextActionResult,
15
+ HandleNextActionForSetupResult,
15
16
  InitPaymentSheetResult,
16
17
  PaymentMethod,
17
18
  PaymentSheet,
@@ -203,6 +204,41 @@ export const handleNextAction = async (
203
204
  }
204
205
  };
205
206
 
207
+ /** Handles any nextAction required to authenticate the SetupIntent.
208
+ * Call this method if you are confirming the SetupIntent on your backend and get a status of requires_action.
209
+ *
210
+ * @param {string} setupIntentClientSecret The client secret associated with the SetupIntent.
211
+ * @param {string=} returnURL An optional return URL so the Stripe SDK can redirect back to your app after authentication. This should match the `return_url` you specified during PaymentIntent confirmation.
212
+ * */
213
+ export const handleNextActionForSetup = async (
214
+ setupIntentClientSecret: string,
215
+ returnURL?: string
216
+ ): Promise<HandleNextActionForSetupResult> => {
217
+ try {
218
+ const { setupIntent, error } =
219
+ Platform.OS === 'ios'
220
+ ? await NativeStripeSdk.handleNextActionForSetup(
221
+ setupIntentClientSecret,
222
+ returnURL ?? null
223
+ )
224
+ : await NativeStripeSdk.handleNextActionForSetup(
225
+ setupIntentClientSecret
226
+ );
227
+ if (error) {
228
+ return {
229
+ error,
230
+ };
231
+ }
232
+ return {
233
+ setupIntent: setupIntent!,
234
+ };
235
+ } catch (error: any) {
236
+ return {
237
+ error: createError(error),
238
+ };
239
+ }
240
+ };
241
+
206
242
  export const confirmSetupIntent = async (
207
243
  paymentIntentClientSecret: string,
208
244
  params: SetupIntent.ConfirmParams,
@@ -1,4 +1,4 @@
1
- import { useState } from 'react';
1
+ import { useState, useCallback } from 'react';
2
2
  import { useStripe } from './useStripe';
3
3
 
4
4
  /**
@@ -12,19 +12,25 @@ export function useFinancialConnectionsSheet() {
12
12
  const { collectBankAccountToken, collectFinancialConnectionsAccounts } =
13
13
  useStripe();
14
14
 
15
- const _collectBankAccountToken = async (clientSecret: string) => {
16
- setLoading(true);
17
- const result = await collectBankAccountToken(clientSecret);
18
- setLoading(false);
19
- return result;
20
- };
15
+ const _collectBankAccountToken = useCallback(
16
+ async (clientSecret: string) => {
17
+ setLoading(true);
18
+ const result = await collectBankAccountToken(clientSecret);
19
+ setLoading(false);
20
+ return result;
21
+ },
22
+ [collectBankAccountToken]
23
+ );
21
24
 
22
- const _collectFinancialConnectionsAccounts = async (clientSecret: string) => {
23
- setLoading(true);
24
- const result = await collectFinancialConnectionsAccounts(clientSecret);
25
- setLoading(false);
26
- return result;
27
- };
25
+ const _collectFinancialConnectionsAccounts = useCallback(
26
+ async (clientSecret: string) => {
27
+ setLoading(true);
28
+ const result = await collectFinancialConnectionsAccounts(clientSecret);
29
+ setLoading(false);
30
+ return result;
31
+ },
32
+ [collectFinancialConnectionsAccounts]
33
+ );
28
34
 
29
35
  return {
30
36
  collectBankAccountToken: _collectBankAccountToken,
@@ -1,7 +1,8 @@
1
- import type { PaymentSheet } from '../types';
2
- import { useState } from 'react';
1
+ import { useState, useCallback } from 'react';
3
2
  import { useStripe } from './useStripe';
4
3
 
4
+ import type { PaymentSheet } from '../types';
5
+
5
6
  /**
6
7
  * usePaymentSheet hook
7
8
  */
@@ -14,33 +15,39 @@ export function usePaymentSheet() {
14
15
  } = useStripe();
15
16
  const [loading, setLoading] = useState(false);
16
17
 
17
- const initPaymentSheet = async (params: PaymentSheet.SetupParams) => {
18
- setLoading(true);
19
- const result = await initPaymentSheetNative(params);
20
- setLoading(false);
21
- return result;
22
- };
18
+ const initPaymentSheet = useCallback(
19
+ async (params: PaymentSheet.SetupParams) => {
20
+ setLoading(true);
21
+ const result = await initPaymentSheetNative(params);
22
+ setLoading(false);
23
+ return result;
24
+ },
25
+ [initPaymentSheetNative]
26
+ );
23
27
 
24
- const presentPaymentSheet = async (options?: PaymentSheet.PresentOptions) => {
25
- setLoading(true);
26
- const result = await presentPaymentSheetNative(options);
27
- setLoading(false);
28
- return result;
29
- };
28
+ const presentPaymentSheet = useCallback(
29
+ async (options?: PaymentSheet.PresentOptions) => {
30
+ setLoading(true);
31
+ const result = await presentPaymentSheetNative(options);
32
+ setLoading(false);
33
+ return result;
34
+ },
35
+ [presentPaymentSheetNative]
36
+ );
30
37
 
31
- const confirmPaymentSheetPayment = async () => {
38
+ const confirmPaymentSheetPayment = useCallback(async () => {
32
39
  setLoading(true);
33
40
  const result = await confirmPaymentSheetPaymentNative();
34
41
  setLoading(false);
35
42
  return result;
36
- };
43
+ }, [confirmPaymentSheetPaymentNative]);
37
44
 
38
- const resetPaymentSheetCustomer = async () => {
45
+ const resetPaymentSheetCustomer = useCallback(async () => {
39
46
  setLoading(true);
40
47
  const result = await resetPaymentSheetCustomerNative();
41
48
  setLoading(false);
42
49
  return result;
43
- };
50
+ }, [resetPaymentSheetCustomerNative]);
44
51
 
45
52
  return {
46
53
  loading,
@@ -7,6 +7,7 @@ import type {
7
7
  RetrieveSetupIntentResult,
8
8
  ConfirmPaymentResult,
9
9
  HandleNextActionResult,
10
+ HandleNextActionForSetupResult,
10
11
  ConfirmSetupIntentResult,
11
12
  CreateTokenForCVCUpdateResult,
12
13
  StripeError,
@@ -36,6 +37,7 @@ import {
36
37
  confirmSetupIntent,
37
38
  createTokenForCVCUpdate,
38
39
  handleNextAction,
40
+ handleNextActionForSetup,
39
41
  handleURLCallback,
40
42
  initPaymentSheet,
41
43
  presentPaymentSheet,
@@ -115,6 +117,16 @@ export function useStripe() {
115
117
  []
116
118
  );
117
119
 
120
+ const _handleNextActionForSetup = useCallback(
121
+ async (
122
+ setupIntentClientSecret: string,
123
+ returnURL?: string
124
+ ): Promise<HandleNextActionForSetupResult> => {
125
+ return handleNextActionForSetup(setupIntentClientSecret, returnURL);
126
+ },
127
+ []
128
+ );
129
+
118
130
  const _confirmSetupIntent = useCallback(
119
131
  async (
120
132
  paymentIntentClientSecret: string,
@@ -308,6 +320,7 @@ export function useStripe() {
308
320
  confirmPayment: _confirmPayment,
309
321
  createPaymentMethod: _createPaymentMethod,
310
322
  handleNextAction: _handleNextAction,
323
+ handleNextActionForSetup: _handleNextActionForSetup,
311
324
  confirmSetupIntent: _confirmSetupIntent,
312
325
  createTokenForCVCUpdate: _createTokenForCVCUpdate,
313
326
  handleURLCallback: _handleURLCallback,
@@ -1,12 +1,20 @@
1
1
  import type { StripeError, GooglePayError } from './Errors';
2
2
 
3
3
  export type GooglePayCardToken = {
4
+ /** The token reference ID. */
4
5
  id: string;
5
- cardLastFour: string;
6
+ /** Last four digits of the FPAN */
7
+ fpanLastFour: string;
8
+ /** Last four digits of the DPAN */
9
+ dpanLastFour: string;
6
10
  network: number;
7
11
  serviceProvider: number;
12
+ /** The name of the issuer. */
8
13
  issuer: string;
14
+ /** The GooglePayCardTokenStatus. */
9
15
  status: GooglePayCardTokenStatus;
16
+ /** Deprecated. Use fpanLastFour or dpanLastFour. */
17
+ cardLastFour: string;
10
18
  };
11
19
 
12
20
  export enum GooglePayCardTokenStatus {
@@ -109,6 +109,16 @@ export type HandleNextActionResult =
109
109
  error: StripeError<CardActionError>;
110
110
  };
111
111
 
112
+ export type HandleNextActionForSetupResult =
113
+ | {
114
+ setupIntent: SetupIntent.Result;
115
+ error?: undefined;
116
+ }
117
+ | {
118
+ setupIntent?: undefined;
119
+ error: StripeError<CardActionError>;
120
+ };
121
+
112
122
  export type ConfirmSetupIntentResult =
113
123
  | {
114
124
  setupIntent: SetupIntent.Result;
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
4
  # Keep stripe_version in sync with https://github.com/stripe/stripe-identity-react-native/blob/main/stripe-identity-react-native.podspec
5
- stripe_version = '~> 23.10.0'
5
+ stripe_version = '~> 23.12.0'
6
6
 
7
7
  Pod::Spec.new do |s|
8
8
  s.name = 'stripe-react-native'