@stripe-sdk/core 1.0.1 → 1.0.2
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/dist/client/index.d.mts +0 -4
- package/dist/client/index.d.ts +0 -4
- package/dist/client/index.js +70 -11
- package/dist/client/index.mjs +71 -12
- package/dist/{index-D8rM_YD4.d.mts → index-BKDJf1Hz.d.mts} +1 -27
- package/dist/{index-D8rM_YD4.d.ts → index-BKDJf1Hz.d.ts} +1 -27
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +601 -231
- package/dist/index.mjs +602 -232
- package/dist/next/index.d.mts +55 -32
- package/dist/next/index.d.ts +55 -32
- package/dist/next/index.js +362 -143
- package/dist/next/index.mjs +362 -143
- package/dist/server/index.d.mts +61 -21
- package/dist/server/index.d.ts +61 -21
- package/dist/server/index.js +546 -237
- package/dist/server/index.mjs +546 -237
- package/dist/server/webhooks/index.d.mts +1 -1
- package/dist/server/webhooks/index.d.ts +1 -1
- package/dist/server/webhooks/index.js +19 -7
- package/dist/server/webhooks/index.mjs +19 -7
- package/package.json +8 -5
- package/dist/client/index.js.map +0 -1
- package/dist/client/index.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/next/index.js.map +0 -1
- package/dist/next/index.mjs.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/index.mjs.map +0 -1
- package/dist/server/webhooks/index.js.map +0 -1
- package/dist/server/webhooks/index.mjs.map +0 -1
package/dist/client/index.d.mts
CHANGED
|
@@ -13,10 +13,6 @@ interface StripeProviderProps {
|
|
|
13
13
|
locale?: string;
|
|
14
14
|
}
|
|
15
15
|
declare function StripeProvider({ publishableKey, children, options, locale, }: StripeProviderProps): react_jsx_runtime.JSX.Element;
|
|
16
|
-
/**
|
|
17
|
-
* Provider for embedding Stripe Elements with a client secret.
|
|
18
|
-
* Use this to wrap payment forms after creating a PaymentIntent or SetupIntent.
|
|
19
|
-
*/
|
|
20
16
|
interface StripeElementsProviderProps {
|
|
21
17
|
publishableKey: string;
|
|
22
18
|
clientSecret: string;
|
package/dist/client/index.d.ts
CHANGED
|
@@ -13,10 +13,6 @@ interface StripeProviderProps {
|
|
|
13
13
|
locale?: string;
|
|
14
14
|
}
|
|
15
15
|
declare function StripeProvider({ publishableKey, children, options, locale, }: StripeProviderProps): react_jsx_runtime.JSX.Element;
|
|
16
|
-
/**
|
|
17
|
-
* Provider for embedding Stripe Elements with a client secret.
|
|
18
|
-
* Use this to wrap payment forms after creating a PaymentIntent or SetupIntent.
|
|
19
|
-
*/
|
|
20
16
|
interface StripeElementsProviderProps {
|
|
21
17
|
publishableKey: string;
|
|
22
18
|
clientSecret: string;
|
package/dist/client/index.js
CHANGED
|
@@ -14,12 +14,26 @@ function useStripeConfig() {
|
|
|
14
14
|
}
|
|
15
15
|
return context;
|
|
16
16
|
}
|
|
17
|
+
function validatePublishableKey(key) {
|
|
18
|
+
if (!key || typeof key !== "string") {
|
|
19
|
+
throw new Error("StripeProvider requires a publishableKey");
|
|
20
|
+
}
|
|
21
|
+
if (key.startsWith("sk_")) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"StripeProvider received a secret key (sk_*). Use a publishable key (pk_*) instead. Secret keys must NEVER be used on the client side."
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
if (!key.startsWith("pk_")) {
|
|
27
|
+
throw new Error('StripeProvider requires a publishable key starting with "pk_"');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
17
30
|
function StripeProvider({
|
|
18
31
|
publishableKey,
|
|
19
32
|
children,
|
|
20
33
|
options,
|
|
21
34
|
locale
|
|
22
35
|
}) {
|
|
36
|
+
validatePublishableKey(publishableKey);
|
|
23
37
|
const stripePromise = react.useMemo(
|
|
24
38
|
() => stripeJs.loadStripe(publishableKey, locale ? { locale } : void 0),
|
|
25
39
|
[publishableKey, locale]
|
|
@@ -34,6 +48,10 @@ function StripeElementsProvider({
|
|
|
34
48
|
locale,
|
|
35
49
|
loader = "auto"
|
|
36
50
|
}) {
|
|
51
|
+
validatePublishableKey(publishableKey);
|
|
52
|
+
if (!clientSecret || typeof clientSecret !== "string") {
|
|
53
|
+
throw new Error("StripeElementsProvider requires a clientSecret");
|
|
54
|
+
}
|
|
37
55
|
const stripePromise = react.useMemo(
|
|
38
56
|
() => stripeJs.loadStripe(publishableKey, locale ? { locale } : void 0),
|
|
39
57
|
[publishableKey, locale]
|
|
@@ -48,9 +66,21 @@ function StripeElementsProvider({
|
|
|
48
66
|
);
|
|
49
67
|
return /* @__PURE__ */ jsxRuntime.jsx(StripeContext.Provider, { value: { publishableKey }, children: /* @__PURE__ */ jsxRuntime.jsx(reactStripeJs.Elements, { stripe: stripePromise, options, children }) });
|
|
50
68
|
}
|
|
69
|
+
function validateReturnUrl(url) {
|
|
70
|
+
try {
|
|
71
|
+
const parsed = new URL(url);
|
|
72
|
+
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
73
|
+
throw new Error("returnUrl must use http or https protocol");
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
throw new Error("returnUrl must be a valid URL");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
51
79
|
function usePayment(options) {
|
|
52
80
|
const stripe = reactStripeJs.useStripe();
|
|
53
81
|
const elements = reactStripeJs.useElements();
|
|
82
|
+
const optionsRef = react.useRef(options);
|
|
83
|
+
optionsRef.current = options;
|
|
54
84
|
const [state, setState] = react.useState({
|
|
55
85
|
isProcessing: false,
|
|
56
86
|
isSuccess: false,
|
|
@@ -62,28 +92,32 @@ function usePayment(options) {
|
|
|
62
92
|
setState((s) => ({ ...s, error: "Stripe not loaded yet" }));
|
|
63
93
|
return { success: false, error: "Stripe not loaded yet" };
|
|
64
94
|
}
|
|
95
|
+
const returnUrl = overrides?.returnUrl ?? optionsRef.current?.returnUrl ?? (typeof window !== "undefined" ? window.location.href : "");
|
|
96
|
+
if (returnUrl && returnUrl !== window.location.href) {
|
|
97
|
+
validateReturnUrl(returnUrl);
|
|
98
|
+
}
|
|
65
99
|
setState({ isProcessing: true, isSuccess: false, error: null, paymentIntentId: null });
|
|
66
100
|
const { error, paymentIntent } = await stripe.confirmPayment({
|
|
67
101
|
elements,
|
|
68
102
|
confirmParams: {
|
|
69
|
-
return_url:
|
|
103
|
+
return_url: returnUrl
|
|
70
104
|
},
|
|
71
105
|
redirect: "if_required"
|
|
72
106
|
});
|
|
73
107
|
if (error) {
|
|
74
108
|
const message = error.message ?? "Payment failed";
|
|
75
109
|
setState({ isProcessing: false, isSuccess: false, error: message, paymentIntentId: null });
|
|
76
|
-
|
|
110
|
+
optionsRef.current?.onError?.(message);
|
|
77
111
|
return { success: false, error: message };
|
|
78
112
|
}
|
|
79
113
|
if (paymentIntent?.status === "succeeded") {
|
|
80
114
|
setState({ isProcessing: false, isSuccess: true, error: null, paymentIntentId: paymentIntent.id });
|
|
81
|
-
|
|
115
|
+
optionsRef.current?.onSuccess?.(paymentIntent.id);
|
|
82
116
|
return { success: true, paymentIntentId: paymentIntent.id };
|
|
83
117
|
}
|
|
84
118
|
setState({ isProcessing: false, isSuccess: false, error: null, paymentIntentId: paymentIntent?.id ?? null });
|
|
85
119
|
return { success: false, status: paymentIntent?.status };
|
|
86
|
-
}, [stripe, elements
|
|
120
|
+
}, [stripe, elements]);
|
|
87
121
|
const reset = react.useCallback(() => {
|
|
88
122
|
setState({ isProcessing: false, isSuccess: false, error: null, paymentIntentId: null });
|
|
89
123
|
}, []);
|
|
@@ -94,9 +128,21 @@ function usePayment(options) {
|
|
|
94
128
|
isReady: !!stripe && !!elements
|
|
95
129
|
};
|
|
96
130
|
}
|
|
131
|
+
function validateReturnUrl2(url) {
|
|
132
|
+
try {
|
|
133
|
+
const parsed = new URL(url);
|
|
134
|
+
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
135
|
+
throw new Error("returnUrl must use http or https protocol");
|
|
136
|
+
}
|
|
137
|
+
} catch {
|
|
138
|
+
throw new Error("returnUrl must be a valid URL");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
97
141
|
function useSetupIntent(options) {
|
|
98
142
|
const stripe = reactStripeJs.useStripe();
|
|
99
143
|
const elements = reactStripeJs.useElements();
|
|
144
|
+
const optionsRef = react.useRef(options);
|
|
145
|
+
optionsRef.current = options;
|
|
100
146
|
const [state, setState] = react.useState({
|
|
101
147
|
isProcessing: false,
|
|
102
148
|
isSuccess: false,
|
|
@@ -109,29 +155,33 @@ function useSetupIntent(options) {
|
|
|
109
155
|
setState((s) => ({ ...s, error: "Stripe not loaded yet" }));
|
|
110
156
|
return { success: false, error: "Stripe not loaded yet" };
|
|
111
157
|
}
|
|
158
|
+
const returnUrl = overrides?.returnUrl ?? optionsRef.current?.returnUrl ?? (typeof window !== "undefined" ? window.location.href : "");
|
|
159
|
+
if (returnUrl && returnUrl !== window.location.href) {
|
|
160
|
+
validateReturnUrl2(returnUrl);
|
|
161
|
+
}
|
|
112
162
|
setState({ isProcessing: true, isSuccess: false, error: null, setupIntentId: null, paymentMethodId: null });
|
|
113
163
|
const { error, setupIntent } = await stripe.confirmSetup({
|
|
114
164
|
elements,
|
|
115
165
|
confirmParams: {
|
|
116
|
-
return_url:
|
|
166
|
+
return_url: returnUrl
|
|
117
167
|
},
|
|
118
168
|
redirect: "if_required"
|
|
119
169
|
});
|
|
120
170
|
if (error) {
|
|
121
171
|
const message = error.message ?? "Setup failed";
|
|
122
172
|
setState({ isProcessing: false, isSuccess: false, error: message, setupIntentId: null, paymentMethodId: null });
|
|
123
|
-
|
|
173
|
+
optionsRef.current?.onError?.(message);
|
|
124
174
|
return { success: false, error: message };
|
|
125
175
|
}
|
|
126
176
|
if (setupIntent?.status === "succeeded") {
|
|
127
177
|
const pmId = typeof setupIntent.payment_method === "string" ? setupIntent.payment_method : setupIntent.payment_method?.id ?? null;
|
|
128
178
|
setState({ isProcessing: false, isSuccess: true, error: null, setupIntentId: setupIntent.id, paymentMethodId: pmId });
|
|
129
|
-
if (pmId)
|
|
179
|
+
if (pmId) optionsRef.current?.onSuccess?.(setupIntent.id, pmId);
|
|
130
180
|
return { success: true, setupIntentId: setupIntent.id, paymentMethodId: pmId };
|
|
131
181
|
}
|
|
132
182
|
setState({ isProcessing: false, isSuccess: false, error: null, setupIntentId: setupIntent?.id ?? null, paymentMethodId: null });
|
|
133
183
|
return { success: false, status: setupIntent?.status };
|
|
134
|
-
}, [stripe, elements
|
|
184
|
+
}, [stripe, elements]);
|
|
135
185
|
const reset = react.useCallback(() => {
|
|
136
186
|
setState({ isProcessing: false, isSuccess: false, error: null, setupIntentId: null, paymentMethodId: null });
|
|
137
187
|
}, []);
|
|
@@ -142,6 +192,14 @@ function useSetupIntent(options) {
|
|
|
142
192
|
isReady: !!stripe && !!elements
|
|
143
193
|
};
|
|
144
194
|
}
|
|
195
|
+
function isValidStripeUrl(url) {
|
|
196
|
+
try {
|
|
197
|
+
const parsed = new URL(url);
|
|
198
|
+
return parsed.hostname.endsWith(".stripe.com") && parsed.protocol === "https:";
|
|
199
|
+
} catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
145
203
|
function useCheckout(options) {
|
|
146
204
|
const [state, setState] = react.useState({
|
|
147
205
|
isLoading: false,
|
|
@@ -168,8 +226,11 @@ function useCheckout(options) {
|
|
|
168
226
|
options.onError?.(message);
|
|
169
227
|
return { success: false, error: message };
|
|
170
228
|
}
|
|
171
|
-
}, [options]);
|
|
229
|
+
}, [options.publishableKey, options.onError]);
|
|
172
230
|
const redirectToPortal = react.useCallback((portalUrl) => {
|
|
231
|
+
if (!isValidStripeUrl(portalUrl)) {
|
|
232
|
+
throw new Error("Invalid portal URL: must be a valid stripe.com HTTPS URL");
|
|
233
|
+
}
|
|
173
234
|
window.location.href = portalUrl;
|
|
174
235
|
}, []);
|
|
175
236
|
return {
|
|
@@ -513,5 +574,3 @@ exports.useCheckout = useCheckout;
|
|
|
513
574
|
exports.usePayment = usePayment;
|
|
514
575
|
exports.useSetupIntent = useSetupIntent;
|
|
515
576
|
exports.useStripeConfig = useStripeConfig;
|
|
516
|
-
//# sourceMappingURL=index.js.map
|
|
517
|
-
//# sourceMappingURL=index.js.map
|
package/dist/client/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useContext, useMemo, useState, useCallback } from 'react';
|
|
1
|
+
import { createContext, useContext, useMemo, useRef, useState, useCallback } from 'react';
|
|
2
2
|
import { loadStripe } from '@stripe/stripe-js';
|
|
3
3
|
import { Elements, useStripe, useElements, LinkAuthenticationElement, PaymentElement } from '@stripe/react-stripe-js';
|
|
4
4
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
@@ -12,12 +12,26 @@ function useStripeConfig() {
|
|
|
12
12
|
}
|
|
13
13
|
return context;
|
|
14
14
|
}
|
|
15
|
+
function validatePublishableKey(key) {
|
|
16
|
+
if (!key || typeof key !== "string") {
|
|
17
|
+
throw new Error("StripeProvider requires a publishableKey");
|
|
18
|
+
}
|
|
19
|
+
if (key.startsWith("sk_")) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
"StripeProvider received a secret key (sk_*). Use a publishable key (pk_*) instead. Secret keys must NEVER be used on the client side."
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
if (!key.startsWith("pk_")) {
|
|
25
|
+
throw new Error('StripeProvider requires a publishable key starting with "pk_"');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
15
28
|
function StripeProvider({
|
|
16
29
|
publishableKey,
|
|
17
30
|
children,
|
|
18
31
|
options,
|
|
19
32
|
locale
|
|
20
33
|
}) {
|
|
34
|
+
validatePublishableKey(publishableKey);
|
|
21
35
|
const stripePromise = useMemo(
|
|
22
36
|
() => loadStripe(publishableKey, locale ? { locale } : void 0),
|
|
23
37
|
[publishableKey, locale]
|
|
@@ -32,6 +46,10 @@ function StripeElementsProvider({
|
|
|
32
46
|
locale,
|
|
33
47
|
loader = "auto"
|
|
34
48
|
}) {
|
|
49
|
+
validatePublishableKey(publishableKey);
|
|
50
|
+
if (!clientSecret || typeof clientSecret !== "string") {
|
|
51
|
+
throw new Error("StripeElementsProvider requires a clientSecret");
|
|
52
|
+
}
|
|
35
53
|
const stripePromise = useMemo(
|
|
36
54
|
() => loadStripe(publishableKey, locale ? { locale } : void 0),
|
|
37
55
|
[publishableKey, locale]
|
|
@@ -46,9 +64,21 @@ function StripeElementsProvider({
|
|
|
46
64
|
);
|
|
47
65
|
return /* @__PURE__ */ jsx(StripeContext.Provider, { value: { publishableKey }, children: /* @__PURE__ */ jsx(Elements, { stripe: stripePromise, options, children }) });
|
|
48
66
|
}
|
|
67
|
+
function validateReturnUrl(url) {
|
|
68
|
+
try {
|
|
69
|
+
const parsed = new URL(url);
|
|
70
|
+
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
71
|
+
throw new Error("returnUrl must use http or https protocol");
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
throw new Error("returnUrl must be a valid URL");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
49
77
|
function usePayment(options) {
|
|
50
78
|
const stripe = useStripe();
|
|
51
79
|
const elements = useElements();
|
|
80
|
+
const optionsRef = useRef(options);
|
|
81
|
+
optionsRef.current = options;
|
|
52
82
|
const [state, setState] = useState({
|
|
53
83
|
isProcessing: false,
|
|
54
84
|
isSuccess: false,
|
|
@@ -60,28 +90,32 @@ function usePayment(options) {
|
|
|
60
90
|
setState((s) => ({ ...s, error: "Stripe not loaded yet" }));
|
|
61
91
|
return { success: false, error: "Stripe not loaded yet" };
|
|
62
92
|
}
|
|
93
|
+
const returnUrl = overrides?.returnUrl ?? optionsRef.current?.returnUrl ?? (typeof window !== "undefined" ? window.location.href : "");
|
|
94
|
+
if (returnUrl && returnUrl !== window.location.href) {
|
|
95
|
+
validateReturnUrl(returnUrl);
|
|
96
|
+
}
|
|
63
97
|
setState({ isProcessing: true, isSuccess: false, error: null, paymentIntentId: null });
|
|
64
98
|
const { error, paymentIntent } = await stripe.confirmPayment({
|
|
65
99
|
elements,
|
|
66
100
|
confirmParams: {
|
|
67
|
-
return_url:
|
|
101
|
+
return_url: returnUrl
|
|
68
102
|
},
|
|
69
103
|
redirect: "if_required"
|
|
70
104
|
});
|
|
71
105
|
if (error) {
|
|
72
106
|
const message = error.message ?? "Payment failed";
|
|
73
107
|
setState({ isProcessing: false, isSuccess: false, error: message, paymentIntentId: null });
|
|
74
|
-
|
|
108
|
+
optionsRef.current?.onError?.(message);
|
|
75
109
|
return { success: false, error: message };
|
|
76
110
|
}
|
|
77
111
|
if (paymentIntent?.status === "succeeded") {
|
|
78
112
|
setState({ isProcessing: false, isSuccess: true, error: null, paymentIntentId: paymentIntent.id });
|
|
79
|
-
|
|
113
|
+
optionsRef.current?.onSuccess?.(paymentIntent.id);
|
|
80
114
|
return { success: true, paymentIntentId: paymentIntent.id };
|
|
81
115
|
}
|
|
82
116
|
setState({ isProcessing: false, isSuccess: false, error: null, paymentIntentId: paymentIntent?.id ?? null });
|
|
83
117
|
return { success: false, status: paymentIntent?.status };
|
|
84
|
-
}, [stripe, elements
|
|
118
|
+
}, [stripe, elements]);
|
|
85
119
|
const reset = useCallback(() => {
|
|
86
120
|
setState({ isProcessing: false, isSuccess: false, error: null, paymentIntentId: null });
|
|
87
121
|
}, []);
|
|
@@ -92,9 +126,21 @@ function usePayment(options) {
|
|
|
92
126
|
isReady: !!stripe && !!elements
|
|
93
127
|
};
|
|
94
128
|
}
|
|
129
|
+
function validateReturnUrl2(url) {
|
|
130
|
+
try {
|
|
131
|
+
const parsed = new URL(url);
|
|
132
|
+
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
133
|
+
throw new Error("returnUrl must use http or https protocol");
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
throw new Error("returnUrl must be a valid URL");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
95
139
|
function useSetupIntent(options) {
|
|
96
140
|
const stripe = useStripe();
|
|
97
141
|
const elements = useElements();
|
|
142
|
+
const optionsRef = useRef(options);
|
|
143
|
+
optionsRef.current = options;
|
|
98
144
|
const [state, setState] = useState({
|
|
99
145
|
isProcessing: false,
|
|
100
146
|
isSuccess: false,
|
|
@@ -107,29 +153,33 @@ function useSetupIntent(options) {
|
|
|
107
153
|
setState((s) => ({ ...s, error: "Stripe not loaded yet" }));
|
|
108
154
|
return { success: false, error: "Stripe not loaded yet" };
|
|
109
155
|
}
|
|
156
|
+
const returnUrl = overrides?.returnUrl ?? optionsRef.current?.returnUrl ?? (typeof window !== "undefined" ? window.location.href : "");
|
|
157
|
+
if (returnUrl && returnUrl !== window.location.href) {
|
|
158
|
+
validateReturnUrl2(returnUrl);
|
|
159
|
+
}
|
|
110
160
|
setState({ isProcessing: true, isSuccess: false, error: null, setupIntentId: null, paymentMethodId: null });
|
|
111
161
|
const { error, setupIntent } = await stripe.confirmSetup({
|
|
112
162
|
elements,
|
|
113
163
|
confirmParams: {
|
|
114
|
-
return_url:
|
|
164
|
+
return_url: returnUrl
|
|
115
165
|
},
|
|
116
166
|
redirect: "if_required"
|
|
117
167
|
});
|
|
118
168
|
if (error) {
|
|
119
169
|
const message = error.message ?? "Setup failed";
|
|
120
170
|
setState({ isProcessing: false, isSuccess: false, error: message, setupIntentId: null, paymentMethodId: null });
|
|
121
|
-
|
|
171
|
+
optionsRef.current?.onError?.(message);
|
|
122
172
|
return { success: false, error: message };
|
|
123
173
|
}
|
|
124
174
|
if (setupIntent?.status === "succeeded") {
|
|
125
175
|
const pmId = typeof setupIntent.payment_method === "string" ? setupIntent.payment_method : setupIntent.payment_method?.id ?? null;
|
|
126
176
|
setState({ isProcessing: false, isSuccess: true, error: null, setupIntentId: setupIntent.id, paymentMethodId: pmId });
|
|
127
|
-
if (pmId)
|
|
177
|
+
if (pmId) optionsRef.current?.onSuccess?.(setupIntent.id, pmId);
|
|
128
178
|
return { success: true, setupIntentId: setupIntent.id, paymentMethodId: pmId };
|
|
129
179
|
}
|
|
130
180
|
setState({ isProcessing: false, isSuccess: false, error: null, setupIntentId: setupIntent?.id ?? null, paymentMethodId: null });
|
|
131
181
|
return { success: false, status: setupIntent?.status };
|
|
132
|
-
}, [stripe, elements
|
|
182
|
+
}, [stripe, elements]);
|
|
133
183
|
const reset = useCallback(() => {
|
|
134
184
|
setState({ isProcessing: false, isSuccess: false, error: null, setupIntentId: null, paymentMethodId: null });
|
|
135
185
|
}, []);
|
|
@@ -140,6 +190,14 @@ function useSetupIntent(options) {
|
|
|
140
190
|
isReady: !!stripe && !!elements
|
|
141
191
|
};
|
|
142
192
|
}
|
|
193
|
+
function isValidStripeUrl(url) {
|
|
194
|
+
try {
|
|
195
|
+
const parsed = new URL(url);
|
|
196
|
+
return parsed.hostname.endsWith(".stripe.com") && parsed.protocol === "https:";
|
|
197
|
+
} catch {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
143
201
|
function useCheckout(options) {
|
|
144
202
|
const [state, setState] = useState({
|
|
145
203
|
isLoading: false,
|
|
@@ -166,8 +224,11 @@ function useCheckout(options) {
|
|
|
166
224
|
options.onError?.(message);
|
|
167
225
|
return { success: false, error: message };
|
|
168
226
|
}
|
|
169
|
-
}, [options]);
|
|
227
|
+
}, [options.publishableKey, options.onError]);
|
|
170
228
|
const redirectToPortal = useCallback((portalUrl) => {
|
|
229
|
+
if (!isValidStripeUrl(portalUrl)) {
|
|
230
|
+
throw new Error("Invalid portal URL: must be a valid stripe.com HTTPS URL");
|
|
231
|
+
}
|
|
171
232
|
window.location.href = portalUrl;
|
|
172
233
|
}, []);
|
|
173
234
|
return {
|
|
@@ -502,5 +563,3 @@ function SubscriptionManager({
|
|
|
502
563
|
}
|
|
503
564
|
|
|
504
565
|
export { CheckoutForm, PricingTable, SetupForm, StripeElementsProvider, StripeProvider, SubscriptionManager, useCheckout, usePayment, useSetupIntent, useStripeConfig };
|
|
505
|
-
//# sourceMappingURL=index.mjs.map
|
|
506
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -6,6 +6,7 @@ interface StripeSDKConfig {
|
|
|
6
6
|
webhookSecret?: string;
|
|
7
7
|
apiVersion?: Stripe__default.LatestApiVersion;
|
|
8
8
|
appInfo?: Stripe__default.AppInfo;
|
|
9
|
+
maxNetworkRetries?: number;
|
|
9
10
|
}
|
|
10
11
|
interface CreatePaymentIntentInput {
|
|
11
12
|
amount: number;
|
|
@@ -328,37 +329,10 @@ declare function createWebhookHandler(config: WebhookConfig): (body: string | Bu
|
|
|
328
329
|
}>;
|
|
329
330
|
/**
|
|
330
331
|
* Helper for Next.js App Router webhook route
|
|
331
|
-
*
|
|
332
|
-
* Usage in app/api/webhooks/stripe/route.ts:
|
|
333
|
-
*
|
|
334
|
-
* ```ts
|
|
335
|
-
* import { createNextWebhookHandler } from '@stripe-sdk/core/webhooks';
|
|
336
|
-
*
|
|
337
|
-
* export const POST = createNextWebhookHandler({
|
|
338
|
-
* handlers: {
|
|
339
|
-
* 'payment_intent.succeeded': async (event) => { ... },
|
|
340
|
-
* 'customer.subscription.created': async (event) => { ... },
|
|
341
|
-
* },
|
|
342
|
-
* });
|
|
343
|
-
* ```
|
|
344
332
|
*/
|
|
345
333
|
declare function createNextWebhookHandler(config: WebhookConfig): (request: Request) => Promise<Response>;
|
|
346
334
|
/**
|
|
347
335
|
* Helper for Next.js Pages Router webhook route
|
|
348
|
-
*
|
|
349
|
-
* Usage in pages/api/webhooks/stripe.ts:
|
|
350
|
-
*
|
|
351
|
-
* ```ts
|
|
352
|
-
* import { createPagesWebhookHandler } from '@stripe-sdk/core/webhooks';
|
|
353
|
-
*
|
|
354
|
-
* export const config = { api: { bodyParser: false } };
|
|
355
|
-
*
|
|
356
|
-
* export default createPagesWebhookHandler({
|
|
357
|
-
* handlers: {
|
|
358
|
-
* 'payment_intent.succeeded': async (event) => { ... },
|
|
359
|
-
* },
|
|
360
|
-
* });
|
|
361
|
-
* ```
|
|
362
336
|
*/
|
|
363
337
|
declare function createPagesWebhookHandler(webhookConfig: WebhookConfig): (req: {
|
|
364
338
|
method?: string;
|
|
@@ -6,6 +6,7 @@ interface StripeSDKConfig {
|
|
|
6
6
|
webhookSecret?: string;
|
|
7
7
|
apiVersion?: Stripe__default.LatestApiVersion;
|
|
8
8
|
appInfo?: Stripe__default.AppInfo;
|
|
9
|
+
maxNetworkRetries?: number;
|
|
9
10
|
}
|
|
10
11
|
interface CreatePaymentIntentInput {
|
|
11
12
|
amount: number;
|
|
@@ -328,37 +329,10 @@ declare function createWebhookHandler(config: WebhookConfig): (body: string | Bu
|
|
|
328
329
|
}>;
|
|
329
330
|
/**
|
|
330
331
|
* Helper for Next.js App Router webhook route
|
|
331
|
-
*
|
|
332
|
-
* Usage in app/api/webhooks/stripe/route.ts:
|
|
333
|
-
*
|
|
334
|
-
* ```ts
|
|
335
|
-
* import { createNextWebhookHandler } from '@stripe-sdk/core/webhooks';
|
|
336
|
-
*
|
|
337
|
-
* export const POST = createNextWebhookHandler({
|
|
338
|
-
* handlers: {
|
|
339
|
-
* 'payment_intent.succeeded': async (event) => { ... },
|
|
340
|
-
* 'customer.subscription.created': async (event) => { ... },
|
|
341
|
-
* },
|
|
342
|
-
* });
|
|
343
|
-
* ```
|
|
344
332
|
*/
|
|
345
333
|
declare function createNextWebhookHandler(config: WebhookConfig): (request: Request) => Promise<Response>;
|
|
346
334
|
/**
|
|
347
335
|
* Helper for Next.js Pages Router webhook route
|
|
348
|
-
*
|
|
349
|
-
* Usage in pages/api/webhooks/stripe.ts:
|
|
350
|
-
*
|
|
351
|
-
* ```ts
|
|
352
|
-
* import { createPagesWebhookHandler } from '@stripe-sdk/core/webhooks';
|
|
353
|
-
*
|
|
354
|
-
* export const config = { api: { bodyParser: false } };
|
|
355
|
-
*
|
|
356
|
-
* export default createPagesWebhookHandler({
|
|
357
|
-
* handlers: {
|
|
358
|
-
* 'payment_intent.succeeded': async (event) => { ... },
|
|
359
|
-
* },
|
|
360
|
-
* });
|
|
361
|
-
* ```
|
|
362
336
|
*/
|
|
363
337
|
declare function createPagesWebhookHandler(webhookConfig: WebhookConfig): (req: {
|
|
364
338
|
method?: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { archivePrice, archiveProduct, attachPaymentMethod, cancelPaymentIntent, cancelSubscription, closeDispute, confirmPaymentIntent, createAccountLink, createCheckoutSession, createConnectAccount, createCoupon, createCustomer, createInvoice, createInvoiceItem, createPaymentIntent, createPaymentLink, createPayout, createPortalSession, createPrice, createProduct, createPromotionCode, createRefund, createSetupIntent, createSubscription, createTransfer, deleteConnectAccount, deleteCoupon, deleteCustomer, detachPaymentMethod, finalizeInvoice, getBalance, getConfig, getStripe, getUpcomingInvoice, initStripe, listBalanceTransactions, listCheckoutSessions, listConnectAccounts, listCoupons, listCustomers, listDisputes, listInvoices, listPaymentIntents, listPaymentMethods, listPayouts, listPrices, listProducts, listPromotionCodes, listRefunds, listSubscriptions, listTransfers, payInvoice, resumeSubscription, retrieveCheckoutSession, retrieveConnectAccount, retrieveCoupon, retrieveCustomer, retrieveDispute, retrieveInvoice, retrievePaymentIntent, retrievePaymentLink, retrievePrice, retrieveProduct, retrievePromotionCode, retrieveRefund, retrieveSetupIntent, retrieveSubscription, searchCustomers, sendInvoice, updateCustomer, updateDispute, updateProduct, updateSubscription, voidInvoice } from './server/index.mjs';
|
|
2
|
-
export { C as CancelSubscriptionInput, a as ConfirmPaymentInput, b as CreateAccountLinkInput, c as CreateCheckoutSessionInput, d as CreateConnectAccountInput, e as CreateCouponInput, f as CreateCustomerInput, g as CreateInvoiceInput, h as CreateInvoiceItemInput, i as CreatePaymentIntentInput, j as CreatePaymentLinkInput, k as CreatePortalSessionInput, l as CreatePriceInput, m as CreateProductInput, n as CreatePromotionCodeInput, o as CreateRefundInput, p as CreateSetupIntentInput, q as CreateSubscriptionInput, r as CreateTransferInput, L as ListCustomersInput, P as PaginationInput, S as SDKError, s as SDKResponse, t as SDKResult, u as StripeSDKConfig, U as UpdateCustomerInput, v as UpdateDisputeInput, w as UpdateProductInput, x as UpdateSubscriptionInput, W as WebhookEventType, y as WebhookHandler, z as WebhookHandlerMap, A as createNextWebhookHandler, B as createPagesWebhookHandler, D as createWebhookHandler } from './index-
|
|
2
|
+
export { C as CancelSubscriptionInput, a as ConfirmPaymentInput, b as CreateAccountLinkInput, c as CreateCheckoutSessionInput, d as CreateConnectAccountInput, e as CreateCouponInput, f as CreateCustomerInput, g as CreateInvoiceInput, h as CreateInvoiceItemInput, i as CreatePaymentIntentInput, j as CreatePaymentLinkInput, k as CreatePortalSessionInput, l as CreatePriceInput, m as CreateProductInput, n as CreatePromotionCodeInput, o as CreateRefundInput, p as CreateSetupIntentInput, q as CreateSubscriptionInput, r as CreateTransferInput, L as ListCustomersInput, P as PaginationInput, S as SDKError, s as SDKResponse, t as SDKResult, u as StripeSDKConfig, U as UpdateCustomerInput, v as UpdateDisputeInput, w as UpdateProductInput, x as UpdateSubscriptionInput, W as WebhookEventType, y as WebhookHandler, z as WebhookHandlerMap, A as createNextWebhookHandler, B as createPagesWebhookHandler, D as createWebhookHandler } from './index-BKDJf1Hz.mjs';
|
|
3
3
|
export { CheckoutForm, PricingTable, SetupForm, StripeElementsProvider, StripeProvider, SubscriptionManager, useCheckout, usePayment, useSetupIntent, useStripeConfig } from './client/index.mjs';
|
|
4
4
|
import 'stripe';
|
|
5
5
|
import 'react/jsx-runtime';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { archivePrice, archiveProduct, attachPaymentMethod, cancelPaymentIntent, cancelSubscription, closeDispute, confirmPaymentIntent, createAccountLink, createCheckoutSession, createConnectAccount, createCoupon, createCustomer, createInvoice, createInvoiceItem, createPaymentIntent, createPaymentLink, createPayout, createPortalSession, createPrice, createProduct, createPromotionCode, createRefund, createSetupIntent, createSubscription, createTransfer, deleteConnectAccount, deleteCoupon, deleteCustomer, detachPaymentMethod, finalizeInvoice, getBalance, getConfig, getStripe, getUpcomingInvoice, initStripe, listBalanceTransactions, listCheckoutSessions, listConnectAccounts, listCoupons, listCustomers, listDisputes, listInvoices, listPaymentIntents, listPaymentMethods, listPayouts, listPrices, listProducts, listPromotionCodes, listRefunds, listSubscriptions, listTransfers, payInvoice, resumeSubscription, retrieveCheckoutSession, retrieveConnectAccount, retrieveCoupon, retrieveCustomer, retrieveDispute, retrieveInvoice, retrievePaymentIntent, retrievePaymentLink, retrievePrice, retrieveProduct, retrievePromotionCode, retrieveRefund, retrieveSetupIntent, retrieveSubscription, searchCustomers, sendInvoice, updateCustomer, updateDispute, updateProduct, updateSubscription, voidInvoice } from './server/index.js';
|
|
2
|
-
export { C as CancelSubscriptionInput, a as ConfirmPaymentInput, b as CreateAccountLinkInput, c as CreateCheckoutSessionInput, d as CreateConnectAccountInput, e as CreateCouponInput, f as CreateCustomerInput, g as CreateInvoiceInput, h as CreateInvoiceItemInput, i as CreatePaymentIntentInput, j as CreatePaymentLinkInput, k as CreatePortalSessionInput, l as CreatePriceInput, m as CreateProductInput, n as CreatePromotionCodeInput, o as CreateRefundInput, p as CreateSetupIntentInput, q as CreateSubscriptionInput, r as CreateTransferInput, L as ListCustomersInput, P as PaginationInput, S as SDKError, s as SDKResponse, t as SDKResult, u as StripeSDKConfig, U as UpdateCustomerInput, v as UpdateDisputeInput, w as UpdateProductInput, x as UpdateSubscriptionInput, W as WebhookEventType, y as WebhookHandler, z as WebhookHandlerMap, A as createNextWebhookHandler, B as createPagesWebhookHandler, D as createWebhookHandler } from './index-
|
|
2
|
+
export { C as CancelSubscriptionInput, a as ConfirmPaymentInput, b as CreateAccountLinkInput, c as CreateCheckoutSessionInput, d as CreateConnectAccountInput, e as CreateCouponInput, f as CreateCustomerInput, g as CreateInvoiceInput, h as CreateInvoiceItemInput, i as CreatePaymentIntentInput, j as CreatePaymentLinkInput, k as CreatePortalSessionInput, l as CreatePriceInput, m as CreateProductInput, n as CreatePromotionCodeInput, o as CreateRefundInput, p as CreateSetupIntentInput, q as CreateSubscriptionInput, r as CreateTransferInput, L as ListCustomersInput, P as PaginationInput, S as SDKError, s as SDKResponse, t as SDKResult, u as StripeSDKConfig, U as UpdateCustomerInput, v as UpdateDisputeInput, w as UpdateProductInput, x as UpdateSubscriptionInput, W as WebhookEventType, y as WebhookHandler, z as WebhookHandlerMap, A as createNextWebhookHandler, B as createPagesWebhookHandler, D as createWebhookHandler } from './index-BKDJf1Hz.js';
|
|
3
3
|
export { CheckoutForm, PricingTable, SetupForm, StripeElementsProvider, StripeProvider, SubscriptionManager, useCheckout, usePayment, useSetupIntent, useStripeConfig } from './client/index.js';
|
|
4
4
|
import 'stripe';
|
|
5
5
|
import 'react/jsx-runtime';
|