@stripe/stripe-react-native 0.28.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.
- package/CHANGELOG.md +95 -68
- package/README.md +2 -2
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonManager.kt +0 -5
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +11 -27
- package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +35 -8
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +131 -6
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +42 -7
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +8 -1
- package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +2 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +14 -1
- package/ios/ApplePayButtonView.swift +4 -18
- package/ios/ApplePayViewController.swift +1 -28
- package/ios/Mappers.swift +1 -0
- package/ios/StripeSdk+PaymentSheet.swift +100 -10
- package/ios/StripeSdk.m +22 -29
- package/ios/StripeSdk.swift +59 -85
- package/jest/mock.js +4 -6
- package/lib/commonjs/NativeStripeSdk.js.map +1 -1
- package/lib/commonjs/components/ApplePayButtonNative.js.map +1 -1
- package/lib/commonjs/components/GooglePayButtonNative.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/hooks/useFinancialConnectionsSheet.js +1 -1
- package/lib/commonjs/hooks/useFinancialConnectionsSheet.js.map +1 -1
- package/lib/commonjs/hooks/usePaymentSheet.js +1 -1
- package/lib/commonjs/hooks/usePaymentSheet.js.map +1 -1
- package/lib/commonjs/hooks/useStripe.js +1 -1
- package/lib/commonjs/hooks/useStripe.js.map +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/ApplePay.js.map +1 -1
- package/lib/commonjs/types/PaymentIntent.js.map +1 -1
- package/lib/commonjs/types/PaymentSheet.js +1 -1
- package/lib/commonjs/types/PaymentSheet.js.map +1 -1
- package/lib/commonjs/types/PlatformPay.js.map +1 -1
- package/lib/commonjs/types/PushProvisioning.js.map +1 -1
- package/lib/commonjs/types/components/GooglePayButtonComponent.js.map +1 -1
- package/lib/commonjs/types/index.js +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/NativeStripeSdk.js.map +1 -1
- package/lib/module/components/ApplePayButtonNative.js.map +1 -1
- package/lib/module/components/GooglePayButtonNative.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/hooks/useFinancialConnectionsSheet.js +1 -1
- package/lib/module/hooks/useFinancialConnectionsSheet.js.map +1 -1
- package/lib/module/hooks/usePaymentSheet.js +1 -1
- package/lib/module/hooks/usePaymentSheet.js.map +1 -1
- package/lib/module/hooks/useStripe.js +1 -1
- package/lib/module/hooks/useStripe.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/ApplePay.js.map +1 -1
- package/lib/module/types/PaymentIntent.js.map +1 -1
- package/lib/module/types/PaymentSheet.js +1 -1
- package/lib/module/types/PaymentSheet.js.map +1 -1
- package/lib/module/types/PlatformPay.js.map +1 -1
- package/lib/module/types/PushProvisioning.js.map +1 -1
- package/lib/module/types/components/GooglePayButtonComponent.js.map +1 -1
- package/lib/module/types/index.js +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/src/NativeStripeSdk.d.ts +5 -15
- package/lib/typescript/src/components/ApplePayButtonNative.d.ts +1 -1
- package/lib/typescript/src/components/GooglePayButtonNative.d.ts +1 -1
- package/lib/typescript/src/functions.d.ts +15 -27
- package/lib/typescript/src/hooks/usePlatformPay.d.ts +1 -1
- package/lib/typescript/src/hooks/useStripe.d.ts +3 -18
- package/lib/typescript/src/index.d.ts +0 -7
- package/lib/typescript/src/types/ApplePay.d.ts +0 -52
- package/lib/typescript/src/types/PaymentIntent.d.ts +3 -2
- package/lib/typescript/src/types/PaymentSheet.d.ts +48 -2
- package/lib/typescript/src/types/PlatformPay.d.ts +34 -4
- package/lib/typescript/src/types/PushProvisioning.d.ts +9 -1
- package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts +0 -1
- package/lib/typescript/src/types/index.d.ts +8 -4
- package/package.json +1 -1
- package/src/NativeStripeSdk.tsx +11 -31
- package/src/components/ApplePayButtonNative.tsx +1 -1
- package/src/components/GooglePayButtonNative.tsx +1 -1
- package/src/functions.ts +87 -197
- package/src/hooks/useFinancialConnectionsSheet.tsx +19 -13
- package/src/hooks/usePaymentSheet.tsx +25 -18
- package/src/hooks/useStripe.tsx +14 -108
- package/src/index.tsx +0 -7
- package/src/types/ApplePay.ts +0 -71
- package/src/types/PaymentIntent.ts +4 -2
- package/src/types/PaymentSheet.ts +86 -2
- package/src/types/PlatformPay.ts +35 -4
- package/src/types/PushProvisioning.ts +9 -1
- package/src/types/components/GooglePayButtonComponent.ts +0 -1
- package/src/types/index.ts +10 -6
- package/stripe-react-native.podspec +1 -1
- package/lib/commonjs/components/ApplePayButton.js +0 -2
- package/lib/commonjs/components/ApplePayButton.js.map +0 -1
- package/lib/commonjs/components/GooglePayButton.js +0 -2
- package/lib/commonjs/components/GooglePayButton.js.map +0 -1
- package/lib/commonjs/hooks/useApplePay.js +0 -2
- package/lib/commonjs/hooks/useApplePay.js.map +0 -1
- package/lib/commonjs/hooks/useGooglePay.js +0 -2
- package/lib/commonjs/hooks/useGooglePay.js.map +0 -1
- package/lib/commonjs/types/GooglePay.js +0 -2
- package/lib/commonjs/types/GooglePay.js.map +0 -1
- package/lib/module/components/ApplePayButton.js +0 -2
- package/lib/module/components/ApplePayButton.js.map +0 -1
- package/lib/module/components/GooglePayButton.js +0 -2
- package/lib/module/components/GooglePayButton.js.map +0 -1
- package/lib/module/hooks/useApplePay.js +0 -2
- package/lib/module/hooks/useApplePay.js.map +0 -1
- package/lib/module/hooks/useGooglePay.js +0 -2
- package/lib/module/hooks/useGooglePay.js.map +0 -1
- package/lib/module/types/GooglePay.js +0 -2
- package/lib/module/types/GooglePay.js.map +0 -1
- package/lib/typescript/src/components/ApplePayButton.d.ts +0 -31
- package/lib/typescript/src/components/GooglePayButton.d.ts +0 -26
- package/lib/typescript/src/hooks/useApplePay.d.ts +0 -54
- package/lib/typescript/src/hooks/useGooglePay.d.ts +0 -11
- package/lib/typescript/src/types/GooglePay.d.ts +0 -47
- package/src/components/ApplePayButton.tsx +0 -108
- package/src/components/GooglePayButton.tsx +0 -58
- package/src/hooks/useApplePay.tsx +0 -161
- package/src/hooks/useGooglePay.tsx +0 -72
- package/src/types/GooglePay.ts +0 -74
package/src/functions.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createError } from './helpers';
|
|
2
2
|
import { MissingRoutingNumber } from './types/Errors';
|
|
3
3
|
import NativeStripeSdk from './NativeStripeSdk';
|
|
4
|
-
import {
|
|
5
|
-
ApplePay,
|
|
6
|
-
ApplePayError,
|
|
7
|
-
ApplePayResult,
|
|
4
|
+
import type {
|
|
8
5
|
PlatformPayError,
|
|
9
6
|
ConfirmPaymentResult,
|
|
10
7
|
ConfirmPaymentSheetPaymentResult,
|
|
@@ -14,19 +11,15 @@ import {
|
|
|
14
11
|
CreatePaymentMethodResult,
|
|
15
12
|
CreateTokenForCVCUpdateResult,
|
|
16
13
|
CreateTokenResult,
|
|
17
|
-
GooglePayInitResult,
|
|
18
14
|
HandleNextActionResult,
|
|
15
|
+
HandleNextActionForSetupResult,
|
|
19
16
|
InitPaymentSheetResult,
|
|
20
17
|
PaymentMethod,
|
|
21
18
|
PaymentSheet,
|
|
22
|
-
PayWithGooglePayResult,
|
|
23
19
|
PresentPaymentSheetResult,
|
|
24
20
|
RetrievePaymentIntentResult,
|
|
25
21
|
RetrieveSetupIntentResult,
|
|
26
22
|
StripeError,
|
|
27
|
-
GooglePay,
|
|
28
|
-
CreateGooglePayPaymentMethodResult,
|
|
29
|
-
OpenApplePaySetupResult,
|
|
30
23
|
Token,
|
|
31
24
|
VerifyMicrodepositsParams,
|
|
32
25
|
VerifyMicrodepositsForPaymentResult,
|
|
@@ -39,10 +32,12 @@ import {
|
|
|
39
32
|
FinancialConnections,
|
|
40
33
|
PlatformPay,
|
|
41
34
|
} from './types';
|
|
42
|
-
import {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
import {
|
|
36
|
+
Platform,
|
|
37
|
+
NativeEventEmitter,
|
|
38
|
+
NativeModules,
|
|
39
|
+
EmitterSubscription,
|
|
40
|
+
} from 'react-native';
|
|
46
41
|
|
|
47
42
|
export const createPaymentMethod = async (
|
|
48
43
|
params: PaymentMethod.CreateParams,
|
|
@@ -176,119 +171,66 @@ export const confirmPayment = async (
|
|
|
176
171
|
}
|
|
177
172
|
};
|
|
178
173
|
|
|
179
|
-
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
export const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return {
|
|
190
|
-
error: {
|
|
191
|
-
code: ApplePayError.Canceled,
|
|
192
|
-
message: APPLE_PAY_NOT_SUPPORTED_MESSAGE,
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
174
|
+
/** Handles any nextAction required to authenticate the PaymentIntent.
|
|
175
|
+
* Call this method if you are using manual confirmation. See https://stripe.com/docs/payments/accept-a-payment?platform=react-native&ui=custom
|
|
176
|
+
*
|
|
177
|
+
* @param {string} paymentIntentClientSecret The client secret associated with the PaymentIntent.
|
|
178
|
+
* @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.
|
|
179
|
+
* */
|
|
180
|
+
export const handleNextAction = async (
|
|
181
|
+
paymentIntentClientSecret: string,
|
|
182
|
+
returnURL?: string
|
|
183
|
+
): Promise<HandleNextActionResult> => {
|
|
197
184
|
try {
|
|
198
|
-
const {
|
|
199
|
-
|
|
200
|
-
|
|
185
|
+
const { paymentIntent, error } =
|
|
186
|
+
Platform.OS === 'ios'
|
|
187
|
+
? await NativeStripeSdk.handleNextAction(
|
|
188
|
+
paymentIntentClientSecret,
|
|
189
|
+
returnURL ?? null
|
|
190
|
+
)
|
|
191
|
+
: await NativeStripeSdk.handleNextAction(paymentIntentClientSecret);
|
|
201
192
|
if (error) {
|
|
202
193
|
return {
|
|
203
194
|
error,
|
|
204
195
|
};
|
|
205
196
|
}
|
|
206
|
-
return { paymentMethod: paymentMethod! };
|
|
207
|
-
} catch (error: any) {
|
|
208
197
|
return {
|
|
209
|
-
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
/** @deprecated Use `updatePlatformPaySheet` instead. */
|
|
215
|
-
export const updateApplePaySummaryItems = async (
|
|
216
|
-
summaryItems: ApplePay.CartSummaryItem[],
|
|
217
|
-
errorAddressFields: Array<{
|
|
218
|
-
field: ApplePay.AddressFields;
|
|
219
|
-
message?: string;
|
|
220
|
-
}> = []
|
|
221
|
-
): Promise<{ error?: StripeError<ApplePayError> }> => {
|
|
222
|
-
if (!(await NativeStripeSdk.isApplePaySupported())) {
|
|
223
|
-
return {
|
|
224
|
-
error: {
|
|
225
|
-
code: ApplePayError.Canceled,
|
|
226
|
-
message: APPLE_PAY_NOT_SUPPORTED_MESSAGE,
|
|
227
|
-
},
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
try {
|
|
232
|
-
await NativeStripeSdk.updateApplePaySummaryItems(
|
|
233
|
-
summaryItems,
|
|
234
|
-
errorAddressFields
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
return {};
|
|
238
|
-
} catch (error: any) {
|
|
239
|
-
return {
|
|
240
|
-
error,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
/** @deprecated Use `confirmPlatformPaySetupIntent` or `confirmPlatformPayPayment` instead. */
|
|
246
|
-
export const confirmApplePayPayment = async (
|
|
247
|
-
clientSecret: string
|
|
248
|
-
): Promise<{ error?: StripeError<ApplePayError> }> => {
|
|
249
|
-
if (!(await NativeStripeSdk.isApplePaySupported())) {
|
|
250
|
-
return {
|
|
251
|
-
error: {
|
|
252
|
-
code: ApplePayError.Canceled,
|
|
253
|
-
message: APPLE_PAY_NOT_SUPPORTED_MESSAGE,
|
|
254
|
-
},
|
|
198
|
+
paymentIntent: paymentIntent!,
|
|
255
199
|
};
|
|
256
|
-
}
|
|
257
|
-
try {
|
|
258
|
-
await NativeStripeSdk.confirmApplePayPayment(clientSecret);
|
|
259
|
-
return {};
|
|
260
200
|
} catch (error: any) {
|
|
261
201
|
return {
|
|
262
|
-
error,
|
|
202
|
+
error: createError(error),
|
|
263
203
|
};
|
|
264
204
|
}
|
|
265
205
|
};
|
|
266
206
|
|
|
267
|
-
/** Handles any nextAction required to authenticate the
|
|
268
|
-
* Call this method if you are
|
|
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.
|
|
269
209
|
*
|
|
270
|
-
* @param {string}
|
|
210
|
+
* @param {string} setupIntentClientSecret The client secret associated with the SetupIntent.
|
|
271
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.
|
|
272
212
|
* */
|
|
273
|
-
export const
|
|
274
|
-
|
|
213
|
+
export const handleNextActionForSetup = async (
|
|
214
|
+
setupIntentClientSecret: string,
|
|
275
215
|
returnURL?: string
|
|
276
|
-
): Promise<
|
|
216
|
+
): Promise<HandleNextActionForSetupResult> => {
|
|
277
217
|
try {
|
|
278
|
-
const {
|
|
218
|
+
const { setupIntent, error } =
|
|
279
219
|
Platform.OS === 'ios'
|
|
280
|
-
? await NativeStripeSdk.
|
|
281
|
-
|
|
220
|
+
? await NativeStripeSdk.handleNextActionForSetup(
|
|
221
|
+
setupIntentClientSecret,
|
|
282
222
|
returnURL ?? null
|
|
283
223
|
)
|
|
284
|
-
: await NativeStripeSdk.
|
|
224
|
+
: await NativeStripeSdk.handleNextActionForSetup(
|
|
225
|
+
setupIntentClientSecret
|
|
226
|
+
);
|
|
285
227
|
if (error) {
|
|
286
228
|
return {
|
|
287
229
|
error,
|
|
288
230
|
};
|
|
289
231
|
}
|
|
290
232
|
return {
|
|
291
|
-
|
|
233
|
+
setupIntent: setupIntent!,
|
|
292
234
|
};
|
|
293
235
|
} catch (error: any) {
|
|
294
236
|
return {
|
|
@@ -345,8 +287,17 @@ export const createTokenForCVCUpdate = async (
|
|
|
345
287
|
}
|
|
346
288
|
};
|
|
347
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Call this method in your app whenever you receive a URL for a Stripe callback.
|
|
292
|
+
* For convenience, you can pass all URLs you receive to this method first, and
|
|
293
|
+
* check the return value to easily determine whether it is a callback URL that Stripe will handle
|
|
294
|
+
* or if your app should process it normally. This is iOS-only, and will always return false on Android.
|
|
295
|
+
*/
|
|
348
296
|
export const handleURLCallback = async (url: string): Promise<boolean> => {
|
|
349
|
-
const stripeHandled =
|
|
297
|
+
const stripeHandled =
|
|
298
|
+
Platform.OS === 'ios'
|
|
299
|
+
? await NativeStripeSdk.handleURLCallback(url)
|
|
300
|
+
: false;
|
|
350
301
|
return stripeHandled;
|
|
351
302
|
};
|
|
352
303
|
|
|
@@ -402,23 +353,48 @@ export const verifyMicrodepositsForSetup = async (
|
|
|
402
353
|
}
|
|
403
354
|
};
|
|
404
355
|
|
|
356
|
+
const eventEmitter = new NativeEventEmitter(NativeModules.StripeSdk);
|
|
357
|
+
let confirmHandlerCallback: EmitterSubscription | null = null;
|
|
358
|
+
let orderTrackingCallbackListener: EmitterSubscription | null = null;
|
|
359
|
+
|
|
405
360
|
export const initPaymentSheet = async (
|
|
406
361
|
params: PaymentSheet.SetupParams
|
|
407
362
|
): Promise<InitPaymentSheetResult> => {
|
|
408
363
|
let result;
|
|
364
|
+
const confirmHandler = params?.intentConfiguration?.confirmHandler;
|
|
365
|
+
if (confirmHandler) {
|
|
366
|
+
confirmHandlerCallback?.remove();
|
|
367
|
+
confirmHandlerCallback = eventEmitter.addListener(
|
|
368
|
+
'onConfirmHandlerCallback',
|
|
369
|
+
({
|
|
370
|
+
paymentMethod,
|
|
371
|
+
shouldSavePaymentMethod,
|
|
372
|
+
}: {
|
|
373
|
+
paymentMethod: PaymentMethod.Result;
|
|
374
|
+
shouldSavePaymentMethod: boolean;
|
|
375
|
+
}) => {
|
|
376
|
+
confirmHandler(
|
|
377
|
+
paymentMethod,
|
|
378
|
+
shouldSavePaymentMethod,
|
|
379
|
+
NativeStripeSdk.intentCreationCallback
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const orderTrackingCallback = params?.applePay?.setOrderTracking;
|
|
386
|
+
if (orderTrackingCallback) {
|
|
387
|
+
orderTrackingCallbackListener?.remove();
|
|
388
|
+
orderTrackingCallbackListener = eventEmitter.addListener(
|
|
389
|
+
'onOrderTrackingCallback',
|
|
390
|
+
() => {
|
|
391
|
+
orderTrackingCallback(NativeStripeSdk.configureOrderTracking);
|
|
392
|
+
}
|
|
393
|
+
);
|
|
394
|
+
}
|
|
409
395
|
|
|
410
|
-
const setOrderTracking = params?.applePay?.setOrderTracking;
|
|
411
396
|
try {
|
|
412
|
-
|
|
413
|
-
result = await NativeStripeSdk.initPaymentSheetWithOrderTracking(
|
|
414
|
-
params,
|
|
415
|
-
() => {
|
|
416
|
-
setOrderTracking(NativeStripeSdk.configureOrderTracking);
|
|
417
|
-
}
|
|
418
|
-
);
|
|
419
|
-
} else {
|
|
420
|
-
result = await NativeStripeSdk.initPaymentSheet(params);
|
|
421
|
-
}
|
|
397
|
+
result = await NativeStripeSdk.initPaymentSheet(params);
|
|
422
398
|
|
|
423
399
|
if (result.error) {
|
|
424
400
|
return {
|
|
@@ -483,92 +459,6 @@ export const resetPaymentSheetCustomer = async (): Promise<null> => {
|
|
|
483
459
|
return await NativeStripeSdk.resetPaymentSheetCustomer();
|
|
484
460
|
};
|
|
485
461
|
|
|
486
|
-
/** @deprecated Use `isPlatformPaySupported` instead. */
|
|
487
|
-
export const isGooglePaySupported = async (
|
|
488
|
-
params?: GooglePay.IsSupportedParams
|
|
489
|
-
): Promise<boolean> => {
|
|
490
|
-
return (
|
|
491
|
-
isAndroid && (await NativeStripeSdk.isGooglePaySupported(params ?? {}))
|
|
492
|
-
);
|
|
493
|
-
};
|
|
494
|
-
|
|
495
|
-
/** @deprecated Use `confirmPlatformPaySetupIntent`, `confirmPlatformPayPayment`, or `createPlatformPayPaymentMethod` instead. */
|
|
496
|
-
export const initGooglePay = async (
|
|
497
|
-
params: GooglePay.InitParams
|
|
498
|
-
): Promise<GooglePayInitResult> => {
|
|
499
|
-
try {
|
|
500
|
-
const { error } = await NativeStripeSdk.initGooglePay(params);
|
|
501
|
-
if (error) {
|
|
502
|
-
return {
|
|
503
|
-
error,
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
return {};
|
|
507
|
-
} catch (error: any) {
|
|
508
|
-
return {
|
|
509
|
-
error,
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
/** @deprecated Use `confirmPlatformPaySetupIntent`, `confirmPlatformPayPayment`, or `createPlatformPayPaymentMethod` instead. */
|
|
515
|
-
export const presentGooglePay = async (
|
|
516
|
-
params: GooglePay.PresentParams
|
|
517
|
-
): Promise<PayWithGooglePayResult> => {
|
|
518
|
-
try {
|
|
519
|
-
const { error } = await NativeStripeSdk.presentGooglePay(params);
|
|
520
|
-
if (error) {
|
|
521
|
-
return {
|
|
522
|
-
error,
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
return {};
|
|
526
|
-
} catch (error: any) {
|
|
527
|
-
return {
|
|
528
|
-
error,
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
/** @deprecated Use `createPlatformPayPaymentMethod` instead. */
|
|
534
|
-
export const createGooglePayPaymentMethod = async (
|
|
535
|
-
params: GooglePay.CreatePaymentMethodParams
|
|
536
|
-
): Promise<CreateGooglePayPaymentMethodResult> => {
|
|
537
|
-
try {
|
|
538
|
-
const { error, paymentMethod } =
|
|
539
|
-
await NativeStripeSdk.createGooglePayPaymentMethod(params);
|
|
540
|
-
if (error) {
|
|
541
|
-
return {
|
|
542
|
-
error,
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
return {
|
|
546
|
-
paymentMethod: paymentMethod!,
|
|
547
|
-
};
|
|
548
|
-
} catch (error: any) {
|
|
549
|
-
return {
|
|
550
|
-
error,
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
/** @deprecated Use `openNativePaySetup` instead. */
|
|
556
|
-
export const openApplePaySetup = async (): Promise<OpenApplePaySetupResult> => {
|
|
557
|
-
try {
|
|
558
|
-
const { error } = await NativeStripeSdk.openApplePaySetup();
|
|
559
|
-
if (error) {
|
|
560
|
-
return {
|
|
561
|
-
error,
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
return {};
|
|
565
|
-
} catch (error: any) {
|
|
566
|
-
return {
|
|
567
|
-
error,
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
|
|
572
462
|
export const collectBankAccountForPayment = async (
|
|
573
463
|
clientSecret: string,
|
|
574
464
|
params: PaymentMethod.CollectBankAccountParams
|
|
@@ -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 =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
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 =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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,
|
package/src/hooks/useStripe.tsx
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
PaymentMethod,
|
|
3
3
|
PaymentIntent,
|
|
4
|
-
ApplePay,
|
|
5
4
|
PaymentSheet,
|
|
6
5
|
CreatePaymentMethodResult,
|
|
7
6
|
RetrievePaymentIntentResult,
|
|
8
7
|
RetrieveSetupIntentResult,
|
|
9
8
|
ConfirmPaymentResult,
|
|
10
9
|
HandleNextActionResult,
|
|
10
|
+
HandleNextActionForSetupResult,
|
|
11
11
|
ConfirmSetupIntentResult,
|
|
12
12
|
CreateTokenForCVCUpdateResult,
|
|
13
|
-
ApplePayResult,
|
|
14
|
-
ApplePayError,
|
|
15
13
|
StripeError,
|
|
16
14
|
InitPaymentSheetResult,
|
|
17
15
|
PresentPaymentSheetResult,
|
|
18
16
|
ConfirmPaymentSheetPaymentResult,
|
|
19
17
|
SetupIntent,
|
|
20
18
|
CreateTokenResult,
|
|
21
|
-
PayWithGooglePayResult,
|
|
22
|
-
GooglePayInitResult,
|
|
23
|
-
GooglePay,
|
|
24
|
-
CreateGooglePayPaymentMethodResult,
|
|
25
|
-
OpenApplePaySetupResult,
|
|
26
19
|
Token,
|
|
27
20
|
VerifyMicrodepositsParams,
|
|
28
21
|
VerifyMicrodepositsForPaymentResult,
|
|
@@ -35,30 +28,21 @@ import type {
|
|
|
35
28
|
PlatformPay,
|
|
36
29
|
PlatformPayError,
|
|
37
30
|
} from '../types';
|
|
38
|
-
import { useCallback
|
|
39
|
-
import { isiOS } from '../helpers';
|
|
40
|
-
import NativeStripeSdk from '../NativeStripeSdk';
|
|
31
|
+
import { useCallback } from 'react';
|
|
41
32
|
import {
|
|
42
33
|
confirmPayment,
|
|
43
34
|
createPaymentMethod,
|
|
44
35
|
retrievePaymentIntent,
|
|
45
36
|
retrieveSetupIntent,
|
|
46
|
-
confirmApplePayPayment,
|
|
47
37
|
confirmSetupIntent,
|
|
48
38
|
createTokenForCVCUpdate,
|
|
49
39
|
handleNextAction,
|
|
40
|
+
handleNextActionForSetup,
|
|
50
41
|
handleURLCallback,
|
|
51
|
-
presentApplePay,
|
|
52
|
-
updateApplePaySummaryItems,
|
|
53
42
|
initPaymentSheet,
|
|
54
43
|
presentPaymentSheet,
|
|
55
44
|
confirmPaymentSheetPayment,
|
|
56
45
|
createToken,
|
|
57
|
-
isGooglePaySupported,
|
|
58
|
-
initGooglePay,
|
|
59
|
-
createGooglePayPaymentMethod,
|
|
60
|
-
presentGooglePay,
|
|
61
|
-
openApplePaySetup,
|
|
62
46
|
collectBankAccountForPayment,
|
|
63
47
|
collectBankAccountForSetup,
|
|
64
48
|
verifyMicrodepositsForPayment,
|
|
@@ -81,20 +65,6 @@ import {
|
|
|
81
65
|
* useStripe hook
|
|
82
66
|
*/
|
|
83
67
|
export function useStripe() {
|
|
84
|
-
const [isApplePaySupported, setApplePaySupported] = useState<boolean | null>(
|
|
85
|
-
null
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
async function checkApplePaySupport() {
|
|
90
|
-
const isSupported =
|
|
91
|
-
isiOS && (await NativeStripeSdk.isApplePaySupported());
|
|
92
|
-
setApplePaySupported(isSupported);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
checkApplePaySupport();
|
|
96
|
-
}, []);
|
|
97
|
-
|
|
98
68
|
const _createPaymentMethod = useCallback(
|
|
99
69
|
async (
|
|
100
70
|
data: PaymentMethod.CreateParams,
|
|
@@ -137,41 +107,22 @@ export function useStripe() {
|
|
|
137
107
|
[]
|
|
138
108
|
);
|
|
139
109
|
|
|
140
|
-
const
|
|
141
|
-
async (params: ApplePay.PresentParams): Promise<ApplePayResult> => {
|
|
142
|
-
return presentApplePay(params);
|
|
143
|
-
},
|
|
144
|
-
[]
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const _updateApplePaySummaryItems = useCallback(
|
|
148
|
-
async (
|
|
149
|
-
summaryItems: ApplePay.CartSummaryItem[],
|
|
150
|
-
errorAddressFields: Array<{
|
|
151
|
-
field: ApplePay.AddressFields;
|
|
152
|
-
message?: string;
|
|
153
|
-
}> = []
|
|
154
|
-
): Promise<{ error?: StripeError<ApplePayError> }> => {
|
|
155
|
-
return updateApplePaySummaryItems(summaryItems, errorAddressFields);
|
|
156
|
-
},
|
|
157
|
-
[]
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const _confirmApplePayPayment = useCallback(
|
|
110
|
+
const _handleNextAction = useCallback(
|
|
161
111
|
async (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
112
|
+
paymentIntentClientSecret: string,
|
|
113
|
+
returnURL?: string
|
|
114
|
+
): Promise<HandleNextActionResult> => {
|
|
115
|
+
return handleNextAction(paymentIntentClientSecret, returnURL);
|
|
165
116
|
},
|
|
166
117
|
[]
|
|
167
118
|
);
|
|
168
119
|
|
|
169
|
-
const
|
|
120
|
+
const _handleNextActionForSetup = useCallback(
|
|
170
121
|
async (
|
|
171
|
-
|
|
122
|
+
setupIntentClientSecret: string,
|
|
172
123
|
returnURL?: string
|
|
173
|
-
): Promise<
|
|
174
|
-
return
|
|
124
|
+
): Promise<HandleNextActionForSetupResult> => {
|
|
125
|
+
return handleNextActionForSetup(setupIntentClientSecret, returnURL);
|
|
175
126
|
},
|
|
176
127
|
[]
|
|
177
128
|
);
|
|
@@ -224,43 +175,6 @@ export function useStripe() {
|
|
|
224
175
|
[]
|
|
225
176
|
);
|
|
226
177
|
|
|
227
|
-
const _isGooglePaySupported = useCallback(
|
|
228
|
-
async (params?: GooglePay.IsSupportedParams): Promise<boolean> => {
|
|
229
|
-
return isGooglePaySupported(params);
|
|
230
|
-
},
|
|
231
|
-
[]
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
const _initGooglePay = useCallback(
|
|
235
|
-
async (params: GooglePay.InitParams): Promise<GooglePayInitResult> => {
|
|
236
|
-
return initGooglePay(params);
|
|
237
|
-
},
|
|
238
|
-
[]
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
const _presentGooglePay = useCallback(
|
|
242
|
-
async (
|
|
243
|
-
params: GooglePay.PresentParams
|
|
244
|
-
): Promise<PayWithGooglePayResult> => {
|
|
245
|
-
return presentGooglePay(params);
|
|
246
|
-
},
|
|
247
|
-
[]
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
const _createGooglePayPaymentMethod = useCallback(
|
|
251
|
-
async (
|
|
252
|
-
params: GooglePay.CreatePaymentMethodParams
|
|
253
|
-
): Promise<CreateGooglePayPaymentMethodResult> => {
|
|
254
|
-
return createGooglePayPaymentMethod(params);
|
|
255
|
-
},
|
|
256
|
-
[]
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
const _openApplePaySetup =
|
|
260
|
-
useCallback(async (): Promise<OpenApplePaySetupResult> => {
|
|
261
|
-
return openApplePaySetup();
|
|
262
|
-
}, []);
|
|
263
|
-
|
|
264
178
|
const _collectBankAccountForPayment = useCallback(
|
|
265
179
|
async (
|
|
266
180
|
clientSecret: string,
|
|
@@ -332,7 +246,7 @@ export function useStripe() {
|
|
|
332
246
|
|
|
333
247
|
const _isPlatformPaySupported = useCallback(
|
|
334
248
|
async (params?: {
|
|
335
|
-
googlePay?:
|
|
249
|
+
googlePay?: PlatformPay.IsGooglePaySupportedParams;
|
|
336
250
|
}): Promise<boolean> => {
|
|
337
251
|
return isPlatformPaySupported(params);
|
|
338
252
|
},
|
|
@@ -406,22 +320,14 @@ export function useStripe() {
|
|
|
406
320
|
confirmPayment: _confirmPayment,
|
|
407
321
|
createPaymentMethod: _createPaymentMethod,
|
|
408
322
|
handleNextAction: _handleNextAction,
|
|
409
|
-
|
|
410
|
-
presentApplePay: _presentApplePay,
|
|
411
|
-
confirmApplePayPayment: _confirmApplePayPayment,
|
|
323
|
+
handleNextActionForSetup: _handleNextActionForSetup,
|
|
412
324
|
confirmSetupIntent: _confirmSetupIntent,
|
|
413
325
|
createTokenForCVCUpdate: _createTokenForCVCUpdate,
|
|
414
|
-
updateApplePaySummaryItems: _updateApplePaySummaryItems,
|
|
415
326
|
handleURLCallback: _handleURLCallback,
|
|
416
327
|
confirmPaymentSheetPayment: _confirmPaymentSheetPayment,
|
|
417
328
|
presentPaymentSheet: _presentPaymentSheet,
|
|
418
329
|
initPaymentSheet: _initPaymentSheet,
|
|
419
330
|
createToken: _createToken,
|
|
420
|
-
isGooglePaySupported: _isGooglePaySupported,
|
|
421
|
-
initGooglePay: _initGooglePay,
|
|
422
|
-
presentGooglePay: _presentGooglePay,
|
|
423
|
-
createGooglePayPaymentMethod: _createGooglePayPaymentMethod,
|
|
424
|
-
openApplePaySetup: _openApplePaySetup,
|
|
425
331
|
collectBankAccountForPayment: _collectBankAccountForPayment,
|
|
426
332
|
collectBankAccountForSetup: _collectBankAccountForSetup,
|
|
427
333
|
verifyMicrodepositsForPayment: _verifyMicrodepositsForPayment,
|