order-management 0.0.74 → 0.0.76

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.
@@ -873,19 +873,27 @@ const getStatusBadgeClass$7 = (status) => {
873
873
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
874
874
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
875
875
  };
876
- const PaymentsPage = () => {
876
+ const RefundsPage = () => {
877
877
  const navigate = reactRouterDom.useNavigate();
878
878
  const [items, setItems] = react.useState([]);
879
- const [statusFilter, setStatusFilter] = react.useState("all");
880
879
  const [orderIdSearch, setOrderIdSearch] = react.useState("");
881
880
  const debouncedOrderId = useDebounce$3(orderIdSearch, 300);
881
+ const [paymentStatusFilter, setPaymentStatusFilter] = react.useState("all");
882
+ const [providerSearch, setProviderSearch] = react.useState("");
883
+ const debouncedProvider = useDebounce$3(providerSearch, 300);
884
+ const [currencySearch, setCurrencySearch] = react.useState("");
885
+ const debouncedCurrency = useDebounce$3(currencySearch, 300);
886
+ const [dateFrom, setDateFrom] = react.useState("");
887
+ const [dateTo, setDateTo] = react.useState("");
888
+ const [amountMin, setAmountMin] = react.useState("");
889
+ const [amountMax, setAmountMax] = react.useState("");
882
890
  const [isLoading, setIsLoading] = react.useState(true);
883
891
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
884
892
  const [error, setError] = react.useState(null);
885
893
  const [offset, setOffset] = react.useState(0);
886
894
  const [count, setCount] = react.useState(0);
887
895
  const limit = 50;
888
- const loadTransactions = react.useCallback(
896
+ const loadRefunds = react.useCallback(
889
897
  async (nextOffset, replace) => {
890
898
  try {
891
899
  if (replace) setIsLoading(true);
@@ -894,18 +902,25 @@ const PaymentsPage = () => {
894
902
  const params = new URLSearchParams();
895
903
  params.set("limit", String(limit));
896
904
  params.set("offset", String(nextOffset));
897
- if (statusFilter !== "all") params.set("status", statusFilter);
898
905
  if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
899
- const response = await fetch(
900
- `/admin/payment-transactions?${params.toString()}`,
901
- { credentials: "include" }
902
- );
906
+ if (paymentStatusFilter !== "all") params.set("payment_status", paymentStatusFilter);
907
+ if (debouncedProvider.trim()) params.set("provider_id", debouncedProvider.trim());
908
+ if (debouncedCurrency.trim()) params.set("currency_code", debouncedCurrency.trim());
909
+ if (dateFrom.trim()) params.set("date_from", dateFrom.trim());
910
+ if (dateTo.trim()) params.set("date_to", dateTo.trim());
911
+ const min = amountMin.trim() ? Number(amountMin) : void 0;
912
+ const max = amountMax.trim() ? Number(amountMax) : void 0;
913
+ if (min != null && !Number.isNaN(min)) params.set("amount_min", String(min));
914
+ if (max != null && !Number.isNaN(max)) params.set("amount_max", String(max));
915
+ const response = await fetch(`/admin/refunds?${params.toString()}`, {
916
+ credentials: "include"
917
+ });
903
918
  if (!response.ok) {
904
919
  const text = await response.text();
905
- throw new Error(text || "Failed to load payment transactions");
920
+ throw new Error(text || "Failed to load refunds");
906
921
  }
907
922
  const payload = await response.json();
908
- const list = payload.transactions ?? [];
923
+ const list = payload.refunds ?? [];
909
924
  setCount(payload.count ?? 0);
910
925
  setOffset(nextOffset + list.length);
911
926
  setItems((prev) => replace ? list : [...prev, ...list]);
@@ -916,46 +931,75 @@ const PaymentsPage = () => {
916
931
  setIsFetchingMore(false);
917
932
  }
918
933
  },
919
- [statusFilter, debouncedOrderId]
934
+ [
935
+ debouncedOrderId,
936
+ paymentStatusFilter,
937
+ debouncedProvider,
938
+ debouncedCurrency,
939
+ dateFrom,
940
+ dateTo,
941
+ amountMin,
942
+ amountMax
943
+ ]
920
944
  );
921
945
  react.useEffect(() => {
922
- void loadTransactions(0, true);
923
- }, [loadTransactions]);
946
+ void loadRefunds(0, true);
947
+ }, [loadRefunds]);
924
948
  const hasMore = react.useMemo(() => offset < count, [offset, count]);
925
- const displayStatus = (t) => {
926
- const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
927
- return s2 !== "" ? s2 : "—";
949
+ const displayAmount = (r) => {
950
+ const code = (r.currency_code ?? "USD").toUpperCase();
951
+ return `${code} ${Number(r.amount)}`;
928
952
  };
929
- const displayAmount = (t) => {
930
- const code = (t.currency_code ?? "USD").toUpperCase();
931
- return `${code} ${Number(t.amount)}`;
953
+ const displayStatus = (r) => {
954
+ const s2 = r.payment_status ?? "";
955
+ return s2 !== "" ? s2 : "—";
932
956
  };
933
957
  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: [
934
958
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
935
959
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
936
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payments" }),
937
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts completed, pending, failed, requires action" })
960
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refunds" }),
961
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Refund recordsamount, order, payment status" })
938
962
  ] }),
939
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
963
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadRefunds(0, true), children: "Refresh" })
940
964
  ] }),
941
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
965
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
942
966
  /* @__PURE__ */ jsxRuntime.jsx(
943
967
  ui.Input,
944
968
  {
945
- placeholder: "Search by Order ID",
969
+ placeholder: "Order ID",
946
970
  value: orderIdSearch,
947
971
  onChange: (e) => setOrderIdSearch(e.target.value),
948
- className: "md:max-w-sm",
949
- "aria-label": "Search by order ID"
972
+ className: "md:max-w-[180px]",
973
+ "aria-label": "Filter by order ID"
950
974
  }
951
975
  ),
