order-management 0.0.89 → 0.0.90

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.
@@ -2,7 +2,7 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
3
3
  import { useState, useEffect, useRef, useCallback, useMemo } from "react";
4
4
  import { Container, Text, Heading, Badge, Button, Label, Select, Textarea, Input } from "@medusajs/ui";
5
- import { CashSolid, PencilSquareSolid, Trash, CreditCard, Receipt, ArrowPath, CheckCircle, ArrowLeft } from "@medusajs/icons";
5
+ import { CashSolid, PencilSquareSolid, Trash, Receipt, ArrowPath, CheckCircle, ArrowLeft, CreditCard } from "@medusajs/icons";
6
6
  import { useNavigate, useParams } from "react-router-dom";
7
7
  function roundRectPath(ctx, x, y, w, h, r) {
8
8
  ctx.beginPath();
@@ -872,216 +872,16 @@ const getStatusBadgeClass$7 = (status) => {
872
872
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
873
873
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
874
874
  };
875
- const PaymentsPage = () => {
876
- const navigate = useNavigate();
877
- const [items, setItems] = useState([]);
878
- const [statusFilter, setStatusFilter] = useState("all");
879
- const [orderIdSearch, setOrderIdSearch] = useState("");
880
- const debouncedOrderId = useDebounce$3(orderIdSearch, 300);
881
- const [isLoading, setIsLoading] = useState(true);
882
- const [isFetchingMore, setIsFetchingMore] = useState(false);
883
- const [error, setError] = useState(null);
884
- const [offset, setOffset] = useState(0);
885
- const [count, setCount] = useState(0);
886
- const limit = 50;
887
- const loadTransactions = useCallback(
888
- async (nextOffset, replace) => {
889
- try {
890
- if (replace) setIsLoading(true);
891
- else setIsFetchingMore(true);
892
- setError(null);
893
- const params = new URLSearchParams();
894
- params.set("limit", String(limit));
895
- params.set("offset", String(nextOffset));
896
- if (statusFilter !== "all") params.set("status", statusFilter);
897
- if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
898
- const response = await fetch(
899
- `/admin/payment-transactions?${params.toString()}`,
900
- { credentials: "include" }
901
- );
902
- if (!response.ok) {
903
- const text = await response.text();
904
- throw new Error(text || "Failed to load payment transactions");
905
- }
906
- const payload = await response.json();
907
- const list = payload.transactions ?? [];
908
- setCount(payload.count ?? 0);
909
- setOffset(nextOffset + list.length);
910
- setItems((prev) => replace ? list : [...prev, ...list]);
911
- } catch (e) {
912
- setError(e instanceof Error ? e.message : "Failed to load");
913
- } finally {
914
- setIsLoading(false);
915
- setIsFetchingMore(false);
916
- }
917
- },
918
- [statusFilter, debouncedOrderId]
919
- );
920
- useEffect(() => {
921
- void loadTransactions(0, true);
922
- }, [loadTransactions]);
923
- const hasMore = useMemo(() => offset < count, [offset, count]);
924
- const displayStatus = (t) => {
925
- const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
926
- return s2 !== "" ? s2 : "—";
927
- };
928
- const displayAmount = (t) => {
929
- const code = (t.currency_code ?? "USD").toUpperCase();
930
- return `${code} ${Number(t.amount)}`;
931
- };
932
- return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
933
- /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
934
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
935
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payments" }),
936
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
937
- ] }),
938
- /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
939
- ] }),
940
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
941
- /* @__PURE__ */ jsx(
942
- Input,
943
- {
944
- placeholder: "Search by Order ID",
945
- value: orderIdSearch,
946
- onChange: (e) => setOrderIdSearch(e.target.value),
947
- className: "md:max-w-sm",
948
- "aria-label": "Search by order ID"
949
- }
950
- ),
951
- /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxs(
952
- "select",
953
- {
954
- value: statusFilter,
955
- onChange: (e) => setStatusFilter(e.target.value),
956
- className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
957
- "aria-label": "Filter by status",
958
- children: [
959
- /* @__PURE__ */ jsx("option", { value: "all", children: "All statuses" }),
960
- /* @__PURE__ */ jsx("option", { value: "pending", children: "Pending" }),
961
- /* @__PURE__ */ jsx("option", { value: "requires_more", children: "Requires more" }),
962
- /* @__PURE__ */ jsx("option", { value: "error", children: "Error" }),
963
- /* @__PURE__ */ jsx("option", { value: "canceled", children: "Canceled" }),
964
- /* @__PURE__ */ jsx("option", { value: "authorized", children: "Authorized" }),
965
- /* @__PURE__ */ jsx("option", { value: "captured", children: "Captured" })
966
- ]
967
- }
968
- ) })
969
- ] }),
970
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
971
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
972
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
973
- ] }) : null,
974
- isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
975
- /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
976
- /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
977
- ] }) : /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
978
- /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
979
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
980
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
981
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
982
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
983
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
984
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
985
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
986
- ] }) }),
987
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxs(
988
- "tr",
989
- {
990
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
991
- onClick: () => navigate(`/payments/${t.payment_session_id}`),
992
- children: [
993
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
994
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
995
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
996
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
997
- Badge,
998
- {
999
- size: "2xsmall",
1000
- className: `uppercase ${getStatusBadgeClass$7(displayStatus(t))}`,
1001
- children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1002
- }
1003
- ) }),
1004
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1005
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1006
- year: "numeric",
1007
- month: "short",
1008
- day: "numeric",
1009
- hour: "numeric",
1010
- minute: "2-digit",
1011
- hour12: true
1012
- }) }),
1013
- /* @__PURE__ */ jsxs("td", { className: "px-4 py-4", children: [
1014
- /* @__PURE__ */ jsx(
1015
- Button,
1016
- {
1017
- variant: "transparent",
1018
- size: "small",
1019
- onClick: (e) => {
1020
- e.stopPropagation();
1021
- navigate(`/payments/${t.payment_session_id}`);
1022
- },
1023
- children: "View details"
1024
- }
1025
- ),
1026
- t.order_id ? /* @__PURE__ */ jsx(
1027
- Button,
1028
- {
1029
- variant: "transparent",
1030
- size: "small",
1031
- onClick: (e) => {
1032
- e.stopPropagation();
1033
- navigate(`/orders/${t.order_id}`);
1034
- },
1035
- children: "Order"
1036
- }
1037
- ) : null
1038
- ] })
1039
- ]
1040
- },
1041
- t.payment_session_id
1042
- )) })
1043
- ] }) }),
1044
- hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
1045
- Button,
1046
- {
1047
- variant: "secondary",
1048
- isLoading: isFetchingMore,
1049
- onClick: () => loadTransactions(offset, false),
1050
- children: "Load more"
1051
- }
1052
- ) }) : null
1053
- ] }) });
1054
- };
1055
- const config$7 = defineRouteConfig({
1056
- label: "Payments",
1057
- icon: CreditCard
1058
- });
1059
- const useDebounce$2 = (value, delay) => {
1060
- const [debouncedValue, setDebouncedValue] = useState(value);
1061
- useEffect(() => {
1062
- const handler = setTimeout(() => setDebouncedValue(value), delay);
1063
- return () => clearTimeout(handler);
1064
- }, [value, delay]);
1065
- return debouncedValue;
1066
- };
1067
- const getStatusBadgeClass$6 = (status) => {
1068
- const s2 = status.toLowerCase();
1069
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1070
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1071
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1072
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1073
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1074
- };
1075
875
  const RefundsPage = () => {
1076
876
  const navigate = useNavigate();
1077
877
  const [items, setItems] = useState([]);
1078
878
  const [orderIdSearch, setOrderIdSearch] = useState("");
1079
- const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
879
+ const debouncedOrderId = useDebounce$3(orderIdSearch, 300);
1080
880
  const [paymentStatusFilter, setPaymentStatusFilter] = useState("all");
1081
881
  const [providerSearch, setProviderSearch] = useState("");
1082
- const debouncedProvider = useDebounce$2(providerSearch, 300);
882
+ const debouncedProvider = useDebounce$3(providerSearch, 300);
1083
883
  const [currencySearch, setCurrencySearch] = useState("");
1084
- const debouncedCurrency = useDebounce$2(currencySearch, 300);
884
+ const debouncedCurrency = useDebounce$3(currencySearch, 300);
1085
885
  const [dateFrom, setDateFrom] = useState("");
1086
886
  const [dateTo, setDateTo] = useState("");
1087
887
  const [amountMin, setAmountMin] = useState("");
@@ -1293,7 +1093,7 @@ const RefundsPage = () => {
1293
1093
  Badge,
1294
1094
  {
1295
1095
  size: "2xsmall",
1296
- className: `uppercase ${getStatusBadgeClass$6(displayStatus(r))}`,
1096
+ className: `uppercase ${getStatusBadgeClass$7(displayStatus(r))}`,
1297
1097
  children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1298
1098
  }
1299
1099
  ) }),
