order-management 0.0.88 → 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.
@@ -1393,206 +1393,6 @@ const useDebounce$1 = (value, delay) => {
1393
1393
  return debouncedValue;
1394
1394
  };
1395
1395
  const getStatusBadgeClass$5 = (status) => {
1396
- const s2 = status.toLowerCase();
1397
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1398
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1399
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1400
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1401
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1402
- };
1403
- const PaymentsPage = () => {
1404
- const navigate = reactRouterDom.useNavigate();
1405
- const [items, setItems] = react.useState([]);
1406
- const [statusFilter, setStatusFilter] = react.useState("all");
1407
- const [orderIdSearch, setOrderIdSearch] = react.useState("");
1408
- const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1409
- const [isLoading, setIsLoading] = react.useState(true);
1410
- const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1411
- const [error, setError] = react.useState(null);
1412
- const [offset, setOffset] = react.useState(0);
1413
- const [count, setCount] = react.useState(0);
1414
- const limit = 50;
1415
- const loadTransactions = react.useCallback(
1416
- async (nextOffset, replace) => {
1417
- try {
1418
- if (replace) setIsLoading(true);
1419
- else setIsFetchingMore(true);
1420
- setError(null);
1421
- const params = new URLSearchParams();
1422
- params.set("limit", String(limit));
1423
- params.set("offset", String(nextOffset));
1424
- if (statusFilter !== "all") params.set("status", statusFilter);
1425
- if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
1426
- const response = await fetch(
1427
- `/admin/payment-transactions?${params.toString()}`,
1428
- { credentials: "include" }
1429
- );
1430
- if (!response.ok) {
1431
- const text = await response.text();
1432
- throw new Error(text || "Failed to load payment transactions");
1433
- }
1434
- const payload = await response.json();
1435
- const list = payload.transactions ?? [];
1436
- setCount(payload.count ?? 0);
1437
- setOffset(nextOffset + list.length);
1438
- setItems((prev) => replace ? list : [...prev, ...list]);
1439
- } catch (e) {
1440
- setError(e instanceof Error ? e.message : "Failed to load");
1441
- } finally {
1442
- setIsLoading(false);
1443
- setIsFetchingMore(false);
1444
- }
1445
- },
1446
- [statusFilter, debouncedOrderId]
1447
- );
1448
- react.useEffect(() => {
1449
- void loadTransactions(0, true);
1450
- }, [loadTransactions]);
1451
- const hasMore = react.useMemo(() => offset < count, [offset, count]);
1452
- const displayStatus = (t) => {
1453
- const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
1454
- return s2 !== "" ? s2 : "—";
1455
- };
1456
- const displayAmount = (t) => {
1457
- const code = (t.currency_code ?? "USD").toUpperCase();
1458
- return `${code} ${Number(t.amount)}`;
1459
- };
1460
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
1461
- /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1462
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1463
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payments" }),
1464
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
1465
- ] }),
1466
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
1467
- ] }),
1468
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1469
- /* @__PURE__ */ jsxRuntime.jsx(
1470
- ui.Input,
1471
- {
1472
- placeholder: "Search by Order ID",
1473
- value: orderIdSearch,
1474
- onChange: (e) => setOrderIdSearch(e.target.value),
1475
- className: "md:max-w-sm",
1476
- "aria-label": "Search by order ID"
1477
- }
1478
- ),
1479
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs(
1480
- "select",
1481
- {
1482
- value: statusFilter,
1483
- onChange: (e) => setStatusFilter(e.target.value),
1484
- 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",
1485
- "aria-label": "Filter by status",
1486
- children: [
1487
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
1488
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
1489
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
1490
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
1491
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
1492
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
1493
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
1494
- ]
1495
- }
1496
- ) })
1497
- ] }),
1498
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1499
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1500
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
1501
- ] }) : null,
1502
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1503
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
1504
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
1505
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
1506
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1507
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1508
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1509
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1510
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1511
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
1512
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1513
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1514
- ] }) }),
1515
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxRuntime.jsxs(
1516
- "tr",
1517
- {
1518
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1519
- onClick: () => navigate(`/payments/${t.payment_session_id}`),
1520
- children: [
1521
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
1522
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
1523
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
1524
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1525
- ui.Badge,
1526
- {
1527
- size: "2xsmall",
1528
- className: `uppercase ${getStatusBadgeClass$5(displayStatus(t))}`,
1529
- children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1530
- }
1531
- ) }),
1532
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1533
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1534
- year: "numeric",
1535
- month: "short",
1536
- day: "numeric",
1537
- hour: "numeric",
1538
- minute: "2-digit",
1539
- hour12: true
1540
- }) }),
1541
- /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-4", children: [
1542
- /* @__PURE__ */ jsxRuntime.jsx(
1543
- ui.Button,
1544
- {
1545
- variant: "transparent",
1546
- size: "small",
1547
- onClick: (e) => {
1548
- e.stopPropagation();
1549
- navigate(`/payments/${t.payment_session_id}`);
1550
- },
1551
- children: "View details"
1552
- }
1553
- ),
1554
- t.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1555
- ui.Button,
1556
- {
1557
- variant: "transparent",
1558
- size: "small",
1559
- onClick: (e) => {
1560
- e.stopPropagation();
1561
- navigate(`/orders/${t.order_id}`);
1562
- },
1563
- children: "Order"
1564
- }
1565
- ) : null
1566
- ] })
1567
- ]
1568
- },
1569
- t.payment_session_id
1570
- )) })
1571
- ] }) }),
1572
- hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1573
- ui.Button,
1574
- {
1575
- variant: "secondary",
1576
- isLoading: isFetchingMore,
1577
- onClick: () => loadTransactions(offset, false),
1578
- children: "Load more"
1579
- }
1580
- ) }) : null
1581
- ] }) });
1582
- };
1583
- const config$5 = adminSdk.defineRouteConfig({
1584
- label: "Payments",
1585
- icon: icons.CreditCard
1586
- });
1587
- const useDebounce = (value, delay) => {
1588
- const [debouncedValue, setDebouncedValue] = react.useState(value);
1589
- react.useEffect(() => {
1590
- const handler = setTimeout(() => setDebouncedValue(value), delay);
1591
- return () => clearTimeout(handler);
1592
- }, [value, delay]);
1593
- return debouncedValue;
1594
- };
1595
- const getStatusBadgeClass$4 = (status) => {
1596
1396
  const statusLower = status.toLowerCase();
1597
1397
  if (statusLower === "requested") {
1598
1398
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -1617,7 +1417,7 @@ const SwapsPage = () => {
1617
1417
  const [statusFilter, setStatusFilter] = react.useState("all");
1618
1418
  const [createdByFilter, setCreatedByFilter] = react.useState("all");
1619
1419
  const [searchQuery, setSearchQuery] = react.useState("");
1620
- const debouncedSearchQuery = useDebounce(searchQuery, 300);
1420
+ const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1621
1421
  const [isLoading, setIsLoading] = react.useState(true);
1622
1422
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1623
1423
  const [error, setError] = react.useState(null);
@@ -1760,7 +1560,7 @@ const SwapsPage = () => {
1760
1560
  ui.Badge,
1761
1561
  {
1762
1562
  size: "2xsmall",
1763
- className: `uppercase ${getStatusBadgeClass$4(swap.status)}`,
1563
+ className: `uppercase ${getStatusBadgeClass$5(swap.status)}`,
1764
1564
  children: swap.status.replace(/_/g, " ")
1765
1565
  }
1766
1566
  ) }),
@@ -1810,11 +1610,11 @@ const SwapsPage = () => {
1810
1610
  ) }) : null