952
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs(
976
+ /* @__PURE__ */ jsxRuntime.jsx(
977
+ ui.Input,
978
+ {
979
+ placeholder: "Provider",
980
+ value: providerSearch,
981
+ onChange: (e) => setProviderSearch(e.target.value),
982
+ className: "md:max-w-[140px]",
983
+ "aria-label": "Filter by provider"
984
+ }
985
+ ),
986
+ /* @__PURE__ */ jsxRuntime.jsx(
987
+ ui.Input,
988
+ {
989
+ placeholder: "Currency",
990
+ value: currencySearch,
991
+ onChange: (e) => setCurrencySearch(e.target.value),
992
+ className: "md:max-w-[100px]",
993
+ "aria-label": "Filter by currency"
994
+ }
995
+ ),
996
+ /* @__PURE__ */ jsxRuntime.jsxs(
953
997
  "select",
954
998
  {
955
- value: statusFilter,
956
- onChange: (e) => setStatusFilter(e.target.value),
957
- 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",
958
- "aria-label": "Filter by status",
999
+ value: paymentStatusFilter,
1000
+ onChange: (e) => setPaymentStatusFilter(e.target.value),
1001
+ 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-[160px]",
1002
+ "aria-label": "Filter by payment status",
959
1003
  children: [
960
1004
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
961
1005
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
@@ -966,52 +1010,103 @@ const PaymentsPage = () => {
966
1010
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
967
1011
  ]
968
1012
  }
969
- ) })
970
- ] }),
1013
+ ),
1014
+ /* @__PURE__ */ jsxRuntime.jsx(
1015
+ ui.Input,
1016
+ {
1017
+ type: "date",
1018
+ placeholder: "From",
1019
+ value: dateFrom,
1020
+ onChange: (e) => setDateFrom(e.target.value),
1021
+ className: "md:max-w-[140px]",
1022
+ "aria-label": "Date from"
1023
+ }
1024
+ ),
1025
+ /* @__PURE__ */ jsxRuntime.jsx(
1026
+ ui.Input,
1027
+ {
1028
+ type: "date",
1029
+ placeholder: "To",
1030
+ value: dateTo,
1031
+ onChange: (e) => setDateTo(e.target.value),
1032
+ className: "md:max-w-[140px]",
1033
+ "aria-label": "Date to"
1034
+ }
1035
+ ),
1036
+ /* @__PURE__ */ jsxRuntime.jsx(
1037
+ ui.Input,
1038
+ {
1039
+ placeholder: "Amount min",
1040
+ value: amountMin,
1041
+ onChange: (e) => setAmountMin(e.target.value),
1042
+ type: "number",
1043
+ min: 0,
1044
+ className: "md:max-w-[100px]",
1045
+ "aria-label": "Refund amount minimum"
1046
+ }
1047
+ ),
1048
+ /* @__PURE__ */ jsxRuntime.jsx(
1049
+ ui.Input,
1050
+ {
1051
+ placeholder: "Amount max",
1052
+ value: amountMax,
1053
+ onChange: (e) => setAmountMax(e.target.value),
1054
+ type: "number",
1055
+ min: 0,
1056
+ className: "md:max-w-[100px]",
1057
+ "aria-label": "Refund amount maximum"
1058
+ }
1059
+ )
1060
+ ] }) }),
971
1061
  error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
972
1062
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
973
- /* @__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" }) })
1063
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => loadRefunds(0, true), children: "Try again" }) })
974
1064
  ] }) : null,
975
- 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: [
976
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
978
- ] }) : /* @__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: [
1065
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading refunds…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1066
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No refunds yet" }),
1067
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Refund records will appear here." })
1068
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full overflow-x-auto rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full table-fixed divide-y divide-ui-border-base", style: { minWidth: 0 }, children: [
979
1069
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
980
- /* @__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" }),
981
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
982
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
983
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
984
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
985
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
986
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1070
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund ID" }),
1071
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1072
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Payment ID" }),
1073
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[8%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1074
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[6%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Currency" }),
1075
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[10%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1076
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[10%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Payment Status" }),
1077
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[14%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Note" }),
1078
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1079
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[8%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
987
1080
  ] }) }),
988
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxRuntime.jsxs(
1081
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((r) => /* @__PURE__ */ jsxRuntime.jsxs(
989
1082
  "tr",
990
1083
  {
991
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
992
- onClick: () => navigate(`/payments/${t.payment_session_id}`),
1084
+ className: "cursor-pointer hover:bg-ui-bg-subtle/60",
1085
+ onClick: () => navigate(`/refunds/${r.refund_id}`),
993
1086
  children: [
994
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
995
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
996
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
997
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1087
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-mono text-sm text-ui-fg-base", title: r.refund_id, children: r.refund_id }),
1088
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-medium text-ui-fg-base", title: r.order_id ?? void 0, children: r.order_id ?? "—" }),
1089
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-mono text-sm text-ui-fg-subtle", title: r.payment_id, children: r.payment_id }),
1090
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", children: displayAmount(r) }),
1091
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle uppercase", children: r.currency_code || "—" }),
1092
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", title: r.provider_id || void 0, children: r.provider_id || "—" }),
1093
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsx(
998
1094
  ui.Badge,
999
1095
  {
1000
1096
  size: "2xsmall",
1001
- className: `uppercase ${getStatusBadgeClass$7(displayStatus(t))}`,
1002
- children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1097
+ className: `uppercase ${getStatusBadgeClass$7(displayStatus(r))}`,
1098
+ children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1003
1099
  }
1004
1100
  ) }),
1005
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1006
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1007
- year: "numeric",
1101
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", title: r.note ?? void 0, children: r.note ?? "" }),
1102
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle text-xs", children: new Date(r.created_at).toLocaleDateString("en-US", {
1008
1103
  month: "short",
1009
1104
  day: "numeric",
1010
1105
  hour: "numeric",
1011
1106
  minute: "2-digit",
1012
1107
  hour12: true
1013
1108
  }) }),
1014
- /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-4", children: [
1109
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-1", children: [
1015
1110
  /* @__PURE__ */ jsxRuntime.jsx(
1016
1111
  ui.Button,
1017
1112
  {
@@ -1019,27 +1114,27 @@ const PaymentsPage = () => {
1019
1114
  size: "small",
1020
1115
  onClick: (e) => {
1021
1116
  e.stopPropagation();
1022
- navigate(`/payments/${t.payment_session_id}`);
1117
+ navigate(`/refunds/${r.refund_id}`);
1023
1118
  },
1024
- children: "View details"
1119
+ children: "Details"
1025
1120
  }
1026
1121
  ),
1027
- t.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1122
+ r.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1028
1123
  ui.Button,
1029
1124
  {
1030
1125
  variant: "transparent",
1031
1126
  size: "small",
1032
1127
  onClick: (e) => {
1033
1128
  e.stopPropagation();
1034
- navigate(`/orders/${t.order_id}`);
1129
+ navigate(`/orders/${r.order_id}`);
1035
1130
  },
1036
1131
  children: "Order"
1037
1132
  }
1038
1133
  ) : null
1039
- ] })
1134
+ ] }) })
1040
1135
  ]
1041
1136
  },
1042
- t.payment_session_id
1137
+ r.refund_id
1043
1138
  )) })
1044
1139
  ] }) }),
1045
1140
  hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1047,15 +1142,15 @@ const PaymentsPage = () => {
1047
1142
  {
1048
1143
  variant: "secondary",
1049
1144
  isLoading: isFetchingMore,
1050
- onClick: () => loadTransactions(offset, false),
1145
+ onClick: () => loadRefunds(offset, false),
1051
1146
  children: "Load more"
1052
1147
  }
1053
1148
  ) }) : null
1054
1149
  ] }) });
1055
1150
  };
1056
1151
  const config$7 = adminSdk.defineRouteConfig({
1057
- label: "Payments",
1058
- icon: icons.CreditCard
1152
+ label: "Refunds",
1153
+ icon: icons.Receipt
1059
1154
  });
