order-management 0.0.86 → 0.0.87

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.
@@ -1096,212 +1096,275 @@ const useDebounce$2 = (value, delay) => {
1096
1096
  return debouncedValue;
1097
1097
  };
1098
1098
  const getStatusBadgeClass$6 = (status) => {
1099
- const statusLower = status.toLowerCase();
1100
- if (statusLower === "requested") {
1101
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1102
- }
1103
- if (statusLower === "received") {
1104
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1105
- }
1106
- if (statusLower === "requires_action") {
1107
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
1108
- }
1109
- if (statusLower === "completed") {
1110
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
1111
- }
1112
- if (statusLower === "canceled") {
1113
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1114
- }
1099
+ const s2 = status.toLowerCase();
1100
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1101
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1102
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1103
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1115
1104
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1116
1105
  };
1117
- const ReturnsPage = () => {
1106
+ const RefundsPage = () => {
1118
1107
  const navigate = reactRouterDom.useNavigate();
1119
1108
  const [items, setItems] = react.useState([]);
1120
- const [statusFilter, setStatusFilter] = react.useState("all");
1121
- const [createdByFilter, setCreatedByFilter] = react.useState("all");
1122
- const [searchQuery, setSearchQuery] = react.useState("");
1123
- const debouncedSearchQuery = useDebounce$2(searchQuery, 300);
1109
+ const [orderIdSearch, setOrderIdSearch] = react.useState("");
1110
+ const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
1111
+ const [paymentStatusFilter, setPaymentStatusFilter] = react.useState("all");
1112
+ const [providerSearch, setProviderSearch] = react.useState("");
1113
+ const debouncedProvider = useDebounce$2(providerSearch, 300);
1114
+ const [currencySearch, setCurrencySearch] = react.useState("");
1115
+ const debouncedCurrency = useDebounce$2(currencySearch, 300);
1116
+ const [dateFrom, setDateFrom] = react.useState("");
1117
+ const [dateTo, setDateTo] = react.useState("");
1118
+ const [amountMin, setAmountMin] = react.useState("");
1119
+ const [amountMax, setAmountMax] = react.useState("");
1124
1120
  const [isLoading, setIsLoading] = react.useState(true);
1125
1121
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1126
1122
  const [error, setError] = react.useState(null);
1127
1123
  const [offset, setOffset] = react.useState(0);
1128
1124
  const [count, setCount] = react.useState(0);
1129
1125
  const limit = 50;
1130
- const loadReturns = react.useCallback(
1131
- async (nextOffset, replace = false) => {
1132
- var _a;
1126
+ const loadRefunds = react.useCallback(
1127
+ async (nextOffset, replace) => {
1133
1128
  try {
1134
- if (replace) {
1135
- setIsLoading(true);
1136
- } else {
1137
- setIsFetchingMore(true);
1138
- }
1129
+ if (replace) setIsLoading(true);
1130
+ else setIsFetchingMore(true);
1139
1131
  setError(null);
1140
1132
  const params = new URLSearchParams();
1141
1133
  params.set("limit", String(limit));
1142
1134
  params.set("offset", String(nextOffset));
1143
- if (statusFilter !== "all") {
1144
- params.set("status", statusFilter);
1145
- }
1146
- if (debouncedSearchQuery.trim()) {
1147
- params.set("q", debouncedSearchQuery.trim());
1148
- }
1149
- if (createdByFilter !== "all") {
1150
- params.set("created_by", createdByFilter);
1151
- }
1152
- params.set("order", "created_at");
1153
- const response = await fetch(
1154
- `/admin/return?${params.toString()}`,
1155
- { credentials: "include" }
1156
- );
1135
+ if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
1136
+ if (paymentStatusFilter !== "all") params.set("payment_status", paymentStatusFilter);
1137
+ if (debouncedProvider.trim()) params.set("provider_id", debouncedProvider.trim());
1138
+ if (debouncedCurrency.trim()) params.set("currency_code", debouncedCurrency.trim());
1139
+ if (dateFrom.trim()) params.set("date_from", dateFrom.trim());
1140
+ if (dateTo.trim()) params.set("date_to", dateTo.trim());
1141
+ const min = amountMin.trim() ? Number(amountMin) : void 0;
1142
+ const max = amountMax.trim() ? Number(amountMax) : void 0;
1143
+ if (min != null && !Number.isNaN(min)) params.set("amount_min", String(min));
1144
+ if (max != null && !Number.isNaN(max)) params.set("amount_max", String(max));
1145
+ const response = await fetch(`/admin/refunds?${params.toString()}`, {
1146
+ credentials: "include"
1147
+ });
1157
1148
  if (!response.ok) {
1158
- const message = await response.text();
1159
- throw new Error(message || "Unable to load return orders");
1149
+ const text = await response.text();
1150
+ throw new Error(text || "Failed to load refunds");
1160
1151
  }
1161
1152
  const payload = await response.json();
1153
+ const list = payload.refunds ?? [];
1162
1154
  setCount(payload.count ?? 0);
1163
- setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
1164
- setItems(
1165
- (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
1166
- );
1167
- } catch (loadError) {
1168
- const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
1169
- setError(message);
1155
+ setOffset(nextOffset + list.length);
1156
+ setItems((prev) => replace ? list : [...prev, ...list]);
1157
+ } catch (e) {
1158
+ setError(e instanceof Error ? e.message : "Failed to load");
1170
1159
  } finally {
1171
1160
  setIsLoading(false);
1172
1161
  setIsFetchingMore(false);
1173
1162
  }
1174
1163
  },
1175
- [statusFilter, createdByFilter, debouncedSearchQuery]
1164
+ [
1165
+ debouncedOrderId,
1166
+ paymentStatusFilter,
1167
+ debouncedProvider,
1168
+ debouncedCurrency,
1169
+ dateFrom,
1170
+ dateTo,
1171
+ amountMin,
1172
+ amountMax
1173
+ ]
1176
1174
  );
1177
1175
  react.useEffect(() => {
1178
- void loadReturns(0, true);
1179
- }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
1176
+ void loadRefunds(0, true);
1177
+ }, [loadRefunds]);
1180
1178
  const hasMore = react.useMemo(() => offset < count, [offset, count]);
1181
- const availableStatuses = react.useMemo(() => {
1182
- const statuses = /* @__PURE__ */ new Set();
1183
- items.forEach((item) => statuses.add(item.status));
1184
- return Array.from(statuses).sort();
1185
- }, [items]);
1179
+ const displayAmount = (r) => {
1180
+ const code = (r.currency_code ?? "USD").toUpperCase();
1181
+ return `${code} ${Number(r.amount)}`;
1182
+ };
1183
+ const displayStatus = (r) => {
1184
+ const s2 = r.payment_status ?? "";
1185
+ return s2 !== "" ? s2 : "—";
1186
+ };
1186
1187
  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: [
1187
1188
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1188
1189
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1189
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Orders" }),
1190
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
1190
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refunds" }),
1191
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Refund records — amount, order, payment status" })
1191
1192
  ] }),
1192
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
1193
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadRefunds(0, true), children: "Refresh" })
1193
1194
  ] }),