1811
1611
  ] }) });
1812
1612
  };
1813
- const config$4 = adminSdk.defineRouteConfig({
1613
+ const config$5 = adminSdk.defineRouteConfig({
1814
1614
  label: "Exchanges",
1815
1615
  icon: icons.ArrowPath
1816
1616
  });
1817
- const getStatusBadgeClass$3 = (status) => {
1617
+ const getStatusBadgeClass$4 = (status) => {
1818
1618
  const s2 = status.toLowerCase();
1819
1619
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1820
1620
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1925,7 +1725,7 @@ const RefundDetailPage = () => {
1925
1725
  ui.Badge,
1926
1726
  {
1927
1727
  size: "2xsmall",
1928
- className: `uppercase ${getStatusBadgeClass$3(paymentStatus)}`,
1728
+ className: `uppercase ${getStatusBadgeClass$4(paymentStatus)}`,
1929
1729
  children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
1930
1730
  }
1931
1731
  ) })
@@ -2002,11 +1802,11 @@ const RefundDetailPage = () => {
2002
1802
  ] }) : null
2003
1803
  ] }) });
2004
1804
  };
2005
- const config$3 = adminSdk.defineRouteConfig({
1805
+ const config$4 = adminSdk.defineRouteConfig({
2006
1806
  label: "Refund details",
2007
1807
  icon: icons.Receipt
2008
1808
  });
2009
- const getStatusBadgeClass$2 = (status) => {
1809
+ const getStatusBadgeClass$3 = (status) => {
2010
1810
  const statusLower = status.toLowerCase();
2011
1811
  if (statusLower === "requested") {
2012
1812
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2017,109 +1817,105 @@ const getStatusBadgeClass$2 = (status) => {
2017
1817
  if (statusLower === "rejected") {
2018
1818
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
2019
1819
  }
1820
+ if (statusLower === "received") {
1821
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1822
+ }
1823
+ if (statusLower === "refunded") {
1824
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
1825
+ }
2020
1826
  if (statusLower === "completed") {
2021
1827
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
2022
1828
  }
2023
- if (statusLower === "cancelled" || statusLower === "canceled") {
1829
+ if (statusLower === "cancelled") {
2024
1830
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2025
1831
  }
2026
- if (statusLower === "pending") {
2027
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2028
- }
2029
1832
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2030
1833
  };
2031
- const SwapDetailPage = () => {
2032
- var _a, _b, _c;
1834
+ const ReturnDetailPage = () => {
1835
+ var _a, _b;
2033
1836
  const navigate = reactRouterDom.useNavigate();
2034
1837
  const { id } = reactRouterDom.useParams();
2035
- const [swap, setSwap] = react.useState(null);
2036
- const [order, setOrder] = react.useState(null);
1838
+ const [returnOrder, setReturnOrder] = react.useState(null);
2037
1839
  const [isLoading, setIsLoading] = react.useState(true);
2038
- react.useState(false);
2039
- const [isCancelling, setIsCancelling] = react.useState(false);
1840
+ const [isRejecting, setIsRejecting] = react.useState(false);
2040
1841
  const [error, setError] = react.useState(null);
2041
1842
  const [updateError, setUpdateError] = react.useState(null);
2042
1843
  const [updateSuccess, setUpdateSuccess] = react.useState(false);
2043
1844
  react.useEffect(() => {
2044
1845
  if (!id) {
2045
- navigate("/swaps");
1846
+ navigate("/returns");
2046
1847
  return;
2047
1848
  }
2048
- const loadSwap = async () => {
1849
+ const loadReturn = async () => {
2049
1850
  try {
2050
1851
  setIsLoading(true);
2051
1852
  setError(null);
2052
- const response = await fetch(`/admin/swaps/${id}`, {
1853
+ const response = await fetch(`/admin/returns/${id}`, {
2053
1854
  credentials: "include"
2054
1855
  });
2055
1856
  if (!response.ok) {
2056
1857
  const message = await response.text();
2057
- throw new Error(message || "Unable to load swap");
1858
+ throw new Error(message || "Unable to load return order");
2058
1859
  }
2059
1860
  const payload = await response.json();
2060
- setSwap(payload.swap);
2061
- setOrder(payload.order || null);
1861
+ setReturnOrder(payload.return);
2062
1862
  } catch (loadError) {
2063
- const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
1863
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2064
1864
  setError(message);
2065
1865
  } finally {
2066
1866
  setIsLoading(false);
2067
1867
  }
2068
1868
  };
2069
- void loadSwap();
1869
+ void loadReturn();
2070
1870
  }, [id, navigate]);
2071
- const handleCancelExchange = async () => {
1871
+ const handleReject = async () => {
2072
1872
  if (!id) {
2073
1873
  return;
2074
1874
  }
2075
1875
  try {
2076
- setIsCancelling(true);
1876
+ setIsRejecting(true);
2077
1877
  setUpdateError(null);
2078
1878
  setUpdateSuccess(false);
2079
- const response = await fetch(`/admin/swaps/${id}/cancel`, {
1879
+ const response = await fetch(`/admin/returns/${id}/reject`, {
2080
1880
  method: "POST",
2081
1881
  headers: {
2082
1882
  "Content-Type": "application/json"
2083
1883
  },
2084
- credentials: "include"
1884
+ credentials: "include",
1885
+ body: JSON.stringify({ reason: "Rejected by admin" })
2085
1886
  });
2086
1887
  if (!response.ok) {
2087
1888
  const message = await response.text();
2088
- throw new Error(message || "Unable to cancel exchange");
1889
+ throw new Error(message || "Unable to reject return");
2089
1890
  }
2090
1891
  const payload = await response.json();
2091
- setSwap(payload.swap);
1892
+ setReturnOrder(payload.return);
2092
1893
  setUpdateSuccess(true);
2093
1894
  setTimeout(() => setUpdateSuccess(false), 3e3);
2094
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
1895
+ const detailResponse = await fetch(`/admin/returns/${id}`, {
2095
1896
  credentials: "include"
2096
1897
  });
2097
1898
  if (detailResponse.ok) {
2098
1899
  const detailPayload = await detailResponse.json();
2099
- setSwap(detailPayload.swap);
2100
- setOrder(detailPayload.order || null);
1900
+ setReturnOrder(detailPayload.return);
2101
1901
  }
2102
- } catch (cancelErr) {
2103
- const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
1902
+ } catch (updateErr) {
1903
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2104
1904
  setUpdateError(message);
2105
1905
  } finally {
2106
- setIsCancelling(false);
1906
+ setIsRejecting(false);
2107
1907
  }
2108
1908
  };
2109
- const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
2110
- const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
2111
- ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
2112
- );
2113
1909
  if (isLoading) {
2114
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swap..." }) }) }) });
1910
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return order..." }) }) }) });
2115
1911
  }
2116
- if (error || !swap) {
1912
+ if (error || !returnOrder) {
2117
1913
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2118
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
2119
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
1914
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
1915
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2120
1916
  ] }) }) });
2121
1917
  }
2122
- const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
1918
+ const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2123
1919
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
2124
1920
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
2125
1921
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -2127,7 +1923,7 @@ const SwapDetailPage = () => {
2127
1923
  {
2128
1924
  variant: "transparent",
2129
1925
  size: "small",
2130
- onClick: () => navigate("/swaps"),
1926
+ onClick: () => navigate("/returns"),
2131
1927
  className: "w-fit",
2132
1928
  children: [
2133
1929
  /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
@@ -2137,67 +1933,81 @@ const SwapDetailPage = () => {
2137
1933
  ),
2138
1934
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2139
1935
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2140
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchange Details" }),
2141
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
1936
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Order Details" }),
1937
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2142
1938
  ] }),
2143
1939
  /* @__PURE__ */ jsxRuntime.jsx(
2144
1940
  ui.Badge,
2145
1941
  {
2146
1942
  size: "small",
2147
- className: `uppercase ${getStatusBadgeClass$2(swap.status)}`,
2148
- children: swap.status.replace(/_/g, " ")
1943
+ className: `uppercase ${getStatusBadgeClass$3(returnOrder.status)}`,
1944
+ children: returnOrder.status.replace(/_/g, " ")
2149
1945
  }
2150
1946
  )
2151
1947
  ] })
2152
1948
  ] }),
2153
- canCancelExchange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
1949
+ returnOrder.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
2154
1950
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
2155
1951
  ui.Button,
2156
1952
  {
2157
1953
  variant: "danger",
2158
- onClick: handleCancelExchange,
2159
- disabled: isCancelling,
2160
- isLoading: isCancelling,
2161
- children: "Cancel Exchange"
1954
+ onClick: handleReject,
1955
+ disabled: isRejecting,
1956
+ isLoading: isRejecting,
1957
+ children: "Reject (Cancel) Return"
2162
1958
  }
2163
1959
  ) }),