@@ -1347,11 +1147,11 @@ const RefundsPage = () => {
1347
1147
  ) }) : null
1348
1148
  ] }) });
1349
1149
  };
1350
- const config$6 = defineRouteConfig({
1150
+ const config$7 = defineRouteConfig({
1351
1151
  label: "Refunds",
1352
1152
  icon: Receipt
1353
1153
  });
1354
- const useDebounce$1 = (value, delay) => {
1154
+ const useDebounce$2 = (value, delay) => {
1355
1155
  const [debouncedValue, setDebouncedValue] = useState(value);
1356
1156
  useEffect(() => {
1357
1157
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1359,7 +1159,7 @@ const useDebounce$1 = (value, delay) => {
1359
1159
  }, [value, delay]);
1360
1160
  return debouncedValue;
1361
1161
  };
1362
- const getStatusBadgeClass$5 = (status) => {
1162
+ const getStatusBadgeClass$6 = (status) => {
1363
1163
  const statusLower = status.toLowerCase();
1364
1164
  if (statusLower === "requested") {
1365
1165
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -1384,7 +1184,7 @@ const ReturnsPage = () => {
1384
1184
  const [statusFilter, setStatusFilter] = useState("all");
1385
1185
  const [createdByFilter, setCreatedByFilter] = useState("all");
1386
1186
  const [searchQuery, setSearchQuery] = useState("");
1387
- const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1187
+ const debouncedSearchQuery = useDebounce$2(searchQuery, 300);
1388
1188
  const [isLoading, setIsLoading] = useState(true);
1389
1189
  const [isFetchingMore, setIsFetchingMore] = useState(false);
1390
1190
  const [error, setError] = useState(null);
@@ -1530,7 +1330,7 @@ const ReturnsPage = () => {
1530
1330
  Badge,
1531
1331
  {
1532
1332
  size: "2xsmall",
1533
- className: `uppercase ${getStatusBadgeClass$5(returnOrder.status)}`,
1333
+ className: `uppercase ${getStatusBadgeClass$6(returnOrder.status)}`,
1534
1334
  children: returnOrder.status.replace(/_/g, " ")
1535
1335
  }
1536
1336
  ) }),
@@ -1579,11 +1379,11 @@ const ReturnsPage = () => {
1579
1379
  ) }) : null
1580
1380
  ] }) });