1194
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1195
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
1195
1196
  /* @__PURE__ */ jsxRuntime.jsx(
1196
1197
  ui.Input,
1197
1198
  {
1198
- placeholder: "Search by return ID, order ID, or customer email",
1199
- value: searchQuery,
1200
- onChange: (event) => setSearchQuery(event.target.value),
1201
- className: "md:max-w-sm"
1199
+ placeholder: "Order ID",
1200
+ value: orderIdSearch,
1201
+ onChange: (e) => setOrderIdSearch(e.target.value),
1202
+ className: "md:max-w-[180px]",
1203
+ "aria-label": "Filter by order ID"
1202
1204
  }
1203
1205
  ),
1204
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
1205
- /* @__PURE__ */ jsxRuntime.jsxs(
1206
- "select",
1207
- {
1208
- value: createdByFilter,
1209
- onChange: (event) => setCreatedByFilter(event.target.value),
1210
- 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",
1211
- children: [
1212
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All (Created by)" }),
1213
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "customer", children: "Customer" }),
1214
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "admin", children: "Admin" })
1215
- ]
1216
- }
1217
- ),
1218
- /* @__PURE__ */ jsxRuntime.jsxs(
1219
- "select",
1220
- {
1221
- value: statusFilter,
1222
- onChange: (event) => setStatusFilter(event.target.value),
1223
- 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",
1224
- children: [
1225
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All Statuses" }),
1226
- availableStatuses.map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1227
- ]
1228
- }
1229
- )
1230
- ] })
1231
- ] }),
1232
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1233
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1234
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1235
- ui.Button,
1206
+ /* @__PURE__ */ jsxRuntime.jsx(
1207
+ ui.Input,
1236
1208
  {
1237
- variant: "secondary",
1238
- onClick: () => loadReturns(0, true),
1239
- children: "Try again"
1209
+ placeholder: "Provider",
1210
+ value: providerSearch,
1211
+ onChange: (e) => setProviderSearch(e.target.value),
1212
+ className: "md:max-w-[140px]",
1213
+ "aria-label": "Filter by provider"
1240
1214
  }
1241
- ) })
1215
+ ),
1216
+ /* @__PURE__ */ jsxRuntime.jsx(
1217
+ ui.Input,
1218
+ {
1219
+ placeholder: "Currency",
1220
+ value: currencySearch,
1221
+ onChange: (e) => setCurrencySearch(e.target.value),
1222
+ className: "md:max-w-[100px]",
1223
+ "aria-label": "Filter by currency"
1224
+ }
1225
+ ),
1226
+ /* @__PURE__ */ jsxRuntime.jsxs(
1227
+ "select",
1228
+ {
1229
+ value: paymentStatusFilter,
1230
+ onChange: (e) => setPaymentStatusFilter(e.target.value),
1231
+ 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]",
1232
+ "aria-label": "Filter by payment status",
1233
+ children: [
1234
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
1235
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
1236
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
1237
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
1238
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
1239
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
1240
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
1241
+ ]
1242
+ }
1243
+ ),
1244
+ /* @__PURE__ */ jsxRuntime.jsx(
1245
+ ui.Input,
1246
+ {
1247
+ type: "date",
1248
+ placeholder: "From",
1249
+ value: dateFrom,
1250
+ onChange: (e) => setDateFrom(e.target.value),
1251
+ className: "md:max-w-[140px]",
1252
+ "aria-label": "Date from"
1253
+ }
1254
+ ),
1255
+ /* @__PURE__ */ jsxRuntime.jsx(
1256
+ ui.Input,
1257
+ {
1258
+ type: "date",
1259
+ placeholder: "To",
1260
+ value: dateTo,
1261
+ onChange: (e) => setDateTo(e.target.value),
1262
+ className: "md:max-w-[140px]",
1263
+ "aria-label": "Date to"
1264
+ }
1265
+ ),
1266
+ /* @__PURE__ */ jsxRuntime.jsx(
1267
+ ui.Input,
1268
+ {
1269
+ placeholder: "Amount min",
1270
+ value: amountMin,
1271
+ onChange: (e) => setAmountMin(e.target.value),
1272
+ type: "number",
1273
+ min: 0,
1274
+ className: "md:max-w-[100px]",
1275
+ "aria-label": "Refund amount minimum"
1276
+ }
1277
+ ),
1278
+ /* @__PURE__ */ jsxRuntime.jsx(
1279
+ ui.Input,
1280
+ {
1281
+ placeholder: "Amount max",
1282
+ value: amountMax,
1283
+ onChange: (e) => setAmountMax(e.target.value),
1284
+ type: "number",
1285
+ min: 0,
1286
+ className: "md:max-w-[100px]",
1287
+ "aria-label": "Refund amount maximum"
1288
+ }
1289
+ )
1290
+ ] }) }),
1291
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1292
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1293
+ /* @__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" }) })
1242
1294
  ] }) : null,
1243
- 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: [
1244
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1245
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1246
- ] }) : /* @__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: [
1295
+ 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: [
1296
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No refunds yet" }),
1297
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Refund records will appear here." })
1298
+ ] }) : /* @__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: [
1247
1299
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1248
- /* @__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" }),
1249
- /* @__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" }),
1250
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1251
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1252
- /* @__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" }),
1253
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1254
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1300
+ /* @__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" }),
1301
+ /* @__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" }),
1302
+ /* @__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" }),
1303
+ /* @__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" }),
1304
+ /* @__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" }),
1305
+ /* @__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" }),
1306
+ /* @__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" }),
1307
+ /* @__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" }),
1308
+ /* @__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" }),
1309
+ /* @__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" })
1255
1310
  ] }) }),
1256
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxRuntime.jsxs(
1311
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((r) => /* @__PURE__ */ jsxRuntime.jsxs(
1257
1312
  "tr",
1258
1313
  {
1259
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1260
- onClick: () => navigate(`/returns/${returnOrder.id}`),
1314
+ className: "cursor-pointer hover:bg-ui-bg-subtle/60",
1315
+ onClick: () => navigate(`/refunds/${r.refund_id}`),
1261
1316
  children: [
1262
- /* @__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 }) }) }),
1263
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1264
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1265
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1317
+ /* @__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 }),
1318
+ /* @__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 ?? "—" }),
1319
+ /* @__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 }),
1320
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", children: displayAmount(r) }),
1321
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle uppercase", children: r.currency_code || "—" }),
1322
+ /* @__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 || "—" }),
1323
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsx(
1266
1324
  ui.Badge,
1267
1325
  {
1268
1326
  size: "2xsmall",
1269
- className: `uppercase ${getStatusBadgeClass$6(returnOrder.status)}`,
1270
- children: returnOrder.status.replace(/_/g, " ")
1327
+ className: `uppercase ${getStatusBadgeClass$6(displayStatus(r))}`,
1328
+ children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1271
1329
  }
1272
1330
  ) }),
1273
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1274
- const amount = returnOrder.refund_amount;
1275
- if (amount == null || amount === void 0) {
1276
- return "—";
1277
- }
1278
- const displayAmount = Number(amount) / 100;
1279
- const currency = returnOrder.currency_code || "$";
1280
- return `${currency}${displayAmount.toFixed(2)}`;
1281
- })() }),
1282
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1283
- year: "numeric",
1331
+ /* @__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 ?? "—" }),
1332
+ /* @__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", {
1284
1333
  month: "short",
1285
1334
  day: "numeric",
1286
1335
  hour: "numeric",
1287
1336
  minute: "2-digit",
1288
1337
  hour12: true
1289
1338
  }) }),
1290
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1291
- ui.Button,
1292
- {
1293
- variant: "transparent",
1294
- size: "small",
1295
- onClick: (e) => {
1296
- e.stopPropagation();
1297
- navigate(`/app/orders/${returnOrder.order_id}`);
1298
- },
1299
- children: "Go to order"
1300
- }
1301
- ) })
1339
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-1", children: [
1340
+ /* @__PURE__ */ jsxRuntime.jsx(
1341
+ ui.Button,
1342
+ {
1343
+ variant: "transparent",
1344
+ size: "small",
1345
+ onClick: (e) => {
1346
+ e.stopPropagation();
1347
+ navigate(`/refunds/${r.refund_id}`);
1348
+ },
1349
+ children: "Details"
1350
+ }
1351
+ ),
1352
+ r.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1353
+ ui.Button,
1354
+ {
1355
+ variant: "transparent",
1356
+ size: "small",
1357
+ onClick: (e) => {
1358
+ e.stopPropagation();
1359
+ navigate(`/orders/${r.order_id}`);
1360
+ },
1361
+ children: "Order"
1362
+ }
1363
+ ) : null
1364
+ ] }) })
1302
1365
  ]
