@cedros/pay-react 1.0.4 → 1.0.5
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/README.md +109 -3
- package/dist/CedrosContext-CFEXGwQg.mjs +2163 -0
- package/dist/CedrosContext-DbndTsTA.js +11 -0
- package/dist/components/CryptoSubscribeButton.d.ts +50 -0
- package/dist/components/CryptoSubscribeButton.d.ts.map +1 -0
- package/dist/components/SubscribeButton.d.ts +55 -0
- package/dist/components/SubscribeButton.d.ts.map +1 -0
- package/dist/components/SubscriptionManagementPanel.d.ts +67 -0
- package/dist/components/SubscriptionManagementPanel.d.ts.map +1 -0
- package/dist/components/subscriptionPanelStyles.d.ts +13 -0
- package/dist/components/subscriptionPanelStyles.d.ts.map +1 -0
- package/dist/context/CedrosContext.d.ts +4 -0
- package/dist/context/CedrosContext.d.ts.map +1 -1
- package/dist/crypto-only.js +1 -1
- package/dist/crypto-only.mjs +2 -2
- package/dist/en-C739WV_-.mjs +19 -0
- package/dist/en-Cz4OpvN-.js +1 -0
- package/dist/hooks/useCryptoSubscription.d.ts +42 -0
- package/dist/hooks/useCryptoSubscription.d.ts.map +1 -0
- package/dist/hooks/useSubscription.d.ts +42 -0
- package/dist/hooks/useSubscription.d.ts.map +1 -0
- package/dist/hooks/useSubscriptionManagement.d.ts +88 -0
- package/dist/hooks/useSubscriptionManagement.d.ts.map +1 -0
- package/dist/i18n/index.d.ts +7 -0
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1658 -361
- package/dist/managers/ManagerCache.d.ts +4 -0
- package/dist/managers/ManagerCache.d.ts.map +1 -1
- package/dist/managers/SubscriptionChangeManager.d.ts +42 -0
- package/dist/managers/SubscriptionChangeManager.d.ts.map +1 -0
- package/dist/managers/SubscriptionManager.d.ts +113 -0
- package/dist/managers/SubscriptionManager.d.ts.map +1 -0
- package/dist/pay-react.css +1 -1
- package/dist/stripe-only.js +1 -1
- package/dist/stripe-only.mjs +2 -2
- package/dist/{styles-DI2LPVdQ.mjs → styles-DFcRS8Uu.mjs} +13 -12
- package/dist/{styles-61pRysGe.js → styles-Dup9uK6S.js} +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.mjs +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/subscription.d.ts +300 -0
- package/dist/types/subscription.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/CedrosContext-B3iCqN6e.js +0 -11
- package/dist/CedrosContext-vX9uqZKp.mjs +0 -1796
- package/dist/en-CSsJl3nf.mjs +0 -19
- package/dist/en-D-uY3ltT.js +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import { ConnectionProvider as
|
|
4
|
-
import { u as
|
|
5
|
-
import { C as
|
|
6
|
-
import { a as
|
|
7
|
-
import { k as
|
|
8
|
-
import { clusterApiUrl as
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { jsxs as w, jsx as u, Fragment as me } from "react/jsx-runtime";
|
|
2
|
+
import G, { useState as U, useCallback as T, useMemo as F, useRef as ke, useEffect as Y } from "react";
|
|
3
|
+
import { ConnectionProvider as De, WalletProvider as qe, useWallet as ye } from "@solana/wallet-adapter-react";
|
|
4
|
+
import { u as $e, c as Re, o as ge, q as Ie, e as he, g as ie, h as be, i as ce, r as Se, P as ze, S as Ue, m as je, s as Oe, t as Te, v as fe, w as Fe } from "./styles-DFcRS8Uu.mjs";
|
|
5
|
+
import { C as Bt, E as Nt, b as Mt, a as _t, d as At, B as Wt, y as Lt, f as Dt, A as qt, D as $t, l as zt, k as Ut, z as jt, p as Ot, j as Ft, x as Ht, F as Kt, n as Qt } from "./styles-DFcRS8Uu.mjs";
|
|
6
|
+
import { a as le, u as ee, g as D, f as Z } from "./CedrosContext-CFEXGwQg.mjs";
|
|
7
|
+
import { k as Yt, C as Vt, j as Xt, i as Jt, L as Zt, b as er, R as tr, l as rr, W as nr, h as sr, d as or, c as ar, m as ir, r as cr, v as lr } from "./CedrosContext-CFEXGwQg.mjs";
|
|
8
|
+
import { clusterApiUrl as He } from "@solana/web3.js";
|
|
9
|
+
import { WalletReadyState as Ee } from "@solana/wallet-adapter-base";
|
|
10
|
+
import { WalletIcon as Ke } from "@solana/wallet-adapter-react-ui";
|
|
11
|
+
import "@solana/wallet-adapter-wallets";
|
|
12
|
+
function Qe(e) {
|
|
13
|
+
switch (e) {
|
|
11
14
|
case "mainnet-beta":
|
|
12
15
|
return "https://api.mainnet-beta.solana.com";
|
|
13
16
|
case "devnet":
|
|
@@ -18,88 +21,88 @@ function Se(t) {
|
|
|
18
21
|
return "https://api.mainnet-beta.solana.com";
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
|
-
function
|
|
24
|
+
function Ge(e) {
|
|
22
25
|
try {
|
|
23
|
-
const
|
|
24
|
-
return `${
|
|
26
|
+
const r = new URL(e);
|
|
27
|
+
return `${r.protocol}//${r.host}`;
|
|
25
28
|
} catch {
|
|
26
|
-
return
|
|
29
|
+
return e;
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
|
-
function
|
|
32
|
+
function Ye(e = {}) {
|
|
30
33
|
const {
|
|
31
|
-
solanaCluster:
|
|
32
|
-
solanaEndpoint:
|
|
34
|
+
solanaCluster: r = "mainnet-beta",
|
|
35
|
+
solanaEndpoint: t,
|
|
33
36
|
customRpcProviders: o = [],
|
|
34
|
-
allowUnsafeScripts:
|
|
35
|
-
additionalScriptSrc:
|
|
37
|
+
allowUnsafeScripts: f = !1,
|
|
38
|
+
additionalScriptSrc: i = [],
|
|
36
39
|
additionalConnectSrc: h = [],
|
|
37
|
-
additionalFrameSrc:
|
|
38
|
-
includeStripe:
|
|
39
|
-
} =
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const b =
|
|
44
|
-
if (
|
|
45
|
-
const
|
|
46
|
-
|
|
40
|
+
additionalFrameSrc: x = [],
|
|
41
|
+
includeStripe: m = !0
|
|
42
|
+
} = e, l = ["'self'"];
|
|
43
|
+
f && l.push("'unsafe-inline'", "'unsafe-eval'"), m && l.push("https://js.stripe.com"), l.push(...i);
|
|
44
|
+
const s = ["'self'"];
|
|
45
|
+
m && s.push("https://api.stripe.com", "https://*.stripe.com");
|
|
46
|
+
const b = Qe(r);
|
|
47
|
+
if (s.push(b), s.push("https://*.solana.com"), t) {
|
|
48
|
+
const d = Ge(t);
|
|
49
|
+
s.includes(d) || s.push(d);
|
|
47
50
|
}
|
|
48
|
-
o.forEach((
|
|
49
|
-
|
|
50
|
-
}),
|
|
51
|
-
const
|
|
52
|
-
return
|
|
51
|
+
o.forEach((d) => {
|
|
52
|
+
s.includes(d) || s.push(d);
|
|
53
|
+
}), s.push(...h);
|
|
54
|
+
const c = ["'self'"];
|
|
55
|
+
return m && c.push("https://js.stripe.com", "https://checkout.stripe.com"), c.push(...x), {
|
|
53
56
|
scriptSrc: l,
|
|
54
|
-
connectSrc:
|
|
55
|
-
frameSrc:
|
|
57
|
+
connectSrc: s,
|
|
58
|
+
frameSrc: c
|
|
56
59
|
};
|
|
57
60
|
}
|
|
58
|
-
function
|
|
59
|
-
const { scriptSrc:
|
|
60
|
-
switch (
|
|
61
|
+
function Ve(e, r = "header") {
|
|
62
|
+
const { scriptSrc: t, connectSrc: o, frameSrc: f } = e;
|
|
63
|
+
switch (r) {
|
|
61
64
|
case "header":
|
|
62
65
|
case "meta":
|
|
63
66
|
case "nextjs":
|
|
64
67
|
case "nginx": {
|
|
65
|
-
const
|
|
66
|
-
return
|
|
68
|
+
const i = [];
|
|
69
|
+
return t.length > 0 && i.push(`script-src ${t.join(" ")}`), o.length > 0 && i.push(`connect-src ${o.join(" ")}`), f.length > 0 && i.push(`frame-src ${f.join(" ")}`), i.join("; ");
|
|
67
70
|
}
|
|
68
71
|
case "helmet": {
|
|
69
|
-
const
|
|
70
|
-
return
|
|
72
|
+
const i = {};
|
|
73
|
+
return t.length > 0 && (i.scriptSrc = t), o.length > 0 && (i.connectSrc = o), f.length > 0 && (i.frameSrc = f), i;
|
|
71
74
|
}
|
|
72
75
|
case "directives":
|
|
73
|
-
return { scriptSrc:
|
|
76
|
+
return { scriptSrc: t, connectSrc: o, frameSrc: f };
|
|
74
77
|
default:
|
|
75
|
-
throw new Error(`Unknown CSP format: ${
|
|
78
|
+
throw new Error(`Unknown CSP format: ${r}`);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
|
-
function
|
|
79
|
-
const
|
|
80
|
-
return
|
|
81
|
+
function ht(e = {}, r = "header") {
|
|
82
|
+
const t = Ye(e);
|
|
83
|
+
return Ve(t, r);
|
|
81
84
|
}
|
|
82
|
-
const
|
|
85
|
+
const bt = {
|
|
83
86
|
HELIUS: "https://*.helius-rpc.com",
|
|
84
87
|
QUICKNODE: "https://*.quicknode.pro",
|
|
85
88
|
ALCHEMY: "https://*.alchemy.com",
|
|
86
89
|
ANKR: "https://rpc.ankr.com",
|
|
87
90
|
TRITON: "https://*.rpcpool.com"
|
|
88
|
-
},
|
|
91
|
+
}, St = {
|
|
89
92
|
/**
|
|
90
93
|
* Mainnet production with custom RPC (recommended)
|
|
91
94
|
*/
|
|
92
|
-
MAINNET_CUSTOM_RPC: (
|
|
95
|
+
MAINNET_CUSTOM_RPC: (e) => ({
|
|
93
96
|
solanaCluster: "mainnet-beta",
|
|
94
|
-
solanaEndpoint:
|
|
97
|
+
solanaEndpoint: e,
|
|
95
98
|
allowUnsafeScripts: !1
|
|
96
99
|
}),
|
|
97
100
|
/**
|
|
98
101
|
* Mainnet with Next.js (requires unsafe-inline/eval)
|
|
99
102
|
*/
|
|
100
|
-
MAINNET_NEXTJS: (
|
|
103
|
+
MAINNET_NEXTJS: (e) => ({
|
|
101
104
|
solanaCluster: "mainnet-beta",
|
|
102
|
-
solanaEndpoint:
|
|
105
|
+
solanaEndpoint: e,
|
|
103
106
|
allowUnsafeScripts: !0
|
|
104
107
|
}),
|
|
105
108
|
/**
|
|
@@ -112,9 +115,9 @@ const Ue = {
|
|
|
112
115
|
/**
|
|
113
116
|
* Crypto-only payments (no Stripe)
|
|
114
117
|
*/
|
|
115
|
-
CRYPTO_ONLY: (
|
|
118
|
+
CRYPTO_ONLY: (e) => ({
|
|
116
119
|
solanaCluster: "mainnet-beta",
|
|
117
|
-
solanaEndpoint:
|
|
120
|
+
solanaEndpoint: e,
|
|
118
121
|
includeStripe: !1
|
|
119
122
|
}),
|
|
120
123
|
/**
|
|
@@ -126,354 +129,1642 @@ const Ue = {
|
|
|
126
129
|
// Don't include Solana RPC endpoints
|
|
127
130
|
customRpcProviders: []
|
|
128
131
|
})
|
|
129
|
-
},
|
|
130
|
-
resource:
|
|
131
|
-
items:
|
|
132
|
-
label:
|
|
132
|
+
}, Xe = ({
|
|
133
|
+
resource: e,
|
|
134
|
+
items: r,
|
|
135
|
+
label: t,
|
|
133
136
|
cardLabel: o,
|
|
134
|
-
cryptoLabel:
|
|
135
|
-
showCard:
|
|
137
|
+
cryptoLabel: f,
|
|
138
|
+
showCard: i = !0,
|
|
136
139
|
showCrypto: h = !0,
|
|
137
|
-
onPaymentAttempt:
|
|
138
|
-
onPaymentSuccess:
|
|
140
|
+
onPaymentAttempt: x,
|
|
141
|
+
onPaymentSuccess: m,
|
|
139
142
|
onPaymentError: l,
|
|
140
|
-
onStripeSuccess:
|
|
143
|
+
onStripeSuccess: s,
|
|
141
144
|
onCryptoSuccess: b,
|
|
142
|
-
onStripeError:
|
|
143
|
-
onCryptoError:
|
|
144
|
-
customerEmail:
|
|
145
|
-
successUrl:
|
|
146
|
-
cancelUrl:
|
|
147
|
-
metadata:
|
|
148
|
-
couponCode:
|
|
149
|
-
autoDetectWallets:
|
|
150
|
-
testPageUrl:
|
|
151
|
-
hideMessages:
|
|
152
|
-
renderModal:
|
|
145
|
+
onStripeError: c,
|
|
146
|
+
onCryptoError: d,
|
|
147
|
+
customerEmail: n,
|
|
148
|
+
successUrl: a,
|
|
149
|
+
cancelUrl: p,
|
|
150
|
+
metadata: C,
|
|
151
|
+
couponCode: P,
|
|
152
|
+
autoDetectWallets: y = !0,
|
|
153
|
+
testPageUrl: B,
|
|
154
|
+
hideMessages: N = !1,
|
|
155
|
+
renderModal: E
|
|
153
156
|
}) => {
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
156
|
-
const { detectSolanaWallets:
|
|
157
|
-
if (!
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
let
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
c,
|
|
157
|
+
const I = le(), [v, k] = U(!1), { status: q, processPayment: R, processCartCheckout: $ } = $e(), { isCartMode: _, effectiveResource: z } = Re(e, r), { t: O } = ge(), L = t || O("ui.purchase"), j = o || O("ui.card"), ue = f || O("ui.usdc_solana"), re = T(async () => {
|
|
158
|
+
if (y && i) {
|
|
159
|
+
const { detectSolanaWallets: A } = await import("./walletDetection-JZR3UCOa.mjs");
|
|
160
|
+
if (!A()) {
|
|
161
|
+
const K = _ ? void 0 : z, Q = _ && r ? Ie(r) : void 0;
|
|
162
|
+
he("stripe", K, Q), x && x("stripe"), ie("stripe", K, Q);
|
|
163
|
+
let M;
|
|
164
|
+
_ && r ? M = await $(
|
|
165
|
+
r,
|
|
164
166
|
a,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
p,
|
|
168
|
+
C,
|
|
169
|
+
n,
|
|
170
|
+
P
|
|
171
|
+
) : z && (M = await R(
|
|
172
|
+
z,
|
|
171
173
|
a,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
p,
|
|
175
|
+
C,
|
|
176
|
+
n,
|
|
177
|
+
P
|
|
178
|
+
)), M && M.success && M.transactionId ? (be("stripe", M.transactionId, K, Q), s ? s(M.transactionId) : m && m(M.transactionId)) : M && !M.success && M.error && (ce("stripe", M.error, K, Q), c ? c(M.error) : l && l(M.error));
|
|
176
179
|
return;
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
|
-
|
|
180
|
-
}, [
|
|
181
|
-
() =>
|
|
182
|
-
[
|
|
183
|
-
),
|
|
184
|
-
isOpen:
|
|
185
|
-
onClose: () =>
|
|
186
|
-
resource:
|
|
187
|
-
items:
|
|
188
|
-
cardLabel:
|
|
189
|
-
cryptoLabel:
|
|
190
|
-
showCard:
|
|
182
|
+
k(!0);
|
|
183
|
+
}, [y, i, _, r, z, $, R, a, p, C, n, P, m, l, s, c, x]), te = F(() => _ && r ? `purchase-cart-${r.map((A) => A.resource).join("-")}` : `purchase-${z || "unknown"}`, [_, r, z]), ne = F(
|
|
184
|
+
() => Se(te, re),
|
|
185
|
+
[te, re]
|
|
186
|
+
), H = q === "loading", se = {
|
|
187
|
+
isOpen: v,
|
|
188
|
+
onClose: () => k(!1),
|
|
189
|
+
resource: _ ? void 0 : z,
|
|
190
|
+
items: _ ? r : void 0,
|
|
191
|
+
cardLabel: j,
|
|
192
|
+
cryptoLabel: ue,
|
|
193
|
+
showCard: i,
|
|
191
194
|
showCrypto: h,
|
|
192
|
-
onPaymentAttempt:
|
|
193
|
-
onPaymentSuccess: (
|
|
194
|
-
|
|
195
|
+
onPaymentAttempt: x,
|
|
196
|
+
onPaymentSuccess: (A) => {
|
|
197
|
+
k(!1), m?.(A);
|
|
195
198
|
},
|
|
196
|
-
onPaymentError: (
|
|
197
|
-
|
|
199
|
+
onPaymentError: (A) => {
|
|
200
|
+
k(!1), l?.(A);
|
|
198
201
|
},
|
|
199
|
-
onStripeSuccess: (
|
|
200
|
-
|
|
202
|
+
onStripeSuccess: (A) => {
|
|
203
|
+
k(!1), s?.(A);
|
|
201
204
|
},
|
|
202
|
-
onCryptoSuccess: (
|
|
203
|
-
|
|
205
|
+
onCryptoSuccess: (A) => {
|
|
206
|
+
k(!1), b?.(A);
|
|
204
207
|
},
|
|
205
|
-
onStripeError: (
|
|
206
|
-
|
|
208
|
+
onStripeError: (A) => {
|
|
209
|
+
k(!1), c?.(A);
|
|
207
210
|
},
|
|
208
|
-
onCryptoError: (
|
|
209
|
-
|
|
211
|
+
onCryptoError: (A) => {
|
|
212
|
+
k(!1), d?.(A);
|
|
210
213
|
},
|
|
211
|
-
customerEmail:
|
|
212
|
-
successUrl:
|
|
213
|
-
cancelUrl:
|
|
214
|
-
metadata:
|
|
215
|
-
couponCode:
|
|
216
|
-
testPageUrl:
|
|
217
|
-
hideMessages:
|
|
214
|
+
customerEmail: n,
|
|
215
|
+
successUrl: a,
|
|
216
|
+
cancelUrl: p,
|
|
217
|
+
metadata: C,
|
|
218
|
+
couponCode: P,
|
|
219
|
+
testPageUrl: B,
|
|
220
|
+
hideMessages: N
|
|
218
221
|
};
|
|
219
|
-
return /* @__PURE__ */
|
|
220
|
-
/* @__PURE__ */
|
|
222
|
+
return /* @__PURE__ */ w("div", { className: I.unstyled ? "" : I.className, style: I.unstyled ? {} : I.style, children: [
|
|
223
|
+
/* @__PURE__ */ u(
|
|
221
224
|
"button",
|
|
222
225
|
{
|
|
223
|
-
onClick:
|
|
224
|
-
disabled:
|
|
225
|
-
className:
|
|
226
|
+
onClick: ne,
|
|
227
|
+
disabled: H,
|
|
228
|
+
className: I.unstyled ? "" : "cedros-theme__button cedros-theme__stripe",
|
|
226
229
|
style: {
|
|
227
230
|
width: "100%",
|
|
228
|
-
cursor:
|
|
229
|
-
opacity:
|
|
231
|
+
cursor: H ? "not-allowed" : "pointer",
|
|
232
|
+
opacity: H ? 0.6 : 1
|
|
230
233
|
},
|
|
231
234
|
type: "button",
|
|
232
|
-
children:
|
|
235
|
+
children: H ? O("ui.processing") : L
|
|
233
236
|
}
|
|
234
237
|
),
|
|
235
|
-
|
|
238
|
+
E ? E(se) : /* @__PURE__ */ u(ze, { ...se })
|
|
236
239
|
] });
|
|
237
240
|
};
|
|
238
|
-
function
|
|
239
|
-
const { resource:
|
|
241
|
+
function wt(e) {
|
|
242
|
+
const { resource: r, items: t, checkout: o = {}, display: f = {}, callbacks: i = {}, advanced: h = {} } = e, { config: x, walletPool: m } = ee(), l = le(), { isCartMode: s } = Re(r, t), b = G.useMemo(() => ({
|
|
240
243
|
marginTop: "0.5rem",
|
|
241
244
|
fontSize: "0.875rem",
|
|
242
245
|
color: l.tokens.surfaceText,
|
|
243
246
|
opacity: 0.7,
|
|
244
247
|
textAlign: "center"
|
|
245
|
-
}), [l.tokens.surfaceText]),
|
|
246
|
-
() => h.wallets && h.wallets.length > 0 ? h.wallets :
|
|
247
|
-
[h.wallets,
|
|
248
|
-
),
|
|
249
|
-
() =>
|
|
250
|
-
[
|
|
251
|
-
),
|
|
252
|
-
() =>
|
|
253
|
-
[
|
|
254
|
-
),
|
|
255
|
-
() =>
|
|
256
|
-
[
|
|
257
|
-
),
|
|
258
|
-
() =>
|
|
259
|
-
[
|
|
260
|
-
),
|
|
261
|
-
() =>
|
|
262
|
-
[
|
|
263
|
-
),
|
|
264
|
-
if (!
|
|
265
|
-
return
|
|
266
|
-
const
|
|
267
|
-
return /* @__PURE__ */
|
|
268
|
-
|
|
269
|
-
|
|
248
|
+
}), [l.tokens.surfaceText]), c = G.useMemo(
|
|
249
|
+
() => h.wallets && h.wallets.length > 0 ? h.wallets : m.getAdapters(),
|
|
250
|
+
[h.wallets, m]
|
|
251
|
+
), d = G.useMemo(
|
|
252
|
+
() => t ? Ie(t) : 0,
|
|
253
|
+
[t]
|
|
254
|
+
), n = G.useMemo(
|
|
255
|
+
() => i.onPaymentSuccess ? (k) => i.onPaymentSuccess({ transactionId: k, method: "stripe" }) : void 0,
|
|
256
|
+
[i.onPaymentSuccess]
|
|
257
|
+
), a = G.useMemo(
|
|
258
|
+
() => i.onPaymentSuccess ? (k) => i.onPaymentSuccess({ transactionId: k, method: "crypto" }) : void 0,
|
|
259
|
+
[i.onPaymentSuccess]
|
|
260
|
+
), p = G.useMemo(
|
|
261
|
+
() => i.onPaymentError ? (k) => i.onPaymentError({ message: k, method: "stripe" }) : void 0,
|
|
262
|
+
[i.onPaymentError]
|
|
263
|
+
), C = G.useMemo(
|
|
264
|
+
() => i.onPaymentError ? (k) => i.onPaymentError({ message: k, method: "crypto" }) : void 0,
|
|
265
|
+
[i.onPaymentError]
|
|
266
|
+
), P = x.solanaEndpoint ?? He(x.solanaCluster);
|
|
267
|
+
if (!r && (!t || t.length === 0))
|
|
268
|
+
return D().error('CedrosPay: Must provide either "resource" or "items" prop'), /* @__PURE__ */ u("div", { className: f.className, style: { color: l.tokens.errorText }, children: "Configuration error: No resource or items provided" });
|
|
269
|
+
const y = f.showCard ?? !0, B = f.showCrypto ?? !0, N = f.showPurchaseButton ?? !1, E = f.layout ?? "vertical", I = f.hideMessages ?? !1, v = h.autoDetectWallets ?? !0;
|
|
270
|
+
return /* @__PURE__ */ u("div", { className: l.unstyled ? f.className : l.className, style: l.unstyled ? {} : l.style, children: /* @__PURE__ */ u(De, { endpoint: P, children: /* @__PURE__ */ u(qe, { wallets: c, autoConnect: !1, children: /* @__PURE__ */ u("div", { className: l.unstyled ? f.className : `cedros-theme__pay ${f.className || ""}`, children: /* @__PURE__ */ w("div", { className: l.unstyled ? "" : `cedros-theme__pay-content cedros-theme__pay-content--${E}`, children: [
|
|
271
|
+
N ? /* @__PURE__ */ u(
|
|
272
|
+
Xe,
|
|
270
273
|
{
|
|
271
|
-
resource:
|
|
272
|
-
items:
|
|
273
|
-
label:
|
|
274
|
-
cardLabel:
|
|
275
|
-
cryptoLabel:
|
|
276
|
-
showCard:
|
|
277
|
-
showCrypto:
|
|
278
|
-
onPaymentAttempt:
|
|
279
|
-
onPaymentSuccess:
|
|
280
|
-
onPaymentError:
|
|
281
|
-
onStripeSuccess:
|
|
282
|
-
onCryptoSuccess:
|
|
283
|
-
onStripeError:
|
|
284
|
-
onCryptoError:
|
|
274
|
+
resource: s ? void 0 : r || t?.[0]?.resource,
|
|
275
|
+
items: s ? t : void 0,
|
|
276
|
+
label: f.purchaseLabel,
|
|
277
|
+
cardLabel: f.cardLabel,
|
|
278
|
+
cryptoLabel: f.cryptoLabel,
|
|
279
|
+
showCard: y,
|
|
280
|
+
showCrypto: B,
|
|
281
|
+
onPaymentAttempt: i.onPaymentAttempt,
|
|
282
|
+
onPaymentSuccess: n,
|
|
283
|
+
onPaymentError: p,
|
|
284
|
+
onStripeSuccess: n,
|
|
285
|
+
onCryptoSuccess: a,
|
|
286
|
+
onStripeError: p,
|
|
287
|
+
onCryptoError: C,
|
|
285
288
|
customerEmail: o.customerEmail,
|
|
286
289
|
successUrl: o.successUrl,
|
|
287
290
|
cancelUrl: o.cancelUrl,
|
|
288
291
|
metadata: o.metadata,
|
|
289
292
|
couponCode: o.couponCode,
|
|
290
|
-
autoDetectWallets:
|
|
293
|
+
autoDetectWallets: v,
|
|
291
294
|
testPageUrl: h.testPageUrl,
|
|
292
|
-
hideMessages:
|
|
293
|
-
renderModal:
|
|
295
|
+
hideMessages: I,
|
|
296
|
+
renderModal: f.renderModal
|
|
294
297
|
}
|
|
295
|
-
) : /* @__PURE__ */
|
|
296
|
-
|
|
297
|
-
|
|
298
|
+
) : /* @__PURE__ */ w(me, { children: [
|
|
299
|
+
y && /* @__PURE__ */ u(
|
|
300
|
+
Ue,
|
|
298
301
|
{
|
|
299
|
-
resource:
|
|
300
|
-
items:
|
|
302
|
+
resource: s ? void 0 : r || t?.[0]?.resource,
|
|
303
|
+
items: s ? t : void 0,
|
|
301
304
|
customerEmail: o.customerEmail,
|
|
302
305
|
successUrl: o.successUrl,
|
|
303
306
|
cancelUrl: o.cancelUrl,
|
|
304
307
|
metadata: o.metadata,
|
|
305
308
|
couponCode: o.couponCode,
|
|
306
|
-
label:
|
|
307
|
-
onAttempt:
|
|
308
|
-
onSuccess:
|
|
309
|
-
onError:
|
|
309
|
+
label: f.cardLabel,
|
|
310
|
+
onAttempt: i.onPaymentAttempt,
|
|
311
|
+
onSuccess: n,
|
|
312
|
+
onError: p
|
|
310
313
|
}
|
|
311
314
|
),
|
|
312
|
-
|
|
313
|
-
|
|
315
|
+
B && /* @__PURE__ */ u(
|
|
316
|
+
je,
|
|
314
317
|
{
|
|
315
|
-
resource:
|
|
316
|
-
items:
|
|
318
|
+
resource: s ? void 0 : r || t?.[0]?.resource,
|
|
319
|
+
items: s ? t : void 0,
|
|
317
320
|
metadata: o.metadata,
|
|
318
321
|
couponCode: o.couponCode,
|
|
319
|
-
label:
|
|
320
|
-
onAttempt:
|
|
321
|
-
onSuccess:
|
|
322
|
-
onError:
|
|
322
|
+
label: f.cryptoLabel,
|
|
323
|
+
onAttempt: i.onPaymentAttempt,
|
|
324
|
+
onSuccess: a,
|
|
325
|
+
onError: C,
|
|
323
326
|
testPageUrl: h.testPageUrl,
|
|
324
|
-
hideMessages:
|
|
327
|
+
hideMessages: I
|
|
325
328
|
}
|
|
326
329
|
)
|
|
327
330
|
] }),
|
|
328
|
-
|
|
331
|
+
s && t && t.length > 1 && !I && /* @__PURE__ */ w("div", { style: b, children: [
|
|
329
332
|
"Checking out ",
|
|
330
|
-
|
|
333
|
+
d,
|
|
331
334
|
" items"
|
|
332
335
|
] })
|
|
333
336
|
] }) }) }) }) });
|
|
334
337
|
}
|
|
335
|
-
function
|
|
336
|
-
const {
|
|
338
|
+
function Je() {
|
|
339
|
+
const { subscriptionManager: e } = ee(), [r, t] = U({
|
|
340
|
+
status: "idle",
|
|
341
|
+
error: null,
|
|
342
|
+
sessionId: null,
|
|
343
|
+
subscriptionStatus: null,
|
|
344
|
+
expiresAt: null
|
|
345
|
+
}), o = T(
|
|
346
|
+
async (x) => {
|
|
347
|
+
t((l) => ({
|
|
348
|
+
...l,
|
|
349
|
+
status: "loading",
|
|
350
|
+
error: null
|
|
351
|
+
}));
|
|
352
|
+
const m = await e.processSubscription(x);
|
|
353
|
+
return t((l) => ({
|
|
354
|
+
...l,
|
|
355
|
+
status: m.success ? "success" : "error",
|
|
356
|
+
error: m.success ? null : m.error || "Subscription failed",
|
|
357
|
+
sessionId: m.success && m.transactionId || null
|
|
358
|
+
})), m;
|
|
359
|
+
},
|
|
360
|
+
[e]
|
|
361
|
+
), f = T(
|
|
362
|
+
async (x) => {
|
|
363
|
+
t((m) => ({
|
|
364
|
+
...m,
|
|
365
|
+
status: "checking",
|
|
366
|
+
error: null
|
|
367
|
+
}));
|
|
368
|
+
try {
|
|
369
|
+
const m = await e.checkSubscriptionStatus(x);
|
|
370
|
+
return t((l) => ({
|
|
371
|
+
...l,
|
|
372
|
+
status: m.active ? "success" : "idle",
|
|
373
|
+
subscriptionStatus: m.status,
|
|
374
|
+
expiresAt: m.expiresAt || m.currentPeriodEnd || null
|
|
375
|
+
})), m;
|
|
376
|
+
} catch (m) {
|
|
377
|
+
const l = m instanceof Error ? m.message : "Failed to check subscription status";
|
|
378
|
+
throw t((s) => ({
|
|
379
|
+
...s,
|
|
380
|
+
status: "error",
|
|
381
|
+
error: l
|
|
382
|
+
})), m;
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
[e]
|
|
386
|
+
), i = T(
|
|
387
|
+
async (x, m, l) => {
|
|
388
|
+
t((s) => ({
|
|
389
|
+
...s,
|
|
390
|
+
status: "loading",
|
|
391
|
+
error: null
|
|
392
|
+
}));
|
|
393
|
+
try {
|
|
394
|
+
const s = await e.requestSubscriptionQuote(
|
|
395
|
+
x,
|
|
396
|
+
m,
|
|
397
|
+
l
|
|
398
|
+
);
|
|
399
|
+
return t((b) => ({
|
|
400
|
+
...b,
|
|
401
|
+
status: "idle"
|
|
402
|
+
})), s;
|
|
403
|
+
} catch (s) {
|
|
404
|
+
const b = s instanceof Error ? s.message : "Failed to get subscription quote";
|
|
405
|
+
throw t((c) => ({
|
|
406
|
+
...c,
|
|
407
|
+
status: "error",
|
|
408
|
+
error: b
|
|
409
|
+
})), s;
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
[e]
|
|
413
|
+
), h = T(() => {
|
|
414
|
+
t({
|
|
415
|
+
status: "idle",
|
|
416
|
+
error: null,
|
|
417
|
+
sessionId: null,
|
|
418
|
+
subscriptionStatus: null,
|
|
419
|
+
expiresAt: null
|
|
420
|
+
});
|
|
421
|
+
}, []);
|
|
422
|
+
return {
|
|
423
|
+
...r,
|
|
424
|
+
processSubscription: o,
|
|
425
|
+
checkStatus: f,
|
|
426
|
+
requestQuote: i,
|
|
427
|
+
reset: h
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
function Ct({
|
|
431
|
+
resource: e,
|
|
432
|
+
interval: r,
|
|
433
|
+
intervalDays: t,
|
|
434
|
+
trialDays: o,
|
|
435
|
+
successUrl: f,
|
|
436
|
+
cancelUrl: i,
|
|
437
|
+
metadata: h,
|
|
438
|
+
customerEmail: x,
|
|
439
|
+
couponCode: m,
|
|
440
|
+
label: l,
|
|
441
|
+
disabled: s = !1,
|
|
442
|
+
onAttempt: b,
|
|
443
|
+
onSuccess: c,
|
|
444
|
+
onError: d,
|
|
445
|
+
className: n = ""
|
|
446
|
+
}) {
|
|
447
|
+
const { status: a, error: p, sessionId: C, processSubscription: P } = Je(), y = le(), { t: B, translations: N } = ge(), E = l || B("ui.subscribe"), I = y.unstyled ? n : `${y.className} cedros-theme__stripe-button ${n}`.trim(), v = p && typeof p != "string" ? p?.code ?? null : null, q = p ? typeof p == "string" ? p : ((L) => {
|
|
448
|
+
if (!L || !N) return "";
|
|
449
|
+
const j = N.errors[L];
|
|
450
|
+
return j ? j.action ? `${j.message} ${j.action}` : j.message : "";
|
|
451
|
+
})(v) : null, R = T(async () => {
|
|
452
|
+
D().debug("[SubscribeButton] executeSubscription:", {
|
|
453
|
+
resource: e,
|
|
454
|
+
interval: r,
|
|
455
|
+
intervalDays: t,
|
|
456
|
+
trialDays: o,
|
|
457
|
+
couponCode: m
|
|
458
|
+
}), he("stripe", e), b && b("stripe"), ie("stripe", e);
|
|
459
|
+
const L = await P({
|
|
460
|
+
resource: e,
|
|
461
|
+
interval: r,
|
|
462
|
+
intervalDays: t,
|
|
463
|
+
trialDays: o,
|
|
464
|
+
customerEmail: x,
|
|
465
|
+
metadata: h,
|
|
466
|
+
couponCode: m,
|
|
467
|
+
successUrl: f,
|
|
468
|
+
cancelUrl: i
|
|
469
|
+
});
|
|
470
|
+
L.success && L.transactionId ? (be("stripe", L.transactionId, e), c && c(L.transactionId)) : !L.success && L.error && (ce("stripe", L.error, e), d && d(L.error));
|
|
471
|
+
}, [
|
|
472
|
+
e,
|
|
473
|
+
r,
|
|
474
|
+
t,
|
|
475
|
+
o,
|
|
476
|
+
x,
|
|
477
|
+
h,
|
|
478
|
+
m,
|
|
479
|
+
f,
|
|
480
|
+
i,
|
|
481
|
+
P,
|
|
482
|
+
b,
|
|
483
|
+
c,
|
|
484
|
+
d
|
|
485
|
+
]), $ = F(() => `subscribe-${e}-${r}`, [e, r]), _ = F(
|
|
486
|
+
() => Se($, R),
|
|
487
|
+
[$, R]
|
|
488
|
+
), z = a === "loading", O = s || z;
|
|
489
|
+
return /* @__PURE__ */ w("div", { className: I, style: y.unstyled ? {} : y.style, children: [
|
|
490
|
+
/* @__PURE__ */ u(
|
|
491
|
+
"button",
|
|
492
|
+
{
|
|
493
|
+
onClick: _,
|
|
494
|
+
disabled: O,
|
|
495
|
+
className: y.unstyled ? n : "cedros-theme__button cedros-theme__stripe",
|
|
496
|
+
type: "button",
|
|
497
|
+
children: z ? B("ui.processing") : E
|
|
498
|
+
}
|
|
499
|
+
),
|
|
500
|
+
q && /* @__PURE__ */ u("div", { className: y.unstyled ? "" : "cedros-theme__error", children: q }),
|
|
501
|
+
C && /* @__PURE__ */ u("div", { className: y.unstyled ? "" : "cedros-theme__success", children: B("ui.redirecting_to_checkout") })
|
|
502
|
+
] });
|
|
503
|
+
}
|
|
504
|
+
function Ze() {
|
|
505
|
+
const { subscriptionManager: e, x402Manager: r, walletManager: t } = ee(), { publicKey: o, signTransaction: f } = ye(), [i, h] = U({
|
|
506
|
+
status: "idle",
|
|
507
|
+
error: null,
|
|
508
|
+
sessionId: null,
|
|
509
|
+
subscriptionStatus: null,
|
|
510
|
+
expiresAt: null
|
|
511
|
+
}), [x, m] = U(null), l = T(() => {
|
|
512
|
+
if (!o) {
|
|
513
|
+
const n = "Wallet not connected";
|
|
514
|
+
return h((a) => ({ ...a, status: "error", error: n })), { valid: !1, error: n };
|
|
515
|
+
}
|
|
516
|
+
if (!f) {
|
|
517
|
+
const n = "Wallet does not support signing";
|
|
518
|
+
return h((a) => ({ ...a, status: "error", error: n })), { valid: !1, error: n };
|
|
519
|
+
}
|
|
520
|
+
return { valid: !0 };
|
|
521
|
+
}, [o, f]), s = T(
|
|
522
|
+
async (n) => {
|
|
523
|
+
if (!o)
|
|
524
|
+
return h((a) => ({
|
|
525
|
+
...a,
|
|
526
|
+
status: "error",
|
|
527
|
+
error: "Wallet not connected"
|
|
528
|
+
})), null;
|
|
529
|
+
h((a) => ({
|
|
530
|
+
...a,
|
|
531
|
+
status: "checking",
|
|
532
|
+
error: null
|
|
533
|
+
}));
|
|
534
|
+
try {
|
|
535
|
+
const a = await e.checkSubscriptionStatus({
|
|
536
|
+
resource: n,
|
|
537
|
+
userId: o.toString()
|
|
538
|
+
});
|
|
539
|
+
return h((p) => ({
|
|
540
|
+
...p,
|
|
541
|
+
status: a.active ? "success" : "idle",
|
|
542
|
+
subscriptionStatus: a.status,
|
|
543
|
+
expiresAt: a.expiresAt || a.currentPeriodEnd || null
|
|
544
|
+
})), a;
|
|
545
|
+
} catch (a) {
|
|
546
|
+
const p = Z(a, "Failed to check subscription status");
|
|
547
|
+
return h((C) => ({
|
|
548
|
+
...C,
|
|
549
|
+
status: "error",
|
|
550
|
+
error: p
|
|
551
|
+
})), null;
|
|
552
|
+
}
|
|
553
|
+
},
|
|
554
|
+
[o, e]
|
|
555
|
+
), b = T(
|
|
556
|
+
async (n, a, p) => {
|
|
557
|
+
h((C) => ({
|
|
558
|
+
...C,
|
|
559
|
+
status: "loading",
|
|
560
|
+
error: null
|
|
561
|
+
}));
|
|
562
|
+
try {
|
|
563
|
+
const C = await e.requestSubscriptionQuote(
|
|
564
|
+
n,
|
|
565
|
+
a,
|
|
566
|
+
p
|
|
567
|
+
);
|
|
568
|
+
return m(C), h((P) => ({
|
|
569
|
+
...P,
|
|
570
|
+
status: "idle"
|
|
571
|
+
})), C;
|
|
572
|
+
} catch (C) {
|
|
573
|
+
const P = Z(C, "Failed to get subscription quote");
|
|
574
|
+
return h((y) => ({
|
|
575
|
+
...y,
|
|
576
|
+
status: "error",
|
|
577
|
+
error: P
|
|
578
|
+
})), null;
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
[e]
|
|
582
|
+
), c = T(
|
|
583
|
+
async (n, a, p) => {
|
|
584
|
+
const C = l();
|
|
585
|
+
if (!C.valid)
|
|
586
|
+
return { success: !1, error: C.error };
|
|
587
|
+
h((P) => ({
|
|
588
|
+
...P,
|
|
589
|
+
status: "loading",
|
|
590
|
+
error: null
|
|
591
|
+
}));
|
|
592
|
+
try {
|
|
593
|
+
const P = await e.requestSubscriptionQuote(
|
|
594
|
+
n,
|
|
595
|
+
a,
|
|
596
|
+
p
|
|
597
|
+
);
|
|
598
|
+
m(P);
|
|
599
|
+
const y = P.requirement;
|
|
600
|
+
if (!r.validateRequirement(y))
|
|
601
|
+
throw new Error("Invalid subscription quote received from server");
|
|
602
|
+
const B = !!y.extra?.feePayer;
|
|
603
|
+
let N;
|
|
604
|
+
if (B) {
|
|
605
|
+
const { transaction: E, blockhash: I } = await r.buildGaslessTransaction({
|
|
606
|
+
resourceId: n,
|
|
607
|
+
userWallet: o.toString(),
|
|
608
|
+
feePayer: y.extra.feePayer,
|
|
609
|
+
couponCode: p?.couponCode
|
|
610
|
+
}), v = t.deserializeTransaction(E), k = await t.partiallySignTransaction({
|
|
611
|
+
transaction: v,
|
|
612
|
+
signTransaction: f,
|
|
613
|
+
blockhash: I
|
|
614
|
+
});
|
|
615
|
+
N = await r.submitGaslessTransaction({
|
|
616
|
+
resource: n,
|
|
617
|
+
partialTx: k,
|
|
618
|
+
couponCode: p?.couponCode,
|
|
619
|
+
resourceType: "regular",
|
|
620
|
+
requirement: y
|
|
621
|
+
});
|
|
622
|
+
} else {
|
|
623
|
+
const E = await t.buildTransaction({
|
|
624
|
+
requirement: y,
|
|
625
|
+
payerPublicKey: o
|
|
626
|
+
}), I = await t.signTransaction({
|
|
627
|
+
transaction: E,
|
|
628
|
+
signTransaction: f
|
|
629
|
+
}), v = t.buildPaymentPayload({
|
|
630
|
+
requirement: y,
|
|
631
|
+
signedTx: I,
|
|
632
|
+
payerPublicKey: o
|
|
633
|
+
});
|
|
634
|
+
N = await r.submitPayment({
|
|
635
|
+
resource: n,
|
|
636
|
+
payload: v,
|
|
637
|
+
couponCode: p?.couponCode,
|
|
638
|
+
resourceType: "regular"
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
if (N.success) {
|
|
642
|
+
const E = await e.checkSubscriptionStatus({
|
|
643
|
+
resource: n,
|
|
644
|
+
userId: o.toString()
|
|
645
|
+
});
|
|
646
|
+
h({
|
|
647
|
+
status: "success",
|
|
648
|
+
error: null,
|
|
649
|
+
sessionId: N.transactionId || null,
|
|
650
|
+
subscriptionStatus: E.status,
|
|
651
|
+
expiresAt: E.expiresAt || E.currentPeriodEnd || null
|
|
652
|
+
});
|
|
653
|
+
} else
|
|
654
|
+
h((E) => ({
|
|
655
|
+
...E,
|
|
656
|
+
status: "error",
|
|
657
|
+
error: N.error || "Subscription payment failed"
|
|
658
|
+
}));
|
|
659
|
+
return N;
|
|
660
|
+
} catch (P) {
|
|
661
|
+
const y = Z(P, "Subscription payment failed");
|
|
662
|
+
return h((B) => ({
|
|
663
|
+
...B,
|
|
664
|
+
status: "error",
|
|
665
|
+
error: y
|
|
666
|
+
})), { success: !1, error: y };
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
[
|
|
670
|
+
l,
|
|
671
|
+
e,
|
|
672
|
+
r,
|
|
673
|
+
t,
|
|
674
|
+
o,
|
|
675
|
+
f
|
|
676
|
+
]
|
|
677
|
+
), d = T(() => {
|
|
678
|
+
h({
|
|
679
|
+
status: "idle",
|
|
680
|
+
error: null,
|
|
681
|
+
sessionId: null,
|
|
682
|
+
subscriptionStatus: null,
|
|
683
|
+
expiresAt: null
|
|
684
|
+
}), m(null);
|
|
685
|
+
}, []);
|
|
686
|
+
return {
|
|
687
|
+
...i,
|
|
688
|
+
quote: x,
|
|
689
|
+
checkStatus: s,
|
|
690
|
+
requestQuote: b,
|
|
691
|
+
processPayment: c,
|
|
692
|
+
reset: d
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
function vt({
|
|
696
|
+
resource: e,
|
|
697
|
+
interval: r,
|
|
698
|
+
intervalDays: t,
|
|
699
|
+
couponCode: o,
|
|
700
|
+
label: f,
|
|
701
|
+
disabled: i = !1,
|
|
702
|
+
onAttempt: h,
|
|
703
|
+
onSuccess: x,
|
|
704
|
+
onError: m,
|
|
705
|
+
className: l = "",
|
|
706
|
+
testPageUrl: s,
|
|
707
|
+
hideMessages: b = !1,
|
|
708
|
+
autoCheckStatus: c = !0
|
|
709
|
+
}) {
|
|
710
|
+
const {
|
|
711
|
+
connected: d,
|
|
712
|
+
connecting: n,
|
|
713
|
+
connect: a,
|
|
714
|
+
disconnect: p,
|
|
715
|
+
select: C,
|
|
716
|
+
wallets: P,
|
|
717
|
+
wallet: y,
|
|
718
|
+
publicKey: B
|
|
719
|
+
} = ye(), {
|
|
720
|
+
status: N,
|
|
721
|
+
error: E,
|
|
722
|
+
subscriptionStatus: I,
|
|
723
|
+
expiresAt: v,
|
|
724
|
+
checkStatus: k,
|
|
725
|
+
processPayment: q
|
|
726
|
+
} = Ze(), R = le(), { solanaError: $ } = ee(), { t: _, translations: z } = ge(), O = f || _("ui.subscribe_with_crypto"), L = ke(q), j = ke(k);
|
|
727
|
+
Y(() => {
|
|
728
|
+
L.current = q, j.current = k;
|
|
729
|
+
}, [q, k]);
|
|
730
|
+
const ue = E && typeof E != "string" ? E?.code ?? null : null, re = $ && typeof $ != "string" ? $?.code ?? null : null, te = (S) => {
|
|
731
|
+
if (!S || !z) return "";
|
|
732
|
+
const W = z.errors[S];
|
|
733
|
+
return W ? W.action ? `${W.message} ${W.action}` : W.message : "";
|
|
734
|
+
}, ne = E ? typeof E == "string" ? E : te(ue) : null, H = $ ? typeof $ == "string" ? $ : te(re) : null, se = F(
|
|
735
|
+
() => P.map((S) => `${S.adapter.name}-${S.readyState}`).join(","),
|
|
736
|
+
[P]
|
|
737
|
+
), A = F(
|
|
738
|
+
() => P.filter(
|
|
739
|
+
({ readyState: S }) => S === Ee.Installed || S === Ee.Loadable
|
|
740
|
+
),
|
|
741
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
742
|
+
[se]
|
|
743
|
+
);
|
|
744
|
+
Y(() => {
|
|
745
|
+
c && d && B && (D().debug("[CryptoSubscribeButton] Auto-checking subscription status"), j.current(e));
|
|
746
|
+
}, [c, d, B, e]), Y(() => {
|
|
747
|
+
N === "success" && I === "active" && (be("crypto", "subscription-active", e), x && x("subscription-active"));
|
|
748
|
+
}, [N, I, e, x]), Y(() => {
|
|
749
|
+
N === "error" && E && (ce("crypto", E, e), m && m(E));
|
|
750
|
+
}, [N, E, e, m]);
|
|
751
|
+
const K = typeof window < "u" && window.top !== window.self, [Q, M] = U(!1), [we, de] = U(!1), [Ce, X] = U(!1), J = $;
|
|
752
|
+
Y(() => {
|
|
753
|
+
let S = !1;
|
|
754
|
+
return S || (async () => {
|
|
755
|
+
if (we && y && !d && !n) {
|
|
756
|
+
D().debug(
|
|
757
|
+
"[CryptoSubscribeButton] Wallet detected, attempting auto-connect:",
|
|
758
|
+
y.adapter.name
|
|
759
|
+
), de(!1), Te(y.adapter.name);
|
|
760
|
+
try {
|
|
761
|
+
await a(), S || D().debug("[CryptoSubscribeButton] Auto-connect successful");
|
|
762
|
+
} catch (pe) {
|
|
763
|
+
if (!S) {
|
|
764
|
+
D().error("[CryptoSubscribeButton] Auto-connect failed:", pe);
|
|
765
|
+
const Le = pe instanceof Error ? pe.message : "Failed to connect wallet";
|
|
766
|
+
fe(Le, y.adapter.name), X(!1);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
})(), () => {
|
|
771
|
+
S = !0;
|
|
772
|
+
};
|
|
773
|
+
}, [y, we, d, n, a]), Y(() => {
|
|
774
|
+
d && Ce && B && y && (Oe(y.adapter.name, B.toString()), D().debug("[CryptoSubscribeButton] Processing pending subscription payment"), X(!1), M(!1), ie("crypto", e), L.current(e, r, { couponCode: o, intervalDays: t }));
|
|
775
|
+
}, [d, Ce, B, y, e, r, o, t]);
|
|
776
|
+
const ve = T(async () => {
|
|
777
|
+
if (D().debug("[CryptoSubscribeButton] executeSubscriptionFlow called", {
|
|
778
|
+
connected: d,
|
|
779
|
+
wallet: y?.adapter.name,
|
|
780
|
+
resource: e,
|
|
781
|
+
interval: r
|
|
782
|
+
}), he("crypto", e), h && h("crypto"), J) {
|
|
783
|
+
D().error("[CryptoSubscribeButton] Solana dependencies missing:", J), ce("crypto", J, e), m && m(J);
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
if (K) {
|
|
787
|
+
const S = s || window.location.href;
|
|
788
|
+
window.open(S, "_blank", "noopener,noreferrer");
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
if (d)
|
|
792
|
+
ie("crypto", e), await q(e, r, { couponCode: o, intervalDays: t });
|
|
793
|
+
else {
|
|
794
|
+
X(!0);
|
|
795
|
+
try {
|
|
796
|
+
if (y)
|
|
797
|
+
D().debug(
|
|
798
|
+
"[CryptoSubscribeButton] Wallet already selected, connecting:",
|
|
799
|
+
y.adapter.name
|
|
800
|
+
), Te(y.adapter.name), await a();
|
|
801
|
+
else {
|
|
802
|
+
if (D().debug("[CryptoSubscribeButton] No wallet selected, showing selector"), A.length === 0) {
|
|
803
|
+
X(!1);
|
|
804
|
+
const S = "No wallets available";
|
|
805
|
+
throw fe(S), new Error(S);
|
|
806
|
+
}
|
|
807
|
+
M(!0);
|
|
808
|
+
}
|
|
809
|
+
} catch (S) {
|
|
810
|
+
X(!1);
|
|
811
|
+
const W = S instanceof Error ? S.message : "Failed to connect wallet";
|
|
812
|
+
D().error("[CryptoSubscribeButton] Connection error:", W), fe(W, y?.adapter.name);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}, [
|
|
816
|
+
d,
|
|
817
|
+
y,
|
|
818
|
+
e,
|
|
819
|
+
r,
|
|
820
|
+
o,
|
|
821
|
+
t,
|
|
822
|
+
K,
|
|
823
|
+
s,
|
|
824
|
+
A,
|
|
825
|
+
a,
|
|
826
|
+
q,
|
|
827
|
+
J,
|
|
828
|
+
h,
|
|
829
|
+
m
|
|
830
|
+
]), xe = F(() => `crypto-subscribe-${e}-${r}`, [e, r]), Ne = F(
|
|
831
|
+
() => Se(xe, ve, {
|
|
832
|
+
cooldownMs: 200,
|
|
833
|
+
deduplicationWindowMs: 0
|
|
834
|
+
}),
|
|
835
|
+
[xe, ve]
|
|
836
|
+
), Pe = N === "loading" || N === "checking", oe = I === "active" || I === "trialing", Me = i || Pe || n || !!J || oe;
|
|
837
|
+
let ae = O;
|
|
838
|
+
if (Pe)
|
|
839
|
+
ae = _("ui.processing");
|
|
840
|
+
else if (oe && v) {
|
|
841
|
+
const S = new Date(v).toLocaleDateString();
|
|
842
|
+
ae = `${_("ui.subscribed_until")} ${S}`;
|
|
843
|
+
} else oe && (ae = _("ui.subscribed"));
|
|
844
|
+
const _e = T(async () => {
|
|
845
|
+
try {
|
|
846
|
+
de(!1), d && await p(), C(null), M(!0);
|
|
847
|
+
} catch (S) {
|
|
848
|
+
D().error("Failed to change wallet:", S);
|
|
849
|
+
}
|
|
850
|
+
}, [d, p, C]), Ae = T(
|
|
851
|
+
(S) => {
|
|
852
|
+
D().debug("[CryptoSubscribeButton] Wallet clicked:", S), M(!1), C(S), de(!0);
|
|
853
|
+
},
|
|
854
|
+
[C]
|
|
855
|
+
), We = T(async () => {
|
|
856
|
+
try {
|
|
857
|
+
await p(), X(!1), typeof window < "u" && window.localStorage && window.localStorage.removeItem("walletName");
|
|
858
|
+
} catch (S) {
|
|
859
|
+
D().error("Failed to disconnect wallet:", S);
|
|
860
|
+
}
|
|
861
|
+
}, [p]);
|
|
862
|
+
return /* @__PURE__ */ w(
|
|
863
|
+
"div",
|
|
864
|
+
{
|
|
865
|
+
className: R.unstyled ? l : `${R.className} cedros-theme__crypto-button ${l || ""}`,
|
|
866
|
+
style: R.unstyled ? {} : R.style,
|
|
867
|
+
children: [
|
|
868
|
+
/* @__PURE__ */ u(
|
|
869
|
+
"button",
|
|
870
|
+
{
|
|
871
|
+
onClick: Ne,
|
|
872
|
+
disabled: Me,
|
|
873
|
+
className: R.unstyled ? l : "cedros-theme__button cedros-theme__crypto",
|
|
874
|
+
type: "button",
|
|
875
|
+
children: ae
|
|
876
|
+
}
|
|
877
|
+
),
|
|
878
|
+
Q && !b && /* @__PURE__ */ u(
|
|
879
|
+
"div",
|
|
880
|
+
{
|
|
881
|
+
className: "cedros-modal-overlay",
|
|
882
|
+
style: {
|
|
883
|
+
position: "fixed",
|
|
884
|
+
top: 0,
|
|
885
|
+
left: 0,
|
|
886
|
+
right: 0,
|
|
887
|
+
bottom: 0,
|
|
888
|
+
backgroundColor: R.tokens.modalOverlay,
|
|
889
|
+
display: "flex",
|
|
890
|
+
alignItems: "center",
|
|
891
|
+
justifyContent: "center",
|
|
892
|
+
zIndex: 9999,
|
|
893
|
+
padding: "1rem"
|
|
894
|
+
},
|
|
895
|
+
onClick: () => M(!1),
|
|
896
|
+
children: /* @__PURE__ */ w(
|
|
897
|
+
"div",
|
|
898
|
+
{
|
|
899
|
+
className: "cedros-modal-content",
|
|
900
|
+
style: {
|
|
901
|
+
backgroundColor: R.tokens.modalBackground,
|
|
902
|
+
borderRadius: "12px",
|
|
903
|
+
padding: "2rem",
|
|
904
|
+
maxWidth: "400px",
|
|
905
|
+
width: "100%",
|
|
906
|
+
boxShadow: "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",
|
|
907
|
+
border: `1px solid ${R.tokens.modalBorder}`
|
|
908
|
+
},
|
|
909
|
+
onClick: (S) => S.stopPropagation(),
|
|
910
|
+
children: [
|
|
911
|
+
/* @__PURE__ */ w(
|
|
912
|
+
"div",
|
|
913
|
+
{
|
|
914
|
+
style: {
|
|
915
|
+
display: "flex",
|
|
916
|
+
justifyContent: "space-between",
|
|
917
|
+
alignItems: "center",
|
|
918
|
+
marginBottom: "1.5rem"
|
|
919
|
+
},
|
|
920
|
+
children: [
|
|
921
|
+
/* @__PURE__ */ u(
|
|
922
|
+
"h3",
|
|
923
|
+
{
|
|
924
|
+
style: {
|
|
925
|
+
margin: 0,
|
|
926
|
+
fontSize: "1.25rem",
|
|
927
|
+
fontWeight: 600,
|
|
928
|
+
color: R.tokens.surfaceText
|
|
929
|
+
},
|
|
930
|
+
children: _("wallet.select_wallet")
|
|
931
|
+
}
|
|
932
|
+
),
|
|
933
|
+
/* @__PURE__ */ u(
|
|
934
|
+
"button",
|
|
935
|
+
{
|
|
936
|
+
onClick: () => M(!1),
|
|
937
|
+
style: Fe(R.tokens.surfaceText),
|
|
938
|
+
"aria-label": "Close modal",
|
|
939
|
+
type: "button",
|
|
940
|
+
children: "×"
|
|
941
|
+
}
|
|
942
|
+
)
|
|
943
|
+
]
|
|
944
|
+
}
|
|
945
|
+
),
|
|
946
|
+
/* @__PURE__ */ u("div", { style: { display: "flex", flexDirection: "column", gap: "0.75rem" }, children: A.map((S) => /* @__PURE__ */ w(
|
|
947
|
+
"button",
|
|
948
|
+
{
|
|
949
|
+
onClick: () => Ae(S.adapter.name),
|
|
950
|
+
style: {
|
|
951
|
+
width: "100%",
|
|
952
|
+
padding: "1rem",
|
|
953
|
+
backgroundColor: R.tokens.surfaceBackground,
|
|
954
|
+
border: `1px solid ${R.tokens.surfaceBorder}`,
|
|
955
|
+
borderRadius: "0.5rem",
|
|
956
|
+
cursor: "pointer",
|
|
957
|
+
fontSize: "1rem",
|
|
958
|
+
textAlign: "left",
|
|
959
|
+
color: R.tokens.surfaceText,
|
|
960
|
+
display: "flex",
|
|
961
|
+
alignItems: "center",
|
|
962
|
+
gap: "1rem",
|
|
963
|
+
transition: "all 0.2s ease"
|
|
964
|
+
},
|
|
965
|
+
onMouseEnter: (W) => {
|
|
966
|
+
W.currentTarget.style.backgroundColor = R.tokens.modalBackground, W.currentTarget.style.borderColor = R.tokens.surfaceText, W.currentTarget.style.transform = "translateY(-2px)";
|
|
967
|
+
},
|
|
968
|
+
onMouseLeave: (W) => {
|
|
969
|
+
W.currentTarget.style.backgroundColor = R.tokens.surfaceBackground, W.currentTarget.style.borderColor = R.tokens.surfaceBorder, W.currentTarget.style.transform = "translateY(0)";
|
|
970
|
+
},
|
|
971
|
+
type: "button",
|
|
972
|
+
children: [
|
|
973
|
+
/* @__PURE__ */ u(Ke, { wallet: S, style: { width: "24px", height: "24px" } }),
|
|
974
|
+
/* @__PURE__ */ u("span", { style: { fontWeight: 500 }, children: S.adapter.name })
|
|
975
|
+
]
|
|
976
|
+
},
|
|
977
|
+
S.adapter.name
|
|
978
|
+
)) })
|
|
979
|
+
]
|
|
980
|
+
}
|
|
981
|
+
)
|
|
982
|
+
}
|
|
983
|
+
),
|
|
984
|
+
d && !b && !Q && /* @__PURE__ */ w(
|
|
985
|
+
"div",
|
|
986
|
+
{
|
|
987
|
+
style: {
|
|
988
|
+
display: "flex",
|
|
989
|
+
justifyContent: "space-between",
|
|
990
|
+
marginTop: "0.5rem",
|
|
991
|
+
fontSize: "0.75rem",
|
|
992
|
+
color: R.tokens.surfaceText,
|
|
993
|
+
opacity: 0.7
|
|
994
|
+
},
|
|
995
|
+
children: [
|
|
996
|
+
/* @__PURE__ */ u(
|
|
997
|
+
"button",
|
|
998
|
+
{
|
|
999
|
+
onClick: _e,
|
|
1000
|
+
style: {
|
|
1001
|
+
background: "none",
|
|
1002
|
+
border: "none",
|
|
1003
|
+
padding: 0,
|
|
1004
|
+
color: "inherit",
|
|
1005
|
+
textDecoration: "none",
|
|
1006
|
+
cursor: "pointer",
|
|
1007
|
+
fontSize: "inherit"
|
|
1008
|
+
},
|
|
1009
|
+
type: "button",
|
|
1010
|
+
children: _("wallet.change")
|
|
1011
|
+
}
|
|
1012
|
+
),
|
|
1013
|
+
/* @__PURE__ */ u(
|
|
1014
|
+
"button",
|
|
1015
|
+
{
|
|
1016
|
+
onClick: We,
|
|
1017
|
+
style: {
|
|
1018
|
+
background: "none",
|
|
1019
|
+
border: "none",
|
|
1020
|
+
padding: 0,
|
|
1021
|
+
color: "inherit",
|
|
1022
|
+
textDecoration: "none",
|
|
1023
|
+
cursor: "pointer",
|
|
1024
|
+
fontSize: "inherit"
|
|
1025
|
+
},
|
|
1026
|
+
type: "button",
|
|
1027
|
+
children: _("ui.disconnect")
|
|
1028
|
+
}
|
|
1029
|
+
)
|
|
1030
|
+
]
|
|
1031
|
+
}
|
|
1032
|
+
),
|
|
1033
|
+
!b && H && /* @__PURE__ */ u("div", { className: R.unstyled ? "" : "cedros-theme__error", children: H }),
|
|
1034
|
+
!b && ne && /* @__PURE__ */ u("div", { className: R.unstyled ? "" : "cedros-theme__error", children: ne }),
|
|
1035
|
+
!b && oe && /* @__PURE__ */ u("div", { className: R.unstyled ? "" : "cedros-theme__success", children: _("ui.subscription_active") })
|
|
1036
|
+
]
|
|
1037
|
+
}
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
function et() {
|
|
1041
|
+
const { subscriptionChangeManager: e } = ee(), [r, t] = U({
|
|
1042
|
+
status: "idle",
|
|
1043
|
+
error: null,
|
|
1044
|
+
subscription: null,
|
|
1045
|
+
changePreview: null
|
|
1046
|
+
}), o = T(
|
|
1047
|
+
async (s, b) => {
|
|
1048
|
+
t((c) => ({ ...c, status: "loading", error: null }));
|
|
1049
|
+
try {
|
|
1050
|
+
const c = await e.getDetails(s, b);
|
|
1051
|
+
return t((d) => ({
|
|
1052
|
+
...d,
|
|
1053
|
+
status: "success",
|
|
1054
|
+
subscription: c
|
|
1055
|
+
})), c;
|
|
1056
|
+
} catch (c) {
|
|
1057
|
+
const d = c instanceof Error ? c.message : "Failed to load subscription";
|
|
1058
|
+
return t((n) => ({ ...n, status: "error", error: d })), null;
|
|
1059
|
+
}
|
|
1060
|
+
},
|
|
1061
|
+
[e]
|
|
1062
|
+
), f = T(
|
|
1063
|
+
async (s, b, c, d) => {
|
|
1064
|
+
t((n) => ({ ...n, status: "loading", error: null }));
|
|
1065
|
+
try {
|
|
1066
|
+
const n = {
|
|
1067
|
+
currentResource: s,
|
|
1068
|
+
newResource: b,
|
|
1069
|
+
userId: c,
|
|
1070
|
+
newInterval: d
|
|
1071
|
+
}, a = await e.previewChange(n);
|
|
1072
|
+
return t((p) => ({
|
|
1073
|
+
...p,
|
|
1074
|
+
status: "idle",
|
|
1075
|
+
changePreview: a
|
|
1076
|
+
})), a;
|
|
1077
|
+
} catch (n) {
|
|
1078
|
+
const a = n instanceof Error ? n.message : "Failed to preview change";
|
|
1079
|
+
return t((p) => ({ ...p, status: "error", error: a })), null;
|
|
1080
|
+
}
|
|
1081
|
+
},
|
|
1082
|
+
[e]
|
|
1083
|
+
), i = T(
|
|
1084
|
+
async (s) => {
|
|
1085
|
+
const { subscription: b } = r;
|
|
1086
|
+
if (!b)
|
|
1087
|
+
return t((c) => ({ ...c, status: "error", error: "No subscription loaded" })), null;
|
|
1088
|
+
t((c) => ({ ...c, status: "loading", error: null }));
|
|
1089
|
+
try {
|
|
1090
|
+
const c = {
|
|
1091
|
+
currentResource: b.resource,
|
|
1092
|
+
newResource: s.newResource,
|
|
1093
|
+
userId: b.id,
|
|
1094
|
+
// Use subscription ID as user identifier
|
|
1095
|
+
newInterval: s.newInterval,
|
|
1096
|
+
prorationBehavior: s.prorationBehavior,
|
|
1097
|
+
immediate: s.immediate
|
|
1098
|
+
}, d = await e.changeSubscription(c);
|
|
1099
|
+
return d.success ? t((n) => ({
|
|
1100
|
+
...n,
|
|
1101
|
+
status: "success",
|
|
1102
|
+
subscription: n.subscription ? {
|
|
1103
|
+
...n.subscription,
|
|
1104
|
+
resource: d.newResource,
|
|
1105
|
+
interval: d.newInterval,
|
|
1106
|
+
status: d.status
|
|
1107
|
+
} : null,
|
|
1108
|
+
changePreview: null
|
|
1109
|
+
})) : t((n) => ({
|
|
1110
|
+
...n,
|
|
1111
|
+
status: "error",
|
|
1112
|
+
error: d.error || "Failed to change subscription"
|
|
1113
|
+
})), d;
|
|
1114
|
+
} catch (c) {
|
|
1115
|
+
const d = c instanceof Error ? c.message : "Failed to change subscription";
|
|
1116
|
+
return t((n) => ({ ...n, status: "error", error: d })), null;
|
|
1117
|
+
}
|
|
1118
|
+
},
|
|
1119
|
+
[e, r.subscription]
|
|
1120
|
+
), h = T(
|
|
1121
|
+
async (s) => {
|
|
1122
|
+
const { subscription: b } = r;
|
|
1123
|
+
if (!b)
|
|
1124
|
+
return t((c) => ({ ...c, status: "error", error: "No subscription loaded" })), null;
|
|
1125
|
+
t((c) => ({ ...c, status: "loading", error: null }));
|
|
1126
|
+
try {
|
|
1127
|
+
const c = {
|
|
1128
|
+
resource: b.resource,
|
|
1129
|
+
userId: b.id,
|
|
1130
|
+
immediate: s
|
|
1131
|
+
}, d = await e.cancel(c);
|
|
1132
|
+
if (d.success) {
|
|
1133
|
+
const n = s ? "canceled" : b.status;
|
|
1134
|
+
t((a) => ({
|
|
1135
|
+
...a,
|
|
1136
|
+
status: "success",
|
|
1137
|
+
subscription: a.subscription ? {
|
|
1138
|
+
...a.subscription,
|
|
1139
|
+
status: n,
|
|
1140
|
+
cancelAtPeriodEnd: !s
|
|
1141
|
+
} : null
|
|
1142
|
+
}));
|
|
1143
|
+
} else
|
|
1144
|
+
t((n) => ({
|
|
1145
|
+
...n,
|
|
1146
|
+
status: "error",
|
|
1147
|
+
error: d.error || "Failed to cancel subscription"
|
|
1148
|
+
}));
|
|
1149
|
+
return d;
|
|
1150
|
+
} catch (c) {
|
|
1151
|
+
const d = c instanceof Error ? c.message : "Failed to cancel subscription";
|
|
1152
|
+
return t((n) => ({ ...n, status: "error", error: d })), null;
|
|
1153
|
+
}
|
|
1154
|
+
},
|
|
1155
|
+
[e, r.subscription]
|
|
1156
|
+
), x = T(
|
|
1157
|
+
async (s, b) => {
|
|
1158
|
+
t((c) => ({ ...c, status: "loading", error: null }));
|
|
1159
|
+
try {
|
|
1160
|
+
const c = await e.getBillingPortalUrl({
|
|
1161
|
+
userId: s,
|
|
1162
|
+
returnUrl: b
|
|
1163
|
+
});
|
|
1164
|
+
return window.location.href = c.url, c;
|
|
1165
|
+
} catch (c) {
|
|
1166
|
+
const d = c instanceof Error ? c.message : "Failed to open billing portal";
|
|
1167
|
+
return t((n) => ({ ...n, status: "error", error: d })), null;
|
|
1168
|
+
}
|
|
1169
|
+
},
|
|
1170
|
+
[e]
|
|
1171
|
+
), m = T(() => {
|
|
1172
|
+
t((s) => ({ ...s, changePreview: null }));
|
|
1173
|
+
}, []), l = T(() => {
|
|
1174
|
+
t({
|
|
1175
|
+
status: "idle",
|
|
1176
|
+
error: null,
|
|
1177
|
+
subscription: null,
|
|
1178
|
+
changePreview: null
|
|
1179
|
+
});
|
|
1180
|
+
}, []);
|
|
1181
|
+
return {
|
|
1182
|
+
...r,
|
|
1183
|
+
loadSubscription: o,
|
|
1184
|
+
previewChange: f,
|
|
1185
|
+
changeSubscription: i,
|
|
1186
|
+
cancelSubscription: h,
|
|
1187
|
+
openBillingPortal: x,
|
|
1188
|
+
clearPreview: m,
|
|
1189
|
+
reset: l
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
const g = {
|
|
1193
|
+
container: {
|
|
1194
|
+
padding: "24px",
|
|
1195
|
+
backgroundColor: "#fff",
|
|
1196
|
+
borderRadius: "8px",
|
|
1197
|
+
border: "1px solid #e5e7eb",
|
|
1198
|
+
fontFamily: "system-ui, -apple-system, sans-serif"
|
|
1199
|
+
},
|
|
1200
|
+
error: {
|
|
1201
|
+
padding: "12px 16px",
|
|
1202
|
+
backgroundColor: "#fef2f2",
|
|
1203
|
+
border: "1px solid #fecaca",
|
|
1204
|
+
borderRadius: "6px",
|
|
1205
|
+
color: "#dc2626",
|
|
1206
|
+
marginBottom: "16px"
|
|
1207
|
+
},
|
|
1208
|
+
loading: {
|
|
1209
|
+
padding: "24px",
|
|
1210
|
+
textAlign: "center",
|
|
1211
|
+
color: "#6b7280"
|
|
1212
|
+
},
|
|
1213
|
+
details: {
|
|
1214
|
+
marginBottom: "24px"
|
|
1215
|
+
},
|
|
1216
|
+
title: {
|
|
1217
|
+
margin: "0 0 16px 0",
|
|
1218
|
+
fontSize: "18px",
|
|
1219
|
+
fontWeight: 600,
|
|
1220
|
+
color: "#111827"
|
|
1221
|
+
},
|
|
1222
|
+
detailRow: {
|
|
1223
|
+
display: "flex",
|
|
1224
|
+
justifyContent: "space-between",
|
|
1225
|
+
alignItems: "center",
|
|
1226
|
+
padding: "8px 0",
|
|
1227
|
+
borderBottom: "1px solid #f3f4f6"
|
|
1228
|
+
},
|
|
1229
|
+
label: {
|
|
1230
|
+
color: "#6b7280",
|
|
1231
|
+
fontSize: "14px"
|
|
1232
|
+
},
|
|
1233
|
+
value: {
|
|
1234
|
+
color: "#111827",
|
|
1235
|
+
fontSize: "14px",
|
|
1236
|
+
fontWeight: 500
|
|
1237
|
+
},
|
|
1238
|
+
statusBadge: {
|
|
1239
|
+
padding: "4px 8px",
|
|
1240
|
+
borderRadius: "4px",
|
|
1241
|
+
color: "#fff",
|
|
1242
|
+
fontSize: "12px",
|
|
1243
|
+
fontWeight: 500,
|
|
1244
|
+
textTransform: "capitalize"
|
|
1245
|
+
},
|
|
1246
|
+
cancelNotice: {
|
|
1247
|
+
marginTop: "12px",
|
|
1248
|
+
padding: "8px 12px",
|
|
1249
|
+
backgroundColor: "#fef3c7",
|
|
1250
|
+
border: "1px solid #fcd34d",
|
|
1251
|
+
borderRadius: "6px",
|
|
1252
|
+
color: "#92400e",
|
|
1253
|
+
fontSize: "13px"
|
|
1254
|
+
},
|
|
1255
|
+
prorationPreview: {
|
|
1256
|
+
padding: "16px",
|
|
1257
|
+
backgroundColor: "#f9fafb",
|
|
1258
|
+
borderRadius: "8px",
|
|
1259
|
+
marginBottom: "24px"
|
|
1260
|
+
},
|
|
1261
|
+
previewTitle: {
|
|
1262
|
+
margin: "0 0 12px 0",
|
|
1263
|
+
fontSize: "16px",
|
|
1264
|
+
fontWeight: 600,
|
|
1265
|
+
color: "#111827"
|
|
1266
|
+
},
|
|
1267
|
+
previewDetails: {
|
|
1268
|
+
marginBottom: "16px"
|
|
1269
|
+
},
|
|
1270
|
+
previewRow: {
|
|
1271
|
+
display: "flex",
|
|
1272
|
+
justifyContent: "space-between",
|
|
1273
|
+
padding: "6px 0",
|
|
1274
|
+
fontSize: "14px",
|
|
1275
|
+
color: "#4b5563"
|
|
1276
|
+
},
|
|
1277
|
+
previewTotal: {
|
|
1278
|
+
borderTop: "1px solid #e5e7eb",
|
|
1279
|
+
marginTop: "8px",
|
|
1280
|
+
paddingTop: "12px",
|
|
1281
|
+
fontWeight: 600,
|
|
1282
|
+
color: "#111827"
|
|
1283
|
+
},
|
|
1284
|
+
previewActions: {
|
|
1285
|
+
display: "flex",
|
|
1286
|
+
gap: "12px",
|
|
1287
|
+
justifyContent: "flex-end"
|
|
1288
|
+
},
|
|
1289
|
+
cancelButton: {
|
|
1290
|
+
padding: "8px 16px",
|
|
1291
|
+
backgroundColor: "#fff",
|
|
1292
|
+
border: "1px solid #d1d5db",
|
|
1293
|
+
borderRadius: "6px",
|
|
1294
|
+
color: "#374151",
|
|
1295
|
+
cursor: "pointer",
|
|
1296
|
+
fontSize: "14px"
|
|
1297
|
+
},
|
|
1298
|
+
confirmButton: {
|
|
1299
|
+
padding: "8px 16px",
|
|
1300
|
+
backgroundColor: "#3b82f6",
|
|
1301
|
+
border: "none",
|
|
1302
|
+
borderRadius: "6px",
|
|
1303
|
+
color: "#fff",
|
|
1304
|
+
cursor: "pointer",
|
|
1305
|
+
fontSize: "14px",
|
|
1306
|
+
fontWeight: 500
|
|
1307
|
+
},
|
|
1308
|
+
plansSection: {
|
|
1309
|
+
marginBottom: "24px"
|
|
1310
|
+
},
|
|
1311
|
+
plansTitle: {
|
|
1312
|
+
margin: "0 0 12px 0",
|
|
1313
|
+
fontSize: "16px",
|
|
1314
|
+
fontWeight: 600,
|
|
1315
|
+
color: "#111827"
|
|
1316
|
+
},
|
|
1317
|
+
plansList: {
|
|
1318
|
+
display: "grid",
|
|
1319
|
+
gridTemplateColumns: "repeat(auto-fit, minmax(200px, 1fr))",
|
|
1320
|
+
gap: "16px"
|
|
1321
|
+
},
|
|
1322
|
+
planCard: {
|
|
1323
|
+
padding: "16px",
|
|
1324
|
+
backgroundColor: "#fff",
|
|
1325
|
+
border: "1px solid #e5e7eb",
|
|
1326
|
+
borderRadius: "8px",
|
|
1327
|
+
textAlign: "center"
|
|
1328
|
+
},
|
|
1329
|
+
currentPlan: {
|
|
1330
|
+
borderColor: "#3b82f6",
|
|
1331
|
+
backgroundColor: "#eff6ff"
|
|
1332
|
+
},
|
|
1333
|
+
planName: {
|
|
1334
|
+
fontSize: "16px",
|
|
1335
|
+
fontWeight: 600,
|
|
1336
|
+
color: "#111827",
|
|
1337
|
+
marginBottom: "4px"
|
|
1338
|
+
},
|
|
1339
|
+
planPrice: {
|
|
1340
|
+
fontSize: "14px",
|
|
1341
|
+
color: "#6b7280",
|
|
1342
|
+
marginBottom: "8px"
|
|
1343
|
+
},
|
|
1344
|
+
planDescription: {
|
|
1345
|
+
fontSize: "12px",
|
|
1346
|
+
color: "#9ca3af",
|
|
1347
|
+
marginBottom: "12px"
|
|
1348
|
+
},
|
|
1349
|
+
currentBadge: {
|
|
1350
|
+
display: "inline-block",
|
|
1351
|
+
padding: "4px 8px",
|
|
1352
|
+
backgroundColor: "#3b82f6",
|
|
1353
|
+
color: "#fff",
|
|
1354
|
+
borderRadius: "4px",
|
|
1355
|
+
fontSize: "12px",
|
|
1356
|
+
fontWeight: 500
|
|
1357
|
+
},
|
|
1358
|
+
changePlanButton: {
|
|
1359
|
+
padding: "8px 16px",
|
|
1360
|
+
backgroundColor: "#f3f4f6",
|
|
1361
|
+
border: "1px solid #d1d5db",
|
|
1362
|
+
borderRadius: "6px",
|
|
1363
|
+
color: "#374151",
|
|
1364
|
+
cursor: "pointer",
|
|
1365
|
+
fontSize: "14px",
|
|
1366
|
+
width: "100%"
|
|
1367
|
+
},
|
|
1368
|
+
actions: {
|
|
1369
|
+
display: "flex",
|
|
1370
|
+
gap: "12px",
|
|
1371
|
+
justifyContent: "flex-end",
|
|
1372
|
+
paddingTop: "16px",
|
|
1373
|
+
borderTop: "1px solid #e5e7eb"
|
|
1374
|
+
},
|
|
1375
|
+
portalButton: {
|
|
1376
|
+
padding: "10px 20px",
|
|
1377
|
+
backgroundColor: "#3b82f6",
|
|
1378
|
+
border: "none",
|
|
1379
|
+
borderRadius: "6px",
|
|
1380
|
+
color: "#fff",
|
|
1381
|
+
cursor: "pointer",
|
|
1382
|
+
fontSize: "14px",
|
|
1383
|
+
fontWeight: 500
|
|
1384
|
+
},
|
|
1385
|
+
cancelSubscriptionButton: {
|
|
1386
|
+
padding: "10px 20px",
|
|
1387
|
+
backgroundColor: "#fff",
|
|
1388
|
+
border: "1px solid #ef4444",
|
|
1389
|
+
borderRadius: "6px",
|
|
1390
|
+
color: "#ef4444",
|
|
1391
|
+
cursor: "pointer",
|
|
1392
|
+
fontSize: "14px"
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
function V(e, r) {
|
|
1396
|
+
return new Intl.NumberFormat("en-US", {
|
|
1397
|
+
style: "currency",
|
|
1398
|
+
currency: r.toUpperCase()
|
|
1399
|
+
}).format(e / 100);
|
|
1400
|
+
}
|
|
1401
|
+
function Be(e) {
|
|
1402
|
+
return new Date(e).toLocaleDateString("en-US", {
|
|
1403
|
+
year: "numeric",
|
|
1404
|
+
month: "long",
|
|
1405
|
+
day: "numeric"
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
function tt(e) {
|
|
1409
|
+
switch (e) {
|
|
1410
|
+
case "active":
|
|
1411
|
+
return "#22c55e";
|
|
1412
|
+
case "trialing":
|
|
1413
|
+
return "#3b82f6";
|
|
1414
|
+
case "past_due":
|
|
1415
|
+
return "#f59e0b";
|
|
1416
|
+
case "canceled":
|
|
1417
|
+
case "expired":
|
|
1418
|
+
return "#ef4444";
|
|
1419
|
+
default:
|
|
1420
|
+
return "#6b7280";
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
function rt({
|
|
1424
|
+
preview: e,
|
|
1425
|
+
onConfirm: r,
|
|
1426
|
+
onCancel: t,
|
|
1427
|
+
isLoading: o
|
|
1428
|
+
}) {
|
|
1429
|
+
const f = e.immediateAmount < 0;
|
|
1430
|
+
return /* @__PURE__ */ w("div", { className: "cedros-proration-preview", style: g.prorationPreview, children: [
|
|
1431
|
+
/* @__PURE__ */ u("h4", { style: g.previewTitle, children: "Change Preview" }),
|
|
1432
|
+
/* @__PURE__ */ w("div", { style: g.previewDetails, children: [
|
|
1433
|
+
/* @__PURE__ */ w("div", { style: g.previewRow, children: [
|
|
1434
|
+
/* @__PURE__ */ u("span", { children: "Current plan:" }),
|
|
1435
|
+
/* @__PURE__ */ w("span", { children: [
|
|
1436
|
+
V(e.currentPlanPrice, e.currency),
|
|
1437
|
+
"/period"
|
|
1438
|
+
] })
|
|
1439
|
+
] }),
|
|
1440
|
+
/* @__PURE__ */ w("div", { style: g.previewRow, children: [
|
|
1441
|
+
/* @__PURE__ */ u("span", { children: "New plan:" }),
|
|
1442
|
+
/* @__PURE__ */ w("span", { children: [
|
|
1443
|
+
V(e.newPlanPrice, e.currency),
|
|
1444
|
+
"/period"
|
|
1445
|
+
] })
|
|
1446
|
+
] }),
|
|
1447
|
+
/* @__PURE__ */ w("div", { style: g.previewRow, children: [
|
|
1448
|
+
/* @__PURE__ */ u("span", { children: "Days remaining:" }),
|
|
1449
|
+
/* @__PURE__ */ w("span", { children: [
|
|
1450
|
+
e.daysRemaining,
|
|
1451
|
+
" days"
|
|
1452
|
+
] })
|
|
1453
|
+
] }),
|
|
1454
|
+
e.prorationDetails && /* @__PURE__ */ w(me, { children: [
|
|
1455
|
+
/* @__PURE__ */ w("div", { style: g.previewRow, children: [
|
|
1456
|
+
/* @__PURE__ */ u("span", { children: "Unused credit:" }),
|
|
1457
|
+
/* @__PURE__ */ w("span", { children: [
|
|
1458
|
+
"-",
|
|
1459
|
+
V(e.prorationDetails.unusedCredit, e.currency)
|
|
1460
|
+
] })
|
|
1461
|
+
] }),
|
|
1462
|
+
/* @__PURE__ */ w("div", { style: g.previewRow, children: [
|
|
1463
|
+
/* @__PURE__ */ u("span", { children: "New plan cost:" }),
|
|
1464
|
+
/* @__PURE__ */ u("span", { children: V(e.prorationDetails.newPlanCost, e.currency) })
|
|
1465
|
+
] })
|
|
1466
|
+
] }),
|
|
1467
|
+
/* @__PURE__ */ w("div", { style: { ...g.previewRow, ...g.previewTotal }, children: [
|
|
1468
|
+
/* @__PURE__ */ u("span", { children: f ? "Credit to account:" : "Amount due now:" }),
|
|
1469
|
+
/* @__PURE__ */ u("span", { style: { color: f ? "#22c55e" : "#ef4444" }, children: V(Math.abs(e.immediateAmount), e.currency) })
|
|
1470
|
+
] }),
|
|
1471
|
+
/* @__PURE__ */ w("div", { style: g.previewRow, children: [
|
|
1472
|
+
/* @__PURE__ */ u("span", { children: "Effective date:" }),
|
|
1473
|
+
/* @__PURE__ */ u("span", { children: Be(e.effectiveDate) })
|
|
1474
|
+
] })
|
|
1475
|
+
] }),
|
|
1476
|
+
/* @__PURE__ */ w("div", { style: g.previewActions, children: [
|
|
1477
|
+
/* @__PURE__ */ u("button", { onClick: t, style: g.cancelButton, disabled: o, children: "Cancel" }),
|
|
1478
|
+
/* @__PURE__ */ u("button", { onClick: r, style: g.confirmButton, disabled: o, children: o ? "Processing..." : "Confirm Change" })
|
|
1479
|
+
] })
|
|
1480
|
+
] });
|
|
1481
|
+
}
|
|
1482
|
+
function xt({
|
|
1483
|
+
resource: e,
|
|
1484
|
+
userId: r,
|
|
1485
|
+
availablePlans: t = [],
|
|
1486
|
+
onSubscriptionChanged: o,
|
|
1487
|
+
onSubscriptionCanceled: f,
|
|
1488
|
+
billingPortalReturnUrl: i,
|
|
1489
|
+
showBillingPortal: h = !1,
|
|
1490
|
+
className: x,
|
|
1491
|
+
style: m
|
|
1492
|
+
}) {
|
|
1493
|
+
const {
|
|
1494
|
+
subscription: l,
|
|
1495
|
+
changePreview: s,
|
|
1496
|
+
status: b,
|
|
1497
|
+
error: c,
|
|
1498
|
+
loadSubscription: d,
|
|
1499
|
+
previewChange: n,
|
|
1500
|
+
changeSubscription: a,
|
|
1501
|
+
cancelSubscription: p,
|
|
1502
|
+
openBillingPortal: C,
|
|
1503
|
+
clearPreview: P
|
|
1504
|
+
} = et();
|
|
1505
|
+
Y(() => {
|
|
1506
|
+
d(e, r);
|
|
1507
|
+
}, [e, r, d]);
|
|
1508
|
+
const y = T(
|
|
1509
|
+
async (v, k) => {
|
|
1510
|
+
await n(e, v, r, k);
|
|
1511
|
+
},
|
|
1512
|
+
[e, r, n]
|
|
1513
|
+
), B = T(async () => {
|
|
1514
|
+
if (!s) return;
|
|
1515
|
+
const v = t.find(
|
|
1516
|
+
(q) => q.price === s.newPlanPrice && q.currency === s.currency
|
|
1517
|
+
);
|
|
1518
|
+
(await a({
|
|
1519
|
+
newResource: v?.resource || e,
|
|
1520
|
+
newInterval: v?.interval,
|
|
1521
|
+
immediate: !0
|
|
1522
|
+
}))?.success && v && o?.(v.resource, v.interval);
|
|
1523
|
+
}, [s, t, e, a, o]), N = T(
|
|
1524
|
+
async (v) => {
|
|
1525
|
+
(await p(v))?.success && f?.();
|
|
1526
|
+
},
|
|
1527
|
+
[p, f]
|
|
1528
|
+
), E = T(() => {
|
|
1529
|
+
C(r, i);
|
|
1530
|
+
}, [r, i, C]), I = b === "loading";
|
|
1531
|
+
return /* @__PURE__ */ w("div", { className: `cedros-subscription-panel ${x || ""}`, style: { ...g.container, ...m }, children: [
|
|
1532
|
+
c && /* @__PURE__ */ u("div", { className: "cedros-subscription-error", style: g.error, children: c }),
|
|
1533
|
+
I && !l && /* @__PURE__ */ u("div", { className: "cedros-subscription-loading", style: g.loading, children: "Loading subscription..." }),
|
|
1534
|
+
l && /* @__PURE__ */ w(me, { children: [
|
|
1535
|
+
/* @__PURE__ */ w("div", { className: "cedros-subscription-details", style: g.details, children: [
|
|
1536
|
+
/* @__PURE__ */ u("h3", { style: g.title, children: "Current Subscription" }),
|
|
1537
|
+
/* @__PURE__ */ w("div", { style: g.detailRow, children: [
|
|
1538
|
+
/* @__PURE__ */ u("span", { style: g.label, children: "Plan:" }),
|
|
1539
|
+
/* @__PURE__ */ u("span", { style: g.value, children: l.resource })
|
|
1540
|
+
] }),
|
|
1541
|
+
/* @__PURE__ */ w("div", { style: g.detailRow, children: [
|
|
1542
|
+
/* @__PURE__ */ u("span", { style: g.label, children: "Status:" }),
|
|
1543
|
+
/* @__PURE__ */ u(
|
|
1544
|
+
"span",
|
|
1545
|
+
{
|
|
1546
|
+
style: {
|
|
1547
|
+
...g.statusBadge,
|
|
1548
|
+
backgroundColor: tt(l.status)
|
|
1549
|
+
},
|
|
1550
|
+
children: l.status
|
|
1551
|
+
}
|
|
1552
|
+
)
|
|
1553
|
+
] }),
|
|
1554
|
+
/* @__PURE__ */ w("div", { style: g.detailRow, children: [
|
|
1555
|
+
/* @__PURE__ */ u("span", { style: g.label, children: "Price:" }),
|
|
1556
|
+
/* @__PURE__ */ w("span", { style: g.value, children: [
|
|
1557
|
+
V(l.pricePerPeriod, l.currency),
|
|
1558
|
+
"/",
|
|
1559
|
+
l.interval
|
|
1560
|
+
] })
|
|
1561
|
+
] }),
|
|
1562
|
+
/* @__PURE__ */ w("div", { style: g.detailRow, children: [
|
|
1563
|
+
/* @__PURE__ */ u("span", { style: g.label, children: "Current period ends:" }),
|
|
1564
|
+
/* @__PURE__ */ u("span", { style: g.value, children: Be(l.currentPeriodEnd) })
|
|
1565
|
+
] }),
|
|
1566
|
+
l.cancelAtPeriodEnd && /* @__PURE__ */ u("div", { style: g.cancelNotice, children: "Subscription will cancel at end of current period" })
|
|
1567
|
+
] }),
|
|
1568
|
+
s && /* @__PURE__ */ u(
|
|
1569
|
+
rt,
|
|
1570
|
+
{
|
|
1571
|
+
preview: s,
|
|
1572
|
+
onConfirm: B,
|
|
1573
|
+
onCancel: P,
|
|
1574
|
+
isLoading: I
|
|
1575
|
+
}
|
|
1576
|
+
),
|
|
1577
|
+
t.length > 0 && !s && /* @__PURE__ */ w("div", { className: "cedros-available-plans", style: g.plansSection, children: [
|
|
1578
|
+
/* @__PURE__ */ u("h4", { style: g.plansTitle, children: "Available Plans" }),
|
|
1579
|
+
/* @__PURE__ */ u("div", { style: g.plansList, children: t.map((v) => {
|
|
1580
|
+
const k = v.resource === l.resource;
|
|
1581
|
+
return /* @__PURE__ */ w(
|
|
1582
|
+
"div",
|
|
1583
|
+
{
|
|
1584
|
+
style: {
|
|
1585
|
+
...g.planCard,
|
|
1586
|
+
...k ? g.currentPlan : {}
|
|
1587
|
+
},
|
|
1588
|
+
children: [
|
|
1589
|
+
/* @__PURE__ */ u("div", { style: g.planName, children: v.name }),
|
|
1590
|
+
/* @__PURE__ */ w("div", { style: g.planPrice, children: [
|
|
1591
|
+
V(v.price, v.currency),
|
|
1592
|
+
"/",
|
|
1593
|
+
v.interval
|
|
1594
|
+
] }),
|
|
1595
|
+
v.description && /* @__PURE__ */ u("div", { style: g.planDescription, children: v.description }),
|
|
1596
|
+
k ? /* @__PURE__ */ u("span", { style: g.currentBadge, children: "Current Plan" }) : /* @__PURE__ */ u(
|
|
1597
|
+
"button",
|
|
1598
|
+
{
|
|
1599
|
+
onClick: () => y(v.resource, v.interval),
|
|
1600
|
+
style: g.changePlanButton,
|
|
1601
|
+
disabled: I,
|
|
1602
|
+
children: v.price > l.pricePerPeriod ? "Upgrade" : "Downgrade"
|
|
1603
|
+
}
|
|
1604
|
+
)
|
|
1605
|
+
]
|
|
1606
|
+
},
|
|
1607
|
+
v.resource
|
|
1608
|
+
);
|
|
1609
|
+
}) })
|
|
1610
|
+
] }),
|
|
1611
|
+
/* @__PURE__ */ w("div", { className: "cedros-subscription-actions", style: g.actions, children: [
|
|
1612
|
+
h && l.paymentMethod === "stripe" && /* @__PURE__ */ u("button", { onClick: E, style: g.portalButton, disabled: I, children: "Manage Billing" }),
|
|
1613
|
+
l.status === "active" && !l.cancelAtPeriodEnd && /* @__PURE__ */ u(
|
|
1614
|
+
"button",
|
|
1615
|
+
{
|
|
1616
|
+
onClick: () => N(!1),
|
|
1617
|
+
style: g.cancelSubscriptionButton,
|
|
1618
|
+
disabled: I,
|
|
1619
|
+
children: "Cancel Subscription"
|
|
1620
|
+
}
|
|
1621
|
+
)
|
|
1622
|
+
] })
|
|
1623
|
+
] })
|
|
1624
|
+
] });
|
|
1625
|
+
}
|
|
1626
|
+
function Pt() {
|
|
1627
|
+
const { x402Manager: e, walletManager: r } = ee(), { publicKey: t, signTransaction: o } = ye(), [f, i] = U({
|
|
337
1628
|
status: "idle",
|
|
338
1629
|
error: null,
|
|
339
1630
|
transactionId: null
|
|
340
|
-
}), [h,
|
|
341
|
-
async (
|
|
1631
|
+
}), [h, x] = U(null), [m, l] = U(null), s = T(
|
|
1632
|
+
async (n) => {
|
|
342
1633
|
try {
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
if (!
|
|
1634
|
+
i((p) => ({ ...p, status: "loading" }));
|
|
1635
|
+
const a = await e.requestQuote({ resource: n });
|
|
1636
|
+
if (!e.validateRequirement(a))
|
|
346
1637
|
throw new Error("Invalid refund requirement received from server");
|
|
347
|
-
return
|
|
348
|
-
} catch (
|
|
349
|
-
const
|
|
350
|
-
throw
|
|
1638
|
+
return x(a), i((p) => ({ ...p, status: "idle" })), a;
|
|
1639
|
+
} catch (a) {
|
|
1640
|
+
const p = Z(a, "Failed to fetch refund requirement");
|
|
1641
|
+
throw i({
|
|
351
1642
|
status: "error",
|
|
352
|
-
error:
|
|
1643
|
+
error: p,
|
|
353
1644
|
transactionId: null
|
|
354
|
-
}),
|
|
1645
|
+
}), a;
|
|
355
1646
|
}
|
|
356
1647
|
},
|
|
357
|
-
[
|
|
358
|
-
), b =
|
|
359
|
-
async (
|
|
360
|
-
if (!
|
|
1648
|
+
[e]
|
|
1649
|
+
), b = T(
|
|
1650
|
+
async (n, a) => {
|
|
1651
|
+
if (!t || !o)
|
|
361
1652
|
throw new Error("Wallet not connected");
|
|
362
1653
|
try {
|
|
363
|
-
|
|
1654
|
+
i({
|
|
364
1655
|
status: "loading",
|
|
365
1656
|
error: null,
|
|
366
1657
|
transactionId: null
|
|
367
1658
|
});
|
|
368
|
-
const
|
|
369
|
-
if (!
|
|
1659
|
+
const p = await e.requestQuote({ resource: n, couponCode: a });
|
|
1660
|
+
if (!e.validateRequirement(p))
|
|
370
1661
|
throw new Error("Invalid refund requirement received");
|
|
371
|
-
|
|
372
|
-
const
|
|
373
|
-
requirement:
|
|
374
|
-
payerPublicKey:
|
|
375
|
-
}),
|
|
376
|
-
transaction:
|
|
1662
|
+
x(p);
|
|
1663
|
+
const C = await r.buildTransaction({
|
|
1664
|
+
requirement: p,
|
|
1665
|
+
payerPublicKey: t
|
|
1666
|
+
}), P = await r.signTransaction({
|
|
1667
|
+
transaction: C,
|
|
377
1668
|
signTransaction: o
|
|
378
|
-
}),
|
|
379
|
-
requirement:
|
|
380
|
-
signedTx:
|
|
381
|
-
payerPublicKey:
|
|
382
|
-
}),
|
|
383
|
-
resource:
|
|
384
|
-
payload:
|
|
385
|
-
couponCode:
|
|
1669
|
+
}), y = r.buildPaymentPayload({
|
|
1670
|
+
requirement: p,
|
|
1671
|
+
signedTx: P,
|
|
1672
|
+
payerPublicKey: t
|
|
1673
|
+
}), B = await e.submitPayment({
|
|
1674
|
+
resource: n,
|
|
1675
|
+
payload: y,
|
|
1676
|
+
couponCode: a,
|
|
386
1677
|
metadata: void 0,
|
|
387
1678
|
// no metadata for refunds
|
|
388
1679
|
resourceType: "refund"
|
|
389
1680
|
});
|
|
390
|
-
return
|
|
1681
|
+
return B.settlement && l(B.settlement), i({
|
|
391
1682
|
status: "success",
|
|
392
1683
|
error: null,
|
|
393
|
-
transactionId:
|
|
394
|
-
}),
|
|
395
|
-
} catch (
|
|
396
|
-
const
|
|
397
|
-
throw
|
|
1684
|
+
transactionId: B.transactionId || P.signature
|
|
1685
|
+
}), B;
|
|
1686
|
+
} catch (p) {
|
|
1687
|
+
const C = Z(p, "Refund payment failed");
|
|
1688
|
+
throw i({
|
|
398
1689
|
status: "error",
|
|
399
|
-
error:
|
|
1690
|
+
error: C,
|
|
400
1691
|
transactionId: null
|
|
401
|
-
}),
|
|
1692
|
+
}), p;
|
|
402
1693
|
}
|
|
403
1694
|
},
|
|
404
|
-
[
|
|
405
|
-
),
|
|
406
|
-
async (
|
|
407
|
-
if (!
|
|
1695
|
+
[t, o, e, r]
|
|
1696
|
+
), c = T(
|
|
1697
|
+
async (n) => {
|
|
1698
|
+
if (!t || !o)
|
|
408
1699
|
throw new Error("Wallet not connected");
|
|
409
1700
|
try {
|
|
410
|
-
|
|
1701
|
+
i({
|
|
411
1702
|
status: "loading",
|
|
412
1703
|
error: null,
|
|
413
1704
|
transactionId: null
|
|
414
1705
|
});
|
|
415
|
-
const
|
|
416
|
-
if (!
|
|
1706
|
+
const a = await e.requestQuote({ resource: n });
|
|
1707
|
+
if (!e.validateRequirement(a))
|
|
417
1708
|
throw new Error("Invalid refund requirement received");
|
|
418
|
-
|
|
419
|
-
const { transaction:
|
|
420
|
-
resourceId:
|
|
421
|
-
userWallet:
|
|
422
|
-
feePayer:
|
|
423
|
-
}),
|
|
424
|
-
transaction:
|
|
1709
|
+
x(a);
|
|
1710
|
+
const { transaction: p } = await e.buildGaslessTransaction({
|
|
1711
|
+
resourceId: n,
|
|
1712
|
+
userWallet: t.toString(),
|
|
1713
|
+
feePayer: a.extra.feePayer
|
|
1714
|
+
}), C = r.deserializeTransaction(p), P = await r.partiallySignTransaction({
|
|
1715
|
+
transaction: C,
|
|
425
1716
|
signTransaction: o
|
|
426
|
-
}),
|
|
427
|
-
resource:
|
|
428
|
-
partialTx:
|
|
1717
|
+
}), y = await e.submitGaslessTransaction({
|
|
1718
|
+
resource: n,
|
|
1719
|
+
partialTx: P,
|
|
429
1720
|
couponCode: void 0,
|
|
430
1721
|
// no couponCode
|
|
431
1722
|
metadata: void 0,
|
|
432
1723
|
// no metadata
|
|
433
1724
|
resourceType: "refund",
|
|
434
|
-
requirement:
|
|
1725
|
+
requirement: a
|
|
435
1726
|
});
|
|
436
|
-
return
|
|
1727
|
+
return y.settlement && l(y.settlement), i({
|
|
437
1728
|
status: "success",
|
|
438
1729
|
error: null,
|
|
439
|
-
transactionId:
|
|
440
|
-
}),
|
|
441
|
-
} catch (
|
|
442
|
-
const
|
|
443
|
-
throw
|
|
1730
|
+
transactionId: y.transactionId || "gasless-refund-tx"
|
|
1731
|
+
}), y;
|
|
1732
|
+
} catch (a) {
|
|
1733
|
+
const p = Z(a, "Gasless refund payment failed");
|
|
1734
|
+
throw i({
|
|
444
1735
|
status: "error",
|
|
445
|
-
error:
|
|
1736
|
+
error: p,
|
|
446
1737
|
transactionId: null
|
|
447
|
-
}),
|
|
1738
|
+
}), a;
|
|
448
1739
|
}
|
|
449
1740
|
},
|
|
450
|
-
[
|
|
451
|
-
),
|
|
452
|
-
|
|
1741
|
+
[t, o, e, r]
|
|
1742
|
+
), d = T(() => {
|
|
1743
|
+
i({
|
|
453
1744
|
status: "idle",
|
|
454
1745
|
error: null,
|
|
455
1746
|
transactionId: null
|
|
456
|
-
}),
|
|
1747
|
+
}), x(null), l(null);
|
|
457
1748
|
}, []);
|
|
458
1749
|
return {
|
|
459
|
-
state:
|
|
1750
|
+
state: f,
|
|
460
1751
|
requirement: h,
|
|
461
|
-
settlement:
|
|
462
|
-
fetchRefundQuote:
|
|
1752
|
+
settlement: m,
|
|
1753
|
+
fetchRefundQuote: s,
|
|
463
1754
|
processRefund: b,
|
|
464
|
-
processGaslessRefund:
|
|
465
|
-
reset:
|
|
1755
|
+
processGaslessRefund: c,
|
|
1756
|
+
reset: d
|
|
466
1757
|
};
|
|
467
1758
|
}
|
|
468
|
-
function
|
|
1759
|
+
function nt() {
|
|
469
1760
|
if (typeof window > "u")
|
|
470
1761
|
return {
|
|
471
1762
|
passed: !0,
|
|
472
1763
|
severity: "info",
|
|
473
1764
|
message: "HTTPS check skipped (SSR environment)"
|
|
474
1765
|
};
|
|
475
|
-
const
|
|
476
|
-
return
|
|
1766
|
+
const e = window.location.protocol === "https:", r = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
|
|
1767
|
+
return e || r ? {
|
|
477
1768
|
passed: !0,
|
|
478
1769
|
severity: "info",
|
|
479
1770
|
message: "HTTPS enforced"
|
|
@@ -484,7 +1775,7 @@ function Ee() {
|
|
|
484
1775
|
recommendation: "Enable HTTPS for all payment pages. Stripe.js requires HTTPS in production."
|
|
485
1776
|
};
|
|
486
1777
|
}
|
|
487
|
-
function
|
|
1778
|
+
function st() {
|
|
488
1779
|
return typeof document > "u" ? {
|
|
489
1780
|
passed: !0,
|
|
490
1781
|
severity: "info",
|
|
@@ -500,7 +1791,7 @@ function we() {
|
|
|
500
1791
|
recommendation: "Configure CSP headers to protect against XSS and CDN compromise. Use generateCSP() helper from @cedros/pay-react."
|
|
501
1792
|
};
|
|
502
1793
|
}
|
|
503
|
-
function
|
|
1794
|
+
function ot() {
|
|
504
1795
|
return process.env.NODE_ENV === "development" || typeof window < "u" && window.location.hostname === "localhost" ? {
|
|
505
1796
|
passed: !0,
|
|
506
1797
|
severity: "info",
|
|
@@ -511,7 +1802,7 @@ function Te() {
|
|
|
511
1802
|
message: "Running in production mode"
|
|
512
1803
|
};
|
|
513
1804
|
}
|
|
514
|
-
function
|
|
1805
|
+
function at() {
|
|
515
1806
|
return {
|
|
516
1807
|
passed: !0,
|
|
517
1808
|
severity: "info",
|
|
@@ -519,7 +1810,7 @@ function Re() {
|
|
|
519
1810
|
recommendation: "Ensure CSP script-src includes https://js.stripe.com"
|
|
520
1811
|
};
|
|
521
1812
|
}
|
|
522
|
-
function
|
|
1813
|
+
function it() {
|
|
523
1814
|
return typeof window > "u" ? {
|
|
524
1815
|
passed: !0,
|
|
525
1816
|
severity: "info",
|
|
@@ -534,28 +1825,28 @@ function be() {
|
|
|
534
1825
|
message: "Mixed content check skipped (HTTP page)"
|
|
535
1826
|
};
|
|
536
1827
|
}
|
|
537
|
-
function
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
],
|
|
545
|
-
let o,
|
|
546
|
-
return
|
|
547
|
-
checks:
|
|
1828
|
+
function kt() {
|
|
1829
|
+
const e = [
|
|
1830
|
+
nt(),
|
|
1831
|
+
st(),
|
|
1832
|
+
ot(),
|
|
1833
|
+
at(),
|
|
1834
|
+
it()
|
|
1835
|
+
], r = e.some((i) => i.severity === "error" && !i.passed), t = e.some((i) => i.severity === "warning" && !i.passed);
|
|
1836
|
+
let o, f;
|
|
1837
|
+
return r ? (o = "vulnerable", f = "Security issues detected. Review errors and apply recommendations.") : t ? (o = "warnings", f = "Minor security warnings detected. Consider applying recommendations.") : (o = "secure", f = "All security checks passed."), {
|
|
1838
|
+
checks: e,
|
|
548
1839
|
overallStatus: o,
|
|
549
|
-
summary:
|
|
1840
|
+
summary: f
|
|
550
1841
|
};
|
|
551
1842
|
}
|
|
552
|
-
function
|
|
553
|
-
process.env.NODE_ENV !== "production" && (console.group("🔒 Cedros Pay Security Report"), console.log(`Status: ${
|
|
554
|
-
const
|
|
555
|
-
console.log(`${
|
|
1843
|
+
function Tt(e) {
|
|
1844
|
+
process.env.NODE_ENV !== "production" && (console.group("🔒 Cedros Pay Security Report"), console.log(`Status: ${e.overallStatus.toUpperCase()}`), console.log(`Summary: ${e.summary}`), console.log(""), e.checks.forEach((r) => {
|
|
1845
|
+
const t = r.passed ? "✅" : r.severity === "error" ? "❌" : "⚠️";
|
|
1846
|
+
console.log(`${t} ${r.message}`), r.recommendation && console.log(` → ${r.recommendation}`);
|
|
556
1847
|
}), console.groupEnd());
|
|
557
1848
|
}
|
|
558
|
-
const
|
|
1849
|
+
const Et = {
|
|
559
1850
|
CSP: "Use generateCSP() from @cedros/pay-react to generate Content Security Policy headers",
|
|
560
1851
|
HTTPS: "Always serve payment pages over HTTPS in production",
|
|
561
1852
|
PACKAGE_UPDATES: "Keep @stripe/stripe-js and @cedros/pay-react updated for security patches",
|
|
@@ -564,64 +1855,70 @@ const He = {
|
|
|
564
1855
|
NO_SRI: "Do NOT use SRI hashes for Stripe.js - use CSP instead"
|
|
565
1856
|
};
|
|
566
1857
|
export {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
1858
|
+
Bt as CEDROS_EVENTS,
|
|
1859
|
+
Yt as CIRCUIT_BREAKER_PRESETS,
|
|
1860
|
+
St as CSP_PRESETS,
|
|
1861
|
+
wt as CedrosPay,
|
|
1862
|
+
Vt as CedrosProvider,
|
|
1863
|
+
Xt as CircuitBreakerOpenError,
|
|
1864
|
+
Jt as CircuitState,
|
|
1865
|
+
je as CryptoButton,
|
|
1866
|
+
vt as CryptoSubscribeButton,
|
|
1867
|
+
Nt as ERROR_CATEGORIES,
|
|
1868
|
+
Zt as LogLevel,
|
|
1869
|
+
er as Logger,
|
|
1870
|
+
Mt as PaymentMethodBadge,
|
|
1871
|
+
ze as PaymentModal,
|
|
1872
|
+
_t as ProductPrice,
|
|
1873
|
+
Xe as PurchaseButton,
|
|
1874
|
+
tr as RATE_LIMITER_PRESETS,
|
|
1875
|
+
rr as RETRY_PRESETS,
|
|
1876
|
+
bt as RPC_PROVIDERS,
|
|
1877
|
+
Et as SECURITY_RECOMMENDATIONS,
|
|
1878
|
+
Ue as StripeButton,
|
|
1879
|
+
Ct as SubscribeButton,
|
|
1880
|
+
xt as SubscriptionManagementPanel,
|
|
1881
|
+
nr as WalletPool,
|
|
1882
|
+
At as calculateDiscountPercentage,
|
|
1883
|
+
sr as createCircuitBreaker,
|
|
1884
|
+
or as createLogger,
|
|
1885
|
+
ar as createRateLimiter,
|
|
1886
|
+
Wt as createTranslator,
|
|
1887
|
+
ir as createWalletPool,
|
|
1888
|
+
Lt as detectLocale,
|
|
1889
|
+
ce as emitPaymentError,
|
|
596
1890
|
ie as emitPaymentProcessing,
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
1891
|
+
he as emitPaymentStart,
|
|
1892
|
+
be as emitPaymentSuccess,
|
|
1893
|
+
Te as emitWalletConnect,
|
|
1894
|
+
Oe as emitWalletConnected,
|
|
1895
|
+
fe as emitWalletError,
|
|
1896
|
+
Ve as formatCSP,
|
|
1897
|
+
Dt as formatCouponCodes,
|
|
1898
|
+
ht as generateCSP,
|
|
1899
|
+
Ye as generateCSPDirectives,
|
|
1900
|
+
qt as getAvailableLocales,
|
|
1901
|
+
$t as getLocalizedError,
|
|
1902
|
+
D as getLogger,
|
|
1903
|
+
zt as getUserErrorMessage,
|
|
1904
|
+
Ut as isRetryableError,
|
|
1905
|
+
jt as loadLocale,
|
|
1906
|
+
Tt as logSecurityReport,
|
|
1907
|
+
Ot as parseCouponCodes,
|
|
1908
|
+
Ft as parseStructuredErrorResponse,
|
|
1909
|
+
cr as retryWithBackoff,
|
|
1910
|
+
Ht as stackCheckoutCoupons,
|
|
1911
|
+
ee as useCedrosContext,
|
|
1912
|
+
le as useCedrosTheme,
|
|
1913
|
+
Ze as useCryptoSubscription,
|
|
1914
|
+
Kt as useLocalizedError,
|
|
1915
|
+
Re as usePaymentMode,
|
|
1916
|
+
Pt as useRefundVerification,
|
|
1917
|
+
$e as useStripeCheckout,
|
|
1918
|
+
Je as useSubscription,
|
|
1919
|
+
et as useSubscriptionManagement,
|
|
1920
|
+
ge as useTranslation,
|
|
1921
|
+
Qt as useX402Payment,
|
|
1922
|
+
lr as validateConfig,
|
|
1923
|
+
kt as validateSecurity
|
|
627
1924
|
};
|