1060
1155
  const useDebounce$2 = (value, delay) => {
1061
1156
  const [debouncedValue, setDebouncedValue] = react.useState(value);
@@ -1066,190 +1161,144 @@ const useDebounce$2 = (value, delay) => {
1066
1161
  return debouncedValue;
1067
1162
  };
1068
1163
  const getStatusBadgeClass$6 = (status) => {
1069
- const statusLower = status.toLowerCase();
1070
- if (statusLower === "requested") {
1071
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1072
- }
1073
- if (statusLower === "received") {
1074
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1075
- }
1076
- if (statusLower === "requires_action") {
1077
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
1078
- }
1079
- if (statusLower === "completed") {
1080
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
1081
- }
1082
- if (statusLower === "canceled") {
1083
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1084
- }
1164
+ const s2 = status.toLowerCase();
1165
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1166
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1167
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1168
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1085
1169
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1086
1170
  };
1087
- const ReturnsPage = () => {
1171
+ const PaymentsPage = () => {
1088
1172
  const navigate = reactRouterDom.useNavigate();
1089
1173
  const [items, setItems] = react.useState([]);
1090
1174
  const [statusFilter, setStatusFilter] = react.useState("all");
1091
- const [createdByFilter, setCreatedByFilter] = react.useState("all");
1092
- const [searchQuery, setSearchQuery] = react.useState("");
1093
- const debouncedSearchQuery = useDebounce$2(searchQuery, 300);
1175
+ const [orderIdSearch, setOrderIdSearch] = react.useState("");
1176
+ const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
1094
1177
  const [isLoading, setIsLoading] = react.useState(true);
1095
1178
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1096
1179
  const [error, setError] = react.useState(null);
1097
1180
  const [offset, setOffset] = react.useState(0);
1098
1181
  const [count, setCount] = react.useState(0);
1099
1182
  const limit = 50;
1100
- const loadReturns = react.useCallback(
1101
- async (nextOffset, replace = false) => {
1102
- var _a;
1183
+ const loadTransactions = react.useCallback(
1184
+ async (nextOffset, replace) => {
1103
1185
  try {
1104
- if (replace) {
1105
- setIsLoading(true);
1106
- } else {
1107
- setIsFetchingMore(true);
1108
- }
1186
+ if (replace) setIsLoading(true);
1187
+ else setIsFetchingMore(true);
1109
1188
  setError(null);
1110
1189
  const params = new URLSearchParams();
1111
1190
  params.set("limit", String(limit));
1112
1191
  params.set("offset", String(nextOffset));
1113
- if (statusFilter !== "all") {
1114
- params.set("status", statusFilter);
1115
- }
1116
- if (debouncedSearchQuery.trim()) {
1117
- params.set("q", debouncedSearchQuery.trim());
1118
- }
1119
- if (createdByFilter !== "all") {
1120
- params.set("created_by", createdByFilter);
1121
- }
1122
- params.set("order", "created_at");
1192
+ if (statusFilter !== "all") params.set("status", statusFilter);
1193
+ if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
1123
1194
  const response = await fetch(
1124
- `/admin/return?${params.toString()}`,
1195
+ `/admin/payment-transactions?${params.toString()}`,
1125
1196
  { credentials: "include" }
1126
1197
  );
1127
1198
  if (!response.ok) {
1128
- const message = await response.text();
1129
- throw new Error(message || "Unable to load return orders");
1199
+ const text = await response.text();
1200
+ throw new Error(text || "Failed to load payment transactions");
1130
1201
  }
1131
1202
  const payload = await response.json();
1203
+ const list = payload.transactions ?? [];
1132
1204
  setCount(payload.count ?? 0);
1133
- setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
1134
- setItems(
1135
- (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
1136
- );
1137
- } catch (loadError) {
1138
- const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
1139
- setError(message);
1205
+ setOffset(nextOffset + list.length);
1206
+ setItems((prev) => replace ? list : [...prev, ...list]);
1207
+ } catch (e) {
1208
+ setError(e instanceof Error ? e.message : "Failed to load");
1140
1209
  } finally {
1141
1210
  setIsLoading(false);
1142
1211
  setIsFetchingMore(false);
1143
1212
  }
1144
1213
  },
1145
- [statusFilter, createdByFilter, debouncedSearchQuery]
1214
+ [statusFilter, debouncedOrderId]
1146
1215
  );
1147
1216
  react.useEffect(() => {
1148
- void loadReturns(0, true);
1149
- }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
1217
+ void loadTransactions(0, true);
1218
+ }, [loadTransactions]);
1150
1219
  const hasMore = react.useMemo(() => offset < count, [offset, count]);
1151
- const availableStatuses = react.useMemo(() => {
1152
- const statuses = /* @__PURE__ */ new Set();
1153
- items.forEach((item) => statuses.add(item.status));
1154
- return Array.from(statuses).sort();
1155
- }, [items]);
1220
+ const displayStatus = (t) => {
1221
+ const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
1222
+ return s2 !== "" ? s2 : "—";
1223
+ };
1224
+ const displayAmount = (t) => {
1225
+ const code = (t.currency_code ?? "USD").toUpperCase();
1226
+ return `${code} ${Number(t.amount)}`;
1227
+ };
1156
1228
  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: [
1157
1229
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1158
1230
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1159
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Orders" }),
1160
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
1231
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payments" }),
1232
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts completed, pending, failed, requires action" })
1161
1233
  ] }),
1162
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
1234
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
1163
1235
  ] }),
1164
1236
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1165
1237
  /* @__PURE__ */ jsxRuntime.jsx(
1166
1238
  ui.Input,
1167
1239
  {
1168
- placeholder: "Search by return ID, order ID, or customer email",
1169
- value: searchQuery,
1170
- onChange: (event) => setSearchQuery(event.target.value),
1171
- className: "md:max-w-sm"
1240
+ placeholder: "Search by Order ID",
1241
+ value: orderIdSearch,
1242
+ onChange: (e) => setOrderIdSearch(e.target.value),
1243
+ className: "md:max-w-sm",
1244
+ "aria-label": "Search by order ID"
1172
1245
  }
1173
1246
  ),
1174
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
1175
- /* @__PURE__ */ jsxRuntime.jsxs(
1176
- "select",
1177
- {
1178
- value: createdByFilter,
1179
- onChange: (event) => setCreatedByFilter(event.target.value),
1180
- 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",
1181
- children: [
1182
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All (Created by)" }),
1183
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "customer", children: "Customer" }),
1184
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "admin", children: "Admin" })
1185
- ]
1186
- }
1187
- ),
1188
- /* @__PURE__ */ jsxRuntime.jsxs(
1189
- "select",
1190
- {
1191
- value: statusFilter,
1192
- onChange: (event) => setStatusFilter(event.target.value),
1193
- 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",
1194
- children: [
1195
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All Statuses" }),
1196
- availableStatuses.map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1197
- ]
1198
- }
1199
- )
1200
- ] })
1201
- ] }),
1202
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1203
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1204
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1205
- ui.Button,
1247
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs(
1248
+ "select",
1206
1249
  {
1207
- variant: "secondary",
1208
- onClick: () => loadReturns(0, true),
1209
- children: "Try again"
1250
+ value: statusFilter,
1251
+ onChange: (e) => setStatusFilter(e.target.value),
1252
+ 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",
1253
+ "aria-label": "Filter by status",
1254
+ children: [
1255
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
1256
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
1257
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
1258
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
1259
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
1260
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
1261
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
1262
+ ]
1210
1263
  }
1211
1264
  ) })