1303
1366
  },
1304
- returnOrder.id
1367
+ r.refund_id
1305
1368
  )) })
1306
1369
  ] }) }),
1307
1370
  hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1309,15 +1372,15 @@ const ReturnsPage = () => {
1309
1372
  {
1310
1373
  variant: "secondary",
1311
1374
  isLoading: isFetchingMore,
1312
- onClick: () => loadReturns(offset, false),
1375
+ onClick: () => loadRefunds(offset, false),
1313
1376
  children: "Load more"
1314
1377
  }
1315
1378
  ) }) : null
1316
1379
  ] }) });
1317
1380
  };
1318
1381
  const config$6 = adminSdk.defineRouteConfig({
1319
- label: "Return Orders",
1320
- icon: icons.ArrowPath
1382
+ label: "Refunds",
1383
+ icon: icons.Receipt
1321
1384
  });
1322
1385
  const useDebounce$1 = (value, delay) => {
1323
1386
  const [debouncedValue, setDebouncedValue] = react.useState(value);
@@ -1328,144 +1391,190 @@ const useDebounce$1 = (value, delay) => {
1328
1391
  return debouncedValue;
1329
1392
  };
1330
1393
  const getStatusBadgeClass$5 = (status) => {
1331
- const s2 = status.toLowerCase();
1332
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1333
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1334
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1335
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1394
+ const statusLower = status.toLowerCase();
1395
+ if (statusLower === "requested") {
1396
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1397
+ }
1398
+ if (statusLower === "received") {
1399
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1400
+ }
1401
+ if (statusLower === "requires_action") {
1402
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
1403
+ }
1404
+ if (statusLower === "completed") {
1405
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
1406
+ }
1407
+ if (statusLower === "canceled") {
1408
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1409
+ }
1336
1410
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1337
1411
  };
1338
- const PaymentsPage = () => {
1412
+ const ReturnsPage = () => {
1339
1413
  const navigate = reactRouterDom.useNavigate();
1340
1414
  const [items, setItems] = react.useState([]);
1341
1415
  const [statusFilter, setStatusFilter] = react.useState("all");
1342
- const [orderIdSearch, setOrderIdSearch] = react.useState("");
1343
- const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1416
+ const [createdByFilter, setCreatedByFilter] = react.useState("all");
1417
+ const [searchQuery, setSearchQuery] = react.useState("");
1418
+ const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1344
1419
  const [isLoading, setIsLoading] = react.useState(true);
1345
1420
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1346
1421
  const [error, setError] = react.useState(null);
1347
1422
  const [offset, setOffset] = react.useState(0);
1348
1423
  const [count, setCount] = react.useState(0);
1349
1424
  const limit = 50;
1350
- const loadTransactions = react.useCallback(
1351
- async (nextOffset, replace) => {
1425
+ const loadReturns = react.useCallback(
1426
+ async (nextOffset, replace = false) => {
1427
+ var _a;
1352
1428
  try {
1353
- if (replace) setIsLoading(true);
1354
- else setIsFetchingMore(true);
1429
+ if (replace) {
1430
+ setIsLoading(true);
1431
+ } else {
1432
+ setIsFetchingMore(true);
1433
+ }
1355
1434
  setError(null);
1356
1435
  const params = new URLSearchParams();
1357
1436
  params.set("limit", String(limit));
1358
1437
  params.set("offset", String(nextOffset));
1359
- if (statusFilter !== "all") params.set("status", statusFilter);
1360
- if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
1438
+ if (statusFilter !== "all") {
1439
+ params.set("status", statusFilter);
1440
+ }
1441
+ if (debouncedSearchQuery.trim()) {
1442
+ params.set("q", debouncedSearchQuery.trim());
1443
+ }
1444
+ if (createdByFilter !== "all") {
1445
+ params.set("created_by", createdByFilter);
1446
+ }
1447
+ params.set("order", "created_at");
1361
1448
  const response = await fetch(
1362
- `/admin/payment-transactions?${params.toString()}`,
1449
+ `/admin/return?${params.toString()}`,
1363
1450
  { credentials: "include" }
1364
1451
  );
1365
1452
  if (!response.ok) {
1366
- const text = await response.text();
1367
- throw new Error(text || "Failed to load payment transactions");
1453
+ const message = await response.text();
1454
+ throw new Error(message || "Unable to load return orders");
1368
1455
  }
1369
1456
  const payload = await response.json();
1370
- const list = payload.transactions ?? [];
1371
1457
  setCount(payload.count ?? 0);
1372
- setOffset(nextOffset + list.length);
1373
- setItems((prev) => replace ? list : [...prev, ...list]);
1374
- } catch (e) {
1375
- setError(e instanceof Error ? e.message : "Failed to load");
1458
+ setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
1459
+ setItems(
1460
+ (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
1461
+ );
1462
+ } catch (loadError) {
1463
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
1464
+ setError(message);
1376
1465
  } finally {
1377
1466
  setIsLoading(false);
1378
1467
  setIsFetchingMore(false);
1379
1468
  }
1380
1469
  },
1381
- [statusFilter, debouncedOrderId]
1470
+ [statusFilter, createdByFilter, debouncedSearchQuery]
1382
1471
  );
1383
1472
  react.useEffect(() => {
1384
- void loadTransactions(0, true);
1385
- }, [loadTransactions]);
1473
+ void loadReturns(0, true);
1474
+ }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
1386
1475
  const hasMore = react.useMemo(() => offset < count, [offset, count]);
1387
- const displayStatus = (t) => {
1388
- const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
1389
- return s2 !== "" ? s2 : "—";
1390
- };
1391
- const displayAmount = (t) => {
1392
- const code = (t.currency_code ?? "USD").toUpperCase();
1393
- return `${code} ${Number(t.amount)}`;
1394
- };
1476
+ const availableStatuses = react.useMemo(() => {
1477
+ const statuses = /* @__PURE__ */ new Set();
1478
+ items.forEach((item) => statuses.add(item.status));
1479
+ return Array.from(statuses).sort();
1480
+ }, [items]);
1395
1481
  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: [
1396
1482
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1397
1483
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1398
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payments" }),
1399
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
1484
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Orders" }),
1485
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
1400
1486
  ] }),
1401
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
1487
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
1402
1488
  ] }),