2164
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
1960
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
1961
+ ] }),
1962
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1963
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
1964
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1965
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1966
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
1967
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
1968
+ ] }),
1969
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
1970
+ ui.Button,
1971
+ {
1972
+ variant: "secondary",
1973
+ onClick: () => {
1974
+ window.open(
1975
+ `/app/orders/${returnOrder.order_id}`,
1976
+ "_blank"
1977
+ );
1978
+ },
1979
+ children: "View order"
1980
+ }
1981
+ ) })
1982
+ ] })
2165
1983
  ] }),
2166
1984
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2167
1985
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2168
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
1986
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2169
1987
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2170
1988
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2171
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2172
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
1989
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
1990
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2173
1991
  ] }),
2174
1992
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2175
1993
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2176
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
2177
- ] }),
2178
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2179
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
2180
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
1994
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.status })
2181
1995
  ] }),
2182
- swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1996
+ returnOrder.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2183
1997
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2184
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
1998
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.reason })
2185
1999
  ] }),
2186
- swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2000
+ returnOrder.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2187
2001
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2188
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
2002
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.note })
2189
2003
  ] }),
2190
2004
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2191
2005
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2192
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2006
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2193
2007
  ] }),
2194
2008
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2195
2009
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2196
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2197
- ] }),
2198
- swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2199
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2200
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
2010
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2201
2011
  ] })
2202
2012
  ] })
2203
2013
  ] }),
@@ -2212,7 +2022,7 @@ const SwapDetailPage = () => {
2212
2022
  ui.Badge,
2213
2023
  {
2214
2024
  size: "2xsmall",
2215
- className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2025
+ className: `uppercase ${getStatusBadgeClass$3(entry.status)}`,
2216
2026
  children: entry.status.replace(/_/g, " ")
2217
2027
  }
2218
2028
  ) }),
@@ -2227,31 +2037,31 @@ const SwapDetailPage = () => {
2227
2037
  )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2228
2038
  ] })
2229
2039
  ] }),
2230
- order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2040
+ returnOrder.order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2231
2041
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2232
2042
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2233
2043
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2234
2044
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2235
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
2045
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.id })
2236
2046
  ] }),
