@reeboot/strapi-payment-plugin 0.0.4 → 0.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.
Files changed (46) hide show
  1. package/dist/_chunks/{Analytics-nBSdLT2v.js → Analytics-CLjtRWYA.js} +68 -51
  2. package/dist/_chunks/{Analytics-DSJqY9ng.mjs → Analytics-CQmAVKsq.mjs} +68 -51
  3. package/dist/_chunks/App-DXN62SV6.mjs +118 -0
  4. package/dist/_chunks/App-Dk7XtjNA.js +120 -0
  5. package/dist/_chunks/{Customers-BpFzfglV.js → Customers-BNDi4QBH.js} +113 -51
  6. package/dist/_chunks/{Customers-C6FH7-zG.mjs → Customers-BQzVBQDT.mjs} +114 -52
  7. package/dist/_chunks/Dashboard-CuHC-dit.mjs +311 -0
  8. package/dist/_chunks/Dashboard-UUwohHZa.js +311 -0
  9. package/dist/_chunks/{Orders-CBkT2YfP.mjs → Orders-65mNfu2i.mjs} +140 -80
  10. package/dist/_chunks/{Orders-OG-pwV-B.js → Orders-CitNCdWE.js} +139 -79
  11. package/dist/_chunks/PaymentList-B0CAzInT.mjs +137 -0
  12. package/dist/_chunks/PaymentList-Dy1BAFoD.js +136 -0
  13. package/dist/_chunks/{Payments-DSDJ-HWm.mjs → Payments-FnhoV_2B.mjs} +175 -136
  14. package/dist/_chunks/{Payments-BLen1P9N.js → Payments-TOnygGIW.js} +173 -134
  15. package/dist/_chunks/Settings-BJtDagUs.js +644 -0
  16. package/dist/_chunks/Settings-EoLSuZLe.mjs +644 -0
  17. package/dist/_chunks/{index-DS_PYNkf.mjs → index-2Zd_T7bD.mjs} +1 -1
  18. package/dist/_chunks/{index-BqqrpI6D.js → index-CHEgJ7e5.js} +1 -1
  19. package/dist/admin/index.js +1 -1
  20. package/dist/admin/index.mjs +1 -1
  21. package/dist/admin/src/components/CustomerList.d.ts +1 -13
  22. package/dist/admin/src/components/IntegrationModal.d.ts +7 -0
  23. package/dist/admin/src/components/OrderList.d.ts +1 -19
  24. package/dist/admin/src/components/PaymentCard.d.ts +2 -33
  25. package/dist/admin/src/components/PaymentList.d.ts +3 -11
  26. package/dist/admin/src/components/RefundModal.d.ts +2 -8
  27. package/dist/admin/src/types/index.d.ts +47 -0
  28. package/dist/server/index.js +197 -91
  29. package/dist/server/index.mjs +197 -91
  30. package/dist/server/src/content-types/index.d.ts +9 -2
  31. package/dist/server/src/content-types/order/index.d.ts +8 -1
  32. package/dist/server/src/content-types/payment/index.d.ts +1 -1
  33. package/dist/server/src/index.d.ts +9 -2
  34. package/dist/server/src/types/api.d.ts +31 -0
  35. package/dist/server/src/types/customer.d.ts +2 -0
  36. package/dist/server/src/types/index.d.ts +4 -179
  37. package/dist/server/src/types/order.d.ts +2 -0
  38. package/dist/server/src/types/payment.d.ts +2 -0
  39. package/package.json +8 -7
  40. package/dist/_chunks/App-B83DZ9NG.js +0 -70
  41. package/dist/_chunks/App-BUSTbkyy.mjs +0 -68
  42. package/dist/_chunks/Dashboard-CNMTzSyc.js +0 -180
  43. package/dist/_chunks/Dashboard-Dbwl0ZBo.mjs +0 -180
  44. package/dist/_chunks/Settings-Dq1xy32B.js +0 -357
  45. package/dist/_chunks/Settings-jmGslDsB.mjs +0 -357
  46. package/dist/admin/src/pages/HomePage.d.ts +0 -2
