@stripe/stripe-react-native 0.27.2 → 0.29.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 +25 -0
- package/README.md +2 -2
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +4 -0
- package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +5 -0
- package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +4 -0
- package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +5 -0
- package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +33 -7
- 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/PaymentSheetFragment.kt +131 -6
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +29 -6
- 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/CardFieldManager.m +1 -0
- package/ios/CardFieldView.swift +6 -0
- package/ios/CardFormManager.m +2 -2
- package/ios/CardFormView.swift +9 -9
- package/ios/StripeSdk+PaymentSheet.swift +100 -10
- package/ios/StripeSdk.m +15 -29
- package/ios/StripeSdk.swift +32 -91
- package/jest/mock.js +0 -6
- package/lib/commonjs/NativeStripeSdk.js.map +1 -1
- package/lib/commonjs/components/ApplePayButtonNative.js.map +1 -1
- package/lib/commonjs/components/CardField.js +1 -1
- package/lib/commonjs/components/CardField.js.map +1 -1
- package/lib/commonjs/components/CardForm.js +1 -1
- package/lib/commonjs/components/CardForm.js.map +1 -1
- package/lib/commonjs/components/GooglePayButtonNative.js.map +1 -1
- package/lib/commonjs/components/PlatformPayButton.js +1 -1
- package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.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/components/CardFieldInput.js.map +1 -1
- package/lib/commonjs/types/components/CardFormView.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/CardField.js +1 -1
- package/lib/module/components/CardField.js.map +1 -1
- package/lib/module/components/CardForm.js +1 -1
- package/lib/module/components/CardForm.js.map +1 -1
- package/lib/module/components/GooglePayButtonNative.js.map +1 -1
- package/lib/module/components/PlatformPayButton.js +1 -1
- package/lib/module/components/PlatformPayButton.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.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/components/CardFieldInput.js.map +1 -1
- package/lib/module/types/components/CardFormView.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 +4 -15
- package/lib/typescript/src/components/ApplePayButtonNative.d.ts +1 -1
- package/lib/typescript/src/components/CardField.d.ts +2 -0
- package/lib/typescript/src/components/CardForm.d.ts +2 -0
- package/lib/typescript/src/components/GooglePayButtonNative.d.ts +1 -1
- package/lib/typescript/src/components/PlatformPayButton.d.ts +2 -1
- package/lib/typescript/src/functions.d.ts +8 -27
- package/lib/typescript/src/hooks/usePlatformPay.d.ts +1 -1
- package/lib/typescript/src/hooks/useStripe.d.ts +2 -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 +35 -5
- package/lib/typescript/src/types/components/CardFieldInput.d.ts +1 -0
- package/lib/typescript/src/types/components/CardFormView.d.ts +1 -0
- package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts +0 -1
- package/lib/typescript/src/types/index.d.ts +1 -4
- package/package.json +1 -1
- package/src/NativeStripeSdk.tsx +6 -31
- package/src/components/ApplePayButtonNative.tsx +1 -1
- package/src/components/CardField.tsx +2 -0
- package/src/components/CardForm.tsx +2 -4
- package/src/components/GooglePayButtonNative.tsx +1 -1
- package/src/components/PlatformPayButton.tsx +2 -1
- package/src/functions.ts +54 -200
- package/src/hooks/useStripe.tsx +2 -109
- 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 +36 -5
- package/src/types/components/CardFieldInput.ts +1 -0
- package/src/types/components/CardFormView.ts +1 -1
- package/src/types/components/GooglePayButtonComponent.ts +0 -1
- package/src/types/index.ts +0 -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,14 @@ import {
|
|
|
14
11
|
CreatePaymentMethodResult,
|
|
15
12
|
CreateTokenForCVCUpdateResult,
|
|
16
13
|
CreateTokenResult,
|
|
17
|
-
GooglePayInitResult,
|
|
18
14
|
HandleNextActionResult,
|
|
19
15
|
InitPaymentSheetResult,
|
|
20
16
|
PaymentMethod,
|
|
21
17
|
PaymentSheet,
|
|
22
|
-
PayWithGooglePayResult,
|
|
23
18
|
PresentPaymentSheetResult,
|
|
24
19
|
RetrievePaymentIntentResult,
|
|
25
20
|
RetrieveSetupIntentResult,
|
|
26
21
|
StripeError,
|
|
27
|
-
GooglePay,
|
|
28
|
-
CreateGooglePayPaymentMethodResult,
|
|
29
|
-
OpenApplePaySetupResult,
|
|
30
22
|
Token,
|
|
31
23
|
VerifyMicrodepositsParams,
|
|
32
24
|
VerifyMicrodepositsForPaymentResult,
|
|
@@ -39,10 +31,12 @@ import {
|
|
|
39
31
|
FinancialConnections,
|
|
40
32
|
PlatformPay,
|
|
41
33
|
} from './types';
|
|
42
|
-
import {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
import {
|
|
35
|
+
Platform,
|
|
36
|
+
NativeEventEmitter,
|
|
37
|
+
NativeModules,
|
|
38
|
+
EmitterSubscription,
|
|
39
|
+
} from 'react-native';
|
|
46
40
|
|
|
47
41
|
export const createPaymentMethod = async (
|
|
48
42
|
params: PaymentMethod.CreateParams,
|
|
@@ -176,94 +170,6 @@ export const confirmPayment = async (
|
|
|
176
170
|
}
|
|
177
171
|
};
|
|
178
172
|
|
|
179
|
-
/** @deprecated Use `isPlatformPaySupported` instead. */
|
|
180
|
-
export const isApplePaySupported = async (): Promise<boolean> => {
|
|
181
|
-
return isiOS && (await NativeStripeSdk.isApplePaySupported());
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
/** @deprecated Use `confirmPlatformPaySetupIntent`, `confirmPlatformPayPayment`, or `createPlatformPayPaymentMethod` instead. */
|
|
185
|
-
export const presentApplePay = async (
|
|
186
|
-
params: ApplePay.PresentParams
|
|
187
|
-
): Promise<ApplePayResult> => {
|
|
188
|
-
if (!(await NativeStripeSdk.isApplePaySupported())) {
|
|
189
|
-
return {
|
|
190
|
-
error: {
|
|
191
|
-
code: ApplePayError.Canceled,
|
|
192
|
-
message: APPLE_PAY_NOT_SUPPORTED_MESSAGE,
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
try {
|
|
198
|
-
const { paymentMethod, error } = await NativeStripeSdk.presentApplePay(
|
|
199
|
-
params
|
|
200
|
-
);
|
|
201
|
-
if (error) {
|
|
202
|
-
return {
|
|
203
|
-
error,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
return { paymentMethod: paymentMethod! };
|
|
207
|
-
} catch (error: any) {
|
|
208
|
-
return {
|
|
209
|
-
error,
|
|
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
|
-
},
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
try {
|
|
258
|
-
await NativeStripeSdk.confirmApplePayPayment(clientSecret);
|
|
259
|
-
return {};
|
|
260
|
-
} catch (error: any) {
|
|
261
|
-
return {
|
|
262
|
-
error,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
173
|
/** Handles any nextAction required to authenticate the PaymentIntent.
|
|
268
174
|
* Call this method if you are using manual confirmation. See https://stripe.com/docs/payments/accept-a-payment?platform=react-native&ui=custom
|
|
269
175
|
*
|
|
@@ -345,8 +251,17 @@ export const createTokenForCVCUpdate = async (
|
|
|
345
251
|
}
|
|
346
252
|
};
|
|
347
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Call this method in your app whenever you receive a URL for a Stripe callback.
|
|
256
|
+
* For convenience, you can pass all URLs you receive to this method first, and
|
|
257
|
+
* check the return value to easily determine whether it is a callback URL that Stripe will handle
|
|
258
|
+
* or if your app should process it normally. This is iOS-only, and will always return false on Android.
|
|
259
|
+
*/
|
|
348
260
|
export const handleURLCallback = async (url: string): Promise<boolean> => {
|
|
349
|
-
const stripeHandled =
|
|
261
|
+
const stripeHandled =
|
|
262
|
+
Platform.OS === 'ios'
|
|
263
|
+
? await NativeStripeSdk.handleURLCallback(url)
|
|
264
|
+
: false;
|
|
350
265
|
return stripeHandled;
|
|
351
266
|
};
|
|
352
267
|
|
|
@@ -402,23 +317,48 @@ export const verifyMicrodepositsForSetup = async (
|
|
|
402
317
|
}
|
|
403
318
|
};
|
|
404
319
|
|
|
320
|
+
const eventEmitter = new NativeEventEmitter(NativeModules.StripeSdk);
|
|
321
|
+
let confirmHandlerCallback: EmitterSubscription | null = null;
|
|
322
|
+
let orderTrackingCallbackListener: EmitterSubscription | null = null;
|
|
323
|
+
|
|
405
324
|
export const initPaymentSheet = async (
|
|
406
325
|
params: PaymentSheet.SetupParams
|
|
407
326
|
): Promise<InitPaymentSheetResult> => {
|
|
408
327
|
let result;
|
|
328
|
+
const confirmHandler = params?.intentConfiguration?.confirmHandler;
|
|
329
|
+
if (confirmHandler) {
|
|
330
|
+
confirmHandlerCallback?.remove();
|
|
331
|
+
confirmHandlerCallback = eventEmitter.addListener(
|
|
332
|
+
'onConfirmHandlerCallback',
|
|
333
|
+
({
|
|
334
|
+
paymentMethod,
|
|
335
|
+
shouldSavePaymentMethod,
|
|
336
|
+
}: {
|
|
337
|
+
paymentMethod: PaymentMethod.Result;
|
|
338
|
+
shouldSavePaymentMethod: boolean;
|
|
339
|
+
}) => {
|
|
340
|
+
confirmHandler(
|
|
341
|
+
paymentMethod,
|
|
342
|
+
shouldSavePaymentMethod,
|
|
343
|
+
NativeStripeSdk.intentCreationCallback
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const orderTrackingCallback = params?.applePay?.setOrderTracking;
|
|
350
|
+
if (orderTrackingCallback) {
|
|
351
|
+
orderTrackingCallbackListener?.remove();
|
|
352
|
+
orderTrackingCallbackListener = eventEmitter.addListener(
|
|
353
|
+
'onOrderTrackingCallback',
|
|
354
|
+
() => {
|
|
355
|
+
orderTrackingCallback(NativeStripeSdk.configureOrderTracking);
|
|
356
|
+
}
|
|
357
|
+
);
|
|
358
|
+
}
|
|
409
359
|
|
|
410
|
-
const setOrderTracking = params?.applePay?.setOrderTracking;
|
|
411
360
|
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
|
-
}
|
|
361
|
+
result = await NativeStripeSdk.initPaymentSheet(params);
|
|
422
362
|
|
|
423
363
|
if (result.error) {
|
|
424
364
|
return {
|
|
@@ -483,92 +423,6 @@ export const resetPaymentSheetCustomer = async (): Promise<null> => {
|
|
|
483
423
|
return await NativeStripeSdk.resetPaymentSheetCustomer();
|
|
484
424
|
};
|
|
485
425
|
|
|
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
426
|
export const collectBankAccountForPayment = async (
|
|
573
427
|
clientSecret: string,
|
|
574
428
|
params: PaymentMethod.CollectBankAccountParams
|
package/src/hooks/useStripe.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
PaymentMethod,
|
|
3
3
|
PaymentIntent,
|
|
4
|
-
ApplePay,
|
|
5
4
|
PaymentSheet,
|
|
6
5
|
CreatePaymentMethodResult,
|
|
7
6
|
RetrievePaymentIntentResult,
|
|
@@ -10,19 +9,12 @@ import type {
|
|
|
10
9
|
HandleNextActionResult,
|
|
11
10
|
ConfirmSetupIntentResult,
|
|
12
11
|
CreateTokenForCVCUpdateResult,
|
|
13
|
-
ApplePayResult,
|
|
14
|
-
ApplePayError,
|
|
15
12
|
StripeError,
|
|
16
13
|
InitPaymentSheetResult,
|
|
17
14
|
PresentPaymentSheetResult,
|
|
18
15
|
ConfirmPaymentSheetPaymentResult,
|
|
19
16
|
SetupIntent,
|
|
20
17
|
CreateTokenResult,
|
|
21
|
-
PayWithGooglePayResult,
|
|
22
|
-
GooglePayInitResult,
|
|
23
|
-
GooglePay,
|
|
24
|
-
CreateGooglePayPaymentMethodResult,
|
|
25
|
-
OpenApplePaySetupResult,
|
|
26
18
|
Token,
|
|
27
19
|
VerifyMicrodepositsParams,
|
|
28
20
|
VerifyMicrodepositsForPaymentResult,
|
|
@@ -35,30 +27,20 @@ import type {
|
|
|
35
27
|
PlatformPay,
|
|
36
28
|
PlatformPayError,
|
|
37
29
|
} from '../types';
|
|
38
|
-
import { useCallback
|
|
39
|
-
import { isiOS } from '../helpers';
|
|
40
|
-
import NativeStripeSdk from '../NativeStripeSdk';
|
|
30
|
+
import { useCallback } from 'react';
|
|
41
31
|
import {
|
|
42
32
|
confirmPayment,
|
|
43
33
|
createPaymentMethod,
|
|
44
34
|
retrievePaymentIntent,
|
|
45
35
|
retrieveSetupIntent,
|
|
46
|
-
confirmApplePayPayment,
|
|
47
36
|
confirmSetupIntent,
|
|
48
37
|
createTokenForCVCUpdate,
|
|
49
38
|
handleNextAction,
|
|
50
39
|
handleURLCallback,
|
|
51
|
-
presentApplePay,
|
|
52
|
-
updateApplePaySummaryItems,
|
|
53
40
|
initPaymentSheet,
|
|
54
41
|
presentPaymentSheet,
|
|
55
42
|
confirmPaymentSheetPayment,
|
|
56
43
|
createToken,
|
|
57
|
-
isGooglePaySupported,
|
|
58
|
-
initGooglePay,
|
|
59
|
-
createGooglePayPaymentMethod,
|
|
60
|
-
presentGooglePay,
|
|
61
|
-
openApplePaySetup,
|
|
62
44
|
collectBankAccountForPayment,
|
|
63
45
|
collectBankAccountForSetup,
|
|
64
46
|
verifyMicrodepositsForPayment,
|
|
@@ -81,20 +63,6 @@ import {
|
|
|
81
63
|
* useStripe hook
|
|
82
64
|
*/
|
|
83
65
|
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
66
|
const _createPaymentMethod = useCallback(
|
|
99
67
|
async (
|
|
100
68
|
data: PaymentMethod.CreateParams,
|
|
@@ -137,35 +105,6 @@ export function useStripe() {
|
|
|
137
105
|
[]
|
|
138
106
|
);
|
|
139
107
|
|
|
140
|
-
const _presentApplePay = useCallback(
|
|
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(
|
|
161
|
-
async (
|
|
162
|
-
clientSecret: string
|
|
163
|
-
): Promise<{ error?: StripeError<ApplePayError> }> => {
|
|
164
|
-
return confirmApplePayPayment(clientSecret);
|
|
165
|
-
},
|
|
166
|
-
[]
|
|
167
|
-
);
|
|
168
|
-
|
|
169
108
|
const _handleNextAction = useCallback(
|
|
170
109
|
async (
|
|
171
110
|
paymentIntentClientSecret: string,
|
|
@@ -224,43 +163,6 @@ export function useStripe() {
|
|
|
224
163
|
[]
|
|
225
164
|
);
|
|
226
165
|
|
|
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
166
|
const _collectBankAccountForPayment = useCallback(
|
|
265
167
|
async (
|
|
266
168
|
clientSecret: string,
|
|
@@ -332,7 +234,7 @@ export function useStripe() {
|
|
|
332
234
|
|
|
333
235
|
const _isPlatformPaySupported = useCallback(
|
|
334
236
|
async (params?: {
|
|
335
|
-
googlePay?:
|
|
237
|
+
googlePay?: PlatformPay.IsGooglePaySupportedParams;
|
|
336
238
|
}): Promise<boolean> => {
|
|
337
239
|
return isPlatformPaySupported(params);
|
|
338
240
|
},
|
|
@@ -406,22 +308,13 @@ export function useStripe() {
|
|
|
406
308
|
confirmPayment: _confirmPayment,
|
|
407
309
|
createPaymentMethod: _createPaymentMethod,
|
|
408
310
|
handleNextAction: _handleNextAction,
|
|
409
|
-
isApplePaySupported: isApplePaySupported,
|
|
410
|
-
presentApplePay: _presentApplePay,
|
|
411
|
-
confirmApplePayPayment: _confirmApplePayPayment,
|
|
412
311
|
confirmSetupIntent: _confirmSetupIntent,
|
|
413
312
|
createTokenForCVCUpdate: _createTokenForCVCUpdate,
|
|
414
|
-
updateApplePaySummaryItems: _updateApplePaySummaryItems,
|
|
415
313
|
handleURLCallback: _handleURLCallback,
|
|
416
314
|
confirmPaymentSheetPayment: _confirmPaymentSheetPayment,
|
|
417
315
|
presentPaymentSheet: _presentPaymentSheet,
|
|
418
316
|
initPaymentSheet: _initPaymentSheet,
|
|
419
317
|
createToken: _createToken,
|
|
420
|
-
isGooglePaySupported: _isGooglePaySupported,
|
|
421
|
-
initGooglePay: _initGooglePay,
|
|
422
|
-
presentGooglePay: _presentGooglePay,
|
|
423
|
-
createGooglePayPaymentMethod: _createGooglePayPaymentMethod,
|
|
424
|
-
openApplePaySetup: _openApplePaySetup,
|
|
425
318
|
collectBankAccountForPayment: _collectBankAccountForPayment,
|
|
426
319
|
collectBankAccountForSetup: _collectBankAccountForSetup,
|
|
427
320
|
verifyMicrodepositsForPayment: _verifyMicrodepositsForPayment,
|
package/src/index.tsx
CHANGED
|
@@ -3,10 +3,7 @@ export { useConfirmPayment } from './hooks/useConfirmPayment';
|
|
|
3
3
|
export { useConfirmSetupIntent } from './hooks/useConfirmSetupIntent';
|
|
4
4
|
export { useStripe } from './hooks/useStripe';
|
|
5
5
|
export { usePlatformPay } from './hooks/usePlatformPay';
|
|
6
|
-
export { useApplePay } from './hooks/useApplePay';
|
|
7
|
-
export type { Props as UseApplePayProps } from './hooks/useApplePay';
|
|
8
6
|
export { usePaymentSheet } from './hooks/usePaymentSheet';
|
|
9
|
-
export { useGooglePay } from './hooks/useGooglePay';
|
|
10
7
|
export { useFinancialConnectionsSheet } from './hooks/useFinancialConnectionsSheet';
|
|
11
8
|
|
|
12
9
|
//components
|
|
@@ -16,14 +13,10 @@ export { CardField } from './components/CardField';
|
|
|
16
13
|
export type { Props as CardFieldProps } from './components/CardField';
|
|
17
14
|
export { CardForm } from './components/CardForm';
|
|
18
15
|
export type { Props as CardFormProps } from './components/CardForm';
|
|
19
|
-
export { ApplePayButton } from './components/ApplePayButton';
|
|
20
|
-
export type { Props as ApplePayButtonProps } from './components/ApplePayButton';
|
|
21
16
|
export { AuBECSDebitForm } from './components/AuBECSDebitForm';
|
|
22
17
|
export type { Props as AuBECSDebitFormProps } from './components/AuBECSDebitForm';
|
|
23
18
|
export { StripeContainer } from './components/StripeContainer';
|
|
24
19
|
export type { Props as StripeContainerProps } from './components/StripeContainer';
|
|
25
|
-
export { GooglePayButton } from './components/GooglePayButton';
|
|
26
|
-
export type { Props as GooglePayButtonProps } from './components/GooglePayButton';
|
|
27
20
|
export { AddToWalletButton } from './components/AddToWalletButton';
|
|
28
21
|
export type { Props as AddToWalletButtonProps } from './components/AddToWalletButton';
|
|
29
22
|
export { AddressSheet } from './components/AddressSheet';
|
package/src/types/ApplePay.ts
CHANGED
|
@@ -1,64 +1,3 @@
|
|
|
1
|
-
export type ContactFieldsType =
|
|
2
|
-
| 'emailAddress'
|
|
3
|
-
| 'name'
|
|
4
|
-
| 'phoneNumber'
|
|
5
|
-
| 'phoneticName'
|
|
6
|
-
| 'postalAddress';
|
|
7
|
-
|
|
8
|
-
export type AddressFields =
|
|
9
|
-
| 'street'
|
|
10
|
-
| 'city'
|
|
11
|
-
| 'subAdministrativeArea'
|
|
12
|
-
| 'state'
|
|
13
|
-
| 'postalCode'
|
|
14
|
-
| 'country'
|
|
15
|
-
| 'countryCode'
|
|
16
|
-
| 'subLocality';
|
|
17
|
-
|
|
18
|
-
export interface ShippingMethod {
|
|
19
|
-
/** A short, localized description. */
|
|
20
|
-
label: string;
|
|
21
|
-
/** The cost associated with this shipping option. */
|
|
22
|
-
amount: string;
|
|
23
|
-
/** When creating items for estimates or charges whose final value is not yet known, set this to true. */
|
|
24
|
-
isPending?: boolean;
|
|
25
|
-
/** A unique identifier for the shipping method. */
|
|
26
|
-
identifier: string;
|
|
27
|
-
/** A user-readable description of the shipping method. For example “Ships in 24 hours.” Don't repeat the content of the 'label' property. */
|
|
28
|
-
detail?: string;
|
|
29
|
-
/** The unix timestamp of the start date of the expected range of delivery or shipping dates for a package, or the time range when an item is available for pickup. Measured in seconds. */
|
|
30
|
-
startDate?: number;
|
|
31
|
-
/** The unix timestamp of the end date of the expected range of delivery or shipping dates for a package, or the time range when an item is available for pickup. Measured in seconds. */
|
|
32
|
-
endDate?: number;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface PostalAddress {
|
|
36
|
-
city?: string;
|
|
37
|
-
country?: string;
|
|
38
|
-
postalCode?: string;
|
|
39
|
-
state?: string;
|
|
40
|
-
street?: string;
|
|
41
|
-
isoCountryCode?: string;
|
|
42
|
-
subAdministrativeArea?: string;
|
|
43
|
-
subLocality?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface ContactName {
|
|
47
|
-
familyName?: string;
|
|
48
|
-
namePrefix?: string;
|
|
49
|
-
nameSuffix?: string;
|
|
50
|
-
givenName?: string;
|
|
51
|
-
middleName?: string;
|
|
52
|
-
nickname?: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface ShippingContact {
|
|
56
|
-
emailAddress?: string;
|
|
57
|
-
name: ContactName;
|
|
58
|
-
phoneNumber?: string;
|
|
59
|
-
postalAddress: PostalAddress;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
1
|
export type CartSummaryItem =
|
|
63
2
|
| DeferredCartSummaryItem
|
|
64
3
|
| ImmediateCartSummaryItem
|
|
@@ -98,13 +37,3 @@ export type RecurringCartSummaryItem = {
|
|
|
98
37
|
label: string;
|
|
99
38
|
amount: string;
|
|
100
39
|
};
|
|
101
|
-
|
|
102
|
-
export interface PresentParams {
|
|
103
|
-
cartItems: CartSummaryItem[];
|
|
104
|
-
country: string;
|
|
105
|
-
currency: string;
|
|
106
|
-
requiredShippingAddressFields?: ContactFieldsType[];
|
|
107
|
-
requiredBillingContactFields?: ContactFieldsType[];
|
|
108
|
-
shippingMethods?: ShippingMethod[];
|
|
109
|
-
jcbEnabled?: boolean;
|
|
110
|
-
}
|
|
@@ -20,13 +20,15 @@ export interface Result {
|
|
|
20
20
|
/** @deprecated Use paymentMethod.id instead. */
|
|
21
21
|
paymentMethodId: string;
|
|
22
22
|
paymentMethod: PaymentMethodResult | null;
|
|
23
|
-
captureMethod:
|
|
24
|
-
confirmationMethod:
|
|
23
|
+
captureMethod: CaptureMethod;
|
|
24
|
+
confirmationMethod: CaptureMethod;
|
|
25
25
|
lastPaymentError: LastPaymentError | null;
|
|
26
26
|
shipping: ShippingDetails | null;
|
|
27
27
|
nextAction: NextAction | null;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
export type CaptureMethod = 'Automatic' | 'Manual';
|
|
31
|
+
|
|
30
32
|
export type ConfirmParams =
|
|
31
33
|
| CardParams
|
|
32
34
|
| IdealParams
|