1581
1381
  };
1582
- const config$5 = defineRouteConfig({
1382
+ const config$6 = defineRouteConfig({
1583
1383
  label: "Return Orders",
1584
1384
  icon: ArrowPath
1585
1385
  });
1586
- const useDebounce = (value, delay) => {
1386
+ const useDebounce$1 = (value, delay) => {
1587
1387
  const [debouncedValue, setDebouncedValue] = useState(value);
1588
1388
  useEffect(() => {
1589
1389
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1591,7 +1391,7 @@ const useDebounce = (value, delay) => {
1591
1391
  }, [value, delay]);
1592
1392
  return debouncedValue;
1593
1393
  };
1594
- const getStatusBadgeClass$4 = (status) => {
1394
+ const getStatusBadgeClass$5 = (status) => {
1595
1395
  const statusLower = status.toLowerCase();
1596
1396
  if (statusLower === "requested") {
1597
1397
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -1616,7 +1416,7 @@ const SwapsPage = () => {
1616
1416
  const [statusFilter, setStatusFilter] = useState("all");
1617
1417
  const [createdByFilter, setCreatedByFilter] = useState("all");
1618
1418
  const [searchQuery, setSearchQuery] = useState("");
1619
- const debouncedSearchQuery = useDebounce(searchQuery, 300);
1419
+ const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1620
1420
  const [isLoading, setIsLoading] = useState(true);
1621
1421
  const [isFetchingMore, setIsFetchingMore] = useState(false);
1622
1422
  const [error, setError] = useState(null);
@@ -1759,7 +1559,7 @@ const SwapsPage = () => {
1759
1559
  Badge,
1760
1560
  {
1761
1561
  size: "2xsmall",
1762
- className: `uppercase ${getStatusBadgeClass$4(swap.status)}`,
1562
+ className: `uppercase ${getStatusBadgeClass$5(swap.status)}`,
1763
1563
  children: swap.status.replace(/_/g, " ")
1764
1564
  }
1765
1565
  ) }),
@@ -1809,11 +1609,11 @@ const SwapsPage = () => {
1809
1609
  ) }) : null
1810
1610
  ] }) });
1811
1611
  };