@@ -0,0 +1,311 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect } from "react";
3
+ import { Box, Flex, Loader, EmptyStateLayout, Button, Typography, Grid, Card, Badge } from "@strapi/design-system";
4
+ import { Plus, PriceTag, ShoppingCart, ArrowClockwise, ChartPie } from "@strapi/icons";
5
+ import { useFetchClient } from "@strapi/strapi/admin";
6
+ import { useIntl } from "react-intl";
7
+ import { P as PLUGIN_ID } from "./index-2Zd_T7bD.mjs";
8
+ import { loadStripe } from "@stripe/stripe-js";
9
+ import { P as PaymentList } from "./PaymentList-B0CAzInT.mjs";
10
+ const Dashboard = () => {
11
+ const { formatMessage } = useIntl();
12
+ const { get, post } = useFetchClient();
13
+ const [stats, setStats] = useState(null);
14
+ const [recentPayments, setRecentPayments] = useState([]);
15
+ const [loading, setLoading] = useState(true);
16
+ const [error, setError] = useState(null);
17
+ const [creatingTest, setCreatingTest] = useState(false);
18
+ useEffect(() => {
19
+ fetchDashboardData();
20
+ }, []);
21
+ const fetchDashboardData = async () => {
22
+ try {
23
+ setLoading(true);
24
+ const { data } = await get(`/${PLUGIN_ID}/admin/dashboard`);
25
+ if (data.success && data.data) {
26
+ setStats({
27
+ totalRevenue: data.data.summary.totalRevenue,
28
+ totalPayments: data.data.summary.totalPayments,
29
+ successfulPayments: data.data.summary.successfulPayments,
30
+ pendingPayments: data.data.summary.totalPayments - data.data.summary.successfulPayments - data.data.summary.failedPayments,
31
+ failedPayments: data.data.summary.failedPayments,
32
+ totalCustomers: data.data.topCustomers.length,
33
+ // Rough estimate
34
+ totalOrders: data.data.summary.totalPayments,
35
+ // Rough estimate
36
+ averageOrderValue: data.data.summary.totalPayments > 0 ? data.data.summary.totalRevenue / data.data.summary.totalPayments : 0
37
+ });
38
+ const formattedPayments = data.data.recentTransactions.map((p) => ({
39
+ ...p,
40
+ id: p.documentId,
41
+ customerEmail: p.customer?.email || "N/A",
42
+ customerName: p.customer ? `${p.customer.first_name || ""} ${p.customer.last_name || ""}`.trim() : void 0
43
+ }));
44
+ setRecentPayments(formattedPayments);
45
+ }
46
+ setLoading(false);
47
+ } catch (err) {
48
+ setError("Failed to fetch dashboard data");
49
+ setLoading(false);
50
+ }
51
+ };
52
+ const createTestPayment = async () => {
53
+ try {
54
+ setCreatingTest(true);
55
+ const { data } = await post(`/${PLUGIN_ID}/admin/create-sample-payment`);
56
+ if (!data.success) throw new Error(data.error?.message || "Failed to process payment");
57
+ const { publishableKey, clientSecret } = data.data;
58
+ if (!publishableKey) {
59
+ throw new Error("Stripe publishable key not configured. Please configure it in plugin settings.");
60
+ }
61
+ if (!clientSecret) {
62
+ throw new Error("Client secret not returned from server");
63
+ }
64
+ const stripe = await loadStripe(publishableKey);
65
+ if (stripe === null) {
66
+ throw new Error("Failed to load Stripe.js");
67
+ }
68
+ const elements = stripe.elements({
69
+ clientSecret,
70
+ appearance: {
71
+ theme: "stripe"
72
+ }
73
+ });
74
+ const paymentElement = elements.create("payment", {
75
+ layout: "tabs"
76
+ });
77
+ const existingModal = document.getElementById("stripe-payment-modal");
78
+ if (existingModal) {
79
+ document.body.removeChild(existingModal);
80
+ }
81
+ const modal = document.createElement("div");
82
+ modal.id = "stripe-payment-modal";
83
+ Object.assign(modal.style, {
84
+ position: "fixed",
85
+ top: "0",
86
+ left: "0",
87
+ width: "100vw",
88
+ height: "100vh",
89
+ background: "rgba(0,0,0,0.5)",
90
+ display: "flex",
91
+ alignItems: "center",
92
+ justifyContent: "center",
93
+ zIndex: "9999"
94
+ });
95
+ const container = document.createElement("div");
96
+ Object.assign(container.style, {
97
+ background: "#fff",
98
+ padding: "2rem",
99
+ borderRadius: "8px",
100
+ minWidth: "400px",
101
+ maxWidth: "500px",
102
+ boxShadow: "0 4px 6px rgba(0, 0, 0, 0.1)"
103
+ });
104
+ const title = document.createElement("h2");
105
+ title.textContent = "Test Payment - $25.00";
106
+ title.style.marginBottom = "1.5rem";
107
+ title.style.fontSize = "1.25rem";
108
+ title.style.fontWeight = "600";
109
+ title.style.color = "#333";
110
+ container.appendChild(title);
111
+ const form = document.createElement("form");
112
+ const paymentContainer = document.createElement("div");
113
+ const elementId = `payment-element-${Date.now()}`;
114
+ paymentContainer.id = elementId;
115
+ paymentContainer.style.marginBottom = "1.5rem";
116
+ paymentContainer.style.minHeight = "200px";
117
+ form.appendChild(paymentContainer);
118
+ const buttonContainer = document.createElement("div");
119
+ buttonContainer.style.display = "flex";
120
+ buttonContainer.style.gap = "1rem";
121
+ buttonContainer.style.marginTop = "1rem";
122
+ const submitButton = document.createElement("button");
123
+ submitButton.type = "submit";
124
+ submitButton.textContent = "Loading...";
125
+ submitButton.disabled = true;
126
+ Object.assign(submitButton.style, {
127
+ flex: "1",
128
+ padding: "0.75rem",
129
+ background: "#635bff",
130
+ color: "white",
131
+ border: "none",
132
+ borderRadius: "4px",
133
+ cursor: "not-allowed",
134
+ fontSize: "16px",
135
+ fontWeight: "500",
136
+ transition: "background 0.2s",
137
+ opacity: "0.7"
138
+ });
139
+ const cancelButton = document.createElement("button");
140
+ cancelButton.type = "button";
141
+ cancelButton.textContent = "Cancel";
142
+ Object.assign(cancelButton.style, {
143
+ padding: "0.75rem 1.5rem",
144
+ background: "#f3f4f6",
145
+ color: "#374151",
146
+ border: "1px solid #d1d5db",
147
+ borderRadius: "4px",
148
+ cursor: "pointer",
149
+ fontSize: "16px",
150
+ fontWeight: "500",
151
+ transition: "background 0.2s"
152
+ });
153
+ cancelButton.onclick = () => {
154
+ document.body.removeChild(modal);
155
+ paymentElement.unmount();
156
+ };
157
+ buttonContainer.appendChild(submitButton);
158
+ buttonContainer.appendChild(cancelButton);
159
+ form.appendChild(buttonContainer);
160
+ container.appendChild(form);
161
+ modal.appendChild(container);
162
+ document.body.appendChild(modal);
163
+ try {
164
+ console.log("Mounting payment element to container:", paymentContainer);
165
+ paymentElement.mount(paymentContainer);
166
+ } catch (e) {
167
+ console.error("Error mounting payment element:", e);
168
+ alert("Failed to mount Stripe payment form");
169
+ document.body.removeChild(modal);
170
+ return;
171
+ }
172
+ paymentElement.on("ready", () => {
173
+ console.log("Payment Element is ready");
174
+ submitButton.disabled = false;
175
+ submitButton.textContent = "Pay $25.00";
176
+ submitButton.style.cursor = "pointer";
177
+ submitButton.style.opacity = "1";
178
+ });
179
+ paymentElement.on("loaderror", (event) => {
180
+ console.error("Payment Element load error:", event);
181
+ const errorMessage = event?.error?.message || "Unknown error loading Stripe form";
182
+ alert(`Failed to load payment form: ${errorMessage}. Please check your keys and network.`);
183
+ document.body.removeChild(modal);
184
+ });
185
+ setCreatingTest(false);
186
+ form.onsubmit = async (e) => {
187
+ e.preventDefault();
188
+ submitButton.disabled = true;
189
+ submitButton.textContent = "Processing...";
190
+ try {
191
+ const result = await stripe.confirmPayment({
192
+ elements,
193
+ redirect: "if_required"
194
+ });
195
+ if (result.error) {
196
+ alert(`Payment failed: ${result.error.message}`);
197
+ submitButton.disabled = false;
198
+ submitButton.textContent = "Pay $25.00";
199
+ } else if (result.paymentIntent && result.paymentIntent.status === "succeeded") {
200
+ alert("Payment successful! ✓");
201
+ document.body.removeChild(modal);
202
+ await fetchDashboardData();
203
+ } else {
204
+ alert("Payment is being processed...");
205
+ submitButton.disabled = false;
206
+ submitButton.textContent = "Pay $25.00";
207
+ }
208
+ } catch (err) {
209
+ console.error("Payment confirmation error:", err);
210
+ alert(`Error: ${err instanceof Error ? err.message : "Payment confirmation failed"}`);
211
+ submitButton.disabled = false;
212
+ submitButton.textContent = "Pay $25.00";
213
+ }
214
+ };
215
+ } catch (err) {
216
+ console.error("Payment initialization error:", err);
217
+ alert(err instanceof Error ? err.message : "An error occurred during payment initialization");
218
+ setCreatingTest(false);
219
+ }
220
+ };
221
+ const formatCurrency = (amount, currency = "USD") => {
222
+ return new Intl.NumberFormat("en-US", {
223
+ style: "currency",
224
+ currency
225
+ }).format(amount);
226
+ };
227
+ if (loading) {
228
+ return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", alignItems: "center", style: { minHeight: "400px" }, children: /* @__PURE__ */ jsx(Loader, {}) }) });
229
+ }
230
+ if (error) {
231
+ return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
232
+ EmptyStateLayout,
233
+ {
234
+ title: "Error loading dashboard",
235
+ subtitle: error,
236
+ action: /* @__PURE__ */ jsx(Button, { onClick: fetchDashboardData, children: formatMessage({ id: "payment-plugin.dashboard.retry", defaultMessage: "Retry" }) })
237
+ }
238
+ ) });
239
+ }
240
+ return /* @__PURE__ */ jsxs(Box, { children: [
241
+ /* @__PURE__ */ jsx(Box, { marginBottom: 4, children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [
242
+ /* @__PURE__ */ jsxs(Box, { children: [
243
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: formatMessage({ id: "payment-plugin.dashboard.title", defaultMessage: "Payment Dashboard" }) }),
244
+ /* @__PURE__ */ jsx(Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({
245
+ id: "payment-plugin.dashboard.subtitle",
246
+ defaultMessage: "Overview of your payment operations"
247
+ }) })
248
+ ] }),
249
+ /* @__PURE__ */ jsx(
250
+ Button,
251
+ {
252
+ onClick: createTestPayment,
253
+ loading: creatingTest,
254
+ variant: "secondary",
255
+ startIcon: /* @__PURE__ */ jsx(Plus, {}),
256
+ children: formatMessage({ id: "payment-plugin.dashboard.initPayment", defaultMessage: "Initialize Sample Payment" })
257
+ }
258
+ )
259
+ ] }) }),
260
+ /* @__PURE__ */ jsxs(Grid.Root, { gap: 4, marginBottom: 8, children: [
261
+ /* @__PURE__ */ jsx(Grid.Item, { col: 3, s: 12, children: /* @__PURE__ */ jsx(Card, { padding: 4, shadow: "tableShadow", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "start", gap: 2, children: [
262
+ /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", width: "100%", children: [
263
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", children: formatMessage({ id: "payment-plugin.dashboard.totalRevenue", defaultMessage: "Total Revenue" }) }),
264
+ /* @__PURE__ */ jsx(Box, { padding: 2, background: "primary100", borderRadius: "50%", children: /* @__PURE__ */ jsx(PriceTag, { width: "1rem", height: "1rem" }) })
265
+ ] }),
266
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", fontWeight: "bold", children: formatCurrency(stats?.totalRevenue || 0) }),
267
+ /* @__PURE__ */ jsx(Badge, { variant: "success", children: "Active" })
268
+ ] }) }) }),
269
+ /* @__PURE__ */ jsx(Grid.Item, { col: 3, s: 12, children: /* @__PURE__ */ jsx(Card, { padding: 4, shadow: "tableShadow", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "start", gap: 2, children: [
270
+ /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", width: "100%", children: [
271
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", children: formatMessage({ id: "payment-plugin.dashboard.totalPayments", defaultMessage: "Total Payments" }) }),
272
+ /* @__PURE__ */ jsx(Box, { padding: 2, background: "secondary100", borderRadius: "50%", children: /* @__PURE__ */ jsx(ShoppingCart, { width: "1rem", height: "1rem" }) })
273
+ ] }),
274
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", fontWeight: "bold", children: stats?.totalPayments || 0 }),
275
+ /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: "Live" })
276
+ ] }) }) }),
277
+ /* @__PURE__ */ jsx(Grid.Item, { col: 3, s: 12, children: /* @__PURE__ */ jsx(Card, { padding: 4, shadow: "tableShadow", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "start", gap: 2, children: [
278
+ /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", width: "100%", children: [
279
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", children: formatMessage({ id: "payment-plugin.dashboard.successRate", defaultMessage: "Success Rate" }) }),
280
+ /* @__PURE__ */ jsx(Box, { padding: 2, background: "success100", borderRadius: "50%", children: /* @__PURE__ */ jsx(ArrowClockwise, { width: "1rem", height: "1rem" }) })
281
+ ] }),
282
+ /* @__PURE__ */ jsxs(Typography, { variant: "alpha", fontWeight: "bold", children: [
283
+ stats ? Math.round(stats.successfulPayments / stats.totalPayments * 100) : 0,
284
+ "%"
285
+ ] }),
286
+ /* @__PURE__ */ jsx(Badge, { variant: "success", children: "Good" })
287
+ ] }) }) }),
288
+ /* @__PURE__ */ jsx(Grid.Item, { col: 3, s: 12, children: /* @__PURE__ */ jsx(Card, { padding: 4, shadow: "tableShadow", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "start", gap: 2, children: [
289
+ /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", width: "100%", children: [
290
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", children: formatMessage({ id: "payment-plugin.dashboard.averageOrderValue", defaultMessage: "AVO" }) }),
291
+ /* @__PURE__ */ jsx(Box, { padding: 2, background: "warning100", borderRadius: "50%", children: /* @__PURE__ */ jsx(ChartPie, { width: "1rem", height: "1rem" }) })
292
+ ] }),
293
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", fontWeight: "bold", children: formatCurrency(stats?.averageOrderValue || 0) }),
294
+ /* @__PURE__ */ jsx(Badge, { variant: "neutral", children: "Calculated" })
295
+ ] }) }) })
296
+ ] }),
297
+ /* @__PURE__ */ jsx(Card, { shadow: "tableShadow", children: /* @__PURE__ */ jsxs(Box, { padding: 4, children: [
298
+ /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 4, children: [
299
+ /* @__PURE__ */ jsxs(Box, { children: [
300
+ /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: formatMessage({ id: "payment-plugin.dashboard.recentPayments", defaultMessage: "Recent Payments" }) }),
301
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "Latest transactions from your customers" })
302
+ ] }),
303
+ /* @__PURE__ */ jsx(Button, { variant: "tertiary", size: "S", children: formatMessage({ id: "payment-plugin.dashboard.viewAll", defaultMessage: "View All" }) })
304
+ ] }),
305
+ /* @__PURE__ */ jsx(PaymentList, { payments: recentPayments, compact: true })
306
+ ] }) })
307
+ ] });
308
+ };
309
+ export {
310
+ Dashboard
311
+ };
@@ -0,0 +1,311 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const designSystem = require("@strapi/design-system");
6
+ const icons = require("@strapi/icons");
7
+ const admin = require("@strapi/strapi/admin");
8
+ const reactIntl = require("react-intl");
9
+ const index = require("./index-CHEgJ7e5.js");
10
+ const stripeJs = require("@stripe/stripe-js");
11
+ const PaymentList = require("./PaymentList-Dy1BAFoD.js");
12
+ const Dashboard = () => {
13
+ const { formatMessage } = reactIntl.useIntl();
14
+ const { get, post } = admin.useFetchClient();
15
+ const [stats, setStats] = React.useState(null);
16
+ const [recentPayments, setRecentPayments] = React.useState([]);
17
+ const [loading, setLoading] = React.useState(true);
18
+ const [error, setError] = React.useState(null);
19
+ const [creatingTest, setCreatingTest] = React.useState(false);
20
+ React.useEffect(() => {
21
+ fetchDashboardData();
22
+ }, []);
23
+ const fetchDashboardData = async () => {
24
+ try {
25
+ setLoading(true);
26
+ const { data } = await get(`/${index.PLUGIN_ID}/admin/dashboard`);
27
+ if (data.success && data.data) {
28
+ setStats({
29
+ totalRevenue: data.data.summary.totalRevenue,
30
+ totalPayments: data.data.summary.totalPayments,
31
+ successfulPayments: data.data.summary.successfulPayments,
32
+ pendingPayments: data.data.summary.totalPayments - data.data.summary.successfulPayments - data.data.summary.failedPayments,
33
+ failedPayments: data.data.summary.failedPayments,
34
+ totalCustomers: data.data.topCustomers.length,
35
+ // Rough estimate
36
+ totalOrders: data.data.summary.totalPayments,
37
+ // Rough estimate
38
+ averageOrderValue: data.data.summary.totalPayments > 0 ? data.data.summary.totalRevenue / data.data.summary.totalPayments : 0
39
+ });
40
+ const formattedPayments = data.data.recentTransactions.map((p) => ({
41
+ ...p,
42
+ id: p.documentId,
43
+ customerEmail: p.customer?.email || "N/A",
44
+ customerName: p.customer ? `${p.customer.first_name || ""} ${p.customer.last_name || ""}`.trim() : void 0
45
+ }));
46
+ setRecentPayments(formattedPayments);
47
+ }
48
+ setLoading(false);
49
+ } catch (err) {
50
+ setError("Failed to fetch dashboard data");
51
+ setLoading(false);
52
+ }
53
+ };
54
+ const createTestPayment = async () => {
55
+ try {
56
+ setCreatingTest(true);
57
+ const { data } = await post(`/${index.PLUGIN_ID}/admin/create-sample-payment`);
58
+ if (!data.success) throw new Error(data.error?.message || "Failed to process payment");
59
+ const { publishableKey, clientSecret } = data.data;
60
+ if (!publishableKey) {
61
+ throw new Error("Stripe publishable key not configured. Please configure it in plugin settings.");
62
+ }
63
+ if (!clientSecret) {
64
+ throw new Error("Client secret not returned from server");
65
+ }
66
+ const stripe = await stripeJs.loadStripe(publishableKey);
67
+ if (stripe === null) {
68
+ throw new Error("Failed to load Stripe.js");
69
+ }
70
+ const elements = stripe.elements({
71
+ clientSecret,
72
+ appearance: {
73
+ theme: "stripe"
74
+ }
75
+ });
76
+ const paymentElement = elements.create("payment", {
77
+ layout: "tabs"
78
+ });
79
+ const existingModal = document.getElementById("stripe-payment-modal");
80
+ if (existingModal) {
81
+ document.body.removeChild(existingModal);
82
+ }
83
+ const modal = document.createElement("div");
84
+ modal.id = "stripe-payment-modal";
85
+ Object.assign(modal.style, {
86
+ position: "fixed",
87
+ top: "0",
88
+ left: "0",
89
+ width: "100vw",
90
+ height: "100vh",
91
+ background: "rgba(0,0,0,0.5)",
92
+ display: "flex",
93
+ alignItems: "center",
94
+ justifyContent: "center",
95
+ zIndex: "9999"
96
+ });
97
+ const container = document.createElement("div");
98
+ Object.assign(container.style, {
99
+ background: "#fff",
100
+ padding: "2rem",
101
+ borderRadius: "8px",
102
+ minWidth: "400px",
103
+ maxWidth: "500px",
104
+ boxShadow: "0 4px 6px rgba(0, 0, 0, 0.1)"
105
+ });
106
+ const title = document.createElement("h2");
107
+ title.textContent = "Test Payment - $25.00";
108
+ title.style.marginBottom = "1.5rem";
109
+ title.style.fontSize = "1.25rem";
110
+ title.style.fontWeight = "600";
111
+ title.style.color = "#333";
112
+ container.appendChild(title);
113
+ const form = document.createElement("form");
114
+ const paymentContainer = document.createElement("div");
115
+ const elementId = `payment-element-${Date.now()}`;
116
+ paymentContainer.id = elementId;
117
+ paymentContainer.style.marginBottom = "1.5rem";
118
+ paymentContainer.style.minHeight = "200px";
119
+ form.appendChild(paymentContainer);
120
+ const buttonContainer = document.createElement("div");
121
+ buttonContainer.style.display = "flex";
122
+ buttonContainer.style.gap = "1rem";
123
+ buttonContainer.style.marginTop = "1rem";
124
+ const submitButton = document.createElement("button");
125
+ submitButton.type = "submit";
126
+ submitButton.textContent = "Loading...";
127
+ submitButton.disabled = true;
128
+ Object.assign(submitButton.style, {
129
+ flex: "1",
130
+ padding: "0.75rem",
131
+ background: "#635bff",
132
+ color: "white",
133
+ border: "none",
134
+ borderRadius: "4px",
135
+ cursor: "not-allowed",
136
+ fontSize: "16px",
137
+ fontWeight: "500",
138
+ transition: "background 0.2s",
139
+ opacity: "0.7"
140
+ });
141
+ const cancelButton = document.createElement("button");
142
+ cancelButton.type = "button";
143
+ cancelButton.textContent = "Cancel";
144
+ Object.assign(cancelButton.style, {
145
+ padding: "0.75rem 1.5rem",
146
+ background: "#f3f4f6",
147
+ color: "#374151",
148
+ border: "1px solid #d1d5db",
149
+ borderRadius: "4px",
150
+ cursor: "pointer",
151
+ fontSize: "16px",
152
+ fontWeight: "500",
153
+ transition: "background 0.2s"
154
+ });
155
+ cancelButton.onclick = () => {
156
+ document.body.removeChild(modal);
157
+ paymentElement.unmount();
158
+ };
159
+ buttonContainer.appendChild(submitButton);
160
+ buttonContainer.appendChild(cancelButton);
161
+ form.appendChild(buttonContainer);
162
+ container.appendChild(form);
163
+ modal.appendChild(container);
164
+ document.body.appendChild(modal);
165
+ try {
166
+ console.log("Mounting payment element to container:", paymentContainer);
167
+ paymentElement.mount(paymentContainer);
168
+ } catch (e) {
169
+ console.error("Error mounting payment element:", e);
170
+ alert("Failed to mount Stripe payment form");
171
+ document.body.removeChild(modal);
172
+ return;
173
+ }
174
+ paymentElement.on("ready", () => {
175
+ console.log("Payment Element is ready");
176
+ submitButton.disabled = false;
177
+ submitButton.textContent = "Pay $25.00";
178
+ submitButton.style.cursor = "pointer";
179
+ submitButton.style.opacity = "1";
180
+ });
181
+ paymentElement.on("loaderror", (event) => {
182
+ console.error("Payment Element load error:", event);
183
+ const errorMessage = event?.error?.message || "Unknown error loading Stripe form";
184
+ alert(`Failed to load payment form: ${errorMessage}. Please check your keys and network.`);
185
+ document.body.removeChild(modal);
186
+ });
187
+ setCreatingTest(false);
188
+ form.onsubmit = async (e) => {
189
+ e.preventDefault();
190
+ submitButton.disabled = true;
191
+ submitButton.textContent = "Processing...";
192
+ try {
193
+ const result = await stripe.confirmPayment({
194
+ elements,
195
+ redirect: "if_required"
196
+ });
197
+ if (result.error) {
198
+ alert(`Payment failed: ${result.error.message}`);
199
+ submitButton.disabled = false;
200
+ submitButton.textContent = "Pay $25.00";
201
+ } else if (result.paymentIntent && result.paymentIntent.status === "succeeded") {
202
+ alert("Payment successful! ✓");
203
+ document.body.removeChild(modal);
204
+ await fetchDashboardData();
205
+ } else {
206
+ alert("Payment is being processed...");
207
+ submitButton.disabled = false;
208
+ submitButton.textContent = "Pay $25.00";
209
+ }
210
+ } catch (err) {
211
+ console.error("Payment confirmation error:", err);
212
+ alert(`Error: ${err instanceof Error ? err.message : "Payment confirmation failed"}`);
213
+ submitButton.disabled = false;
214
+ submitButton.textContent = "Pay $25.00";
215
+ }
216
+ };
217
+ } catch (err) {
218
+ console.error("Payment initialization error:", err);
219
+ alert(err instanceof Error ? err.message : "An error occurred during payment initialization");
220
+ setCreatingTest(false);
221
+ }
222
+ };
223
+ const formatCurrency = (amount, currency = "USD") => {
224
+ return new Intl.NumberFormat("en-US", {
225
+ style: "currency",
226
+ currency
227
+ }).format(amount);
228
+ };
229
+ if (loading) {
230
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", alignItems: "center", style: { minHeight: "400px" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, {}) }) });
231
+ }
232
+ if (error) {
233
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
234
+ designSystem.EmptyStateLayout,
235
+ {
236
+ title: "Error loading dashboard",
237
+ subtitle: error,
238
+ action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: fetchDashboardData, children: formatMessage({ id: "payment-plugin.dashboard.retry", defaultMessage: "Retry" }) })
239
+ }
240
+ ) });
241
+ }
242
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
243
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", children: [
244
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
245
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", tag: "h1", children: formatMessage({ id: "payment-plugin.dashboard.title", defaultMessage: "Payment Dashboard" }) }),
246
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({
247
+ id: "payment-plugin.dashboard.subtitle",
248
+ defaultMessage: "Overview of your payment operations"
249
+ }) })
250
+ ] }),
251
+ /* @__PURE__ */ jsxRuntime.jsx(
252
+ designSystem.Button,
253
+ {
254
+ onClick: createTestPayment,
255
+ loading: creatingTest,
256
+ variant: "secondary",
257
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
258
+ children: formatMessage({ id: "payment-plugin.dashboard.initPayment", defaultMessage: "Initialize Sample Payment" })
259
+ }
260
+ )
261
+ ] }) }),
262
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 4, marginBottom: 8, children: [
263
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 3, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { padding: 4, shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "start", gap: 2, children: [
264
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", width: "100%", children: [
265
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", children: formatMessage({ id: "payment-plugin.dashboard.totalRevenue", defaultMessage: "Total Revenue" }) }),
266
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 2, background: "primary100", borderRadius: "50%", children: /* @__PURE__ */ jsxRuntime.jsx(icons.PriceTag, { width: "1rem", height: "1rem" }) })
267
+ ] }),
268
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", fontWeight: "bold", children: formatCurrency(stats?.totalRevenue || 0) }),
269
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { variant: "success", children: "Active" })
270
+ ] }) }) }),
271
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 3, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { padding: 4, shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "start", gap: 2, children: [
272
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", width: "100%", children: [
273
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", children: formatMessage({ id: "payment-plugin.dashboard.totalPayments", defaultMessage: "Total Payments" }) }),
274
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 2, background: "secondary100", borderRadius: "50%", children: /* @__PURE__ */ jsxRuntime.jsx(icons.ShoppingCart, { width: "1rem", height: "1rem" }) })
275
+ ] }),
276
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", fontWeight: "bold", children: stats?.totalPayments || 0 }),
277
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { variant: "secondary", children: "Live" })
278
+ ] }) }) }),
279
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 3, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { padding: 4, shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "start", gap: 2, children: [
280
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", width: "100%", children: [
281
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", children: formatMessage({ id: "payment-plugin.dashboard.successRate", defaultMessage: "Success Rate" }) }),
282
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 2, background: "success100", borderRadius: "50%", children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, { width: "1rem", height: "1rem" }) })
283
+ ] }),
284
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "alpha", fontWeight: "bold", children: [
285
+ stats ? Math.round(stats.successfulPayments / stats.totalPayments * 100) : 0,
286
+ "%"
287
+ ] }),
288
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { variant: "success", children: "Good" })
289
+ ] }) }) }),
290
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 3, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { padding: 4, shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "start", gap: 2, children: [
291
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", width: "100%", children: [
292
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", children: formatMessage({ id: "payment-plugin.dashboard.averageOrderValue", defaultMessage: "AVO" }) }),
293
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 2, background: "warning100", borderRadius: "50%", children: /* @__PURE__ */ jsxRuntime.jsx(icons.ChartPie, { width: "1rem", height: "1rem" }) })
294
+ ] }),
295
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", fontWeight: "bold", children: formatCurrency(stats?.averageOrderValue || 0) }),
296
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { variant: "neutral", children: "Calculated" })
297
+ ] }) }) })
298
+ ] }),
299
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 4, children: [
300
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 4, children: [
301
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
302
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", tag: "h2", children: formatMessage({ id: "payment-plugin.dashboard.recentPayments", defaultMessage: "Recent Payments" }) }),
303
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "Latest transactions from your customers" })
304
+ ] }),
305
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", size: "S", children: formatMessage({ id: "payment-plugin.dashboard.viewAll", defaultMessage: "View All" }) })
306
+ ] }),
307
+ /* @__PURE__ */ jsxRuntime.jsx(PaymentList.PaymentList, { payments: recentPayments, compact: true })
308
+ ] }) })
309
+ ] });
310
+ };
311
+ exports.Dashboard = Dashboard;