1265
+ ] }),
1266
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1267
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1268
+ /* @__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" }) })
1212
1269
  ] }) : null,
1213
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return orders..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1214
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1215
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1270
+ 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: [
1271
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
1272
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
1216
1273
  ] }) : /* @__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: [
1217
1274
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1218
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
1219
1275
  /* @__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" }),
1220
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1276
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1277
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1221
1278
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1222
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
1279
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
1223
1280
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1224
1281
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1225
1282
  ] }) }),
1226
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxRuntime.jsxs(
1283
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxRuntime.jsxs(
1227
1284
  "tr",
1228
1285
  {
1229
1286
  className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1230
- onClick: () => navigate(`/returns/${returnOrder.id}`),
1287
+ onClick: () => navigate(`/payments/${t.payment_session_id}`),
1231
1288
  children: [
1232
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: returnOrder.id }) }) }),
1233
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1234
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1289
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "" }),
1290
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
1291
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
1235
1292
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1236
1293
  ui.Badge,
1237
1294
  {
1238
1295
  size: "2xsmall",
1239
- className: `uppercase ${getStatusBadgeClass$6(returnOrder.status)}`,
1240
- children: returnOrder.status.replace(/_/g, " ")
1296
+ className: `uppercase ${getStatusBadgeClass$6(displayStatus(t))}`,
1297
+ children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1241
1298
  }
1242
1299
  ) }),
1243
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1244
- const amount = returnOrder.refund_amount;
1245
- if (amount == null || amount === void 0) {
1246
- return "—";
1247
- }
1248
- const displayAmount = Number(amount) / 100;
1249
- const currency = returnOrder.currency_code || "$";
1250
- return `${currency}${displayAmount.toFixed(2)}`;
1251
- })() }),
1252
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1300
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1301
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1253
1302
  year: "numeric",
1254
1303
  month: "short",
1255
1304
  day: "numeric",
@@ -1257,21 +1306,35 @@ const ReturnsPage = () => {
1257
1306
  minute: "2-digit",
1258
1307
  hour12: true
1259
1308
  }) }),
1260
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1261
- ui.Button,
1262
- {
1263
- variant: "transparent",
1264
- size: "small",
1265
- onClick: (e) => {
1266
- e.stopPropagation();
1267
- navigate(`/app/orders/${returnOrder.order_id}`);
1268
- },
1269
- children: "Go to order"
1270
- }
1271
- ) })
1309
+ /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-4", children: [
1310
+ /* @__PURE__ */ jsxRuntime.jsx(
1311
+ ui.Button,
1312
+ {
1313
+ variant: "transparent",
1314
+ size: "small",
1315
+ onClick: (e) => {
1316
+ e.stopPropagation();
1317
+ navigate(`/payments/${t.payment_session_id}`);
1318
+ },
1319
+ children: "View details"
1320
+ }
1321
+ ),
1322
+ t.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1323
+ ui.Button,
1324
+ {
1325
+ variant: "transparent",
1326
+ size: "small",
1327
+ onClick: (e) => {
1328
+ e.stopPropagation();
1329
+ navigate(`/orders/${t.order_id}`);
1330
+ },
1331
+ children: "Order"
1332
+ }
1333
+ ) : null
1334
+ ] })
1272
1335
  ]
1273
1336
  },
1274
- returnOrder.id
1337
+ t.payment_session_id
1275
1338
  )) })
1276
1339
  ] }) }),
1277
1340
  hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1279,15 +1342,15 @@ const ReturnsPage = () => {
1279
1342
  {
1280
1343
  variant: "secondary",
1281
1344
  isLoading: isFetchingMore,
1282
- onClick: () => loadReturns(offset, false),
1345
+ onClick: () => loadTransactions(offset, false),
1283
1346
  children: "Load more"
1284
1347
  }
1285
1348
  ) }) : null
1286
1349
  ] }) });
1287
1350
  };
1288
1351
  const config$6 = adminSdk.defineRouteConfig({
1289
- label: "Return Orders",
1290
- icon: icons.ArrowPath
1352
+ label: "Payments",
1353
+ icon: icons.CreditCard
1291
1354
  });
1292
1355
  const useDebounce$1 = (value, delay) => {
1293
1356
  const [debouncedValue, setDebouncedValue] = react.useState(value);
@@ -1298,275 +1361,212 @@ const useDebounce$1 = (value, delay) => {
1298
1361
  return debouncedValue;
1299
1362
  };
1300
1363
  const getStatusBadgeClass$5 = (status) => {
1301
- const s2 = status.toLowerCase();
1302
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1303
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1304
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1305
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1364
+ const statusLower = status.toLowerCase();
1365
+ if (statusLower === "requested") {
1366
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1367
+ }
1368
+ if (statusLower === "received") {
1369
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1370
+ }
1371
+ if (statusLower === "requires_action") {
1372
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
1373
+ }
1374
+ if (statusLower === "completed") {
1375
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
1376
+ }
1377
+ if (statusLower === "canceled") {
1378
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1379
+ }
1306
1380
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1307
1381
  };
1308
- const RefundsPage = () => {
1382
+ const ReturnsPage = () => {
1309
1383
  const navigate = reactRouterDom.useNavigate();
1310
1384
  const [items, setItems] = react.useState([]);
1311
- const [orderIdSearch, setOrderIdSearch] = react.useState("");
1312
- const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1313
- const [paymentStatusFilter, setPaymentStatusFilter] = react.useState("all");
1314
- const [providerSearch, setProviderSearch] = react.useState("");
1315
- const debouncedProvider = useDebounce$1(providerSearch, 300);
1316
- const [currencySearch, setCurrencySearch] = react.useState("");
1317
- const debouncedCurrency = useDebounce$1(currencySearch, 300);
1318
- const [dateFrom, setDateFrom] = react.useState("");
1319
- const [dateTo, setDateTo] = react.useState("");
1320
- const [amountMin, setAmountMin] = react.useState("");
1321
- const [amountMax, setAmountMax] = react.useState("");
1385
+ const [statusFilter, setStatusFilter] = react.useState("all");
1386
+ const [createdByFilter, setCreatedByFilter] = react.useState("all");
1387
+ const [searchQuery, setSearchQuery] = react.useState("");
1388
+ const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1322
1389
  const [isLoading, setIsLoading] = react.useState(true);
1323
1390
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1324
1391
  const [error, setError] = react.useState(null);
1325
1392
  const [offset, setOffset] = react.useState(0);
1326
1393
  const [count, setCount] = react.useState(0);
1327
1394
  const limit = 50;
1328
- const loadRefunds = react.useCallback(
1329
- async (nextOffset, replace) => {
1395
+ const loadReturns = react.useCallback(
1396
+ async (nextOffset, replace = false) => {
1397
+ var _a;
1330
1398
  try {
1331
- if (replace) setIsLoading(true);
1332
- else setIsFetchingMore(true);
1399
+ if (replace) {
1400
+ setIsLoading(true);
1401
+ } else {
1402
+ setIsFetchingMore(true);
1403
+ }
1333
1404
  setError(null);
1334
1405
  const params = new URLSearchParams();
1335
1406
  params.set("limit", String(limit));
1336
1407
  params.set("offset", String(nextOffset));
1337
- if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
1338
- if (paymentStatusFilter !== "all") params.set("payment_status", paymentStatusFilter);
1339
- if (debouncedProvider.trim()) params.set("provider_id", debouncedProvider.trim());
1340
- if (debouncedCurrency.trim()) params.set("currency_code", debouncedCurrency.trim());
1341
- if (dateFrom.trim()) params.set("date_from", dateFrom.trim());
1342
- if (dateTo.trim()) params.set("date_to", dateTo.trim());
1343
- const min = amountMin.trim() ? Number(amountMin) : void 0;
1344
- const max = amountMax.trim() ? Number(amountMax) : void 0;
1345
- if (min != null && !Number.isNaN(min)) params.set("amount_min", String(min));
1346
- if (max != null && !Number.isNaN(max)) params.set("amount_max", String(max));
1347
- const response = await fetch(`/admin/refunds?${params.toString()}`, {
1348
- credentials: "include"
1349
- });
1408
+ if (statusFilter !== "all") {
1409
+ params.set("status", statusFilter);
1410
+ }
1411
+ if (debouncedSearchQuery.trim()) {
1412
+ params.set("q", debouncedSearchQuery.trim());
1413
+ }
1414
+ if (createdByFilter !== "all") {
1415
+ params.set("created_by", createdByFilter);
1416
+ }
1417
+ params.set("order", "created_at");
1418
+ const response = await fetch(
1419
+ `/admin/return?${params.toString()}`,
1420
+ { credentials: "include" }
1421
+ );
1350
1422
  if (!response.ok) {
1351
- const text = await response.text();
1352
- throw new Error(text || "Failed to load refunds");
1423
+ const message = await response.text();
1424
+ throw new Error(message || "Unable to load return orders");
1353
1425
  }
1354
1426
  const payload = await response.json();
1355
- const list = payload.refunds ?? [];
1356
1427
  setCount(payload.count ?? 0);
1357
- setOffset(nextOffset + list.length);
1358
- setItems((prev) => replace ? list : [...prev, ...list]);
1359
- } catch (e) {
1360
- setError(e instanceof Error ? e.message : "Failed to load");
1428
+ setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
1429
+ setItems(
1430
+ (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
1431
+ );
1432
+ } catch (loadError) {
1433
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
1434
+ setError(message);
1361
1435
  } finally {
1362
1436
  setIsLoading(false);
1363
1437
  setIsFetchingMore(false);
1364
1438
  }
1365
1439
  },
1366
- [
1367
- debouncedOrderId,
1368
- paymentStatusFilter,
1369
- debouncedProvider,
1370
- debouncedCurrency,
1371
- dateFrom,
1372
- dateTo,
1373
- amountMin,
1374
- amountMax
1375
- ]
1440
+ [statusFilter, createdByFilter, debouncedSearchQuery]
1376
1441
  );
1377
1442
  react.useEffect(() => {
1378
- void loadRefunds(0, true);
1379
- }, [loadRefunds]);
1443
+ void loadReturns(0, true);
1444
+ }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
1380
1445
  const hasMore = react.useMemo(() => offset < count, [offset, count]);
1381
- const displayAmount = (r) => {
1382
- const code = (r.currency_code ?? "USD").toUpperCase();
1383
- return `${code} ${Number(r.amount)}`;
1384
- };
1385
- const displayStatus = (r) => {
1386
- const s2 = r.payment_status ?? "";
1387
- return s2 !== "" ? s2 : "—";
1388
- };
1446
+ const availableStatuses = react.useMemo(() => {
1447
+ const statuses = /* @__PURE__ */ new Set();
1448
+ items.forEach((item) => statuses.add(item.status));
1449
+ return Array.from(statuses).sort();
1450
+ }, [items]);
1389
1451
  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: [
1390
1452
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1391
1453
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1392
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refunds" }),
1393
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Refund records amount, order, payment status" })
1454
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Orders" }),
1455
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
1394
1456
  ] }),
1395
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadRefunds(0, true), children: "Refresh" })
1457
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
1396
1458
  ] }),