1812
- const config$4 = defineRouteConfig({
1612
+ const config$5 = defineRouteConfig({
1813
1613
  label: "Exchanges",
1814
1614
  icon: ArrowPath
1815
1615
  });
1816
- const getStatusBadgeClass$3 = (status) => {
1616
+ const getStatusBadgeClass$4 = (status) => {
1817
1617
  const s2 = status.toLowerCase();
1818
1618
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1819
1619
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1821,14 +1621,18 @@ const getStatusBadgeClass$3 = (status) => {
1821
1621
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1822
1622
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1823
1623
  };
1824
- const PaymentDetailPage = () => {
1825
- var _a;
1624
+ const formatAmount = (value) => {
1625
+ return String(value);
1626
+ };
1627
+ const RefundDetailPage = () => {
1628
+ var _a, _b, _c;
1826
1629
  const navigate = useNavigate();
1827
1630
  const params = useParams();
1828
1631
  const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
1829
1632
  const [detail, setDetail] = useState(null);
1830
1633
  const [loading, setLoading] = useState(!!id);
1831
1634
  const [error, setError] = useState(null);
1635
+ const [gatewayExpanded, setGatewayExpanded] = useState(false);
1832
1636
  useEffect(() => {
1833
1637
  if (!id) {
1834
1638
  setLoading(false);
@@ -1837,7 +1641,7 @@ const PaymentDetailPage = () => {
1837
1641
  let cancelled = false;
1838
1642
  setLoading(true);
1839
1643
  setError(null);
1840
- fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
1644
+ fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
1841
1645
  if (!res.ok) throw new Error(res.statusText || "Failed to load");
1842
1646
  return res.json();
1843
1647
  }).then((data) => {
@@ -1851,140 +1655,17 @@ const PaymentDetailPage = () => {
1851
1655
  cancelled = true;
1852
1656
  };
1853
1657
  }, [id]);
1854
- const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
1855
- const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
1856
- const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
1857
- const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
1658
+ const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
1659
+ const hasGatewayData = ((_c = detail == null ? void 0 : detail.payment) == null ? void 0 : _c.payment_data) && typeof detail.payment.payment_data === "object" && Object.keys(detail.payment.payment_data).length > 0;
1858
1660
  return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
1859
1661
  /* @__PURE__ */ jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1860
- /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
1861
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payment session" }),
1862
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
1662
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
1663
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Refund details" }),
1664
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
1863
1665
  ] }) }),
1864
1666
  error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1865
1667
  /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1866
- /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
1867
- ] }) : loading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
1868
- /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1869
- /* @__PURE__ */ jsxs("div", { children: [
1870
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
1871
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsx(
1872
- Button,
1873
- {
1874
- variant: "transparent",
1875
- size: "small",
1876
- onClick: () => navigate(`/orders/${detail.order_id}`),
1877
- children: detail.order_id
1878
- }
1879
- ) : /* @__PURE__ */ jsx(Text, { children: "—" }) })
1880
- ] }),
1881
- /* @__PURE__ */ jsxs("div", { children: [
1882
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
1883
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: displayAmount })
1884
- ] }),
1885
- /* @__PURE__ */ jsxs("div", { children: [
1886
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
1887
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.provider_id })
1888
- ] }),
1889
- /* @__PURE__ */ jsxs("div", { children: [
1890
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
1891
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
1892
- Badge,
1893
- {
1894
- size: "2xsmall",
1895
- className: `uppercase ${getStatusBadgeClass$3(displayStatus)}`,
1896
- children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
1897
- }
1898
- ) })
1899
- ] }),
1900
- /* @__PURE__ */ jsxs("div", { children: [
1901
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
1902
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: sessionStatusRaw })
1903
- ] }),
1904
- /* @__PURE__ */ jsxs("div", { children: [
1905
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
1906
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: paymentStatusRaw })
1907
- ] }),
1908
- /* @__PURE__ */ jsxs("div", { children: [
1909
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
1910
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
1911
- ] }),
1912
- /* @__PURE__ */ jsxs("div", { children: [
1913
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
1914
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
1915
- year: "numeric",
1916
- month: "short",
1917
- day: "numeric",
1918
- hour: "numeric",
1919
- minute: "2-digit",
1920
- hour12: true
1921
- }) })
1922
- ] })
1923
- ] }) }),
1924
- Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1925
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
1926
- /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.data, null, 2) })
1927
- ] }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
1928
- ] }) : null
1929
- ] }) });
1930
- };
1931
- const config$3 = defineRouteConfig({
1932
- label: "Payment details",
1933
- icon: CreditCard
1934
- });
1935
- const getStatusBadgeClass$2 = (status) => {
1936
- const s2 = status.toLowerCase();
1937
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1938
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1939
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1940
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1941
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1942
- };
1943
- const formatAmount = (value) => {
1944
- return String(value);
1945
- };
1946
- const RefundDetailPage = () => {
1947
- var _a, _b, _c;
1948
- const navigate = useNavigate();
1949
- const params = useParams();
1950
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
1951
- const [detail, setDetail] = useState(null);
1952
- const [loading, setLoading] = useState(!!id);
1953
- const [error, setError] = useState(null);
1954
- const [gatewayExpanded, setGatewayExpanded] = useState(false);
1955
- useEffect(() => {
1956
- if (!id) {
1957
- setLoading(false);
1958
- return;
1959
- }
1960
- let cancelled = false;
1961
- setLoading(true);
1962
- setError(null);
1963
- fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
1964
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
1965
- return res.json();
1966
- }).then((data) => {
1967
- if (!cancelled) setDetail(data);
1968
- }).catch((e) => {
1969
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
1970
- }).finally(() => {
1971
- if (!cancelled) setLoading(false);
1972
- });
1973
- return () => {
1974
- cancelled = true;
1975
- };
1976
- }, [id]);
1977
- const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
1978
- const hasGatewayData = ((_c = detail == null ? void 0 : detail.payment) == null ? void 0 : _c.payment_data) && typeof detail.payment.payment_data === "object" && Object.keys(detail.payment.payment_data).length > 0;
1979
- return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
1980
- /* @__PURE__ */ jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1981
- /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
1982
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Refund details" }),
1983
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
1984
- ] }) }),
1985
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1986
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1987
- /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
1668
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
1988
1669
  ] }) : loading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