2237
2047
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2238
2048
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2239
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
2049
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2240
2050
  ] }),
2241
2051
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2242
2052
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2243
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2053
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2244
2054
  ] }),
2245
- order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2055
+ returnOrder.order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2246
2056
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2247
2057
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
2248
- order.currency_code || "$",
2249
- (Number(order.total) / 100).toFixed(2)
2058
+ returnOrder.order.currency_code || "$",
2059
+ (Number(returnOrder.order.total) / 100).toFixed(2)
2250
2060
  ] })
2251
2061
  ] })
2252
2062
  ] })
2253
2063
  ] }),
2254
- swap.return_items && swap.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2064
+ returnOrder.return_items && returnOrder.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2255
2065
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2256
2066
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2257
2067
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
@@ -2259,152 +2069,22 @@ const SwapDetailPage = () => {
2259
2069
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2260
2070
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2261
2071
  ] }) }),
2262
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2072
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2263
2073
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2264
2074
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2265
2075
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2266
2076
  ] }, item.id || index)) })
2267
2077
  ] }) })
2268
2078
  ] }),
2269
- swap.new_items && swap.new_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2270
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2271
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2272
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2273
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2274
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2275
- ] }) }),
2276
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2277
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2278
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2279
- ] }, item.variant_id || index)) })
2280
- ] }) })
2281
- ] })
2282
- ] }) });
2283
- };
2284
- const config$2 = adminSdk.defineRouteConfig({
2285
- label: "Swap Details",
2286
- icon: icons.ArrowPath
2287
- });
2288
- const getStatusBadgeClass$1 = (status) => {
2289
- const s2 = status.toLowerCase();
2290
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2291
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2292
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2293
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2294
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2295
- };
2296
- const PaymentDetailPage = () => {
2297
- var _a;
2298
- const navigate = reactRouterDom.useNavigate();
2299
- const params = reactRouterDom.useParams();
2300
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2301
- const [detail, setDetail] = react.useState(null);
2302
- const [loading, setLoading] = react.useState(!!id);
2303
- const [error, setError] = react.useState(null);
2304
- react.useEffect(() => {
2305
- if (!id) {
2306
- setLoading(false);
2307
- return;
2308
- }
2309
- let cancelled = false;
2310
- setLoading(true);
2311
- setError(null);
2312
- fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2313
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2314
- return res.json();
2315
- }).then((data) => {
2316
- if (!cancelled) setDetail(data);
2317
- }).catch((e) => {
2318
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2319
- }).finally(() => {
2320
- if (!cancelled) setLoading(false);
2321
- });
2322
- return () => {
2323
- cancelled = true;
2324
- };
2325
- }, [id]);
2326
- const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
2327
- const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
2328
- const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
2329
- const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
2330
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
2331
- /* @__PURE__ */ jsxRuntime.jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2332
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
2333
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payment session" }),
2334
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
2335
- ] }) }),
2336
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2337
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2338
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
2339
- ] }) : loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
2340
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2341
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2342
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
2343
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
2344
- ui.Button,
2345
- {
2346
- variant: "transparent",
2347
- size: "small",
2348
- onClick: () => navigate(`/orders/${detail.order_id}`),
2349
- children: detail.order_id
2350
- }
2351
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "—" }) })
2352
- ] }),
2353
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2354
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2355
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: displayAmount })
2356
- ] }),
2357
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2358
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2359
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.provider_id })
2360
- ] }),
2361
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2362
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2363
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2364
- ui.Badge,
2365
- {
2366
- size: "2xsmall",
2367
- className: `uppercase ${getStatusBadgeClass$1(displayStatus)}`,
2368
- children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2369
- }
2370
- ) })
2371
- ] }),
2372
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2373
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
2374
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: sessionStatusRaw })
2375
- ] }),
2376
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2377
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
2378
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: paymentStatusRaw })
2379
- ] }),
2380
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2381
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
2382
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
2383
- ] }),
2384
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2385
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
2386
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2387
- year: "numeric",
2388
- month: "short",
2389
- day: "numeric",
2390
- hour: "numeric",
2391
- minute: "2-digit",
2392
- hour12: true
2393
- }) })
2394
- ] })
2395
- ] }) }),
2396
- Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2397
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2398
- /* @__PURE__ */ jsxRuntime.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) })
2399
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
2400
- ] }) : null
2079
+ updateError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-error bg-ui-bg-error-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", children: updateError }) }),
2080
+ updateSuccess && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2401
2081
  ] }) });
2402
2082
  };