1397
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
1398
- /* @__PURE__ */ jsxRuntime.jsx(
1399
- ui.Input,
1400
- {
1401
- placeholder: "Order ID",
1402
- value: orderIdSearch,
1403
- onChange: (e) => setOrderIdSearch(e.target.value),
1404
- className: "md:max-w-[180px]",
1405
- "aria-label": "Filter by order ID"
1406
- }
1407
- ),
1408
- /* @__PURE__ */ jsxRuntime.jsx(
1409
- ui.Input,
1410
- {
1411
- placeholder: "Provider",
1412
- value: providerSearch,
1413
- onChange: (e) => setProviderSearch(e.target.value),
1414
- className: "md:max-w-[140px]",
1415
- "aria-label": "Filter by provider"
1416
- }
1417
- ),
1418
- /* @__PURE__ */ jsxRuntime.jsx(
1419
- ui.Input,
1420
- {
1421
- placeholder: "Currency",
1422
- value: currencySearch,
1423
- onChange: (e) => setCurrencySearch(e.target.value),
1424
- className: "md:max-w-[100px]",
1425
- "aria-label": "Filter by currency"
1426
- }
1427
- ),
1428
- /* @__PURE__ */ jsxRuntime.jsxs(
1429
- "select",
1430
- {
1431
- value: paymentStatusFilter,
1432
- onChange: (e) => setPaymentStatusFilter(e.target.value),
1433
- 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-[160px]",
1434
- "aria-label": "Filter by payment status",
1435
- children: [
1436
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
1437
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
1438
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
1439
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
1440
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
1441
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
1442
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
1443
- ]
1444
- }
1445
- ),
1446
- /* @__PURE__ */ jsxRuntime.jsx(
1447
- ui.Input,
1448
- {
1449
- type: "date",
1450
- placeholder: "From",
1451
- value: dateFrom,
1452
- onChange: (e) => setDateFrom(e.target.value),
1453
- className: "md:max-w-[140px]",
1454
- "aria-label": "Date from"
1455
- }
1456
- ),
1457
- /* @__PURE__ */ jsxRuntime.jsx(
1458
- ui.Input,
1459
- {
1460
- type: "date",
1461
- placeholder: "To",
1462
- value: dateTo,
1463
- onChange: (e) => setDateTo(e.target.value),
1464
- className: "md:max-w-[140px]",
1465
- "aria-label": "Date to"
1466
- }
1467
- ),
1459
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1468
1460
  /* @__PURE__ */ jsxRuntime.jsx(
1469
1461
  ui.Input,
1470
1462
  {
1471
- placeholder: "Amount min",
1472
- value: amountMin,
1473
- onChange: (e) => setAmountMin(e.target.value),
1474
- type: "number",
1475
- min: 0,
1476
- className: "md:max-w-[100px]",
1477
- "aria-label": "Refund amount minimum"
1463
+ placeholder: "Search by return ID, order ID, or customer email",
1464
+ value: searchQuery,
1465
+ onChange: (event) => setSearchQuery(event.target.value),
1466
+ className: "md:max-w-sm"
1478
1467
  }
1479
1468
  ),
1480
- /* @__PURE__ */ jsxRuntime.jsx(
1481
- ui.Input,
1482
- {
1483
- placeholder: "Amount max",
1484
- value: amountMax,
1485
- onChange: (e) => setAmountMax(e.target.value),
1486
- type: "number",
1487
- min: 0,
1488
- className: "md:max-w-[100px]",
1489
- "aria-label": "Refund amount maximum"
1490
- }
1491
- )
1492
- ] }) }),
1469
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
1470
+ /* @__PURE__ */ jsxRuntime.jsxs(
1471
+ "select",
1472
+ {
1473
+ value: createdByFilter,
1474
+ onChange: (event) => setCreatedByFilter(event.target.value),
1475
+ 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",
1476
+ children: [
1477
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All (Created by)" }),
1478
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "customer", children: "Customer" }),
1479
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "admin", children: "Admin" })
1480
+ ]
1481
+ }
1482
+ ),
1483
+ /* @__PURE__ */ jsxRuntime.jsxs(
1484
+ "select",
1485
+ {
1486
+ value: statusFilter,
1487
+ onChange: (event) => setStatusFilter(event.target.value),
1488
+ 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",
1489
+ children: [
1490
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All Statuses" }),
1491
+ availableStatuses.map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1492
+ ]
1493
+ }
1494
+ )
1495
+ ] })
1496
+ ] }),
1493
1497
  error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1494