1989
1670
  /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1990
1671
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
@@ -2043,7 +1724,7 @@ const RefundDetailPage = () => {
2043
1724
  Badge,
2044
1725
  {
2045
1726
  size: "2xsmall",
2046
- className: `uppercase ${getStatusBadgeClass$2(paymentStatus)}`,
1727
+ className: `uppercase ${getStatusBadgeClass$4(paymentStatus)}`,
2047
1728
  children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2048
1729
  }
2049
1730
  ) })
@@ -2120,11 +1801,11 @@ const RefundDetailPage = () => {
2120
1801
  ] }) : null
2121
1802
  ] }) });
2122
1803
  };
2123
- const config$2 = defineRouteConfig({
1804
+ const config$4 = defineRouteConfig({
2124
1805
  label: "Refund details",
2125
1806
  icon: Receipt
2126
1807
  });
2127
- const getStatusBadgeClass$1 = (status) => {
1808
+ const getStatusBadgeClass$3 = (status) => {
2128
1809
  const statusLower = status.toLowerCase();
2129
1810
  if (statusLower === "requested") {
2130
1811
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2258,7 +1939,7 @@ const ReturnDetailPage = () => {
2258
1939
  Badge,
2259
1940
  {
2260
1941
  size: "small",
2261
- className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
1942
+ className: `uppercase ${getStatusBadgeClass$3(returnOrder.status)}`,
2262
1943
  children: returnOrder.status.replace(/_/g, " ")
2263
1944
  }
2264
1945
  )
@@ -2340,7 +2021,7 @@ const ReturnDetailPage = () => {
2340
2021
  Badge,
2341
2022
  {
2342
2023
  size: "2xsmall",
2343
- className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
2024
+ className: `uppercase ${getStatusBadgeClass$3(entry.status)}`,
2344
2025
  children: entry.status.replace(/_/g, " ")
2345
2026
  }
2346
2027
  ) }),
@@ -2398,11 +2079,11 @@ const ReturnDetailPage = () => {
2398
2079
  updateSuccess && /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2399
2080
  ] }) });
2400
2081
  };
2401
- const config$1 = defineRouteConfig({
2082
+ const config$3 = defineRouteConfig({
2402
2083
  label: "Return Order Details",
2403
2084
  icon: CheckCircle
2404
2085
  });
2405
- const getStatusBadgeClass = (status) => {
2086
+ const getStatusBadgeClass$2 = (status) => {
2406
2087
  const statusLower = status.toLowerCase();
2407
2088
  if (statusLower === "requested") {
2408
2089
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2540,7 +2221,7 @@ const SwapDetailPage = () => {
2540
2221
  Badge,
2541
2222
  {
2542
2223
  size: "small",
2543
- className: `uppercase ${getStatusBadgeClass(swap.status)}`,
2224
+ className: `uppercase ${getStatusBadgeClass$2(swap.status)}`,
2544
2225
  children: swap.status.replace(/_/g, " ")
2545
2226
  }
2546
2227
  )
@@ -2608,7 +2289,7 @@ const SwapDetailPage = () => {
2608
2289
  Badge,
2609
2290
  {
2610
2291
  size: "2xsmall",
2611
- className: `uppercase ${getStatusBadgeClass(entry.status)}`,
2292
+ className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2612
2293
  children: entry.status.replace(/_/g, " ")
2613
2294
  }
2614
2295
  ) }),
@@ -2677,10 +2358,329 @@ const SwapDetailPage = () => {
2677
2358
  ] })
2678
2359
  ] }) });
2679
2360
  };