2403
- const config$1 = adminSdk.defineRouteConfig({
2404
- label: "Payment details",
2405
- icon: icons.CreditCard
2083
+ const config$3 = adminSdk.defineRouteConfig({
2084
+ label: "Return Order Details",
2085
+ icon: icons.CheckCircle
2406
2086
  });
2407
- const getStatusBadgeClass = (status) => {
2087
+ const getStatusBadgeClass$2 = (status) => {
2408
2088
  const statusLower = status.toLowerCase();
2409
2089
  if (statusLower === "requested") {
2410
2090
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2415,105 +2095,109 @@ const getStatusBadgeClass = (status) => {
2415
2095
  if (statusLower === "rejected") {
2416
2096
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
2417
2097
  }
2418
- if (statusLower === "received") {
2419
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2420
- }
2421
- if (statusLower === "refunded") {
2422
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
2423
- }
2424
2098
  if (statusLower === "completed") {
2425
2099
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
2426
2100
  }
2427
- if (statusLower === "cancelled") {
2101
+ if (statusLower === "cancelled" || statusLower === "canceled") {
2428
2102
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2429
2103
  }
2104
+ if (statusLower === "pending") {
2105
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2106
+ }
2430
2107
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2431
2108
  };
2432
- const ReturnDetailPage = () => {
2433
- var _a, _b;
2109
+ const SwapDetailPage = () => {
2110
+ var _a, _b, _c;
2434
2111
  const navigate = reactRouterDom.useNavigate();
2435
2112
  const { id } = reactRouterDom.useParams();
2436
- const [returnOrder, setReturnOrder] = react.useState(null);
2113
+ const [swap, setSwap] = react.useState(null);
2114
+ const [order, setOrder] = react.useState(null);
2437
2115
  const [isLoading, setIsLoading] = react.useState(true);
2438
- const [isRejecting, setIsRejecting] = react.useState(false);
2116
+ react.useState(false);
2117
+ const [isCancelling, setIsCancelling] = react.useState(false);
2439
2118
  const [error, setError] = react.useState(null);
2440
2119
  const [updateError, setUpdateError] = react.useState(null);
2441
2120
  const [updateSuccess, setUpdateSuccess] = react.useState(false);
2442
2121
  react.useEffect(() => {
2443
2122
  if (!id) {
2444
- navigate("/returns");
2123
+ navigate("/swaps");
2445
2124
  return;
2446
2125
  }
2447
- const loadReturn = async () => {
2126
+ const loadSwap = async () => {
2448
2127
  try {
2449
2128
  setIsLoading(true);
2450
2129
  setError(null);
2451
- const response = await fetch(`/admin/returns/${id}`, {
2130
+ const response = await fetch(`/admin/swaps/${id}`, {
2452
2131
  credentials: "include"
2453
2132
  });
2454
2133
  if (!response.ok) {
2455
2134
  const message = await response.text();
2456
- throw new Error(message || "Unable to load return order");
2135
+ throw new Error(message || "Unable to load swap");
2457
2136
  }
2458
2137
  const payload = await response.json();
2459
- setReturnOrder(payload.return);
2138
+ setSwap(payload.swap);
2139
+ setOrder(payload.order || null);
2460
2140
  } catch (loadError) {
2461
- const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2141
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
2462
2142
  setError(message);
2463
2143
  } finally {
2464
2144
  setIsLoading(false);
2465
2145
  }
2466
2146
  };
2467
- void loadReturn();
2147
+ void loadSwap();
2468
2148
  }, [id, navigate]);
2469
- const handleReject = async () => {
2149
+ const handleCancelExchange = async () => {
2470
2150
  if (!id) {
2471
2151
  return;
2472
2152
  }
2473
2153
  try {
2474
- setIsRejecting(true);
2154
+ setIsCancelling(true);
2475
2155
  setUpdateError(null);
2476
2156
  setUpdateSuccess(false);
2477
- const response = await fetch(`/admin/returns/${id}/reject`, {
2157
+ const response = await fetch(`/admin/swaps/${id}/cancel`, {
2478
2158
  method: "POST",
2479
2159
  headers: {
2480
2160
  "Content-Type": "application/json"
2481
2161
  },
2482
- credentials: "include",
2483
- body: JSON.stringify({ reason: "Rejected by admin" })
2162
+ credentials: "include"
2484
2163
  });
2485
2164
  if (!response.ok) {
2486
2165
  const message = await response.text();
2487
- throw new Error(message || "Unable to reject return");
2166
+ throw new Error(message || "Unable to cancel exchange");
2488
2167
  }
2489
2168
  const payload = await response.json();
2490
- setReturnOrder(payload.return);
2169
+ setSwap(payload.swap);
2491
2170
  setUpdateSuccess(true);
2492
2171
  setTimeout(() => setUpdateSuccess(false), 3e3);
2493
- const detailResponse = await fetch(`/admin/returns/${id}`, {
2172
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
2494
2173
  credentials: "include"
2495
2174
  });
2496
2175
  if (detailResponse.ok) {
2497
2176
  const detailPayload = await detailResponse.json();
2498
- setReturnOrder(detailPayload.return);
2177
+ setSwap(detailPayload.swap);
2178
+ setOrder(detailPayload.order || null);
2499
2179
  }
2500
- } catch (updateErr) {
2501
- const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2180
+ } catch (cancelErr) {
2181
+ const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
2502
2182
  setUpdateError(message);
2503
2183
  } finally {
2504
- setIsRejecting(false);
2184
+ setIsCancelling(false);
2505
2185
  }
2506
2186
  };
2187
+ const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
2188
+ const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
2189
+ ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
2190
+ );
2507
2191
  if (isLoading) {
2508
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return order..." }) }) }) });
2192
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swap..." }) }) }) });
2509
2193
  }
2510
- if (error || !returnOrder) {
2194
+ if (error || !swap) {
2511
2195
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2512
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
2513
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2196
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
2197
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
2514
2198
  ] }) }) });
2515
2199
  }
2516
- const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2200
+ const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
2517
2201
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
2518
2202
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
2519
2203
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -2521,7 +2205,7 @@ const ReturnDetailPage = () => {
2521
2205
  {
2522
2206
  variant: "transparent",
2523
2207
  size: "small",
2524
- onClick: () => navigate("/returns"),
2208
+ onClick: () => navigate("/swaps"),
2525
2209
  className: "w-fit",
2526
2210
  children: [
2527
2211
  /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
@@ -2531,81 +2215,67 @@ const ReturnDetailPage = () => {
2531
2215
  ),
2532
2216
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2533
2217
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2534
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Order Details" }),
2535
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2218
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchange Details" }),
2219
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
2536
2220
  ] }),
2537
2221
  /* @__PURE__ */ jsxRuntime.jsx(
2538
2222
  ui.Badge,
2539
2223
  {
2540
2224
  size: "small",
2541
- className: `uppercase ${getStatusBadgeClass(returnOrder.status)}`,
2542
- children: returnOrder.status.replace(/_/g, " ")
2225
+ className: `uppercase ${getStatusBadgeClass$2(swap.status)}`,
2226
+ children: swap.status.replace(/_/g, " ")
2543
2227
  }
2544
2228
  )
2545
2229
  ] })
2546
2230
  ] }),
2547
- returnOrder.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
2231
+ canCancelExchange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
2548
2232
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
2549
2233
  ui.Button,
2550
2234
  {
2551
2235
  variant: "danger",
2552
- onClick: handleReject,
2553
- disabled: isRejecting,
2554
- isLoading: isRejecting,
2555
- children: "Reject (Cancel) Return"
2236
+ onClick: handleCancelExchange,
2237
+ disabled: isCancelling,
2238
+ isLoading: isCancelling,
2239
+ children: "Cancel Exchange"
2556
2240
  }
2557
2241
  ) }),