1403
1489
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1404
1490
  /* @__PURE__ */ jsxRuntime.jsx(
1405
1491
  ui.Input,
1406
1492
  {
1407
- placeholder: "Search by Order ID",
1408
- value: orderIdSearch,
1409
- onChange: (e) => setOrderIdSearch(e.target.value),
1410
- className: "md:max-w-sm",
1411
- "aria-label": "Search by order ID"
1493
+ placeholder: "Search by return ID, order ID, or customer email",
1494
+ value: searchQuery,
1495
+ onChange: (event) => setSearchQuery(event.target.value),
1496
+ className: "md:max-w-sm"
1412
1497
  }
1413
1498
  ),
1414
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs(
1415
- "select",
1416
- {
1417
- value: statusFilter,
1418
- onChange: (e) => setStatusFilter(e.target.value),
1419
- 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",
1420
- "aria-label": "Filter by status",
1421
- children: [
1422
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
1423
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
1424
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
1425
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
1426
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
1427
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
1428
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
1429
- ]
1430
- }
1431
- ) })
1499
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
1500
+ /* @__PURE__ */ jsxRuntime.jsxs(
1501
+ "select",
1502
+ {
1503
+ value: createdByFilter,
1504
+ onChange: (event) => setCreatedByFilter(event.target.value),
1505
+ 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",
1506
+ children: [
1507
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All (Created by)" }),
1508
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "customer", children: "Customer" }),
1509
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "admin", children: "Admin" })
1510
+ ]
1511
+ }
1512
+ ),
1513
+ /* @__PURE__ */ jsxRuntime.jsxs(
1514
+ "select",
1515
+ {
1516
+ value: statusFilter,
1517
+ onChange: (event) => setStatusFilter(event.target.value),
1518
+ 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",
1519
+ children: [
1520
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All Statuses" }),
1521
+ availableStatuses.map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1522
+ ]
1523
+ }
1524
+ )
1525
+ ] })
1432
1526
  ] }),
1433
1527
  error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1434
1528
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1435
- /* @__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" }) })
1529
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1530
+ ui.Button,
1531
+ {
1532
+ variant: "secondary",
1533
+ onClick: () => loadReturns(0, true),
1534
+ children: "Try again"
1535
+ }
1536
+ ) })
1436
1537
  ] }) : null,
1437
- 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: [
1438
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
1439
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
1538
+ 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: [
1539
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1540
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1440
1541
  ] }) : /* @__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: [
1441
1542
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1543
+ /* @__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" }),
1442
1544
  /* @__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" }),
1443
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1444
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1545
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1445
1546
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1446
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
1547
+ /* @__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" }),
1447
1548
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1448
1549
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1449
1550
  ] }) }),
1450
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxRuntime.jsxs(
1551
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxRuntime.jsxs(
1451
1552
  "tr",
1452
1553
  {
1453
1554
  className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1454
- onClick: () => navigate(`/payments/${t.payment_session_id}`),
1555
+ onClick: () => navigate(`/returns/${returnOrder.id}`),
1455
1556
  children: [
1456
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
1457
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
1458
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
1557
+ /* @__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 }) }) }),
1558
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1559
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1459
1560
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1460
1561
  ui.Badge,
1461
1562
  {
1462
1563
  size: "2xsmall",
1463
- className: `uppercase ${getStatusBadgeClass$5(displayStatus(t))}`,
1464
- children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1564
+ className: `uppercase ${getStatusBadgeClass$5(returnOrder.status)}`,
1565
+ children: returnOrder.status.replace(/_/g, " ")
1465
1566
  }
1466
1567
  ) }),
1467
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1468
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1568
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1569
+ const amount = returnOrder.refund_amount;
1570
+ if (amount == null || amount === void 0) {
1571
+ return "—";
1572
+ }
1573
+ const displayAmount = Number(amount) / 100;
1574
+ const currency = returnOrder.currency_code || "$";
1575
+ return `${currency}${displayAmount.toFixed(2)}`;
1576
+ })() }),
1577
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1469
1578
  year: "numeric",
1470
1579
  month: "short",
1471
1580
  day: "numeric",
@@ -1473,35 +1582,21 @@ const PaymentsPage = () => {
1473
1582
  minute: "2-digit",
1474
1583
  hour12: true
1475
1584
  }) }),
1476
- /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-4", children: [
1477
- /* @__PURE__ */ jsxRuntime.jsx(
1478
- ui.Button,
1479
- {
1480
- variant: "transparent",
1481
- size: "small",
1482
- onClick: (e) => {
1483
- e.stopPropagation();
1484
- navigate(`/payments/${t.payment_session_id}`);
1485
- },
1486
- children: "View details"
1487
- }
1488
- ),
1489
- t.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1490
- ui.Button,
1491
- {
1492
- variant: "transparent",
1493
- size: "small",
1494
- onClick: (e) => {
1495
- e.stopPropagation();
1496
- navigate(`/orders/${t.order_id}`);
1497
- },
1498
- children: "Order"
1499
- }
1500
- ) : null
1501
- ] })
1585
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1586
+ ui.Button,
1587
+ {
1588
+ variant: "transparent",
1589
+ size: "small",
1590
+ onClick: (e) => {
1591
+ e.stopPropagation();
1592
+ navigate(`/app/orders/${returnOrder.order_id}`);
1593
+ },
1594
+ children: "Go to order"
1595
+ }
1596
+ ) })
1502
1597
  ]
1503
1598
  },
1504
- t.payment_session_id
1599
+ returnOrder.id
1505
1600
  )) })
1506
1601
  ] }) }),
1507
1602
  hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1509,15 +1604,15 @@ const PaymentsPage = () => {
1509
1604
  {
1510
1605
  variant: "secondary",
1511
1606
  isLoading: isFetchingMore,
1512
- onClick: () => loadTransactions(offset, false),
1607
+ onClick: () => loadReturns(offset, false),
1513
1608
  children: "Load more"
1514
1609
  }
1515
1610
  ) }) : null
1516
1611
  ] }) });
1517
1612
  };
1518
1613
  const config$5 = adminSdk.defineRouteConfig({
1519
- label: "Payments",
1520
- icon: icons.CreditCard
1614
+ label: "Return Orders",
1615
+ icon: icons.ArrowPath
1521
1616
  });