2680
- const config = defineRouteConfig({
2361
+ const config$2 = defineRouteConfig({
2681
2362
  label: "Swap Details",
2682
2363
  icon: ArrowPath
2683
2364
  });
2365
+ const useDebounce = (value, delay) => {
2366
+ const [debouncedValue, setDebouncedValue] = useState(value);
2367
+ useEffect(() => {
2368
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
2369
+ return () => clearTimeout(handler);
2370
+ }, [value, delay]);
2371
+ return debouncedValue;
2372
+ };
2373
+ const getStatusBadgeClass$1 = (status) => {
2374
+ const s2 = status.toLowerCase();
2375
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2376
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2377
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2378
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2379
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2380
+ };
2381
+ const PaymentsPage = () => {
2382
+ const navigate = useNavigate();
2383
+ const [items, setItems] = useState([]);
2384
+ const [statusFilter, setStatusFilter] = useState("all");
2385
+ const [orderIdSearch, setOrderIdSearch] = useState("");
2386
+ const debouncedOrderId = useDebounce(orderIdSearch, 300);
2387
+ const [isLoading, setIsLoading] = useState(true);
2388
+ const [isFetchingMore, setIsFetchingMore] = useState(false);
2389
+ const [error, setError] = useState(null);
2390
+ const [offset, setOffset] = useState(0);
2391
+ const [count, setCount] = useState(0);
2392
+ const limit = 50;
2393
+ const loadTransactions = useCallback(
2394
+ async (nextOffset, replace) => {
2395
+ try {
2396
+ if (replace) setIsLoading(true);
2397
+ else setIsFetchingMore(true);
2398
+ setError(null);
2399
+ const params = new URLSearchParams();
2400
+ params.set("limit", String(limit));
2401
+ params.set("offset", String(nextOffset));
2402
+ if (statusFilter !== "all") params.set("status", statusFilter);
2403
+ if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
2404
+ const response = await fetch(
2405
+ `/admin/payment-transactions?${params.toString()}`,
2406
+ { credentials: "include" }
2407
+ );
2408
+ if (!response.ok) {
2409
+ const text = await response.text();
2410
+ throw new Error(text || "Failed to load payment transactions");
2411
+ }
2412
+ const payload = await response.json();
2413
+ const list = payload.transactions ?? [];
2414
+ setCount(payload.count ?? 0);
2415
+ setOffset(nextOffset + list.length);
2416
+ setItems((prev) => replace ? list : [...prev, ...list]);
2417
+ } catch (e) {
2418
+ setError(e instanceof Error ? e.message : "Failed to load");
2419
+ } finally {
2420
+ setIsLoading(false);
2421
+ setIsFetchingMore(false);
2422
+ }
2423
+ },
2424
+ [statusFilter, debouncedOrderId]
2425
+ );
2426
+ useEffect(() => {
2427
+ void loadTransactions(0, true);
2428
+ }, [loadTransactions]);
2429
+ const hasMore = useMemo(() => offset < count, [offset, count]);
2430
+ const displayStatus = (t) => {
2431
+ const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
2432
+ return s2 !== "" ? s2 : "—";
2433
+ };
2434
+ const displayAmount = (t) => {
2435
+ const code = (t.currency_code ?? "USD").toUpperCase();
2436
+ return `${code} ${Number(t.amount)}`;
2437
+ };
2438
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
2439
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
2440
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2441
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payments" }),
2442
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
2443
+ ] }),
2444
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
2445
+ ] }),
2446
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
2447
+ /* @__PURE__ */ jsx(
2448
+ Input,
2449
+ {
2450
+ placeholder: "Search by Order ID",
2451
+ value: orderIdSearch,
2452
+ onChange: (e) => setOrderIdSearch(e.target.value),
2453
+ className: "md:max-w-sm",
2454
+ "aria-label": "Search by order ID"
2455
+ }
2456
+ ),
2457
+ /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxs(
2458
+ "select",
2459
+ {
2460
+ value: statusFilter,
2461
+ onChange: (e) => setStatusFilter(e.target.value),
2462
+ className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
2463
+ "aria-label": "Filter by status",
2464
+ children: [
2465
+ /* @__PURE__ */ jsx("option", { value: "all", children: "All statuses" }),
2466
+ /* @__PURE__ */ jsx("option", { value: "pending", children: "Pending" }),
2467
+ /* @__PURE__ */ jsx("option", { value: "requires_more", children: "Requires more" }),
2468
+ /* @__PURE__ */ jsx("option", { value: "error", children: "Error" }),
2469
+ /* @__PURE__ */ jsx("option", { value: "canceled", children: "Canceled" }),
2470
+ /* @__PURE__ */ jsx("option", { value: "authorized", children: "Authorized" }),
2471
+ /* @__PURE__ */ jsx("option", { value: "captured", children: "Captured" })
2472
+ ]
2473
+ }
2474
+ ) })
2475
+ ] }),
2476
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2477
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2478
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
2479
+ ] }) : null,
2480
+ isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
2481
+ /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
2482
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
2483
+ ] }) : /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2484
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
2485
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
2486
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
2487
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
2488
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
2489
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
2490
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
2491
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
2492
+ ] }) }),
2493
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxs(
2494
+ "tr",
2495
+ {
2496
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
2497
+ onClick: () => navigate(`/payments/${t.payment_session_id}`),
2498
+ children: [
2499
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
2500
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
2501
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
2502
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
2503
+ Badge,
2504
+ {
2505
+ size: "2xsmall",
2506
+ className: `uppercase ${getStatusBadgeClass$1(displayStatus(t))}`,
2507
+ children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
2508
+ }
2509
+ ) }),
2510
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
2511
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
2512
+ year: "numeric",
2513
+ month: "short",
2514
+ day: "numeric",
2515
+ hour: "numeric",
2516
+ minute: "2-digit",
2517
+ hour12: true
2518
+ }) }),
2519
+ /* @__PURE__ */ jsxs("td", { className: "px-4 py-4", children: [
2520
+ /* @__PURE__ */ jsx(
2521
+ Button,
2522
+ {
2523
+ variant: "transparent",
2524
+ size: "small",
2525
+ onClick: (e) => {
2526
+ e.stopPropagation();
2527
+ navigate(`/payments/${t.payment_session_id}`);
2528
+ },
2529
+ children: "View details"
2530
+ }
2531
+ ),
2532
+ t.order_id ? /* @__PURE__ */ jsx(
2533
+ Button,
2534
+ {
2535
+ variant: "transparent",
2536
+ size: "small",
2537
+ onClick: (e) => {
2538
+ e.stopPropagation();
2539
+ navigate(`/orders/${t.order_id}`);
2540
+ },
2541
+ children: "Order"
2542
+ }
2543
+ ) : null
2544
+ ] })
2545
+ ]
2546
+ },
2547
+ t.payment_session_id
2548
+ )) })
2549
+ ] }) }),
2550
+ hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
2551
+ Button,
2552
+ {
2553
+ variant: "secondary",
2554
+ isLoading: isFetchingMore,
2555
+ onClick: () => loadTransactions(offset, false),
2556
+ children: "Load more"
2557
+ }
2558
+ ) }) : null
2559
+ ] }) });
2560
+ };
2561
+ const config$1 = defineRouteConfig({
2562
+ label: "Payments",
2563
+ icon: CreditCard
2564
+ });
2565
+ const getStatusBadgeClass = (status) => {
2566
+ const s2 = status.toLowerCase();
2567
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2568
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2569
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2570
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2571
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2572
+ };
2573
+ const PaymentDetailPage = () => {
2574
+ var _a;
2575
+ const navigate = useNavigate();
2576
+ const params = useParams();
2577
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2578
+ const [detail, setDetail] = useState(null);
2579
+ const [loading, setLoading] = useState(!!id);
2580
+ const [error, setError] = useState(null);
2581
+ useEffect(() => {
2582
+ if (!id) {
2583
+ setLoading(false);
2584
+ return;
2585
+ }
2586
+ let cancelled = false;
2587
+ setLoading(true);
2588
+ setError(null);
2589
+ fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2590
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
2591
+ return res.json();
2592
+ }).then((data) => {
2593
+ if (!cancelled) setDetail(data);
2594
+ }).catch((e) => {
2595
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2596
+ }).finally(() => {
2597
+ if (!cancelled) setLoading(false);
2598
+ });
2599
+ return () => {
2600
+ cancelled = true;
2601
+ };
2602
+ }, [id]);
2603
+ const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
2604
+ const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
2605
+ const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
2606
+ const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
2607
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
2608
+ /* @__PURE__ */ jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2609
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
2610
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payment session" }),
2611
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
2612
+ ] }) }),
2613
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2614
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2615
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
2616
+ ] }) : loading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
2617
+ /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2618
+ /* @__PURE__ */ jsxs("div", { children: [
2619
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
2620
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsx(
2621
+ Button,
2622
+ {
2623
+ variant: "transparent",
2624
+ size: "small",
2625
+ onClick: () => navigate(`/orders/${detail.order_id}`),
2626
+ children: detail.order_id
2627
+ }
2628
+ ) : /* @__PURE__ */ jsx(Text, { children: "—" }) })
2629
+ ] }),
2630
+ /* @__PURE__ */ jsxs("div", { children: [
2631
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2632
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: displayAmount })
2633
+ ] }),
2634
+ /* @__PURE__ */ jsxs("div", { children: [
2635
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2636
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.provider_id })
2637
+ ] }),
2638
+ /* @__PURE__ */ jsxs("div", { children: [
2639
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2640
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2641
+ Badge,
2642
+ {
2643
+ size: "2xsmall",
2644
+ className: `uppercase ${getStatusBadgeClass(displayStatus)}`,
2645
+ children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2646
+ }
2647
+ ) })
2648
+ ] }),
2649
+ /* @__PURE__ */ jsxs("div", { children: [
2650
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
2651
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: sessionStatusRaw })
2652
+ ] }),
2653
+ /* @__PURE__ */ jsxs("div", { children: [
2654
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
2655
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: paymentStatusRaw })
2656
+ ] }),
2657
+ /* @__PURE__ */ jsxs("div", { children: [
2658
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
2659
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
2660
+ ] }),
2661
+ /* @__PURE__ */ jsxs("div", { children: [
2662
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
2663
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2664
+ year: "numeric",
2665
+ month: "short",
2666
+ day: "numeric",
2667
+ hour: "numeric",
2668
+ minute: "2-digit",
2669
+ hour12: true
2670
+ }) })
2671
+ ] })
2672
+ ] }) }),
2673
+ Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2674
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2675
+ /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.data, null, 2) })
2676
+ ] }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
2677
+ ] }) : null
2678
+ ] }) });
2679
+ };
2680
+ const config = defineRouteConfig({
2681
+ label: "Payment details",
2682
+ icon: CreditCard
2683
+ });
2684
2684
  const i18nTranslations0 = {};