2558
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
2559
- ] }),
2560
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2561
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
2562
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2563
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2564
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2565
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2566
- ] }),
2567
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
2568
- ui.Button,
2569
- {
2570
- variant: "secondary",
2571
- onClick: () => {
2572
- window.open(
2573
- `/app/orders/${returnOrder.order_id}`,
2574
- "_blank"
2575
- );
2576
- },
2577
- children: "View order"
2578
- }
2579
- ) })
2580
- ] })
2242
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
2581
2243
  ] }),
2582
2244
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2583
2245
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2584
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2246
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
2585
2247
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2586
2248
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2587
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2588
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2249
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2250
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
2589
2251
  ] }),
2590
2252
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2591
2253
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2592
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.status })
2254
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
2593
2255
  ] }),
2594
- returnOrder.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2256
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2257
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
2258
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
2259
+ ] }),
2260
+ swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2595
2261
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2596
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.reason })
2262
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
2597
2263
  ] }),
2598
- returnOrder.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2264
+ swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2599
2265
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2600
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.note })
2266
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
2601
2267
  ] }),
2602
2268
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2603
2269
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2604
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2270
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2605
2271
  ] }),
2606
2272
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2607
2273
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2608
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2274
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2275
+ ] }),
2276
+ swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2277
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2278
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
2609
2279
  ] })
2610
2280
  ] })
2611
2281
  ] }),
@@ -2620,7 +2290,7 @@ const ReturnDetailPage = () => {
2620
2290
  ui.Badge,
2621
2291
  {
2622
2292
  size: "2xsmall",
2623
- className: `uppercase ${getStatusBadgeClass(entry.status)}`,
2293
+ className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2624
2294
  children: entry.status.replace(/_/g, " ")
2625
2295
  }
2626
2296
  ) }),
@@ -2635,31 +2305,31 @@ const ReturnDetailPage = () => {
2635
2305
  )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2636
2306
  ] })
2637
2307
  ] }),
2638
- returnOrder.order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2308
+ order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2639
2309
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2640
2310
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2641
2311
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2642
2312
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2643
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.id })
2313
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
2644
2314
  ] }),
2645
2315
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2646
2316
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2647
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2317
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
2648
2318
  ] }),
2649
2319
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2650
2320
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2651
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2321
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2652
2322
  ] }),
2653
- returnOrder.order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2323
+ order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2654
2324
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2655
2325
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
2656
- returnOrder.order.currency_code || "$",
2657
- (Number(returnOrder.order.total) / 100).toFixed(2)
2326
+ order.currency_code || "$",
2327
+ (Number(order.total) / 100).toFixed(2)
2658
2328
  ] })
2659
2329
  ] })
2660
2330
  ] })
2661
2331
  ] }),
2662
- returnOrder.return_items && returnOrder.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2332
+ swap.return_items && swap.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2663
2333
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2664
2334
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2665
2335
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
@@ -2667,117 +2337,447 @@ const ReturnDetailPage = () => {
2667
2337
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2668
2338
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2669
2339
  ] }) }),
2670
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2340
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2671
2341
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2672
2342
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2673
2343
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2674
2344
  ] }, item.id || index)) })
2675
2345
  ] }) })
2676
2346
  ] }),
2677
- updateError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-error bg-ui-bg-error-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", children: updateError }) }),
2678
- updateSuccess && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2347
+ swap.new_items && swap.new_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2348
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2349
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2350
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2351
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2352
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2353
+ ] }) }),
2354
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2355
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2356
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2357
+ ] }, item.variant_id || index)) })
2358
+ ] }) })
2359
+ ] })
2679
2360
  ] }) });
2680
2361
  };
