@arnaudjnn/billing-tools 0.23.0 → 0.24.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/dist/ui/index.d.ts +42 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +81 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +22 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
2
|
+
import { type Appearance, type StripeElementLocale } from "@stripe/stripe-js";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export type BillingCheckoutProviderProps = {
|
|
5
|
+
/** Stripe publishable key (pk_…). Safe in the browser by design. */
|
|
6
|
+
publishableKey: string;
|
|
7
|
+
/** Client secret of the PaymentIntent/SetupIntent the SERVER created. */
|
|
8
|
+
clientSecret: string;
|
|
9
|
+
/** Stripe Elements appearance, so the form inherits the host app's theme. */
|
|
10
|
+
appearance?: Appearance;
|
|
11
|
+
/** e.g. "it" — defaults to the browser's locale. */
|
|
12
|
+
locale?: StripeElementLocale;
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
/** Wraps Stripe's <Elements> with the bits every consumer would otherwise repeat. */
|
|
16
|
+
export declare function BillingCheckoutProvider({ publishableKey, clientSecret, appearance, locale, children, }: BillingCheckoutProviderProps): React.JSX.Element;
|
|
17
|
+
export type BillingPaymentFormProps = {
|
|
18
|
+
/** Where Stripe returns the browser after an off-site step (3DS, bank redirect). */
|
|
19
|
+
returnUrl: string;
|
|
20
|
+
/** Rendered as the submit button. Receives the live submitting state. */
|
|
21
|
+
children: (state: {
|
|
22
|
+
submitting: boolean;
|
|
23
|
+
}) => React.ReactNode;
|
|
24
|
+
/** Called after the intent is confirmed without a redirect. */
|
|
25
|
+
onSuccess?: () => void;
|
|
26
|
+
/** Called with a human-readable message when Stripe declines or validation fails. */
|
|
27
|
+
onError?: (message: string) => void;
|
|
28
|
+
className?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The card/payment-method form: Stripe's PaymentElement plus confirmation.
|
|
32
|
+
*
|
|
33
|
+
* The button is passed in as a render prop rather than styled here, so the host
|
|
34
|
+
* app's own Button keeps the design system consistent — this component owns the
|
|
35
|
+
* Stripe wiring, not the look.
|
|
36
|
+
*
|
|
37
|
+
* `redirect: "if_required"` keeps the common card case on-page and only leaves
|
|
38
|
+
* for methods that genuinely need it (3DS challenge, bank redirects).
|
|
39
|
+
*/
|
|
40
|
+
export declare function BillingPaymentForm({ returnUrl, children, onSuccess, onError, className, }: BillingPaymentFormProps): React.JSX.Element;
|
|
41
|
+
export { PaymentElement, useElements, useStripe };
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAY,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAc,KAAK,UAAU,EAAe,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACvG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA8B/B,MAAM,MAAM,4BAA4B,GAAG;IACzC,oEAAoE;IACpE,cAAc,EAAE,MAAM,CAAC;IACvB,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,oDAAoD;IACpD,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,qFAAqF;AACrF,wBAAgB,uBAAuB,CAAC,EACtC,cAAc,EACd,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,GACT,EAAE,4BAA4B,qBAO9B;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,oFAAoF;IACpF,SAAS,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,UAAU,EAAE,OAAO,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,CAAC;IAC9D,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,qFAAqF;IACrF,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,SAAS,EACT,QAAQ,EACR,SAAS,EACT,OAAO,EACP,SAAS,GACV,EAAE,uBAAuB,qBAqCzB;AAED,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
4
|
+
import { loadStripe } from "@stripe/stripe-js";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
// The checkout UI, so every consumer app mounts the SAME payment form instead of
|
|
7
|
+
// re-deriving one from the Stripe docs.
|
|
8
|
+
//
|
|
9
|
+
// Imported from a SEPARATE entry point — `@arnaudjnn/billing-tools/ui` — because
|
|
10
|
+
// the rest of this package is server-side (WorkOS, Stripe secret key, MCP tools)
|
|
11
|
+
// and must never reach a browser bundle. React and the Stripe browser SDKs are
|
|
12
|
+
// declared as OPTIONAL peer dependencies, so the CLI and the MCP server keep
|
|
13
|
+
// installing without them; only an app that imports `/ui` needs them present.
|
|
14
|
+
//
|
|
15
|
+
// The provider owns exactly two things a consumer shouldn't have to rediscover:
|
|
16
|
+
// the publishable-key singleton (loadStripe must be called once per page, not
|
|
17
|
+
// once per render) and the Elements options shape. Everything money-related still
|
|
18
|
+
// happens on the server — this only collects a payment method and confirms an
|
|
19
|
+
// intent whose client secret the server minted.
|
|
20
|
+
// loadStripe returns a promise and Stripe asks that it be created once. Keyed by
|
|
21
|
+
// publishable key so a consumer switching keys (test → live) still gets one
|
|
22
|
+
// instance per key rather than one forever.
|
|
23
|
+
const stripeCache = new Map();
|
|
24
|
+
function stripeFor(publishableKey) {
|
|
25
|
+
const hit = stripeCache.get(publishableKey);
|
|
26
|
+
if (hit)
|
|
27
|
+
return hit;
|
|
28
|
+
const p = loadStripe(publishableKey);
|
|
29
|
+
stripeCache.set(publishableKey, p);
|
|
30
|
+
return p;
|
|
31
|
+
}
|
|
32
|
+
/** Wraps Stripe's <Elements> with the bits every consumer would otherwise repeat. */
|
|
33
|
+
export function BillingCheckoutProvider({ publishableKey, clientSecret, appearance, locale, children, }) {
|
|
34
|
+
const stripe = React.useMemo(() => stripeFor(publishableKey), [publishableKey]);
|
|
35
|
+
return (_jsx(Elements, { stripe: stripe, options: { clientSecret, appearance, locale }, children: children }));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The card/payment-method form: Stripe's PaymentElement plus confirmation.
|
|
39
|
+
*
|
|
40
|
+
* The button is passed in as a render prop rather than styled here, so the host
|
|
41
|
+
* app's own Button keeps the design system consistent — this component owns the
|
|
42
|
+
* Stripe wiring, not the look.
|
|
43
|
+
*
|
|
44
|
+
* `redirect: "if_required"` keeps the common card case on-page and only leaves
|
|
45
|
+
* for methods that genuinely need it (3DS challenge, bank redirects).
|
|
46
|
+
*/
|
|
47
|
+
export function BillingPaymentForm({ returnUrl, children, onSuccess, onError, className, }) {
|
|
48
|
+
const stripe = useStripe();
|
|
49
|
+
const elements = useElements();
|
|
50
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
51
|
+
async function onSubmit(e) {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
if (!stripe || !elements || submitting)
|
|
54
|
+
return;
|
|
55
|
+
setSubmitting(true);
|
|
56
|
+
try {
|
|
57
|
+
// Surface field-level problems before touching the intent.
|
|
58
|
+
const submitted = await elements.submit();
|
|
59
|
+
if (submitted.error) {
|
|
60
|
+
onError?.(submitted.error.message ?? "Dati di pagamento non validi");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const { error } = await stripe.confirmPayment({
|
|
64
|
+
elements,
|
|
65
|
+
confirmParams: { return_url: returnUrl },
|
|
66
|
+
redirect: "if_required",
|
|
67
|
+
});
|
|
68
|
+
if (error) {
|
|
69
|
+
onError?.(error.message ?? "Pagamento non riuscito");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
onSuccess?.();
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
setSubmitting(false);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return (_jsxs("form", { onSubmit: onSubmit, className: className, children: [_jsx(PaymentElement, {}), children({ submitting })] }));
|
|
79
|
+
}
|
|
80
|
+
export { PaymentElement, useElements, useStripe };
|
|
81
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,UAAU,EAA0D,MAAM,mBAAmB,CAAC;AACvG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,iFAAiF;AACjF,wCAAwC;AACxC,EAAE;AACF,iFAAiF;AACjF,iFAAiF;AACjF,+EAA+E;AAC/E,6EAA6E;AAC7E,8EAA8E;AAC9E,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,kFAAkF;AAClF,8EAA8E;AAC9E,gDAAgD;AAEhD,iFAAiF;AACjF,4EAA4E;AAC5E,4CAA4C;AAC5C,MAA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C3D,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC1C,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;gBACpB,OAAO,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,IAAI,8BAA8B,CAAC,CAAC;gBACrE,OAAO;YACT,CAAC;YACD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC;gBAC5C,QAAQ;gBACR,aAAa,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE;gBACxC,QAAQ,EAAE,aAAa;aACxB,CAAC,CAAC;YACH,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,IAAI,wBAAwB,CAAC,CAAC;gBACrD,OAAO;YACT,CAAC;YACD,SAAS,EAAE,EAAE,CAAC;QAChB,CAAC;gBAAS,CAAC;YACT,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,CACL,gBAAM,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,aAC5C,KAAC,cAAc,KAAG,EACjB,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC,IACpB,CACR,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arnaudjnn/billing-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "The get-paid engine for Stripe + WorkOS apps, for humans and AI agents. Drop-in API-key auth, token/credit + subscription billing, auth.md agent registration, and MPP machine payments, as MCP tools, a REST API, and a CLI. Framework-agnostic, storage-pluggable.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Arnaud Jeannin",
|
|
@@ -44,6 +44,11 @@
|
|
|
44
44
|
"types": "./dist/cli/index.d.ts",
|
|
45
45
|
"import": "./dist/cli/index.js",
|
|
46
46
|
"default": "./dist/cli/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./ui": {
|
|
49
|
+
"types": "./dist/ui/index.d.ts",
|
|
50
|
+
"import": "./dist/ui/index.js",
|
|
51
|
+
"default": "./dist/ui/index.js"
|
|
47
52
|
}
|
|
48
53
|
},
|
|
49
54
|
"files": [
|
|
@@ -67,12 +72,24 @@
|
|
|
67
72
|
},
|
|
68
73
|
"peerDependencies": {
|
|
69
74
|
"@modelcontextprotocol/sdk": ">=1.25.0",
|
|
75
|
+
"@stripe/react-stripe-js": "^5 || ^6",
|
|
76
|
+
"@stripe/stripe-js": "^8 || ^9",
|
|
70
77
|
"mcp-handler": ">=1.1.0",
|
|
78
|
+
"react": "^18 || ^19",
|
|
71
79
|
"zod": "^3.25.0"
|
|
72
80
|
},
|
|
73
81
|
"peerDependenciesMeta": {
|
|
74
82
|
"mcp-handler": {
|
|
75
83
|
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"react": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
88
|
+
"@stripe/react-stripe-js": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
91
|
+
"@stripe/stripe-js": {
|
|
92
|
+
"optional": true
|
|
76
93
|
}
|
|
77
94
|
},
|
|
78
95
|
"devDependencies": {
|
|
@@ -80,8 +97,12 @@
|
|
|
80
97
|
"@semantic-release/changelog": "^6.0.3",
|
|
81
98
|
"@semantic-release/exec": "^6.0.3",
|
|
82
99
|
"@semantic-release/git": "^10.0.1",
|
|
100
|
+
"@stripe/react-stripe-js": "^6.8.0",
|
|
101
|
+
"@stripe/stripe-js": "^9.12.1",
|
|
83
102
|
"@types/node": "^20",
|
|
103
|
+
"@types/react": "^19.2.17",
|
|
84
104
|
"mcp-handler": "^1.1.0",
|
|
105
|
+
"react": "^19.2.8",
|
|
85
106
|
"semantic-release": "^24.2.0",
|
|
86
107
|
"typescript": "^5",
|
|
87
108
|
"zod": "^3.25.76"
|