2685
2685
  const widgetModule = { widgets: [
2686
2686
  {
@@ -2694,10 +2694,6 @@ const widgetModule = { widgets: [
2694
2694
  ] };
2695
2695
  const routeModule = {
2696
2696
  routes: [
2697
- {
2698
- Component: PaymentsPage,
2699
- path: "/payments"
2700
- },
2701
2697
  {
2702
2698
  Component: RefundsPage,
2703
2699
  path: "/refunds"
@@ -2710,10 +2706,6 @@ const routeModule = {
2710
2706
  Component: SwapsPage,
2711
2707
  path: "/swaps"
2712
2708
  },
2713
- {
2714
- Component: PaymentDetailPage,
2715
- path: "/payments/:id"
2716
- },
2717
2709
  {
2718
2710
  Component: RefundDetailPage,
2719
2711
  path: "/refunds/:id"
@@ -2725,56 +2717,64 @@ const routeModule = {
2725
2717
  {
2726
2718
  Component: SwapDetailPage,
2727
2719
  path: "/swaps/:id"
2720
+ },
2721
+ {
2722
+ Component: PaymentsPage,
2723
+ path: "/payments"
2724
+ },
2725
+ {
2726
+ Component: PaymentDetailPage,
2727
+ path: "/payments/:id"
2728
2728
  }
2729
2729
  ]
2730
2730
  };
2731
2731
  const menuItemModule = {
2732
2732
  menuItems: [
2733
2733
  {
2734
- label: config$7.label,
2735
- icon: config$7.icon,
2734
+ label: config$6.label,
2735
+ icon: config$6.icon,
2736
+ path: "/returns",
2737
+ nested: void 0
2738
+ },
2739
+ {
2740
+ label: config$1.label,
2741
+ icon: config$1.icon,
2736
2742
  path: "/payments",
2737
2743
  nested: void 0
2738
2744
  },
2739
2745
  {
2740
- label: config$6.label,
2741
- icon: config$6.icon,
2746
+ label: config$7.label,
2747
+ icon: config$7.icon,
2742
2748
  path: "/refunds",
2743
2749
  nested: void 0
2744
2750
  },
2745
2751
  {
2746
2752
  label: config$5.label,
2747
2753
  icon: config$5.icon,
2748
- path: "/returns",
2749
- nested: void 0
2750
- },
2751
- {
2752
- label: config$4.label,
2753
- icon: config$4.icon,
2754
2754
  path: "/swaps",
2755
2755
  nested: void 0
2756
2756
  },
2757
2757
  {
2758
2758
  label: config$3.label,
2759
2759
  icon: config$3.icon,
2760
- path: "/payments/:id",
2760
+ path: "/returns/:id",
2761
2761
  nested: void 0
2762
2762
  },
2763
2763
  {
2764
- label: config$2.label,
2765
- icon: config$2.icon,
2764
+ label: config$4.label,
2765
+ icon: config$4.icon,
2766
2766
  path: "/refunds/:id",
2767
2767
  nested: void 0
2768
2768
  },
2769
2769
  {
2770
- label: config$1.label,
2771
- icon: config$1.icon,
2772
- path: "/returns/:id",
2770
+ label: config.label,
2771
+ icon: config.icon,
2772
+ path: "/payments/:id",
2773
2773
  nested: void 0
2774
2774
  },
2775
2775
  {
2776
- label: config.label,
2777
- icon: config.icon,
2776
+ label: config$2.label,
2777
+ icon: config$2.icon,
2778
2778
  path: "/swaps/:id",
2779
2779
  nested: void 0
2780
2780
  }