1522
1617
  const useDebounce = (value, delay) => {
1523
1618
  const [debouncedValue, setDebouncedValue] = react.useState(value);
@@ -1535,27 +1630,19 @@ const getStatusBadgeClass$4 = (status) => {
1535
1630
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1536
1631
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1537
1632
  };
1538
- const RefundsPage = () => {
1633
+ const PaymentsPage = () => {
1539
1634
  const navigate = reactRouterDom.useNavigate();
1540
1635
  const [items, setItems] = react.useState([]);
1636
+ const [statusFilter, setStatusFilter] = react.useState("all");
1541
1637
  const [orderIdSearch, setOrderIdSearch] = react.useState("");
1542
1638
  const debouncedOrderId = useDebounce(orderIdSearch, 300);
1543
- const [paymentStatusFilter, setPaymentStatusFilter] = react.useState("all");
1544
- const [providerSearch, setProviderSearch] = react.useState("");
1545
- const debouncedProvider = useDebounce(providerSearch, 300);
1546
- const [currencySearch, setCurrencySearch] = react.useState("");
1547
- const debouncedCurrency = useDebounce(currencySearch, 300);
1548
- const [dateFrom, setDateFrom] = react.useState("");
1549
- const [dateTo, setDateTo] = react.useState("");
1550
- const [amountMin, setAmountMin] = react.useState("");
1551
- const [amountMax, setAmountMax] = react.useState("");
1552
1639
  const [isLoading, setIsLoading] = react.useState(true);
1553
1640
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1554
1641
  const [error, setError] = react.useState(null);
1555
1642
  const [offset, setOffset] = react.useState(0);
1556
1643
  const [count, setCount] = react.useState(0);
1557
1644
  const limit = 50;
1558
- const loadRefunds = react.useCallback(
1645
+ const loadTransactions = react.useCallback(
1559
1646
  async (nextOffset, replace) => {
1560
1647
  try {
1561
1648
  if (replace) setIsLoading(true);
@@ -1564,25 +1651,18 @@ const RefundsPage = () => {
1564
1651
  const params = new URLSearchParams();
1565
1652
  params.set("limit", String(limit));
1566
1653
  params.set("offset", String(nextOffset));
1654
+ if (statusFilter !== "all") params.set("status", statusFilter);
1567
1655
  if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
1568
- if (paymentStatusFilter !== "all") params.set("payment_status", paymentStatusFilter);
1569
- if (debouncedProvider.trim()) params.set("provider_id", debouncedProvider.trim());
1570
- if (debouncedCurrency.trim()) params.set("currency_code", debouncedCurrency.trim());
1571
- if (dateFrom.trim()) params.set("date_from", dateFrom.trim());
1572
- if (dateTo.trim()) params.set("date_to", dateTo.trim());
1573
- const min = amountMin.trim() ? Number(amountMin) : void 0;
1574
- const max = amountMax.trim() ? Number(amountMax) : void 0;
1575
- if (min != null && !Number.isNaN(min)) params.set("amount_min", String(min));
1576
- if (max != null && !Number.isNaN(max)) params.set("amount_max", String(max));
1577
- const response = await fetch(`/admin/refunds?${params.toString()}`, {
1578
- credentials: "include"
1579
- });
1656
+ const response = await fetch(
1657
+ `/admin/payment-transactions?${params.toString()}`,
1658
+ { credentials: "include" }
1659
+ );
1580
1660
  if (!response.ok) {
1581
1661
  const text = await response.text();
1582
- throw new Error(text || "Failed to load refunds");
1662
+ throw new Error(text || "Failed to load payment transactions");
1583
1663
  }
1584
1664
  const payload = await response.json();
1585
- const list = payload.refunds ?? [];
1665
+ const list = payload.transactions ?? [];
1586
1666
  setCount(payload.count ?? 0);
1587
1667
  setOffset(nextOffset + list.length);
1588
1668
  setItems((prev) => replace ? list : [...prev, ...list]);
@@ -1593,75 +1673,46 @@ const RefundsPage = () => {
1593
1673
  setIsFetchingMore(false);
1594
1674
  }
1595
1675
  },
1596
- [
1597
- debouncedOrderId,
1598
- paymentStatusFilter,
1599
- debouncedProvider,
1600
- debouncedCurrency,
1601
- dateFrom,
1602
- dateTo,
1603
- amountMin,
1604
- amountMax
1605
- ]
1676
+ [statusFilter, debouncedOrderId]
1606
1677
  );
1607
1678
  react.useEffect(() => {
1608
- void loadRefunds(0, true);
1609
- }, [loadRefunds]);
1679
+ void loadTransactions(0, true);
1680
+ }, [loadTransactions]);
1610
1681
  const hasMore = react.useMemo(() => offset < count, [offset, count]);
1611
- const displayAmount = (r) => {
1612
- const code = (r.currency_code ?? "USD").toUpperCase();
1613
- return `${code} ${Number(r.amount)}`;
1614
- };
1615
- const displayStatus = (r) => {
1616
- const s2 = r.payment_status ?? "";
1682
+ const displayStatus = (t) => {
1683
+ const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
1617
1684
  return s2 !== "" ? s2 : "—";
1618
1685
  };
1686
+ const displayAmount = (t) => {
1687
+ const code = (t.currency_code ?? "USD").toUpperCase();
1688
+ return `${code} ${Number(t.amount)}`;
1689
+ };
1619
1690
  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: [
1620
1691
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1621
1692
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1622
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refunds" }),
1623
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Refund records — amount, order, payment status" })
1693
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payments" }),
1694
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
1624
1695
  ] }),
1625
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadRefunds(0, true), children: "Refresh" })
1696
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
1626
1697
  ] }),
1627
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
1698
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1628
1699
  /* @__PURE__ */ jsxRuntime.jsx(
1629
1700
  ui.Input,
1630
1701
  {
1631
- placeholder: "Order ID",
1702
+ placeholder: "Search by Order ID",
1632
1703
  value: orderIdSearch,
1633
1704
  onChange: (e) => setOrderIdSearch(e.target.value),
1634
- className: "md:max-w-[180px]",
1635
- "aria-label": "Filter by order ID"
1636
- }
1637
- ),
1638
- /* @__PURE__ */ jsxRuntime.jsx(
1639
- ui.Input,
1640
- {
1641
- placeholder: "Provider",
1642
- value: providerSearch,
1643
- onChange: (e) => setProviderSearch(e.target.value),
1644
- className: "md:max-w-[140px]",
1645
- "aria-label": "Filter by provider"
1646
- }
1647
- ),
1648
- /* @__PURE__ */ jsxRuntime.jsx(
1649
- ui.Input,
1650
- {
1651
- placeholder: "Currency",
1652
- value: currencySearch,
1653
- onChange: (e) => setCurrencySearch(e.target.value),
1654
- className: "md:max-w-[100px]",
1655
- "aria-label": "Filter by currency"
1705
+ className: "md:max-w-sm",
1706
+ "aria-label": "Search by order ID"
1656
1707
  }
1657
1708
  ),