1498
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1495
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => loadRefunds(0, true), children: "Try again" }) })
1499
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1500
+ ui.Button,
1501
+ {
1502
+ variant: "secondary",
1503
+ onClick: () => loadReturns(0, true),
1504
+ children: "Try again"
1505
+ }
1506
+ ) })
1496
1507
  ] }) : null,
1497
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading refunds…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1498
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No refunds yet" }),
1499
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Refund records will appear here." })
1500
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full overflow-x-auto rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full table-fixed divide-y divide-ui-border-base", style: { minWidth: 0 }, children: [
1508
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return orders..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1509
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1510
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1511
+ ] }) : /* @__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: [
1501
1512
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1502
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund ID" }),
1503
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1504
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Payment ID" }),
1505
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[8%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1506
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[6%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Currency" }),
1507
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[10%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1508
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[10%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Payment Status" }),
1509
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[14%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Note" }),
1510
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1511
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[8%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1513
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
1514
+ /* @__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" }),
1515
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1516
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1517
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
1518
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1519
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1512
1520
  ] }) }),
1513
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((r) => /* @__PURE__ */ jsxRuntime.jsxs(
1521
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxRuntime.jsxs(
1514
1522
  "tr",
1515
1523
  {
1516
- className: "cursor-pointer hover:bg-ui-bg-subtle/60",
1517
- onClick: () => navigate(`/refunds/${r.refund_id}`),
1524
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1525
+ onClick: () => navigate(`/returns/${returnOrder.id}`),
1518
1526
  children: [
1519
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-mono text-sm text-ui-fg-base", title: r.refund_id, children: r.refund_id }),
1520
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-medium text-ui-fg-base", title: r.order_id ?? void 0, children: r.order_id ?? "—" }),
1521
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-mono text-sm text-ui-fg-subtle", title: r.payment_id, children: r.payment_id }),
1522
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", children: displayAmount(r) }),
1523
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle uppercase", children: r.currency_code || "—" }),
1524
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", title: r.provider_id || void 0, children: r.provider_id || "—" }),
1525
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsx(
1527
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: returnOrder.id }) }) }),
1528
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1529
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1530
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1526
1531
  ui.Badge,
1527
1532
  {
1528
1533
  size: "2xsmall",
1529
- className: `uppercase ${getStatusBadgeClass$5(displayStatus(r))}`,
1530
- children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1534
+ className: `uppercase ${getStatusBadgeClass$5(returnOrder.status)}`,
1535
+ children: returnOrder.status.replace(/_/g, " ")
1531
1536
  }
1532
1537
  ) }),
1533
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", title: r.note ?? void 0, children: r.note ?? "—" }),
1534
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle text-xs", children: new Date(r.created_at).toLocaleDateString("en-US", {
1538
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1539
+ const amount = returnOrder.refund_amount;
1540
+ if (amount == null || amount === void 0) {
1541
+ return "—";
1542
+ }
1543
+ const displayAmount = Number(amount) / 100;
1544
+ const currency = returnOrder.currency_code || "$";
1545
+ return `${currency}${displayAmount.toFixed(2)}`;
1546
+ })() }),
1547
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1548
+ year: "numeric",
1535
1549
  month: "short",
1536
1550
  day: "numeric",
1537
1551
  hour: "numeric",
1538
1552
  minute: "2-digit",
1539
1553
  hour12: true
1540
1554
  }) }),
1541
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-1", children: [
1542
- /* @__PURE__ */ jsxRuntime.jsx(
1543
- ui.Button,
1544
- {
1545
- variant: "transparent",
1546
- size: "small",
1547
- onClick: (e) => {
1548
- e.stopPropagation();
1549
- navigate(`/refunds/${r.refund_id}`);
1550
- },
1551
- children: "Details"
1552
- }
1553
- ),
1554
- r.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1555
- ui.Button,
1556
- {
1557
- variant: "transparent",
1558
- size: "small",
1559
- onClick: (e) => {
1560
- e.stopPropagation();
1561
- navigate(`/orders/${r.order_id}`);
1562
- },
1563
- children: "Order"
1564
- }
1565
- ) : null
1566
- ] }) })
1555
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1556
+ ui.Button,
1557
+ {
1558
+ variant: "transparent",
1559
+ size: "small",
1560
+ onClick: (e) => {
1561
+ e.stopPropagation();
1562
+ navigate(`/app/orders/${returnOrder.order_id}`);
1563
+ },
1564
+ children: "Go to order"
1565
+ }
1566
+ ) })
1567
1567
  ]
1568
1568
  },
1569
- r.refund_id
1569
+ returnOrder.id
1570
1570
  )) })
1571
1571
  ] }) }),
1572
1572
  hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1574,15 +1574,15 @@ const RefundsPage = () => {
1574
1574
  {
1575
1575
  variant: "secondary",
1576
1576
  isLoading: isFetchingMore,
1577
- onClick: () => loadRefunds(offset, false),
1577
+ onClick: () => loadReturns(offset, false),
1578
1578
  children: "Load more"
1579
1579
  }
1580
1580
  ) }) : null
1581
1581
  ] }) });
1582
1582
  };
1583
1583
  const config$5 = adminSdk.defineRouteConfig({
1584
- label: "Refunds",
1585
- icon: icons.Receipt
1584
+ label: "Return Orders",
1585
+ icon: icons.ArrowPath
1586
1586
  });
1587
1587
  const useDebounce = (value, delay) => {
1588
1588
  const [debouncedValue, setDebouncedValue] = react.useState(value);
@@ -1810,11 +1810,203 @@ const SwapsPage = () => {
1810
1810
  ) }) : null
1811
1811
  ] }) });
1812
1812
  };
