@stripe/stripe-react-native 0.63.0 → 0.65.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/android/.idea/AndroidProjectSystem.xml +6 -0
- package/android/.idea/caches/deviceStreaming.xml +835 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +17 -0
- package/android/.idea/migrations.xml +10 -0
- package/android/.idea/misc.xml +10 -0
- package/android/.idea/runConfigurations.xml +17 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +2 -2
- package/android/detekt/detekt-baseline.xml +146 -0
- package/android/detekt/detekt.gradle +45 -0
- package/android/detekt/detekt.yml +722 -0
- package/android/gradle.properties +1 -1
- package/android/local.properties +8 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherManager.kt +0 -1
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +22 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodMessagingElementConfig.kt +2 -3
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +82 -4
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +5 -5
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +2 -4
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +36 -0
- package/android/src/onramp/java/com/reactnativestripesdk/OnrampMappers.kt +43 -0
- package/android/src/onramp/java/com/reactnativestripesdk/OnrampSdkModule.kt +5 -1
- package/android/src/test/java/com/reactnativestripesdk/PaymentMethodMessagingElementConfigTest.kt +3 -3
- package/android/src/test/java/com/reactnativestripesdk/mappers/MappersTest.kt +33 -0
- package/android/src/test/java/com/reactnativestripesdk/mappers/OnrampMappersTest.kt +298 -0
- package/ios/AddressSheet/AddressSheetUtils.swift +23 -0
- package/ios/AddressSheet/AddressSheetView.swift +9 -14
- package/ios/Mappers.swift +74 -5
- package/ios/PaymentMethodFactory.swift +19 -0
- package/ios/PaymentMethodMessagingElementConfig.swift +6 -3
- package/ios/PaymentMethodMessagingElementView.swift +19 -0
- package/ios/StripeSdk-Bridging-Header.h +1 -0
- package/ios/StripeSdk.mm +1 -1
- package/ios/StripeSdkImpl.swift +38 -102
- package/ios/StripeSwiftInterop.h +1 -0
- package/jest/mock.js +3 -0
- package/lib/commonjs/components/AddToWalletButton.js +1 -1
- package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
- package/lib/commonjs/components/AddressSheet.js +1 -1
- package/lib/commonjs/components/AddressSheet.js.map +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.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/PaymentMethodMessagingElement.js +2 -0
- package/lib/commonjs/components/PaymentMethodMessagingElement.js.map +1 -0
- package/lib/commonjs/components/PlatformPayButton.js +1 -1
- package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
- package/lib/commonjs/components/StripeContainer.js +1 -1
- package/lib/commonjs/components/StripeContainer.js.map +1 -1
- package/lib/commonjs/components/StripeProvider.js +1 -1
- package/lib/commonjs/components/StripeProvider.js.map +1 -1
- package/lib/commonjs/connect/Components.js +1 -1
- package/lib/commonjs/connect/Components.js.map +1 -1
- package/lib/commonjs/connect/ConnectComponentsProvider.js +1 -1
- package/lib/commonjs/connect/ConnectComponentsProvider.js.map +1 -1
- package/lib/commonjs/connect/EmbeddedComponent.js +1 -1
- package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -1
- package/lib/commonjs/connect/ModalCloseButton.js +1 -1
- package/lib/commonjs/connect/ModalCloseButton.js.map +1 -1
- package/lib/commonjs/connect/NavigationBar.js +1 -1
- package/lib/commonjs/connect/NavigationBar.js.map +1 -1
- package/lib/commonjs/connect/testUtils.js +1 -1
- package/lib/commonjs/connect/testUtils.js.map +1 -1
- package/lib/commonjs/events.js +1 -1
- package/lib/commonjs/events.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/helpers.js +1 -1
- package/lib/commonjs/hooks/useCheckout.js +2 -0
- package/lib/commonjs/hooks/useCheckout.js.map +1 -0
- package/lib/commonjs/hooks/useOnramp.js +1 -1
- package/lib/commonjs/hooks/useOnramp.js.map +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeAddToWalletButton.js +1 -1
- package/lib/commonjs/specs/NativeAddressSheet.js +1 -1
- package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
- package/lib/commonjs/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/commonjs/specs/NativeCardField.js +1 -1
- package/lib/commonjs/specs/NativeCardField.js.map +1 -1
- package/lib/commonjs/specs/NativeCardForm.js +1 -1
- package/lib/commonjs/specs/NativeCardForm.js.map +1 -1
- package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js +1 -1
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/specs/NativeGooglePayButton.js +1 -1
- package/lib/commonjs/specs/NativeNavigationBar.js +1 -1
- package/lib/commonjs/specs/NativeOnrampSdkModule.js +1 -1
- package/lib/commonjs/specs/NativeOnrampSdkModule.js.map +1 -1
- package/lib/commonjs/specs/NativePaymentMethodMessagingElement.js +1 -1
- package/lib/commonjs/specs/NativePaymentMethodMessagingElement.js.map +1 -1
- package/lib/commonjs/specs/NativeStripeContainer.js +1 -1
- package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/commonjs/types/Checkout.js +2 -0
- package/lib/commonjs/types/Checkout.js.map +1 -0
- package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/types/Onramp.js.map +1 -1
- package/lib/commonjs/types/PaymentIntent.js.map +1 -1
- package/lib/commonjs/types/PaymentSheet.js.map +1 -1
- package/lib/module/components/AddToWalletButton.js +1 -1
- package/lib/module/components/AddToWalletButton.js.map +1 -1
- package/lib/module/components/AddressSheet.js +1 -1
- package/lib/module/components/AddressSheet.js.map +1 -1
- package/lib/module/components/AuBECSDebitForm.js +1 -1
- package/lib/module/components/AuBECSDebitForm.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/PaymentMethodMessagingElement.js +2 -0
- package/lib/module/components/PaymentMethodMessagingElement.js.map +1 -0
- package/lib/module/components/PlatformPayButton.js +1 -1
- package/lib/module/components/PlatformPayButton.js.map +1 -1
- package/lib/module/components/StripeContainer.js +1 -1
- package/lib/module/components/StripeContainer.js.map +1 -1
- package/lib/module/components/StripeProvider.js +1 -1
- package/lib/module/components/StripeProvider.js.map +1 -1
- package/lib/module/connect/Components.js +1 -1
- package/lib/module/connect/Components.js.map +1 -1
- package/lib/module/connect/ConnectComponentsProvider.js +1 -1
- package/lib/module/connect/ConnectComponentsProvider.js.map +1 -1
- package/lib/module/connect/EmbeddedComponent.js +1 -1
- package/lib/module/connect/EmbeddedComponent.js.map +1 -1
- package/lib/module/connect/ModalCloseButton.js +1 -1
- package/lib/module/connect/ModalCloseButton.js.map +1 -1
- package/lib/module/connect/NavigationBar.js +1 -1
- package/lib/module/connect/NavigationBar.js.map +1 -1
- package/lib/module/connect/testUtils.js +1 -1
- package/lib/module/connect/testUtils.js.map +1 -1
- package/lib/module/events.js +1 -1
- package/lib/module/events.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/helpers.js +1 -1
- package/lib/module/hooks/useCheckout.js +2 -0
- package/lib/module/hooks/useCheckout.js.map +1 -0
- package/lib/module/hooks/useOnramp.js +1 -1
- package/lib/module/hooks/useOnramp.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeAddToWalletButton.js +1 -1
- package/lib/module/specs/NativeAddressSheet.js +1 -1
- package/lib/module/specs/NativeApplePayButton.js +1 -1
- package/lib/module/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/module/specs/NativeCardField.js +1 -1
- package/lib/module/specs/NativeCardField.js.map +1 -1
- package/lib/module/specs/NativeCardForm.js +1 -1
- package/lib/module/specs/NativeCardForm.js.map +1 -1
- package/lib/module/specs/NativeConnectAccountOnboardingView.js +1 -1
- package/lib/module/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/module/specs/NativeGooglePayButton.js +1 -1
- package/lib/module/specs/NativeNavigationBar.js +1 -1
- package/lib/module/specs/NativeOnrampSdkModule.js +1 -1
- package/lib/module/specs/NativeOnrampSdkModule.js.map +1 -1
- package/lib/module/specs/NativePaymentMethodMessagingElement.js +1 -1
- package/lib/module/specs/NativePaymentMethodMessagingElement.js.map +1 -1
- package/lib/module/specs/NativeStripeContainer.js +1 -1
- package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/module/types/Checkout.js +2 -0
- package/lib/module/types/Checkout.js.map +1 -0
- package/lib/module/types/EmbeddedPaymentElement.js +1 -1
- package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/module/types/Onramp.js.map +1 -1
- package/lib/module/types/PaymentIntent.js.map +1 -1
- package/lib/module/types/PaymentSheet.js.map +1 -1
- package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts +41 -0
- package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts.map +1 -0
- package/lib/typescript/src/connect/testUtils.d.ts +4 -0
- package/lib/typescript/src/connect/testUtils.d.ts.map +1 -1
- package/lib/typescript/src/events.d.ts.map +1 -1
- package/lib/typescript/src/functions.d.ts +2 -0
- package/lib/typescript/src/functions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCheckout.d.ts +21 -0
- package/lib/typescript/src/hooks/useCheckout.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useOnramp.d.ts +9 -3
- package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts +1 -1
- package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePaymentMethodMessagingElement.d.ts +1 -6
- package/lib/typescript/src/specs/NativePaymentMethodMessagingElement.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +16 -1
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
- package/lib/typescript/src/types/Checkout.d.ts +336 -0
- package/lib/typescript/src/types/Checkout.d.ts.map +1 -0
- package/lib/typescript/src/types/NextAction.d.ts +8 -1
- package/lib/typescript/src/types/NextAction.d.ts.map +1 -1
- package/lib/typescript/src/types/Onramp.d.ts +40 -1
- package/lib/typescript/src/types/Onramp.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentIntent.d.ts +11 -1
- package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentMethod.d.ts +10 -6
- package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentSheet.d.ts +22 -6
- package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
- package/lib/typescript/src/types/components/PaymentMethodMessagingElementComponent.d.ts +16 -1
- package/lib/typescript/src/types/components/PaymentMethodMessagingElementComponent.d.ts.map +1 -1
- package/package.json +8 -5
- package/src/components/PaymentMethodMessagingElement.tsx +109 -0
- package/src/components/StripeProvider.tsx +1 -1
- package/src/connect/testUtils.ts +2 -0
- package/src/events.ts +9 -3
- package/src/functions.ts +1 -1
- package/src/hooks/useCheckout.tsx +168 -0
- package/src/hooks/useOnramp.tsx +45 -24
- package/src/index.tsx +4 -0
- package/src/specs/NativeOnrampSdkModule.ts +1 -1
- package/src/specs/NativePaymentMethodMessagingElement.ts +0 -7
- package/src/specs/NativeStripeSdkModule.ts +53 -1
- package/src/types/Checkout.ts +377 -0
- package/src/types/NextAction.ts +9 -0
- package/src/types/Onramp.ts +45 -1
- package/src/types/PaymentIntent.ts +10 -0
- package/src/types/PaymentMethod.ts +9 -6
- package/src/types/PaymentSheet.ts +29 -6
- package/src/types/components/PaymentMethodMessagingElementComponent.tsx +17 -1
- package/stripe-react-native.podspec +8 -8
- package/android/spotless.gradle +0 -19
- package/android/src/main/java/com/reactnativestripesdk/FakeOnrampSdkModule.kt +0 -155
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
2
|
+
import NativeStripeSdk from '../specs/NativeStripeSdkModule';
|
|
3
|
+
import type { Checkout } from '../types/Checkout';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Initializes a Stripe Checkout Session and returns a reactive handle.
|
|
7
|
+
*
|
|
8
|
+
* The session is fetched from Stripe when the hook mounts. `state` is `null`
|
|
9
|
+
* until the initial load completes, then transitions between `loaded` and
|
|
10
|
+
* `loading` as mutations are performed.
|
|
11
|
+
*
|
|
12
|
+
* Pass the returned `checkout` to `initPaymentSheet` to complete the purchase.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export function useCheckout(
|
|
17
|
+
clientSecret: string,
|
|
18
|
+
configuration?: Checkout.Configuration
|
|
19
|
+
): {
|
|
20
|
+
/** The current loading state of the checkout session. `null` until the initial load completes. */
|
|
21
|
+
state: Checkout.State | null;
|
|
22
|
+
/** A handle to the session with methods for mutations. */
|
|
23
|
+
checkout: Checkout;
|
|
24
|
+
/** Set if the initial session load fails. Undefined otherwise. */
|
|
25
|
+
error?: Checkout.Error;
|
|
26
|
+
} {
|
|
27
|
+
const [state, setState] = useState<Checkout.State | null>(null);
|
|
28
|
+
const [error, setError] = useState<Checkout.Error | undefined>(undefined);
|
|
29
|
+
|
|
30
|
+
// Ref so mutation callbacks don't need it as a dependency.
|
|
31
|
+
const sessionKeyRef = useRef<string | null>(null);
|
|
32
|
+
|
|
33
|
+
// Load session on mount / clientSecret change.
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
let cancelled = false;
|
|
36
|
+
sessionKeyRef.current = null;
|
|
37
|
+
setState(null);
|
|
38
|
+
setError(undefined);
|
|
39
|
+
|
|
40
|
+
(async () => {
|
|
41
|
+
try {
|
|
42
|
+
const result = await NativeStripeSdk.initCheckoutSession(
|
|
43
|
+
clientSecret,
|
|
44
|
+
configuration ?? {}
|
|
45
|
+
);
|
|
46
|
+
if (cancelled) return;
|
|
47
|
+
sessionKeyRef.current = result.sessionKey;
|
|
48
|
+
setState(result.state);
|
|
49
|
+
} catch (e: any) {
|
|
50
|
+
if (cancelled) return;
|
|
51
|
+
setError({
|
|
52
|
+
code: e.code ?? 'Failed',
|
|
53
|
+
message: e.message ?? 'Failed to initialize checkout session',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
// Ignore in-flight init if unmounted or clientSecret changed.
|
|
59
|
+
return () => {
|
|
60
|
+
cancelled = true;
|
|
61
|
+
};
|
|
62
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
+
}, [clientSecret]);
|
|
64
|
+
|
|
65
|
+
// Sets `loading`, calls native, applies returned state. Reverts on error.
|
|
66
|
+
const withLoading = useCallback(
|
|
67
|
+
async (fn: (sessionKey: string) => Promise<Checkout.State>) => {
|
|
68
|
+
const key = sessionKeyRef.current;
|
|
69
|
+
if (!key) {
|
|
70
|
+
throw { code: 'Failed', message: 'Checkout session not initialized.' };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setState((prev) =>
|
|
74
|
+
prev ? { status: 'loading', session: prev.session } : prev
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const newState = await fn(key);
|
|
79
|
+
setState(newState);
|
|
80
|
+
} catch (e: any) {
|
|
81
|
+
setState((prev) =>
|
|
82
|
+
prev?.status === 'loading'
|
|
83
|
+
? { status: 'loaded', session: prev.session }
|
|
84
|
+
: prev
|
|
85
|
+
);
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
[]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Mutation methods — each delegates to withLoading.
|
|
93
|
+
const checkout: Checkout = {
|
|
94
|
+
get sessionKey(): string {
|
|
95
|
+
if (!sessionKeyRef.current) {
|
|
96
|
+
throw new Error('Checkout session not initialized.');
|
|
97
|
+
}
|
|
98
|
+
return sessionKeyRef.current;
|
|
99
|
+
},
|
|
100
|
+
updateShippingAddress: useCallback(
|
|
101
|
+
(address, name, phone) =>
|
|
102
|
+
withLoading((key) =>
|
|
103
|
+
NativeStripeSdk.checkoutUpdateShippingAddress(
|
|
104
|
+
key,
|
|
105
|
+
address,
|
|
106
|
+
name ?? null,
|
|
107
|
+
phone ?? null
|
|
108
|
+
)
|
|
109
|
+
),
|
|
110
|
+
[withLoading]
|
|
111
|
+
),
|
|
112
|
+
updateBillingAddress: useCallback(
|
|
113
|
+
(address, name, phone) =>
|
|
114
|
+
withLoading((key) =>
|
|
115
|
+
NativeStripeSdk.checkoutUpdateBillingAddress(
|
|
116
|
+
key,
|
|
117
|
+
address,
|
|
118
|
+
name ?? null,
|
|
119
|
+
phone ?? null
|
|
120
|
+
)
|
|
121
|
+
),
|
|
122
|
+
[withLoading]
|
|
123
|
+
),
|
|
124
|
+
applyPromotionCode: useCallback(
|
|
125
|
+
(code) =>
|
|
126
|
+
withLoading((key) =>
|
|
127
|
+
NativeStripeSdk.checkoutApplyPromotionCode(key, code)
|
|
128
|
+
),
|
|
129
|
+
[withLoading]
|
|
130
|
+
),
|
|
131
|
+
removePromotionCode: useCallback(
|
|
132
|
+
() =>
|
|
133
|
+
withLoading((key) => NativeStripeSdk.checkoutRemovePromotionCode(key)),
|
|
134
|
+
[withLoading]
|
|
135
|
+
),
|
|
136
|
+
updateLineItemQuantity: useCallback(
|
|
137
|
+
(lineItemId, quantity) =>
|
|
138
|
+
withLoading((key) =>
|
|
139
|
+
NativeStripeSdk.checkoutUpdateLineItemQuantity(
|
|
140
|
+
key,
|
|
141
|
+
lineItemId,
|
|
142
|
+
quantity
|
|
143
|
+
)
|
|
144
|
+
),
|
|
145
|
+
[withLoading]
|
|
146
|
+
),
|
|
147
|
+
selectShippingOption: useCallback(
|
|
148
|
+
(id) =>
|
|
149
|
+
withLoading((key) =>
|
|
150
|
+
NativeStripeSdk.checkoutSelectShippingOption(key, id)
|
|
151
|
+
),
|
|
152
|
+
[withLoading]
|
|
153
|
+
),
|
|
154
|
+
updateTaxId: useCallback(
|
|
155
|
+
(type, value) =>
|
|
156
|
+
withLoading((key) =>
|
|
157
|
+
NativeStripeSdk.checkoutUpdateTaxId(key, type, value)
|
|
158
|
+
),
|
|
159
|
+
[withLoading]
|
|
160
|
+
),
|
|
161
|
+
refresh: useCallback(
|
|
162
|
+
() => withLoading((key) => NativeStripeSdk.checkoutRefresh(key)),
|
|
163
|
+
[withLoading]
|
|
164
|
+
),
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return { state, checkout, error };
|
|
168
|
+
}
|
package/src/hooks/useOnramp.tsx
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
import { EventSubscription } from 'react-native';
|
|
1
|
+
import { EventSubscription, Platform } from 'react-native';
|
|
2
2
|
import NativeOnrampSdk from '../specs/NativeOnrampSdkModule';
|
|
3
3
|
import { Onramp, OnrampError, StripeError } from '../types';
|
|
4
|
-
import type { Address
|
|
4
|
+
import type { Address } from '../types';
|
|
5
5
|
import { useCallback } from 'react';
|
|
6
6
|
import { addOnrampListener } from '../events';
|
|
7
7
|
import { CryptoPaymentToken } from '../types/Onramp';
|
|
8
8
|
|
|
9
|
+
export function requireOnrampModule() {
|
|
10
|
+
if (NativeOnrampSdk == null) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
Platform.select({
|
|
13
|
+
ios: "Onramp module is not available. Add 'stripe-react-native/Onramp' to your Podfile.",
|
|
14
|
+
android:
|
|
15
|
+
"Onramp module is not available. Add 'StripeSdk_includeOnramp=true' to gradle.properties.",
|
|
16
|
+
default:
|
|
17
|
+
"Onramp module is not available. Enable the Onramp pod on iOS and set 'StripeSdk_includeOnramp=true' on Android.",
|
|
18
|
+
}) ?? 'Onramp module is not available.'
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return NativeOnrampSdk;
|
|
22
|
+
}
|
|
23
|
+
|
|
9
24
|
let onCheckoutClientSecretRequestedSubscription: EventSubscription | null =
|
|
10
25
|
null;
|
|
11
26
|
|
|
@@ -17,14 +32,14 @@ export function useOnramp() {
|
|
|
17
32
|
async (
|
|
18
33
|
config: Onramp.Configuration
|
|
19
34
|
): Promise<{ error?: StripeError<OnrampError> }> => {
|
|
20
|
-
return
|
|
35
|
+
return requireOnrampModule().configureOnramp(config);
|
|
21
36
|
},
|
|
22
37
|
[]
|
|
23
38
|
);
|
|
24
39
|
|
|
25
40
|
const _hasLinkAccount = useCallback(
|
|
26
41
|
async (email: string): Promise<Onramp.HasLinkAccountResult> => {
|
|
27
|
-
return
|
|
42
|
+
return requireOnrampModule().hasLinkAccount(email);
|
|
28
43
|
},
|
|
29
44
|
[]
|
|
30
45
|
);
|
|
@@ -33,7 +48,7 @@ export function useOnramp() {
|
|
|
33
48
|
async (
|
|
34
49
|
info: Onramp.LinkUserInfo
|
|
35
50
|
): Promise<Onramp.RegisterLinkUserResult> => {
|
|
36
|
-
return
|
|
51
|
+
return requireOnrampModule().registerLinkUser(info);
|
|
37
52
|
},
|
|
38
53
|
[]
|
|
39
54
|
);
|
|
@@ -43,7 +58,10 @@ export function useOnramp() {
|
|
|
43
58
|
walletAddress: string,
|
|
44
59
|
network: Onramp.CryptoNetwork
|
|
45
60
|
): Promise<{ error?: StripeError<OnrampError> }> => {
|
|
46
|
-
return
|
|
61
|
+
return requireOnrampModule().registerWalletAddress(
|
|
62
|
+
walletAddress,
|
|
63
|
+
network
|
|
64
|
+
);
|
|
47
65
|
},
|
|
48
66
|
[]
|
|
49
67
|
);
|
|
@@ -52,14 +70,14 @@ export function useOnramp() {
|
|
|
52
70
|
async (
|
|
53
71
|
kycInfo: Onramp.KycInfo
|
|
54
72
|
): Promise<{ error?: StripeError<OnrampError> }> => {
|
|
55
|
-
return
|
|
73
|
+
return requireOnrampModule().attachKycInfo(kycInfo);
|
|
56
74
|
},
|
|
57
75
|
[]
|
|
58
76
|
);
|
|
59
77
|
|
|
60
78
|
const _presentKycInfoVerification = useCallback(
|
|
61
79
|
async (updatedAddress: Address | null): Promise<Onramp.VerifyKycResult> => {
|
|
62
|
-
return
|
|
80
|
+
return requireOnrampModule().presentKycInfoVerification(updatedAddress);
|
|
63
81
|
},
|
|
64
82
|
[]
|
|
65
83
|
);
|
|
@@ -68,7 +86,7 @@ export function useOnramp() {
|
|
|
68
86
|
async (
|
|
69
87
|
linkAuthTokenClientSecret: string
|
|
70
88
|
): Promise<{ error?: StripeError<OnrampError> }> => {
|
|
71
|
-
return
|
|
89
|
+
return requireOnrampModule().authenticateUserWithToken(
|
|
72
90
|
linkAuthTokenClientSecret
|
|
73
91
|
);
|
|
74
92
|
},
|
|
@@ -77,7 +95,7 @@ export function useOnramp() {
|
|
|
77
95
|
|
|
78
96
|
const _updatePhoneNumber = useCallback(
|
|
79
97
|
async (phone: string): Promise<{ error?: StripeError<OnrampError> }> => {
|
|
80
|
-
return
|
|
98
|
+
return requireOnrampModule().updatePhoneNumber(phone);
|
|
81
99
|
},
|
|
82
100
|
[]
|
|
83
101
|
);
|
|
@@ -85,7 +103,7 @@ export function useOnramp() {
|
|
|
85
103
|
const _verifyIdentity = useCallback(async (): Promise<{
|
|
86
104
|
error?: StripeError<OnrampError>;
|
|
87
105
|
}> => {
|
|
88
|
-
return
|
|
106
|
+
return requireOnrampModule().verifyIdentity();
|
|
89
107
|
}, []);
|
|
90
108
|
|
|
91
109
|
/**
|
|
@@ -107,16 +125,14 @@ export function useOnramp() {
|
|
|
107
125
|
): Promise<Onramp.CollectPaymentMethodResult>;
|
|
108
126
|
(
|
|
109
127
|
paymentMethod: 'PlatformPay',
|
|
110
|
-
platformPayParams:
|
|
128
|
+
platformPayParams: Onramp.OnrampPlatformPayParams
|
|
111
129
|
): Promise<Onramp.CollectPaymentMethodResult>;
|
|
112
130
|
} = useCallback(
|
|
113
131
|
async (
|
|
114
132
|
paymentMethod: OnrampPaymentMethod,
|
|
115
|
-
platformPayParams?:
|
|
116
|
-
| PlatformPay.PaymentMethodParams
|
|
117
|
-
| Record<string, never>
|
|
133
|
+
platformPayParams?: Onramp.OnrampPlatformPayParams | Record<string, never>
|
|
118
134
|
): Promise<Onramp.CollectPaymentMethodResult> => {
|
|
119
|
-
return
|
|
135
|
+
return requireOnrampModule().collectPaymentMethod(
|
|
120
136
|
paymentMethod,
|
|
121
137
|
(platformPayParams ?? {}) as any
|
|
122
138
|
);
|
|
@@ -126,7 +142,7 @@ export function useOnramp() {
|
|
|
126
142
|
|
|
127
143
|
const _createCryptoPaymentToken =
|
|
128
144
|
useCallback(async (): Promise<Onramp.CreateCryptoPaymentTokenResult> => {
|
|
129
|
-
return
|
|
145
|
+
return requireOnrampModule().createCryptoPaymentToken();
|
|
130
146
|
}, []);
|
|
131
147
|
|
|
132
148
|
const _performCheckout = useCallback(
|
|
@@ -140,20 +156,20 @@ export function useOnramp() {
|
|
|
140
156
|
async () => {
|
|
141
157
|
try {
|
|
142
158
|
const clientSecret = await provideCheckoutClientSecret();
|
|
143
|
-
|
|
159
|
+
requireOnrampModule().provideCheckoutClientSecret(clientSecret);
|
|
144
160
|
} catch (error: any) {
|
|
145
|
-
|
|
161
|
+
requireOnrampModule().provideCheckoutClientSecret(null);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
);
|
|
149
|
-
return
|
|
165
|
+
return requireOnrampModule().performCheckout(onrampSessionId);
|
|
150
166
|
},
|
|
151
167
|
[]
|
|
152
168
|
);
|
|
153
169
|
|
|
154
170
|
const _authorize = useCallback(
|
|
155
171
|
async (linkAuthIntentId: string): Promise<Onramp.AuthorizeResult> => {
|
|
156
|
-
return
|
|
172
|
+
return requireOnrampModule().onrampAuthorize(linkAuthIntentId);
|
|
157
173
|
},
|
|
158
174
|
[]
|
|
159
175
|
);
|
|
@@ -162,7 +178,7 @@ export function useOnramp() {
|
|
|
162
178
|
async (
|
|
163
179
|
token: CryptoPaymentToken
|
|
164
180
|
): Promise<Onramp.PaymentDisplayDataResult> => {
|
|
165
|
-
return
|
|
181
|
+
return requireOnrampModule().getCryptoTokenDisplayData(token);
|
|
166
182
|
},
|
|
167
183
|
[]
|
|
168
184
|
);
|
|
@@ -170,7 +186,7 @@ export function useOnramp() {
|
|
|
170
186
|
const _logOut = useCallback(async (): Promise<{
|
|
171
187
|
error?: StripeError<OnrampError>;
|
|
172
188
|
}> => {
|
|
173
|
-
return
|
|
189
|
+
return requireOnrampModule().logout();
|
|
174
190
|
}, []);
|
|
175
191
|
|
|
176
192
|
const _isAuthError = (error?: StripeError<OnrampError>): boolean => {
|
|
@@ -273,7 +289,12 @@ export function useOnramp() {
|
|
|
273
289
|
* @param platformPayParams Platform-specific parameters (required when `paymentMethod` is 'PlatformPay').
|
|
274
290
|
* - iOS: provide `applePay` params
|
|
275
291
|
* - Android: provide `googlePay` params
|
|
276
|
-
*
|
|
292
|
+
* - To receive Apple Pay billing details back as `kycInfo`, request `.name` and/or `.postalAddress`
|
|
293
|
+
* in `applePay.requiredBillingContactFields`
|
|
294
|
+
* - To receive Google Pay billing details back as `kycInfo`, ensure that the `GooglePayConfig`
|
|
295
|
+
* passed to `configure` has `billingAddressConfig` with `format` set to `Full` and the desired fields
|
|
296
|
+
* set to `true`.
|
|
297
|
+
* @returns Promise that resolves to an object with displayData, optional kycInfo, or error
|
|
277
298
|
*/
|
|
278
299
|
collectPaymentMethod: _collectPaymentMethod,
|
|
279
300
|
|
package/src/index.tsx
CHANGED
|
@@ -36,6 +36,10 @@ export * from './types/EmbeddedPaymentElement';
|
|
|
36
36
|
export * from './types/PaymentSheet';
|
|
37
37
|
export * from './types/ConfirmationToken';
|
|
38
38
|
|
|
39
|
+
export * from './types/components/PaymentMethodMessagingElementComponent';
|
|
40
|
+
export type { Props as PaymentMethodMessagingElementProps } from './components/PaymentMethodMessagingElement';
|
|
41
|
+
export { PaymentMethodMessagingElement } from './components/PaymentMethodMessagingElement';
|
|
42
|
+
|
|
39
43
|
//connect components
|
|
40
44
|
export {
|
|
41
45
|
ConnectComponentsProvider,
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import type { HostComponent, ViewProps } from 'react-native';
|
|
2
|
-
import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
2
|
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
4
3
|
import {
|
|
5
4
|
PaymentMethodMessagingElementAppearance,
|
|
6
5
|
PaymentMethodMessagingElementConfiguration,
|
|
7
|
-
PaymentMethodMessagingElementState,
|
|
8
6
|
} from '../types/components/PaymentMethodMessagingElementComponent';
|
|
9
7
|
import { UnsafeMixed } from './utils';
|
|
10
8
|
|
|
11
|
-
interface StateChangeEvent {
|
|
12
|
-
result: UnsafeMixed<PaymentMethodMessagingElementState>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
export interface NativeProps extends ViewProps {
|
|
16
10
|
appearance?: UnsafeMixed<PaymentMethodMessagingElementAppearance>;
|
|
17
11
|
configuration: UnsafeMixed<PaymentMethodMessagingElementConfiguration>;
|
|
18
|
-
onStateChange: DirectEventHandler<StateChangeEvent>;
|
|
19
12
|
}
|
|
20
13
|
|
|
21
14
|
type ComponentType = HostComponent<NativeProps>;
|
|
@@ -36,6 +36,7 @@ import type {
|
|
|
36
36
|
VerifyMicrodepositsParams,
|
|
37
37
|
CreateRadarSessionResult,
|
|
38
38
|
} from '../types';
|
|
39
|
+
import type { Checkout } from '../types/Checkout';
|
|
39
40
|
import type {
|
|
40
41
|
EmbeddedPaymentElementConfiguration,
|
|
41
42
|
EmbeddedPaymentElementResult,
|
|
@@ -63,7 +64,7 @@ export interface Spec extends TurboModule {
|
|
|
63
64
|
): Promise<HandleNextActionForSetupResult>;
|
|
64
65
|
confirmPayment(
|
|
65
66
|
paymentIntentClientSecret: string,
|
|
66
|
-
params
|
|
67
|
+
params: UnsafeObject<PaymentIntent.ConfirmParams> | null,
|
|
67
68
|
options?: UnsafeObject<PaymentIntent.ConfirmOptions>
|
|
68
69
|
): Promise<ConfirmPaymentResult>;
|
|
69
70
|
confirmSetupIntent(
|
|
@@ -117,6 +118,8 @@ export interface Spec extends TurboModule {
|
|
|
117
118
|
deviceType: string;
|
|
118
119
|
appName: string;
|
|
119
120
|
appVersion: string;
|
|
121
|
+
isNewArchitecture: boolean;
|
|
122
|
+
reactNativeVersion: string;
|
|
120
123
|
};
|
|
121
124
|
};
|
|
122
125
|
canAddCardToWallet(
|
|
@@ -205,6 +208,55 @@ export interface Spec extends TurboModule {
|
|
|
205
208
|
clearEmbeddedPaymentOption(viewTag: Int32): Promise<void>;
|
|
206
209
|
createRadarSession(): Promise<CreateRadarSessionResult>;
|
|
207
210
|
|
|
211
|
+
// Checkout Session
|
|
212
|
+
|
|
213
|
+
initCheckoutSession(
|
|
214
|
+
clientSecret: string,
|
|
215
|
+
configuration: UnsafeObject<Checkout.Configuration>
|
|
216
|
+
): Promise<UnsafeObject<{ sessionKey: string; state: Checkout.State }>>;
|
|
217
|
+
|
|
218
|
+
checkoutUpdateShippingAddress(
|
|
219
|
+
sessionKey: string,
|
|
220
|
+
address: UnsafeObject<Checkout.Address>,
|
|
221
|
+
name: string | null,
|
|
222
|
+
phone: string | null
|
|
223
|
+
): Promise<UnsafeObject<Checkout.State>>;
|
|
224
|
+
|
|
225
|
+
checkoutUpdateBillingAddress(
|
|
226
|
+
sessionKey: string,
|
|
227
|
+
address: UnsafeObject<Checkout.Address>,
|
|
228
|
+
name: string | null,
|
|
229
|
+
phone: string | null
|
|
230
|
+
): Promise<UnsafeObject<Checkout.State>>;
|
|
231
|
+
|
|
232
|
+
checkoutApplyPromotionCode(
|
|
233
|
+
sessionKey: string,
|
|
234
|
+
code: string
|
|
235
|
+
): Promise<UnsafeObject<Checkout.State>>;
|
|
236
|
+
|
|
237
|
+
checkoutRemovePromotionCode(
|
|
238
|
+
sessionKey: string
|
|
239
|
+
): Promise<UnsafeObject<Checkout.State>>;
|
|
240
|
+
|
|
241
|
+
checkoutUpdateLineItemQuantity(
|
|
242
|
+
sessionKey: string,
|
|
243
|
+
lineItemId: string,
|
|
244
|
+
quantity: number
|
|
245
|
+
): Promise<UnsafeObject<Checkout.State>>;
|
|
246
|
+
|
|
247
|
+
checkoutSelectShippingOption(
|
|
248
|
+
sessionKey: string,
|
|
249
|
+
id: string
|
|
250
|
+
): Promise<UnsafeObject<Checkout.State>>;
|
|
251
|
+
|
|
252
|
+
checkoutUpdateTaxId(
|
|
253
|
+
sessionKey: string,
|
|
254
|
+
type: string,
|
|
255
|
+
value: string
|
|
256
|
+
): Promise<UnsafeObject<Checkout.State>>;
|
|
257
|
+
|
|
258
|
+
checkoutRefresh(sessionKey: string): Promise<UnsafeObject<Checkout.State>>;
|
|
259
|
+
|
|
208
260
|
setFinancialConnectionsForceNativeFlow(enabled: boolean): Promise<void>;
|
|
209
261
|
|
|
210
262
|
openAuthenticatedWebView(
|