1658
- /* @__PURE__ */ jsxRuntime.jsxs(
1709
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs(
1659
1710
  "select",
1660
1711
  {
1661
- value: paymentStatusFilter,
1662
- onChange: (e) => setPaymentStatusFilter(e.target.value),
1663
- 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]",
1664
- "aria-label": "Filter by payment status",
1712
+ value: statusFilter,
1713
+ onChange: (e) => setStatusFilter(e.target.value),
1714
+ 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",
1715
+ "aria-label": "Filter by status",
1665
1716
  children: [
1666
1717
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
1667
1718
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
@@ -1672,103 +1723,52 @@ const RefundsPage = () => {
1672
1723
  /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
1673
1724
  ]
1674
1725
  }
1675
- ),
1676
- /* @__PURE__ */ jsxRuntime.jsx(
1677
- ui.Input,
1678
- {
1679
- type: "date",
1680
- placeholder: "From",
1681
- value: dateFrom,
1682
- onChange: (e) => setDateFrom(e.target.value),
1683
- className: "md:max-w-[140px]",
1684
- "aria-label": "Date from"
1685
- }
1686
- ),
1687
- /* @__PURE__ */ jsxRuntime.jsx(
1688
- ui.Input,
1689
- {
1690
- type: "date",
1691
- placeholder: "To",
1692
- value: dateTo,
1693
- onChange: (e) => setDateTo(e.target.value),
1694
- className: "md:max-w-[140px]",
1695
- "aria-label": "Date to"
1696
- }
1697
- ),
1698
- /* @__PURE__ */ jsxRuntime.jsx(
1699
- ui.Input,
1700
- {
1701
- placeholder: "Amount min",
1702
- value: amountMin,
1703
- onChange: (e) => setAmountMin(e.target.value),
1704
- type: "number",
1705
- min: 0,
1706
- className: "md:max-w-[100px]",
1707
- "aria-label": "Refund amount minimum"
1708
- }
1709
- ),
1710
- /* @__PURE__ */ jsxRuntime.jsx(
1711
- ui.Input,
1712
- {
1713
- placeholder: "Amount max",
1714
- value: amountMax,
1715
- onChange: (e) => setAmountMax(e.target.value),
1716
- type: "number",
1717
- min: 0,
1718
- className: "md:max-w-[100px]",
1719
- "aria-label": "Refund amount maximum"
1720
- }
1721
- )
1722
- ] }) }),
1726
+ ) })
1727
+ ] }),
1723
1728
  error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1724
1729
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1725
- /* @__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" }) })
1730
+ /* @__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" }) })
1726
1731
  ] }) : null,
1727
- 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: [
1728
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No refunds yet" }),
1729
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Refund records will appear here." })
1730
- ] }) : /* @__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: [
1732
+ 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: [
1733
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
1734
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
1735
+ ] }) : /* @__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: [
1731
1736
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1732
- /* @__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" }),
1733
- /* @__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" }),
1734
- /* @__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" }),
1735
- /* @__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" }),
1736
- /* @__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" }),
1737
- /* @__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" }),
1738
- /* @__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" }),
1739
- /* @__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" }),
1740
- /* @__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" }),
1741
- /* @__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" })
1737
+ /* @__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" }),
1738
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1739
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1740
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1741
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
1742
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1743
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1742
1744
  ] }) }),
1743
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((r) => /* @__PURE__ */ jsxRuntime.jsxs(
1745
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxRuntime.jsxs(
1744
1746
  "tr",
1745
1747
  {
1746
- className: "cursor-pointer hover:bg-ui-bg-subtle/60",
1747
- onClick: () => navigate(`/refunds/${r.refund_id}`),
1748
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1749
+ onClick: () => navigate(`/payments/${t.payment_session_id}`),
1748
1750
  children: [
1749
- /* @__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 }),
1750
- /* @__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 ?? "—" }),
1751
- /* @__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 }),
1752
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", children: displayAmount(r) }),
1753
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle uppercase", children: r.currency_code || "—" }),
1754
- /* @__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 || "—" }),
1755
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsx(
1751
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
1752
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
1753
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
1754
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1756
1755
  ui.Badge,
1757
1756
  {
1758
1757
  size: "2xsmall",
1759
- className: `uppercase ${getStatusBadgeClass$4(displayStatus(r))}`,
1760
- children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1758
+ className: `uppercase ${getStatusBadgeClass$4(displayStatus(t))}`,
1759
+ children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1761
1760
  }
1762
1761
  ) }),
1763
- /* @__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 ?? "—" }),
1764
- /* @__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", {
1762
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1763
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1764
+ year: "numeric",
1765
1765
  month: "short",
1766
1766
  day: "numeric",
1767
1767
  hour: "numeric",
1768
1768
  minute: "2-digit",
1769
1769
  hour12: true
1770
1770
  }) }),
1771
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-1", children: [
1771
+ /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-4", children: [
1772
1772
  /* @__PURE__ */ jsxRuntime.jsx(
1773
1773
  ui.Button,
1774
1774
  {
@@ -1776,27 +1776,27 @@ const RefundsPage = () => {
1776
1776
  size: "small",
1777
1777
  onClick: (e) => {
1778
1778
  e.stopPropagation();
1779
- navigate(`/refunds/${r.refund_id}`);
1779
+ navigate(`/payments/${t.payment_session_id}`);
1780
1780
  },
1781
- children: "Details"
1781
+ children: "View details"
1782
1782
  }
1783
1783
  ),
1784
- r.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1784
+ t.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1785
1785
  ui.Button,
1786
1786
  {
1787
1787
  variant: "transparent",
1788
1788
  size: "small",
1789
1789
  onClick: (e) => {
1790
1790
  e.stopPropagation();
1791
- navigate(`/orders/${r.order_id}`);
1791
+ navigate(`/orders/${t.order_id}`);
1792
1792
  },
1793
1793
  children: "Order"
1794
1794
  }
1795
1795
  ) : null
1796
- ] }) })
1796
+ ] })
1797
1797
  ]
1798
1798
  },
1799
- r.refund_id
1799
+ t.payment_session_id
1800
1800
  )) })
1801
1801
  ] }) }),
1802
1802
  hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1804,15 +1804,15 @@ const RefundsPage = () => {
1804
1804
  {
1805
1805
  variant: "secondary",
1806
1806
  isLoading: isFetchingMore,
1807
- onClick: () => loadRefunds(offset, false),
1807
+ onClick: () => loadTransactions(offset, false),
1808
1808
  children: "Load more"
1809
1809
  }
1810
1810
  ) }) : null
1811
1811
  ] }) });
1812
1812
  };
1813
1813
  const config$4 = adminSdk.defineRouteConfig({
1814
- label: "Refunds",
1815
- icon: icons.Receipt
1814
+ label: "Payments",
1815
+ icon: icons.CreditCard
1816
1816
  });
1817
1817
  const getStatusBadgeClass$3 = (status) => {
1818
1818
  const statusLower = status.toLowerCase();
@@ -2089,11 +2089,203 @@ const SwapDetailPage = () => {
2089
2089
  ] })
2090
2090
  ] }) });
2091
2091
  };
