@reeboot/strapi-payment-plugin 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +378 -119
  2. package/dist/_chunks/Analytics-C2GKvPDX.js +355 -0
  3. package/dist/_chunks/Analytics-Chydh3dg.mjs +355 -0
  4. package/dist/_chunks/App-BCbEuN6h.mjs +68 -0
  5. package/dist/_chunks/App-E2k2mo5p.js +70 -0
  6. package/dist/_chunks/Customers-B8BlQ1BO.mjs +273 -0
  7. package/dist/_chunks/Customers-D0O5ET5C.js +273 -0
  8. package/dist/_chunks/Dashboard-CuqclLak.js +180 -0
  9. package/dist/_chunks/Dashboard-D8-ifJqB.mjs +180 -0
  10. package/dist/_chunks/Orders-5WGSzPGo.js +308 -0
  11. package/dist/_chunks/Orders-ClJJaQrX.mjs +308 -0
  12. package/dist/_chunks/Payments-CIMyOC3n.js +489 -0
  13. package/dist/_chunks/Payments-CRnRBf48.mjs +489 -0
  14. package/dist/_chunks/Settings-BXMLePI_.js +357 -0
  15. package/dist/_chunks/Settings-TeAvV4RH.mjs +357 -0
  16. package/dist/_chunks/en-BJocyOVu.mjs +240 -0
  17. package/dist/_chunks/en-BkVAf_R4.js +240 -0
  18. package/dist/_chunks/index-BTk7a2T5.js +66 -0
  19. package/dist/_chunks/index-Bz8V_5zH.mjs +67 -0
  20. package/dist/admin/index.js +2 -63
  21. package/dist/admin/index.mjs +2 -63
  22. package/dist/admin/src/components/AnalyticsChart.d.ts +19 -0
  23. package/dist/admin/src/components/CustomerList.d.ts +21 -0
  24. package/dist/admin/src/components/OrderList.d.ts +27 -0
  25. package/dist/admin/src/components/PaymentCard.d.ts +39 -0
  26. package/dist/admin/src/components/PaymentList.d.ts +19 -0
  27. package/dist/admin/src/components/RefundModal.d.ts +15 -0
  28. package/dist/admin/src/pages/Analytics.d.ts +2 -0
  29. package/dist/admin/src/pages/Customers.d.ts +2 -0
  30. package/dist/admin/src/pages/Dashboard.d.ts +2 -0
  31. package/dist/admin/src/pages/HomePage.d.ts +1 -1
  32. package/dist/admin/src/pages/Orders.d.ts +2 -0
  33. package/dist/admin/src/pages/Payments.d.ts +2 -0
  34. package/dist/admin/src/pages/Settings.d.ts +2 -0
  35. package/dist/admin/src/pluginId.d.ts +1 -1
  36. package/dist/server/index.js +1746 -984
  37. package/dist/server/index.mjs +1748 -986
  38. package/dist/server/src/bootstrap.d.ts +5 -11
  39. package/dist/server/src/config/index.d.ts +0 -10
  40. package/dist/server/src/content-types/customer/index.d.ts +69 -0
  41. package/dist/server/src/content-types/index.d.ts +123 -39
  42. package/dist/server/src/content-types/{product.d.ts → order/index.d.ts} +26 -19
  43. package/dist/server/src/content-types/{subscription.d.ts → payment/index.d.ts} +30 -21
  44. package/dist/server/src/controllers/controller.d.ts +5 -12
  45. package/dist/server/src/controllers/index.d.ts +29 -34
  46. package/dist/server/src/controllers/stripe.d.ts +104 -0
  47. package/dist/server/src/index.d.ts +179 -139
  48. package/dist/server/src/middlewares/index.d.ts +19 -1
  49. package/dist/server/src/policies/index.d.ts +3 -1
  50. package/dist/server/src/routes/{admin-routes.d.ts → admin/index.d.ts} +4 -4
  51. package/dist/server/src/routes/content-api/index.d.ts +21 -0
  52. package/dist/server/src/routes/index.d.ts +11 -16
  53. package/dist/server/src/services/index.d.ts +2 -38
  54. package/dist/server/src/services/{stripeDriver.d.ts → stripe.d.ts} +52 -59
  55. package/dist/server/src/types/index.d.ts +179 -0
  56. package/package.json +20 -25
  57. package/dist/_chunks/App-DD7GyuRr.mjs +0 -1424
  58. package/dist/_chunks/App-KZVBFRwo.js +0 -1424
  59. package/dist/_chunks/en-B4KWt_jN.js +0 -4
  60. package/dist/_chunks/en-Byx4XI2L.mjs +0 -4
  61. package/dist/admin/src/components/Header.d.ts +0 -2
  62. package/dist/admin/src/components/NavigationMenu.d.ts +0 -2
  63. package/dist/admin/src/components/Sidebar.d.ts +0 -2
  64. package/dist/admin/src/components/TransactionDetailsModal.d.ts +0 -18
  65. package/dist/admin/src/components/TransactionList.d.ts +0 -18
  66. package/dist/admin/src/pages/ConfigurationPage.d.ts +0 -2
  67. package/dist/admin/src/pages/DashboardPage.d.ts +0 -2
  68. package/dist/admin/src/pages/ProductsPage.d.ts +0 -2
  69. package/dist/admin/src/pages/SubscriptionsPage.d.ts +0 -2
  70. package/dist/admin/src/pages/TransactionsPage.d.ts +0 -2
  71. package/dist/server/src/controllers/product.d.ts +0 -18
  72. package/dist/server/src/controllers/subscription.d.ts +0 -16
  73. package/dist/server/src/controllers/webhook.d.ts +0 -10
  74. package/dist/server/src/routes/content-api.d.ts +0 -12
  75. package/dist/server/src/routes/product.d.ts +0 -2
  76. package/dist/server/src/routes/refund-routes.d.ts +0 -13
  77. package/dist/server/src/routes/subscription.d.ts +0 -5
  78. package/dist/server/src/routes/webhook.d.ts +0 -15
  79. package/dist/server/src/services/paypalDriver.d.ts +0 -47
  80. package/dist/server/src/services/product.d.ts +0 -7
  81. package/dist/server/src/services/service.d.ts +0 -26
  82. package/dist/server/src/services/subscription.d.ts +0 -9
  83. package/dist/server/src/services/sync.d.ts +0 -13
  84. package/jest.config.js +0 -13