1813
- const config$4 = adminSdk.defineRouteConfig({
1814
- label: "Exchanges",
1815
- icon: icons.ArrowPath
1813
+ const config$4 = adminSdk.defineRouteConfig({
1814
+ label: "Exchanges",
1815
+ icon: icons.ArrowPath
1816
+ });
1817
+ const getStatusBadgeClass$3 = (status) => {
1818
+ const s2 = status.toLowerCase();
1819
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1820
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1821
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1822
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1823
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1824
+ };
1825
+ const formatAmount = (value) => {
1826
+ return String(value);
1827
+ };
1828
+ const RefundDetailPage = () => {
1829
+ var _a, _b, _c;
1830
+ const navigate = reactRouterDom.useNavigate();
1831
+ const params = reactRouterDom.useParams();
1832
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
1833
+ const [detail, setDetail] = react.useState(null);
1834
+ const [loading, setLoading] = react.useState(!!id);
1835
+ const [error, setError] = react.useState(null);
1836
+ const [gatewayExpanded, setGatewayExpanded] = react.useState(false);
1837
+ react.useEffect(() => {
1838
+ if (!id) {
1839
+ setLoading(false);
1840
+ return;
1841
+ }
1842
+ let cancelled = false;
1843
+ setLoading(true);
1844
+ setError(null);
1845
+ fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
1846
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
1847
+ return res.json();
1848
+ }).then((data) => {
1849
+ if (!cancelled) setDetail(data);
1850
+ }).catch((e) => {
1851
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
1852
+ }).finally(() => {
1853
+ if (!cancelled) setLoading(false);
1854
+ });
1855
+ return () => {
1856
+ cancelled = true;
1857
+ };
1858
+ }, [id]);
1859
+ const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
1860
+ const hasGatewayData = ((_c = detail == null ? void 0 : detail.payment) == null ? void 0 : _c.payment_data) && typeof detail.payment.payment_data === "object" && Object.keys(detail.payment.payment_data).length > 0;
1861
+ 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: [
1862
+ /* @__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: [
1863
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
1864
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refund details" }),
1865
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
1866
+ ] }) }),
1867
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1868
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1869
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
1870
+ ] }) : 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: [
1871
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1872
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
1873
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1874
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1875
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
1876
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
1877
+ ] }),
1878
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1879
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
1880
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
1881
+ ] }),
1882
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1883
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
1884
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
1885
+ ] }),
1886
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1887
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
1888
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
1889
+ year: "numeric",
1890
+ month: "short",
1891
+ day: "numeric",
1892
+ hour: "numeric",
1893
+ minute: "2-digit",
1894
+ hour12: true
1895
+ }) })
1896
+ ] }),
1897
+ detail.refund.created_by ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1898
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
1899
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
1900
+ ] }) : null
1901
+ ] })
1902
+ ] }),
1903
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1904
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
1905
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1906
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1907
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
1908
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
1909
+ ] }),
1910
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1911
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
1912
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
1913
+ ] }),
1914
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1915
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
1916
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
1917
+ ] }),
1918
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1919
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
1920
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
1921
+ ] }),
1922
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1923
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
1924
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
1925
+ ui.Badge,
1926
+ {
1927
+ size: "2xsmall",
1928
+ className: `uppercase ${getStatusBadgeClass$3(paymentStatus)}`,
1929
+ children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
1930
+ }
1931
+ ) })
1932
+ ] }),
1933
+ detail.computed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1934
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1935
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
1936
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
1937
+ ] }),
1938
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1939
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
1940
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
1941
+ ] }),
1942
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1943
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
1944
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "mt-1 block", children: [
1945
+ detail.computed.refund_percentage.toFixed(1),
1946
+ "%"
1947
+ ] })
1948
+ ] })
1949
+ ] }) : null
1950
+ ] })
1951
+ ] }),
1952
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1953
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
1954
+ detail.order ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1955
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1956
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
1957
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
1958
+ ui.Button,
1959
+ {
1960
+ variant: "transparent",
1961
+ size: "small",
1962
+ onClick: () => navigate(`/orders/${detail.order.order_id}`),
1963
+ children: detail.order.order_number ?? detail.order.order_id
1964
+ }
1965
+ ) })
1966
+ ] }),
1967
+ detail.order.total != null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1968
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
1969
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
1970
+ ] }) : null,
1971
+ detail.order.customer_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1972
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
1973
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
1974
+ ] }) : null,
1975
+ detail.order.region ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1976
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
1977
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.region })
1978
+ ] }) : null,
1979
+ detail.order.fulfillment_status ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1980
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
1981
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
1982
+ ] }) : null
1983
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
1984
+ ] }),
1985
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1986
+ /* @__PURE__ */ jsxRuntime.jsxs(
1987
+ "button",
1988
+ {
1989
+ type: "button",
1990
+ className: "flex w-full items-center justify-between text-left",
1991
+ onClick: () => setGatewayExpanded((prev) => !prev),
1992
+ "aria-expanded": gatewayExpanded,
1993
+ "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
1994
+ children: [
1995
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
1996
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
1997
+ ]
1998
+ }
1999
+ ),
2000
+ gatewayExpanded && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4", children: hasGatewayData ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.payment.payment_data, null, 2) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No gateway payload for this payment." }) })
2001
+ ] })
2002
+ ] }) : null
2003
+ ] }) });
2004
+ };
2005
+ const config$3 = adminSdk.defineRouteConfig({
2006
+ label: "Refund details",
2007
+ icon: icons.Receipt
1816
2008
  });
1817
- const getStatusBadgeClass$3 = (status) => {
2009
+ const getStatusBadgeClass$2 = (status) => {
1818
2010
  const s2 = status.toLowerCase();
1819
2011
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1820
2012
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1893,7 +2085,7 @@ const PaymentDetailPage = () => {
1893
2085
  ui.Badge,
1894
2086
  {
1895
2087
  size: "2xsmall",
1896
- className: `uppercase ${getStatusBadgeClass$3(displayStatus)}`,
2088
+ className: `uppercase ${getStatusBadgeClass$2(displayStatus)}`,
1897
2089
  children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
1898
2090
  }
1899
2091
  ) })
@@ -1929,11 +2121,11 @@ const PaymentDetailPage = () => {
1929
2121
  ] }) : null
1930
2122
  ] }) });
1931
2123
  };
1932
- const config$3 = adminSdk.defineRouteConfig({
2124
+ const config$2 = adminSdk.defineRouteConfig({
1933
2125
  label: "Payment details",
1934
2126
  icon: icons.CreditCard
1935
2127
  });
1936
- const getStatusBadgeClass$2 = (status) => {
2128
+ const getStatusBadgeClass$1 = (status) => {
1937
2129
  const statusLower = status.toLowerCase();
1938
2130
  if (statusLower === "requested") {
1939
2131
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2067,7 +2259,7 @@ const ReturnDetailPage = () => {
2067
2259
  ui.Badge,
2068
2260
  {
2069
2261
  size: "small",
2070
- className: `uppercase ${getStatusBadgeClass$2(returnOrder.status)}`,
2262
+ className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
2071
2263
  children: returnOrder.status.replace(/_/g, " ")
2072
2264
  }
2073
2265
  )
@@ -2149,7 +2341,7 @@ const ReturnDetailPage = () => {
2149
2341
  ui.Badge,
2150
2342
  {
2151
2343
  size: "2xsmall",
2152
- className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2344
+ className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
2153
2345
  children: entry.status.replace(/_/g, " ")
2154
2346
  }
2155
2347
  ) }),
@@ -2207,202 +2399,10 @@ const ReturnDetailPage = () => {
2207
2399
  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" }) })
2208
2400
  ] }) });
2209
2401
  };