2092
- const config$3 = adminSdk.defineRouteConfig({
2093
- label: "Swap Details",
2094
- icon: icons.ArrowPath
2092
+ const config$3 = adminSdk.defineRouteConfig({
2093
+ label: "Swap Details",
2094
+ icon: icons.ArrowPath
2095
+ });
2096
+ const getStatusBadgeClass$2 = (status) => {
2097
+ const s2 = status.toLowerCase();
2098
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2099
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2100
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2101
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2102
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2103
+ };
2104
+ const formatAmount = (value) => {
2105
+ return String(value);
2106
+ };
2107
+ const RefundDetailPage = () => {
2108
+ var _a, _b, _c;
2109
+ const navigate = reactRouterDom.useNavigate();
2110
+ const params = reactRouterDom.useParams();
2111
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2112
+ const [detail, setDetail] = react.useState(null);
2113
+ const [loading, setLoading] = react.useState(!!id);
2114
+ const [error, setError] = react.useState(null);
2115
+ const [gatewayExpanded, setGatewayExpanded] = react.useState(false);
2116
+ react.useEffect(() => {
2117
+ if (!id) {
2118
+ setLoading(false);
2119
+ return;
2120
+ }
2121
+ let cancelled = false;
2122
+ setLoading(true);
2123
+ setError(null);
2124
+ fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
2125
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
2126
+ return res.json();
2127
+ }).then((data) => {
2128
+ if (!cancelled) setDetail(data);
2129
+ }).catch((e) => {
2130
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2131
+ }).finally(() => {
2132
+ if (!cancelled) setLoading(false);
2133
+ });
2134
+ return () => {
2135
+ cancelled = true;
2136
+ };
2137
+ }, [id]);
2138
+ const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
2139
+ 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;
2140
+ 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: [
2141
+ /* @__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: [
2142
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
2143
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refund details" }),
2144
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
2145
+ ] }) }),
2146
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2147
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2148
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
2149
+ ] }) : 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: [
2150
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2151
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
2152
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2153
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2154
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
2155
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
2156
+ ] }),
2157
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2158
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2159
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
2160
+ ] }),
2161
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2162
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2163
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2164
+ ] }),
2165
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2166
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2167
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2168
+ year: "numeric",
2169
+ month: "short",
2170
+ day: "numeric",
2171
+ hour: "numeric",
2172
+ minute: "2-digit",
2173
+ hour12: true
2174
+ }) })
2175
+ ] }),
2176
+ detail.refund.created_by ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2177
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
2178
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
2179
+ ] }) : null
2180
+ ] })
2181
+ ] }),
2182
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2183
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
2184
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2185
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2186
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
2187
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
2188
+ ] }),
2189
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2190
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
2191
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2192
+ ] }),
2193
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2194
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
2195
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2196
+ ] }),
2197
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2198
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2199
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
2200
+ ] }),
2201
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2202
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2203
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2204
+ ui.Badge,
2205
+ {
2206
+ size: "2xsmall",
2207
+ className: `uppercase ${getStatusBadgeClass$2(paymentStatus)}`,
2208
+ children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2209
+ }
2210
+ ) })
2211
+ ] }),
2212
+ detail.computed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2213
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2214
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
2215
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
2216
+ ] }),
2217
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2218
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
2219
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
2220
+ ] }),
2221
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2222
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
2223
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "mt-1 block", children: [
2224
+ detail.computed.refund_percentage.toFixed(1),
2225
+ "%"
2226
+ ] })
2227
+ ] })
2228
+ ] }) : null
2229
+ ] })
2230
+ ] }),
2231
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2232
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
2233
+ detail.order ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2234
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2235
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
2236
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2237
+ ui.Button,
2238
+ {
2239
+ variant: "transparent",
2240
+ size: "small",
2241
+ onClick: () => navigate(`/orders/${detail.order.order_id}`),
2242
+ children: detail.order.order_number ?? detail.order.order_id
2243
+ }
2244
+ ) })
2245
+ ] }),
2246
+ detail.order.total != null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2247
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
2248
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
2249
+ ] }) : null,
2250
+ detail.order.customer_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2251
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
2252
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
2253
+ ] }) : null,
2254
+ detail.order.region ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2255
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
2256
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.region })
2257
+ ] }) : null,
2258
+ detail.order.fulfillment_status ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2259
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
2260
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
2261
+ ] }) : null
2262
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
2263
+ ] }),
2264
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2265
+ /* @__PURE__ */ jsxRuntime.jsxs(
2266
+ "button",
2267
+ {
2268
+ type: "button",
2269
+ className: "flex w-full items-center justify-between text-left",
2270
+ onClick: () => setGatewayExpanded((prev) => !prev),
2271
+ "aria-expanded": gatewayExpanded,
2272
+ "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
2273
+ children: [
2274
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
2275
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
2276
+ ]
2277
+ }
2278
+ ),
2279
+ 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." }) })
2280
+ ] })
2281
+ ] }) : null
2282
+ ] }) });
2283
+ };
2284
+ const config$2 = adminSdk.defineRouteConfig({
2285
+ label: "Refund details",
2286
+ icon: icons.Receipt
2095
2287
  });
2096
- const getStatusBadgeClass$2 = (status) => {
2288
+ const getStatusBadgeClass$1 = (status) => {
2097
2289
  const statusLower = status.toLowerCase();
2098
2290
  if (statusLower === "requested") {
2099
2291
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2227,7 +2419,7 @@ const ReturnDetailPage = () => {
2227
2419
  ui.Badge,
2228
2420
  {
2229
2421
  size: "small",
2230
- className: `uppercase ${getStatusBadgeClass$2(returnOrder.status)}`,
2422
+ className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
2231
2423
  children: returnOrder.status.replace(/_/g, " ")
2232
2424
  }
2233
2425
  )
@@ -2309,7 +2501,7 @@ const ReturnDetailPage = () => {
2309
2501
  ui.Badge,
2310
2502
  {
2311
2503
  size: "2xsmall",
2312
- className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2504
+ className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
2313
2505
  children: entry.status.replace(/_/g, " ")
2314
2506
  }
2315
2507
  ) }),
@@ -2367,11 +2559,11 @@ const ReturnDetailPage = () => {
2367
2559
  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" }) })
2368
2560
  ] }) });
2369
2561
  };
2370
- const config$2 = adminSdk.defineRouteConfig({
2562
+ const config$1 = adminSdk.defineRouteConfig({
2371
2563
  label: "Return Order Details",
2372
2564
  icon: icons.CheckCircle
2373
2565
  });
2374
- const getStatusBadgeClass$1 = (status) => {
2566
+ const getStatusBadgeClass = (status) => {
2375
2567
  const s2 = status.toLowerCase();
2376
2568
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2377
2569
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -2450,7 +2642,7 @@ const PaymentDetailPage = () => {
2450
2642
  ui.Badge,
2451
2643
  {
2452
2644
  size: "2xsmall",
2453
- className: `uppercase ${getStatusBadgeClass$1(displayStatus)}`,
2645
+ className: `uppercase ${getStatusBadgeClass(displayStatus)}`,
2454
2646
  children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2455
2647
  }
2456
2648
  ) })
@@ -2486,202 +2678,10 @@ const PaymentDetailPage = () => {
2486
2678
  ] }) : null
2487
2679
  ] }) });
2488
2680
  };