@@ -0,0 +1,180 @@
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 admin = require("@strapi/strapi/admin");
7
+ const reactIntl = require("react-intl");
8
+ const index = require("./index-BTk7a2T5.js");
9
+ const Dashboard = () => {
10
+ const { formatMessage } = reactIntl.useIntl();
11
+ const { get, post } = admin.useFetchClient();
12
+ const [stats, setStats] = React.useState(null);
13
+ const [recentPayments, setRecentPayments] = React.useState([]);
14
+ const [loading, setLoading] = React.useState(true);
15
+ const [error, setError] = React.useState(null);
16
+ const [creatingTest, setCreatingTest] = React.useState(false);
17
+ React.useEffect(() => {
18
+ fetchDashboardData();
19
+ }, []);
20
+ const fetchDashboardData = async () => {
21
+ try {
22
+ setLoading(true);
23
+ const { data } = await get(`/${index.PLUGIN_ID}/admin/dashboard`);
24
+ if (data.success && data.data) {
25
+ setStats({
26
+ totalRevenue: data.data.summary.totalRevenue,
27
+ totalPayments: data.data.summary.totalPayments,
28
+ successfulPayments: data.data.summary.successfulPayments,
29
+ pendingPayments: data.data.summary.totalPayments - data.data.summary.successfulPayments - data.data.summary.failedPayments,
30
+ failedPayments: data.data.summary.failedPayments,
31
+ totalCustomers: data.data.topCustomers.length,
32
+ // Rough estimate
33
+ totalOrders: data.data.summary.totalPayments,
34
+ // Rough estimate
35
+ averageOrderValue: data.data.summary.totalPayments > 0 ? data.data.summary.totalRevenue / data.data.summary.totalPayments : 0
36
+ });
37
+ const formattedPayments = data.data.recentTransactions.map((p) => ({
38
+ id: p.documentId,
39
+ amount: p.amount,
40
+ currency: p.currency,
41
+ status: p.status,
42
+ customerEmail: p.customer?.email || "N/A",
43
+ createdAt: p.createdAt,
44
+ paymentMethod: p.payment_method || "N/A"
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) {
59
+ alert(`Payment flow successfully initialized!
60
+ Customer: ${data.data.customer.email}
61
+ Order: ${data.data.order.documentId}
62
+ Stripe Payment Intent: ${data.data.stripePaymentIntent.id}
63
+ Status: ${data.data.stripePaymentIntent.status}`);
64
+ } else {
65
+ throw new Error(data.error?.message || "Failed to process payment");
66
+ }
67
+ await fetchDashboardData();
68
+ } catch (err) {
69
+ console.error("Failed to process payment", err);
70
+ alert(err instanceof Error ? err.message : "An error occurred during payment initialization");
71
+ } finally {
72
+ setCreatingTest(false);
73
+ }
74
+ };
75
+ const formatCurrency = (amount, currency = "USD") => {
76
+ return new Intl.NumberFormat("en-US", {
77
+ style: "currency",
78
+ currency
79
+ }).format(amount);
80
+ };
81
+ const formatDate = (dateString) => {
82
+ return new Date(dateString).toLocaleDateString("en-US", {
83
+ year: "numeric",
84
+ month: "short",
85
+ day: "numeric",
86
+ hour: "2-digit",
87
+ minute: "2-digit"
88
+ });
89
+ };
90
+ const getStatusBadge = (status) => {
91
+ const statusConfig = {
92
+ succeeded: { color: "success", labelId: "payment-plugin.payments.succeeded", defaultLabel: "Success" },
93
+ pending: { color: "warning", labelId: "payment-plugin.payments.pending", defaultLabel: "Pending" },
94
+ failed: { color: "danger", labelId: "payment-plugin.payments.failed", defaultLabel: "Failed" },
95
+ refunded: { color: "info", labelId: "payment-plugin.payments.refunded", defaultLabel: "Refunded" }
96
+ };
97
+ const config = statusConfig[status] || statusConfig.pending;
98
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { size: "S", backgroundColor: config.color, children: formatMessage({ id: config.labelId, defaultMessage: config.defaultLabel }) });
99
+ };
100
+ if (loading) {
101
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingLeft: 10, paddingRight: 10, paddingTop: 4, paddingBottom: 10, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", alignItems: "center", style: { minHeight: "400px" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, {}) }) });
102
+ }
103
+ if (error) {
104
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingLeft: 10, paddingRight: 10, paddingTop: 4, paddingBottom: 10, children: /* @__PURE__ */ jsxRuntime.jsx(
105
+ designSystem.EmptyStateLayout,
106
+ {
107
+ title: "Error loading dashboard",
108
+ subtitle: error,
109
+ action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: fetchDashboardData, children: formatMessage({ id: "payment-plugin.dashboard.retry", defaultMessage: "Retry" }) })
110
+ }
111
+ ) });
112
+ }
113
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { paddingLeft: 10, paddingRight: 10, paddingTop: 4, paddingBottom: 10, children: [
114
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", children: [
115
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
116
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", tag: "h1", children: formatMessage({ id: "payment-plugin.dashboard.title", defaultMessage: "Payment Dashboard" }) }),
117
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({
118
+ id: "payment-plugin.dashboard.subtitle",
119
+ defaultMessage: "Overview of your payment operations"
120
+ }) })
121
+ ] }),
122
+ /* @__PURE__ */ jsxRuntime.jsx(
123
+ designSystem.Button,
124
+ {
125
+ onClick: createTestPayment,
126
+ loading: creatingTest,
127
+ variant: "secondary",
128
+ children: formatMessage({ id: "payment-plugin.dashboard.initPayment", defaultMessage: "Initialize Sample Payment" })
129
+ }
130
+ )
131
+ ] }) }),
132
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 4, marginBottom: 8, children: [
133
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 3, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
134
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: "payment-plugin.dashboard.totalRevenue", defaultMessage: "Total Revenue" }) }),
135
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", children: formatCurrency(stats?.totalRevenue || 0) })
136
+ ] }) }) }) }),
137
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 3, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
138
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: "payment-plugin.dashboard.totalPayments", defaultMessage: "Total Payments" }) }),
139
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", children: stats?.totalPayments || 0 })
140
+ ] }) }) }) }),
141
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 3, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
142
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: "payment-plugin.dashboard.successRate", defaultMessage: "Success Rate" }) }),
143
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "delta", fontWeight: "bold", children: [
144
+ stats ? Math.round(stats.successfulPayments / stats.totalPayments * 100) : 0,
145
+ "%"
146
+ ] })
147
+ ] }) }) }) }),
148
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 3, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
149
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: "payment-plugin.dashboard.averageOrderValue", defaultMessage: "Average Order Value" }) }),
150
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", children: formatCurrency(stats?.averageOrderValue || 0) })
151
+ ] }) }) }) })
152
+ ] }),
153
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 4, children: [
154
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 4, children: [
155
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", tag: "h2", children: formatMessage({ id: "payment-plugin.dashboard.recentPayments", defaultMessage: "Recent Payments" }) }),
156
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", size: "S", children: formatMessage({ id: "payment-plugin.dashboard.viewAll", defaultMessage: "View All" }) })
157
+ ] }),
158
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { children: [
159
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
160
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.customer", defaultMessage: "Customer" }) }) }),
161
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.amount", defaultMessage: "Amount" }) }) }),
162
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.status", defaultMessage: "Status" }) }) }),
163
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.paymentMethod", defaultMessage: "Payment Method" }) }) }),
164
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.date", defaultMessage: "Date" }) }) })
165
+ ] }) }),
166
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: recentPayments.map((payment) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
167
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", children: payment.customerEmail }) }),
168
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", fontWeight: "bold", children: formatCurrency(payment.amount, payment.currency) }) }),
169
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: getStatusBadge(payment.status) }),
170
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: formatMessage({
171
+ id: `payment-plugin.payments.${payment.paymentMethod}`,
172
+ defaultMessage: payment.paymentMethod
173
+ }) }) }),
174
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: formatDate(payment.createdAt) }) })
175
+ ] }, payment.id)) })
176
+ ] })
177
+ ] }) })
178
+ ] });
179
+ };
180
+ exports.Dashboard = Dashboard;
@@ -0,0 +1,180 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect } from "react";
3
+ import { Box, Flex, Loader, EmptyStateLayout, Button, Typography, Grid, Card, Table, Thead, Tr, Th, Tbody, Td, Badge } from "@strapi/design-system";
4
+ import { useFetchClient } from "@strapi/strapi/admin";
5
+ import { useIntl } from "react-intl";
6
+ import { P as PLUGIN_ID } from "./index-Bz8V_5zH.mjs";
7
+ const Dashboard = () => {
8
+ const { formatMessage } = useIntl();
9
+ const { get, post } = useFetchClient();
10
+ const [stats, setStats] = useState(null);
11
+ const [recentPayments, setRecentPayments] = useState([]);
12
+ const [loading, setLoading] = useState(true);
13
+ const [error, setError] = useState(null);
14
+ const [creatingTest, setCreatingTest] = useState(false);
15
+ useEffect(() => {
16
+ fetchDashboardData();
17
+ }, []);
18
+ const fetchDashboardData = async () => {
19
+ try {
20
+ setLoading(true);
21
+ const { data } = await get(`/${PLUGIN_ID}/admin/dashboard`);
22
+ if (data.success && data.data) {
23
+ setStats({
24
+ totalRevenue: data.data.summary.totalRevenue,
25
+ totalPayments: data.data.summary.totalPayments,
26
+ successfulPayments: data.data.summary.successfulPayments,
27
+ pendingPayments: data.data.summary.totalPayments - data.data.summary.successfulPayments - data.data.summary.failedPayments,
28
+ failedPayments: data.data.summary.failedPayments,
29
+ totalCustomers: data.data.topCustomers.length,
30
+ // Rough estimate
31
+ totalOrders: data.data.summary.totalPayments,
32
+ // Rough estimate
33
+ averageOrderValue: data.data.summary.totalPayments > 0 ? data.data.summary.totalRevenue / data.data.summary.totalPayments : 0
34
+ });
35
+ const formattedPayments = data.data.recentTransactions.map((p) => ({
36
+ id: p.documentId,
37
+ amount: p.amount,
38
+ currency: p.currency,
39
+ status: p.status,
40
+ customerEmail: p.customer?.email || "N/A",
41
+ createdAt: p.createdAt,
42
+ paymentMethod: p.payment_method || "N/A"
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) {
57
+ alert(`Payment flow successfully initialized!
58
+ Customer: ${data.data.customer.email}
59
+ Order: ${data.data.order.documentId}
60
+ Stripe Payment Intent: ${data.data.stripePaymentIntent.id}
61
+ Status: ${data.data.stripePaymentIntent.status}`);
62
+ } else {
63
+ throw new Error(data.error?.message || "Failed to process payment");
64
+ }
65
+ await fetchDashboardData();
66
+ } catch (err) {
67
+ console.error("Failed to process payment", err);
68
+ alert(err instanceof Error ? err.message : "An error occurred during payment initialization");
69
+ } finally {
70
+ setCreatingTest(false);
71
+ }
72
+ };
73
+ const formatCurrency = (amount, currency = "USD") => {
74
+ return new Intl.NumberFormat("en-US", {
75
+ style: "currency",
76
+ currency
77
+ }).format(amount);
78
+ };
79
+ const formatDate = (dateString) => {
80
+ return new Date(dateString).toLocaleDateString("en-US", {
81
+ year: "numeric",
82
+ month: "short",
83
+ day: "numeric",
84
+ hour: "2-digit",
85
+ minute: "2-digit"
86
+ });
87
+ };
88
+ const getStatusBadge = (status) => {
89
+ const statusConfig = {
90
+ succeeded: { color: "success", labelId: "payment-plugin.payments.succeeded", defaultLabel: "Success" },
91
+ pending: { color: "warning", labelId: "payment-plugin.payments.pending", defaultLabel: "Pending" },
92
+ failed: { color: "danger", labelId: "payment-plugin.payments.failed", defaultLabel: "Failed" },
93
+ refunded: { color: "info", labelId: "payment-plugin.payments.refunded", defaultLabel: "Refunded" }
94
+ };
95
+ const config = statusConfig[status] || statusConfig.pending;
96
+ return /* @__PURE__ */ jsx(Badge, { size: "S", backgroundColor: config.color, children: formatMessage({ id: config.labelId, defaultMessage: config.defaultLabel }) });
97
+ };
98
+ if (loading) {
99
+ return /* @__PURE__ */ jsx(Box, { paddingLeft: 10, paddingRight: 10, paddingTop: 4, paddingBottom: 10, children: /* @__PURE__ */ jsx(Flex, { justifyContent: "center", alignItems: "center", style: { minHeight: "400px" }, children: /* @__PURE__ */ jsx(Loader, {}) }) });
100
+ }
101
+ if (error) {
102
+ return /* @__PURE__ */ jsx(Box, { paddingLeft: 10, paddingRight: 10, paddingTop: 4, paddingBottom: 10, children: /* @__PURE__ */ jsx(
103
+ EmptyStateLayout,
104
+ {
105
+ title: "Error loading dashboard",
106
+ subtitle: error,
107
+ action: /* @__PURE__ */ jsx(Button, { onClick: fetchDashboardData, children: formatMessage({ id: "payment-plugin.dashboard.retry", defaultMessage: "Retry" }) })
108
+ }
109
+ ) });
110
+ }
111
+ return /* @__PURE__ */ jsxs(Box, { paddingLeft: 10, paddingRight: 10, paddingTop: 4, paddingBottom: 10, children: [
112
+ /* @__PURE__ */ jsx(Box, { marginBottom: 4, children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [
113
+ /* @__PURE__ */ jsxs(Box, { children: [
114
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: formatMessage({ id: "payment-plugin.dashboard.title", defaultMessage: "Payment Dashboard" }) }),
115
+ /* @__PURE__ */ jsx(Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({
116
+ id: "payment-plugin.dashboard.subtitle",
117
+ defaultMessage: "Overview of your payment operations"
118
+ }) })
119
+ ] }),
120
+ /* @__PURE__ */ jsx(
121
+ Button,
122
+ {
123
+ onClick: createTestPayment,
124
+ loading: creatingTest,
125
+ variant: "secondary",
126
+ children: formatMessage({ id: "payment-plugin.dashboard.initPayment", defaultMessage: "Initialize Sample Payment" })
127
+ }
128
+ )
129
+ ] }) }),
130
+ /* @__PURE__ */ jsxs(Grid.Root, { gap: 4, marginBottom: 8, children: [
131
+ /* @__PURE__ */ jsx(Grid.Item, { col: 3, children: /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
132
+ /* @__PURE__ */ jsx(Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: "payment-plugin.dashboard.totalRevenue", defaultMessage: "Total Revenue" }) }),
133
+ /* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "bold", children: formatCurrency(stats?.totalRevenue || 0) })
134
+ ] }) }) }) }),
135
+ /* @__PURE__ */ jsx(Grid.Item, { col: 3, children: /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
136
+ /* @__PURE__ */ jsx(Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: "payment-plugin.dashboard.totalPayments", defaultMessage: "Total Payments" }) }),
137
+ /* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "bold", children: stats?.totalPayments || 0 })
138
+ ] }) }) }) }),
139
+ /* @__PURE__ */ jsx(Grid.Item, { col: 3, children: /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
140
+ /* @__PURE__ */ jsx(Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: "payment-plugin.dashboard.successRate", defaultMessage: "Success Rate" }) }),
141
+ /* @__PURE__ */ jsxs(Typography, { variant: "delta", fontWeight: "bold", children: [
142
+ stats ? Math.round(stats.successfulPayments / stats.totalPayments * 100) : 0,
143
+ "%"
144
+ ] })
145
+ ] }) }) }) }),
146
+ /* @__PURE__ */ jsx(Grid.Item, { col: 3, children: /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
147
+ /* @__PURE__ */ jsx(Typography, { variant: "epsilon", textColor: "neutral600", children: formatMessage({ id: "payment-plugin.dashboard.averageOrderValue", defaultMessage: "Average Order Value" }) }),
148
+ /* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "bold", children: formatCurrency(stats?.averageOrderValue || 0) })
149
+ ] }) }) }) })
150
+ ] }),
151
+ /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(Box, { padding: 4, children: [
152
+ /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 4, children: [
153
+ /* @__PURE__ */ jsx(Typography, { variant: "beta", tag: "h2", children: formatMessage({ id: "payment-plugin.dashboard.recentPayments", defaultMessage: "Recent Payments" }) }),
154
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "S", children: formatMessage({ id: "payment-plugin.dashboard.viewAll", defaultMessage: "View All" }) })
155
+ ] }),
156
+ /* @__PURE__ */ jsxs(Table, { children: [
157
+ /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
158
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.customer", defaultMessage: "Customer" }) }) }),
159
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.amount", defaultMessage: "Amount" }) }) }),
160
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.status", defaultMessage: "Status" }) }) }),
161
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.paymentMethod", defaultMessage: "Payment Method" }) }) }),
162
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "epsilon", children: formatMessage({ id: "payment-plugin.dashboard.date", defaultMessage: "Date" }) }) })
163
+ ] }) }),
164
+ /* @__PURE__ */ jsx(Tbody, { children: recentPayments.map((payment) => /* @__PURE__ */ jsxs(Tr, { children: [
165
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: payment.customerEmail }) }),
166
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", fontWeight: "bold", children: formatCurrency(payment.amount, payment.currency) }) }),
167
+ /* @__PURE__ */ jsx(Td, { children: getStatusBadge(payment.status) }),
168
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
169
+ id: `payment-plugin.payments.${payment.paymentMethod}`,
170
+ defaultMessage: payment.paymentMethod
171
+ }) }) }),
172
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatDate(payment.createdAt) }) })
173
+ ] }, payment.id)) })
174
+ ] })
175
+ ] }) })
176
+ ] });
177
+ };
178
+ export {
179
+ Dashboard
180
+ };