2681
- const config = adminSdk.defineRouteConfig({
2682
- label: "Return Order Details",
2683
- icon: icons.CheckCircle
2362
+ const config$2 = adminSdk.defineRouteConfig({
2363
+ label: "Swap Details",
2364
+ icon: icons.ArrowPath
2684
2365
  });
2685
- const i18nTranslations0 = {};
2686
- const widgetModule = { widgets: [
2687
- {
2688
- Component: OrderGiftItemsWidget,
2689
- zone: ["order.details.side.after"]
2690
- },
2691
- {
2692
- Component: OrderRefundContextWidget,
2693
- zone: ["order.details.after"]
2694
- }
2695
- ] };
2696
- const routeModule = {
2697
- routes: [
2698
- {
2699
- Component: RefundsPage,
2700
- path: "/refunds"
2701
- },
2702
- {
2703
- Component: ReturnsPage,
2704
- path: "/returns"
2705
- },
2706
- {
2707
- Component: PaymentsPage,
2708
- path: "/payments"
2709
- },
2710
- {
2711
- Component: SwapsPage,
2712
- path: "/swaps"
2713
- },
2714
- {
2715
- Component: RefundDetailPage,
2716
- path: "/refunds/:id"
2717
- },
2718
- {
2719
- Component: SwapDetailPage,
2720
- path: "/swaps/:id"
2721
- },
2722
- {
2723
- Component: PaymentDetailPage,
2724
- path: "/payments/:id"
2725
- },
2726
- {
2727
- Component: ReturnDetailPage,
2728
- path: "/returns/:id"
2729
- }
2730
- ]
2366
+ const useDebounce = (value, delay) => {
2367
+ const [debouncedValue, setDebouncedValue] = react.useState(value);
2368
+ react.useEffect(() => {
2369
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
2370
+ return () => clearTimeout(handler);
2371
+ }, [value, delay]);
2372
+ return debouncedValue;
2731
2373
  };
2732
- const menuItemModule = {
2733
- menuItems: [
2734
- {
2735
- label: config$5.label,
2736
- icon: config$5.icon,
2737
- path: "/payments",
2738
- nested: void 0
2739
- },
2740
- {
2741
- label: config$6.label,
2742
- icon: config$6.icon,
2743
- path: "/returns",
2744
- nested: void 0
2745
- },
2746
- {
2747
- label: config$7.label,
2748
- icon: config$7.icon,
2749
- path: "/refunds",
2750
- nested: void 0
2374
+ const getStatusBadgeClass$1 = (status) => {
2375
+ const s2 = status.toLowerCase();
2376
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2377
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2378
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2379
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2380
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2381
+ };
2382
+ const PaymentsPage = () => {
2383
+ const navigate = reactRouterDom.useNavigate();
2384
+ const [items, setItems] = react.useState([]);
2385
+ const [statusFilter, setStatusFilter] = react.useState("all");
2386
+ const [orderIdSearch, setOrderIdSearch] = react.useState("");
2387
+ const debouncedOrderId = useDebounce(orderIdSearch, 300);
2388
+ const [isLoading, setIsLoading] = react.useState(true);
2389
+ const [isFetchingMore, setIsFetchingMore] = react.useState(false);
2390
+ const [error, setError] = react.useState(null);
2391
+ const [offset, setOffset] = react.useState(0);
2392
+ const [count, setCount] = react.useState(0);
2393
+ const limit = 50;
2394
+ const loadTransactions = react.useCallback(
2395
+ async (nextOffset, replace) => {
2396
+ try {
2397
+ if (replace) setIsLoading(true);
2398
+ else setIsFetchingMore(true);
2399
+ setError(null);
2400
+ const params = new URLSearchParams();
2401
+ params.set("limit", String(limit));
2402
+ params.set("offset", String(nextOffset));
2403
+ if (statusFilter !== "all") params.set("status", statusFilter);
2404
+ if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
2405
+ const response = await fetch(
2406
+ `/admin/payment-transactions?${params.toString()}`,
2407
+ { credentials: "include" }
2408
+ );
2409
+ if (!response.ok) {
2410
+ const text = await response.text();
2411
+ throw new Error(text || "Failed to load payment transactions");
2412
+ }
2413
+ const payload = await response.json();
2414
+ const list = payload.transactions ?? [];
2415
+ setCount(payload.count ?? 0);
2416
+ setOffset(nextOffset + list.length);
2417
+ setItems((prev) => replace ? list : [...prev, ...list]);
2418
+ } catch (e) {
2419
+ setError(e instanceof Error ? e.message : "Failed to load");
2420
+ } finally {
2421
+ setIsLoading(false);
2422
+ setIsFetchingMore(false);
2423
+ }
2424
+ },
2425
+ [statusFilter, debouncedOrderId]
2426
+ );
2427
+ react.useEffect(() => {
2428
+ void loadTransactions(0, true);
2429
+ }, [loadTransactions]);
2430
+ const hasMore = react.useMemo(() => offset < count, [offset, count]);
2431
+ const displayStatus = (t) => {
2432
+ const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
2433
+ return s2 !== "" ? s2 : "—";
2434
+ };
2435
+ const displayAmount = (t) => {
2436
+ const code = (t.currency_code ?? "USD").toUpperCase();
2437
+ return `${code} ${Number(t.amount)}`;
2438
+ };
2439
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
2440
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
2441
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2442
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payments" }),
2443
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
2444
+ ] }),
2445
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
2446
+ ] }),
2447
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
2448
+ /* @__PURE__ */ jsxRuntime.jsx(
2449
+ ui.Input,
2450
+ {
2451
+ placeholder: "Search by Order ID",
2452
+ value: orderIdSearch,
2453
+ onChange: (e) => setOrderIdSearch(e.target.value),
2454
+ className: "md:max-w-sm",
2455
+ "aria-label": "Search by order ID"
2456
+ }
2457
+ ),
2458
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs(
2459
+ "select",
2460
+ {
2461
+ value: statusFilter,
2462
+ onChange: (e) => setStatusFilter(e.target.value),
2463
+ 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",
2464
+ "aria-label": "Filter by status",
2465
+ children: [
2466
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
2467
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
2468
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
2469
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
2470
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
2471
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
2472
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
2473
+ ]
2474
+ }
2475
+ ) })
2476
+ ] }),
2477
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2478
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2479
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
2480
+ ] }) : null,
2481
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
2482
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
2483
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
2484
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2485
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2486
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
2487
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
2488
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
2489
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
2490
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
2491
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
2492
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
2493
+ ] }) }),
2494
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxRuntime.jsxs(
2495
+ "tr",
2496
+ {
2497
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
2498
+ onClick: () => navigate(`/payments/${t.payment_session_id}`),
2499
+ children: [
2500
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
2501
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
2502
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
2503
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
2504
+ ui.Badge,
2505
+ {
2506
+ size: "2xsmall",
2507
+ className: `uppercase ${getStatusBadgeClass$1(displayStatus(t))}`,
2508
+ children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
2509
+ }
2510
+ ) }),
2511
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
2512
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
2513
+ year: "numeric",
2514
+ month: "short",
2515
+ day: "numeric",
2516
+ hour: "numeric",
2517
+ minute: "2-digit",
2518
+ hour12: true
2519
+ }) }),
2520
+ /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-4", children: [
2521
+ /* @__PURE__ */ jsxRuntime.jsx(
2522
+ ui.Button,
2523
+ {
2524
+ variant: "transparent",
2525
+ size: "small",
2526
+ onClick: (e) => {
2527
+ e.stopPropagation();
2528
+ navigate(`/payments/${t.payment_session_id}`);
2529
+ },
2530
+ children: "View details"
2531
+ }
2532
+ ),
2533
+ t.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
2534
+ ui.Button,
2535
+ {
2536
+ variant: "transparent",
2537
+ size: "small",
2538
+ onClick: (e) => {
2539
+ e.stopPropagation();
2540
+ navigate(`/orders/${t.order_id}`);
2541
+ },
2542
+ children: "Order"
2543
+ }
2544
+ ) : null
2545
+ ] })
2546
+ ]
2547
+ },
2548
+ t.payment_session_id
2549
+ )) })
2550
+ ] }) }),
2551
+ hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
2552
+ ui.Button,
2553
+ {
2554
+ variant: "secondary",
2555
+ isLoading: isFetchingMore,
2556
+ onClick: () => loadTransactions(offset, false),
2557
+ children: "Load more"
2558
+ }
2559
+ ) }) : null
2560
+ ] }) });
2561
+ };
2562
+ const config$1 = adminSdk.defineRouteConfig({
2563
+ label: "Payments",
2564
+ icon: icons.CreditCard
2565
+ });
2566
+ const getStatusBadgeClass = (status) => {
2567
+ const s2 = status.toLowerCase();
2568
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2569
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2570
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2571
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2572
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2573
+ };
2574
+ const PaymentDetailPage = () => {
2575
+ var _a;
2576
+ const navigate = reactRouterDom.useNavigate();
2577
+ const params = reactRouterDom.useParams();
2578
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2579
+ const [detail, setDetail] = react.useState(null);
2580
+ const [loading, setLoading] = react.useState(!!id);
2581
+ const [error, setError] = react.useState(null);
2582
+ react.useEffect(() => {
2583
+ if (!id) {
2584
+ setLoading(false);
2585
+ return;
2586
+ }
2587
+ let cancelled = false;
2588
+ setLoading(true);
2589
+ setError(null);
2590
+ fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2591
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
2592
+ return res.json();
2593
+ }).then((data) => {
2594
+ if (!cancelled) setDetail(data);
2595
+ }).catch((e) => {
2596
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2597
+ }).finally(() => {
2598
+ if (!cancelled) setLoading(false);
2599
+ });
2600
+ return () => {
2601
+ cancelled = true;
2602
+ };
2603
+ }, [id]);
2604
+ const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
2605
+ const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
2606
+ const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
2607
+ const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
2608
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
2609
+ /* @__PURE__ */ jsxRuntime.jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2610
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
2611
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payment session" }),
2612
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
2613
+ ] }) }),
2614
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2615
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2616
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
2617
+ ] }) : loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
2618
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2619
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2620
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
2621
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
2622
+ ui.Button,
2623
+ {
2624
+ variant: "transparent",
2625
+ size: "small",
2626
+ onClick: () => navigate(`/orders/${detail.order_id}`),
2627
+ children: detail.order_id
2628
+ }
2629
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "—" }) })
2630
+ ] }),
2631
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2632
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2633
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: displayAmount })
2634
+ ] }),
2635
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2636
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2637
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.provider_id })
2638
+ ] }),
2639
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2640
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2641
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2642
+ ui.Badge,
2643
+ {
2644
+ size: "2xsmall",
2645
+ className: `uppercase ${getStatusBadgeClass(displayStatus)}`,
2646
+ children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2647
+ }
2648
+ ) })
2649
+ ] }),
2650
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2651
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
2652
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: sessionStatusRaw })
2653
+ ] }),
2654
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2655
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
2656
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: paymentStatusRaw })
2657
+ ] }),
2658
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2659
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
2660
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
2661
+ ] }),
2662
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2663
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
2664
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2665
+ year: "numeric",
2666
+ month: "short",
2667
+ day: "numeric",
2668
+ hour: "numeric",
2669
+ minute: "2-digit",
2670
+ hour12: true
2671
+ }) })
2672
+ ] })
2673
+ ] }) }),
2674
+ Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2675
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2676
+ /* @__PURE__ */ jsxRuntime.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) })
2677
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
2678
+ ] }) : null
2679
+ ] }) });
2680
+ };
2681
+ const config = adminSdk.defineRouteConfig({
2682
+ label: "Payment details",
2683
+ icon: icons.CreditCard
2684
+ });
2685
+ const i18nTranslations0 = {};
2686
+ const widgetModule = { widgets: [
2687
+ {
2688
+ Component: OrderGiftItemsWidget,
2689
+ zone: ["order.details.side.after"]
2690
+ },
2691
+ {
2692
+ Component: OrderRefundContextWidget,
2693
+ zone: ["order.details.after"]
2694
+ }
2695
+ ] };
2696
+ const routeModule = {
2697
+ routes: [
2698
+ {
2699
+ Component: RefundsPage,
2700
+ path: "/refunds"
2751
2701
  },
2752
2702
  {
2753
- label: config$4.label,
2754
- icon: config$4.icon,
2755
- path: "/swaps",
2756
- nested: void 0
2703
+ Component: ReturnsPage,
2704
+ path: "/returns"
2757
2705
  },
2758
2706
  {
2759
- label: config.label,
2760
- icon: config.icon,
2761
- path: "/returns/:id",
2707
+ Component: SwapsPage,
2708
+ path: "/swaps"
2709
+ },
2710
+ {
2711
+ Component: RefundDetailPage,
2712
+ path: "/refunds/:id"
2713
+ },
2714
+ {
2715
+ Component: ReturnDetailPage,
2716
+ path: "/returns/:id"
2717
+ },
2718
+ {
2719
+ Component: SwapDetailPage,
2720
+ path: "/swaps/:id"
2721
+ },
2722
+ {
2723
+ Component: PaymentsPage,
2724
+ path: "/payments"
2725
+ },
2726
+ {
2727
+ Component: PaymentDetailPage,
2728
+ path: "/payments/:id"
2729
+ }
2730
+ ]
2731
+ };
2732
+ const menuItemModule = {
2733
+ menuItems: [
2734
+ {
2735
+ label: config$6.label,
2736
+ icon: config$6.icon,
2737
+ path: "/returns",
2762
2738
  nested: void 0
2763
2739
  },
2764
2740
  {
2765
2741
  label: config$1.label,
2766
2742
  icon: config$1.icon,
2767
- path: "/payments/:id",
2743
+ path: "/payments",
2768
2744
  nested: void 0
2769
2745
  },
2770
2746
  {
2771
- label: config$2.label,
2772
- icon: config$2.icon,
2773
- path: "/swaps/:id",
2747
+ label: config$7.label,
2748
+ icon: config$7.icon,
2749
+ path: "/refunds",
2750
+ nested: void 0
2751
+ },
2752
+ {
2753
+ label: config$5.label,
2754
+ icon: config$5.icon,
2755
+ path: "/swaps",
2774
2756
  nested: void 0
2775
2757
  },
2776
2758
  {
2777
2759
  label: config$3.label,
2778
2760
  icon: config$3.icon,
2761
+ path: "/returns/:id",
2762
+ nested: void 0
2763
+ },
2764
+ {
2765
+ label: config$4.label,
2766
+ icon: config$4.icon,
2779
2767
  path: "/refunds/:id",
2780
2768
  nested: void 0
2769
+ },
2770
+ {
2771
+ label: config.label,
2772
+ icon: config.icon,
2773
+ path: "/payments/:id",
2774
+ nested: void 0
2775
+ },
2776
+ {
2777
+ label: config$2.label,
2778
+ icon: config$2.icon,
2779
+ path: "/swaps/:id",
2780
+ nested: void 0
2781
2781
  }
2782
2782
  ]
2783
2783
  };