2489
- const config$1 = adminSdk.defineRouteConfig({
2681
+ const config = adminSdk.defineRouteConfig({
2490
2682
  label: "Payment details",
2491
2683
  icon: icons.CreditCard
2492
2684
  });
2493
- const getStatusBadgeClass = (status) => {
2494
- const s2 = status.toLowerCase();
2495
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2496
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2497
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2498
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2499
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2500
- };
2501
- const formatAmount = (value) => {
2502
- return String(value);
2503
- };
2504
- const RefundDetailPage = () => {
2505
- var _a, _b, _c;
2506
- const navigate = reactRouterDom.useNavigate();
2507
- const params = reactRouterDom.useParams();
2508
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2509
- const [detail, setDetail] = react.useState(null);
2510
- const [loading, setLoading] = react.useState(!!id);
2511
- const [error, setError] = react.useState(null);
2512
- const [gatewayExpanded, setGatewayExpanded] = react.useState(false);
2513
- react.useEffect(() => {
2514
- if (!id) {
2515
- setLoading(false);
2516
- return;
2517
- }
2518
- let cancelled = false;
2519
- setLoading(true);
2520
- setError(null);
2521
- fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
2522
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2523
- return res.json();
2524
- }).then((data) => {
2525
- if (!cancelled) setDetail(data);
2526
- }).catch((e) => {
2527
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2528
- }).finally(() => {
2529
- if (!cancelled) setLoading(false);
2530
- });
2531
- return () => {
2532
- cancelled = true;
2533
- };
2534
- }, [id]);
2535
- const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
2536
- 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;
2537
- 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: [
2538
- /* @__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: [
2539
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
2540
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refund details" }),
2541
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
2542
- ] }) }),
2543
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2544
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2545
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
2546
- ] }) : 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: [
2547
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2548
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
2549
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2550
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2551
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
2552
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
2553
- ] }),
2554
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2555
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2556
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
2557
- ] }),
2558
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2559
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2560
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2561
- ] }),
2562
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2563
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2564
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2565
- year: "numeric",
2566
- month: "short",
2567
- day: "numeric",
2568
- hour: "numeric",
2569
- minute: "2-digit",
2570
- hour12: true
2571
- }) })
2572
- ] }),
2573
- detail.refund.created_by ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2574
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
2575
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
2576
- ] }) : null
2577
- ] })
2578
- ] }),
2579
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2580
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
2581
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2582
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2583
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
2584
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
2585
- ] }),
2586
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2587
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
2588
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2589
- ] }),
2590
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2591
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
2592
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2593
- ] }),
2594
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2595
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2596
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
2597
- ] }),
2598
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2599
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2600
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2601
- ui.Badge,
2602
- {
2603
- size: "2xsmall",
2604
- className: `uppercase ${getStatusBadgeClass(paymentStatus)}`,
2605
- children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2606
- }
2607
- ) })
2608
- ] }),
2609
- detail.computed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2610
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2611
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
2612
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
2613
- ] }),
2614
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2615
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
2616
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
2617
- ] }),
2618
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2619
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
2620
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "mt-1 block", children: [
2621
- detail.computed.refund_percentage.toFixed(1),
2622
- "%"
2623
- ] })
2624
- ] })
2625
- ] }) : null
2626
- ] })
2627
- ] }),
2628
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2629
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
2630
- detail.order ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2631
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2632
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
2633
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2634
- ui.Button,
2635
- {
2636
- variant: "transparent",
2637
- size: "small",
2638
- onClick: () => navigate(`/orders/${detail.order.order_id}`),
2639
- children: detail.order.order_number ?? detail.order.order_id
2640
- }
2641
- ) })
2642
- ] }),
2643
- detail.order.total != null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2644
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
2645
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
2646
- ] }) : null,
2647
- detail.order.customer_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2648
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
2649
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
2650
- ] }) : null,
2651
- detail.order.region ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2652
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
2653
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.region })
2654
- ] }) : null,
2655
- detail.order.fulfillment_status ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2656
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
2657
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
2658
- ] }) : null
2659
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
2660
- ] }),
2661
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2662
- /* @__PURE__ */ jsxRuntime.jsxs(
2663
- "button",
2664
- {
2665
- type: "button",
2666
- className: "flex w-full items-center justify-between text-left",
2667
- onClick: () => setGatewayExpanded((prev) => !prev),
2668
- "aria-expanded": gatewayExpanded,
2669
- "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
2670
- children: [
2671
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
2672
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
2673
- ]
2674
- }
2675
- ),
2676
- 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." }) })
2677
- ] })
2678
- ] }) : null
2679
- ] }) });
2680
- };
2681
- const config = adminSdk.defineRouteConfig({
2682
- label: "Refund details",
2683
- icon: icons.Receipt
2684
- });
2685
2685
  const i18nTranslations0 = {};
2686
2686
  const widgetModule = { widgets: [
2687
2687
  {
@@ -2699,6 +2699,10 @@ const routeModule = {
2699
2699
  Component: SwapsPage,
2700
2700
  path: "/swaps"
2701
2701
  },
2702
+ {
2703
+ Component: RefundsPage,
2704
+ path: "/refunds"
2705
+ },
2702
2706
  {
2703
2707
  Component: ReturnsPage,
2704
2708
  path: "/returns"
@@ -2707,14 +2711,14 @@ const routeModule = {
2707
2711
  Component: PaymentsPage,
2708
2712
  path: "/payments"
2709
2713
  },
2710
- {
2711
- Component: RefundsPage,
2712
- path: "/refunds"
2713
- },
2714
2714
  {
2715
2715
  Component: SwapDetailPage,
2716
2716
  path: "/swaps/:id"
2717
2717
  },
2718
+ {
2719
+ Component: RefundDetailPage,
2720
+ path: "/refunds/:id"
2721
+ },
2718
2722
  {
2719
2723
  Component: ReturnDetailPage,
2720
2724
  path: "/returns/:id"
@@ -2722,24 +2726,26 @@ const routeModule = {
2722
2726
  {
2723
2727
  Component: PaymentDetailPage,
2724
2728
  path: "/payments/:id"
2725
- },
2726
- {
2727
- Component: RefundDetailPage,
2728
- path: "/refunds/:id"
2729
2729
  }
2730
2730
  ]
2731
2731
  };
2732
2732
  const menuItemModule = {
2733
2733
  menuItems: [
2734
2734
  {
2735
- label: config$4.label,
2736
- icon: config$4.icon,
2735
+ label: config$5.label,
2736
+ icon: config$5.icon,
2737
+ path: "/returns",
2738
+ nested: void 0
2739
+ },
2740
+ {
2741
+ label: config$6.label,
2742
+ icon: config$6.icon,
2737
2743
  path: "/refunds",
2738
2744
  nested: void 0
2739
2745
  },
2740
2746
  {
2741
- label: config$5.label,
2742
- icon: config$5.icon,
2747
+ label: config$4.label,
2748
+ icon: config$4.icon,
2743
2749
  path: "/payments",
2744
2750
  nested: void 0
2745
2751
  },
@@ -2750,27 +2756,21 @@ const menuItemModule = {
2750
2756
  nested: void 0
2751
2757
  },
2752
2758
  {
2753
- label: config$6.label,
2754
- icon: config$6.icon,
2755
- path: "/returns",
2759
+ label: config$1.label,
2760
+ icon: config$1.icon,
2761
+ path: "/returns/:id",
2756
2762
  nested: void 0
2757
2763
  },
2758
2764
  {
2759
2765
  label: config.label,
2760
2766
  icon: config.icon,
2761
- path: "/refunds/:id",
2762
- nested: void 0
2763
- },
2764
- {
2765
- label: config$1.label,
2766
- icon: config$1.icon,
2767
2767
  path: "/payments/:id",
2768
2768
  nested: void 0
2769
2769
  },
2770
2770
  {
2771
2771
  label: config$2.label,
2772
2772
  icon: config$2.icon,
2773
- path: "/returns/:id",
2773
+ path: "/refunds/:id",
2774
2774
  nested: void 0
2775
2775
  },
2776
2776
  {