2210
- const config$2 = adminSdk.defineRouteConfig({
2402
+ const config$1 = adminSdk.defineRouteConfig({
2211
2403
  label: "Return Order Details",
2212
2404
  icon: icons.CheckCircle
2213
2405
  });
2214
- const getStatusBadgeClass$1 = (status) => {
2215
- const s2 = status.toLowerCase();
2216
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2217
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2218
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2219
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2220
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2221
- };
2222
- const formatAmount = (value) => {
2223
- return String(value);
2224
- };
2225
- const RefundDetailPage = () => {
2226
- var _a, _b, _c;
2227
- const navigate = reactRouterDom.useNavigate();
2228
- const params = reactRouterDom.useParams();
2229
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2230
- const [detail, setDetail] = react.useState(null);
2231
- const [loading, setLoading] = react.useState(!!id);
2232
- const [error, setError] = react.useState(null);
2233
- const [gatewayExpanded, setGatewayExpanded] = react.useState(false);
2234
- react.useEffect(() => {
2235
- if (!id) {
2236
- setLoading(false);
2237
- return;
2238
- }
2239
- let cancelled = false;
2240
- setLoading(true);
2241
- setError(null);
2242
- fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
2243
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2244
- return res.json();
2245
- }).then((data) => {
2246
- if (!cancelled) setDetail(data);
2247
- }).catch((e) => {
2248
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2249
- }).finally(() => {
2250
- if (!cancelled) setLoading(false);
2251
- });
2252
- return () => {
2253
- cancelled = true;
2254
- };
2255
- }, [id]);
2256
- const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
2257
- const hasGatewayData = ((_c = detail == null ? void 0 : detail.payment) == null ? void 0 : _c.payment_data) && typeof detail.payment.payment_data === "object" && Object.keys(detail.payment.payment_data).length > 0;
2258
- 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: [
2259
- /* @__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: [
2260
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
2261
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refund details" }),
2262
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
2263
- ] }) }),
2264
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2265
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2266
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
2267
- ] }) : 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: [
2268
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2269
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
2270
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2271
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2272
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
2273
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
2274
- ] }),
2275
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2276
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2277
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
2278
- ] }),
2279
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2280
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2281
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2282
- ] }),
2283
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2284
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2285
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2286
- year: "numeric",
2287
- month: "short",
2288
- day: "numeric",
2289
- hour: "numeric",
2290
- minute: "2-digit",
2291
- hour12: true
2292
- }) })
2293
- ] }),
2294
- detail.refund.created_by ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2295
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
2296
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
2297
- ] }) : null
2298
- ] })
2299
- ] }),
2300
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2301
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
2302
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2303
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2304
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
2305
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
2306
- ] }),
2307
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2308
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
2309
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2310
- ] }),
2311
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2312
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
2313
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2314
- ] }),
2315
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2316
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2317
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
2318
- ] }),
2319
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2320
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2321
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2322
- ui.Badge,
2323
- {
2324
- size: "2xsmall",
2325
- className: `uppercase ${getStatusBadgeClass$1(paymentStatus)}`,
2326
- children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2327
- }
2328
- ) })
2329
- ] }),
2330
- detail.computed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2331
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2332
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
2333
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
2334
- ] }),
2335
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2336
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
2337
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
2338
- ] }),
2339
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2340
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
2341
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "mt-1 block", children: [
2342
- detail.computed.refund_percentage.toFixed(1),
2343
- "%"
2344
- ] })
2345
- ] })
2346
- ] }) : null
2347
- ] })
2348
- ] }),
2349
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2350
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
2351
- detail.order ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2352
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2353
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
2354
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2355
- ui.Button,
2356
- {
2357
- variant: "transparent",
2358
- size: "small",
2359
- onClick: () => navigate(`/orders/${detail.order.order_id}`),
2360
- children: detail.order.order_number ?? detail.order.order_id
2361
- }
2362
- ) })
2363
- ] }),
2364
- detail.order.total != null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2365
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
2366
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
2367
- ] }) : null,
2368
- detail.order.customer_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2369
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
2370
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
2371
- ] }) : null,
2372
- detail.order.region ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2373
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
2374
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.region })
2375
- ] }) : null,
2376
- detail.order.fulfillment_status ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2377
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
2378
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
2379
- ] }) : null
2380
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
2381
- ] }),
2382
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2383
- /* @__PURE__ */ jsxRuntime.jsxs(
2384
- "button",
2385
- {
2386
- type: "button",
2387
- className: "flex w-full items-center justify-between text-left",
2388
- onClick: () => setGatewayExpanded((prev) => !prev),
2389
- "aria-expanded": gatewayExpanded,
2390
- "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
2391
- children: [
2392
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
2393
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
2394
- ]
2395
- }
2396
- ),
2397
- gatewayExpanded && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4", children: hasGatewayData ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.payment.payment_data, null, 2) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No gateway payload for this payment." }) })
2398
- ] })
2399
- ] }) : null
2400
- ] }) });
2401
- };
2402
- const config$1 = adminSdk.defineRouteConfig({
2403
- label: "Refund details",
2404
- icon: icons.Receipt
2405
- });
2406
2406
  const getStatusBadgeClass = (status) => {
2407
2407
  const statusLower = status.toLowerCase();
2408
2408
  if (statusLower === "requested") {
@@ -2695,6 +2695,10 @@ const widgetModule = { widgets: [
2695
2695
  ] };
2696
2696
  const routeModule = {
2697
2697
  routes: [
2698
+ {
2699
+ Component: RefundsPage,
2700
+ path: "/refunds"
2701
+ },
2698
2702
  {
2699
2703
  Component: PaymentsPage,
2700
2704
  path: "/payments"
@@ -2703,14 +2707,14 @@ const routeModule = {
2703
2707
  Component: ReturnsPage,
2704
2708
  path: "/returns"
2705
2709
  },
2706
- {
2707
- Component: RefundsPage,
2708
- path: "/refunds"
2709
- },
2710
2710
  {
2711
2711
  Component: SwapsPage,
2712
2712
  path: "/swaps"
2713
2713
  },
2714
+ {
2715
+ Component: RefundDetailPage,
2716
+ path: "/refunds/:id"
2717
+ },
2714
2718
  {
2715
2719
  Component: PaymentDetailPage,
2716
2720
  path: "/payments/:id"
@@ -2719,10 +2723,6 @@ const routeModule = {
2719
2723
  Component: ReturnDetailPage,
2720
2724
  path: "/returns/:id"
2721
2725
  },
2722
- {
2723
- Component: RefundDetailPage,
2724
- path: "/refunds/:id"
2725
- },
2726
2726
  {
2727
2727
  Component: SwapDetailPage,
2728
2728
  path: "/swaps/:id"
@@ -2732,20 +2732,20 @@ const routeModule = {
2732
2732
  const menuItemModule = {
2733
2733
  menuItems: [
2734
2734
  {
2735
- label: config$7.label,
2736
- icon: config$7.icon,
2735
+ label: config$6.label,
2736
+ icon: config$6.icon,
2737
2737
  path: "/payments",
2738
2738
  nested: void 0
2739
2739
  },
2740
2740
  {
2741
- label: config$5.label,
2742
- icon: config$5.icon,
2741
+ label: config$7.label,
2742
+ icon: config$7.icon,
2743
2743
  path: "/refunds",
2744
2744
  nested: void 0
2745
2745
  },
2746
2746
  {
2747
- label: config$6.label,
2748
- icon: config$6.icon,
2747
+ label: config$5.label,
2748
+ icon: config$5.icon,
2749
2749
  path: "/returns",
2750
2750
  nested: void 0
2751
2751
  },
@@ -2758,19 +2758,13 @@ const menuItemModule = {
2758
2758
  {
2759
2759
  label: config$3.label,
2760
2760
  icon: config$3.icon,
2761
- path: "/payments/:id",
2762
- nested: void 0
2763
- },
2764
- {
2765
- label: config$1.label,
2766
- icon: config$1.icon,
2767
2761
  path: "/refunds/:id",
2768
2762
  nested: void 0
2769
2763
  },
2770
2764
  {
2771
2765
  label: config$2.label,
2772
2766
  icon: config$2.icon,
2773
- path: "/returns/:id",
2767
+ path: "/payments/:id",
2774
2768
  nested: void 0
2775
2769
  },
2776
2770
  {
@@ -2778,6 +2772,12 @@ const menuItemModule = {
2778
2772
  icon: config.icon,
2779
2773
  path: "/swaps/:id",
2780
2774
  nested: void 0
2775
+ },
2776
+ {
2777
+ label: config$1.label,
2778
+ icon: config$1.icon,
2779
+ path: "/returns/:id",
2780
+ nested: void 0
2781
2781
  }
2782
2782
  ]
2783
2783
  };