@easypayment/medusa-paypal 0.2.8 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/.medusa/server/src/admin/index.js +18 -405
  2. package/.medusa/server/src/admin/index.mjs +18 -405
  3. package/.medusa/server/src/api/store/paypal/webhook/route.d.ts.map +1 -1
  4. package/.medusa/server/src/api/store/paypal/webhook/route.js +1 -1
  5. package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -1
  6. package/.medusa/server/src/jobs/paypal-reconcile.d.ts.map +1 -1
  7. package/.medusa/server/src/jobs/paypal-reconcile.js +0 -36
  8. package/.medusa/server/src/jobs/paypal-reconcile.js.map +1 -1
  9. package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -1
  10. package/.medusa/server/src/jobs/paypal-webhook-retry.js +1 -1
  11. package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -1
  12. package/.medusa/server/src/modules/paypal/index.d.ts +0 -28
  13. package/.medusa/server/src/modules/paypal/index.d.ts.map +1 -1
  14. package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.d.ts +6 -0
  15. package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.d.ts.map +1 -0
  16. package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js +28 -0
  17. package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js.map +1 -0
  18. package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.d.ts +6 -0
  19. package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.d.ts.map +1 -0
  20. package/.medusa/server/src/modules/paypal/migrations/{20260301090000_create_paypal_audit_log.js → 20261201090000_remove_paypal_audit_log.js} +10 -10
  21. package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.js.map +1 -0
  22. package/.medusa/server/src/modules/paypal/service.d.ts +2 -91
  23. package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
  24. package/.medusa/server/src/modules/paypal/service.js +2 -142
  25. package/.medusa/server/src/modules/paypal/service.js.map +1 -1
  26. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +0 -13
  27. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -1
  28. package/.medusa/server/src/modules/paypal/webhook-processor.js +0 -96
  29. package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/admin/routes/settings/paypal/_components/Tabs.tsx +0 -3
  32. package/src/admin/routes/settings/paypal/additional-settings/page.tsx +218 -226
  33. package/src/api/store/paypal/webhook/route.ts +1 -2
  34. package/src/jobs/paypal-reconcile.ts +0 -37
  35. package/src/jobs/paypal-webhook-retry.ts +1 -2
  36. package/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.ts +25 -0
  37. package/src/modules/paypal/migrations/{20260301090000_create_paypal_audit_log.ts → 20261201090000_remove_paypal_audit_log.ts} +8 -8
  38. package/src/modules/paypal/service.ts +2 -170
  39. package/src/modules/paypal/webhook-processor.ts +2 -114
  40. package/.medusa/server/src/api/admin/paypal/audit-logs/route.d.ts +0 -3
  41. package/.medusa/server/src/api/admin/paypal/audit-logs/route.d.ts.map +0 -1
  42. package/.medusa/server/src/api/admin/paypal/audit-logs/route.js +0 -12
  43. package/.medusa/server/src/api/admin/paypal/audit-logs/route.js.map +0 -1
  44. package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.d.ts +0 -3
  45. package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.d.ts.map +0 -1
  46. package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.js +0 -17
  47. package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.js.map +0 -1
  48. package/.medusa/server/src/api/admin/paypal/disputes/route.d.ts +0 -3
  49. package/.medusa/server/src/api/admin/paypal/disputes/route.d.ts.map +0 -1
  50. package/.medusa/server/src/api/admin/paypal/disputes/route.js +0 -27
  51. package/.medusa/server/src/api/admin/paypal/disputes/route.js.map +0 -1
  52. package/.medusa/server/src/api/admin/paypal/disputes/summary/route.d.ts +0 -3
  53. package/.medusa/server/src/api/admin/paypal/disputes/summary/route.d.ts.map +0 -1
  54. package/.medusa/server/src/api/admin/paypal/disputes/summary/route.js +0 -17
  55. package/.medusa/server/src/api/admin/paypal/disputes/summary/route.js.map +0 -1
  56. package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.d.ts +0 -3
  57. package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.d.ts.map +0 -1
  58. package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.js +0 -8
  59. package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.js.map +0 -1
  60. package/.medusa/server/src/api/store/paypal/disputes/route.d.ts +0 -3
  61. package/.medusa/server/src/api/store/paypal/disputes/route.d.ts.map +0 -1
  62. package/.medusa/server/src/api/store/paypal/disputes/route.js +0 -46
  63. package/.medusa/server/src/api/store/paypal/disputes/route.js.map +0 -1
  64. package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.d.ts +0 -6
  65. package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.d.ts.map +0 -1
  66. package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.js.map +0 -1
  67. package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.d.ts +0 -6
  68. package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.d.ts.map +0 -1
  69. package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.js +0 -43
  70. package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.js.map +0 -1
  71. package/.medusa/server/src/modules/paypal/models/paypal_audit_log.d.ts +0 -7
  72. package/.medusa/server/src/modules/paypal/models/paypal_audit_log.d.ts.map +0 -1
  73. package/.medusa/server/src/modules/paypal/models/paypal_audit_log.js +0 -10
  74. package/.medusa/server/src/modules/paypal/models/paypal_audit_log.js.map +0 -1
  75. package/.medusa/server/src/modules/paypal/models/paypal_dispute.d.ts +0 -16
  76. package/.medusa/server/src/modules/paypal/models/paypal_dispute.d.ts.map +0 -1
  77. package/.medusa/server/src/modules/paypal/models/paypal_dispute.js +0 -19
  78. package/.medusa/server/src/modules/paypal/models/paypal_dispute.js.map +0 -1
  79. package/src/admin/routes/settings/paypal/audit-logs/page.tsx +0 -127
  80. package/src/admin/routes/settings/paypal/disputes/page.tsx +0 -186
  81. package/src/admin/routes/settings/paypal/reconciliation-status/page.tsx +0 -120
  82. package/src/api/admin/paypal/audit-logs/route.ts +0 -13
  83. package/src/api/admin/paypal/disputes/[id]/route.ts +0 -19
  84. package/src/api/admin/paypal/disputes/route.ts +0 -30
  85. package/src/api/admin/paypal/disputes/summary/route.ts +0 -18
  86. package/src/api/admin/paypal/reconciliation-status/route.ts +0 -7
  87. package/src/api/store/paypal/disputes/route.ts +0 -67
  88. package/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.ts +0 -40
  89. package/src/modules/paypal/models/paypal_audit_log.ts +0 -9
  90. package/src/modules/paypal/models/paypal_dispute.ts +0 -18
@@ -14,12 +14,9 @@ const TABS = [
14
14
  { label: "PayPal Connection", to: `${BASE}/connection` },
15
15
  { label: "PayPal Settings", to: `${BASE}/paypal-settings` },
16
16
  { label: "Advanced Card Payments", to: `${BASE}/advanced-card-payments` },
17
- { label: "Disputes", to: `${BASE}/disputes` },
18
- { label: "Reconciliation Status", to: `${BASE}/reconciliation-status` },
19
17
  /* { label: "Google Pay", to: `${BASE}/google-pay` },
20
18
  { label: "Apple Pay", to: `${BASE}/apple-pay` },
21
19
  { label: "Pay Later Messaging", to: `${BASE}/pay-later-messaging` }, */
22
- { label: "Audit Logs", to: `${BASE}/audit-logs` },
23
20
  { label: "Additional Settings", to: `${BASE}/additional-settings` }
24
21
  ];
25
22
  function isActive(pathname, to) {
@@ -40,7 +37,7 @@ function PayPalTabs() {
40
37
  );
41
38
  }) }) });
42
39
  }
43
- async function adminFetch$5(path, opts = {}) {
40
+ async function adminFetch$2(path, opts = {}) {
44
41
  var _a;
45
42
  const { method = "GET", body, query } = opts;
46
43
  let url = path;
@@ -83,7 +80,6 @@ const DEFAULT_FORM$1 = {
83
80
  skipOrderReviewPage: true,
84
81
  invoicePrefix: "WC-",
85
82
  creditCardStatementName: "PayPal",
86
- enableLogging: true,
87
83
  logPath: "/uploads/wc-logs/"
88
84
  };
89
85
  function mergeWithDefaults$1(saved) {
@@ -124,7 +120,7 @@ function AdditionalSettingsTab() {
124
120
  (async () => {
125
121
  try {
126
122
  setLoading(true);
127
- const json = await adminFetch$5("/admin/paypal/settings");
123
+ const json = await adminFetch$2("/admin/paypal/settings");
128
124
  const payload = (json == null ? void 0 : json.data) ?? json;
129
125
  const saved = payload == null ? void 0 : payload.additional_settings;
130
126
  if (saved && typeof saved === "object") setForm(mergeWithDefaults$1(saved));
@@ -138,7 +134,7 @@ function AdditionalSettingsTab() {
138
134
  try {
139
135
  setSaving(true);
140
136
  setToast(null);
141
- const json = await adminFetch$5("/admin/paypal/settings", { method: "POST", body: { additional_settings: form } });
137
+ const json = await adminFetch$2("/admin/paypal/settings", { method: "POST", body: { additional_settings: form } });
142
138
  const payload = (json == null ? void 0 : json.data) ?? json;
143
139
  const saved = payload == null ? void 0 : payload.additional_settings;
144
140
  if (saved && typeof saved === "object") setForm(mergeWithDefaults$1(saved));
@@ -159,7 +155,7 @@ function AdditionalSettingsTab() {
159
155
  SectionCard$2,
160
156
  {
161
157
  title: "Additional Settings",
162
- description: "These settings control checkout behavior, PayPal experience, and logging.",
158
+ description: "These settings control checkout behavior and PayPal experience.",
163
159
  right: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
164
160
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onSave, disabled: saving || loading, className: "rounded-md bg-ui-button-neutral px-4 py-2 text-sm font-medium text-ui-fg-on-color shadow-sm hover:opacity-90 disabled:opacity-60", children: saving ? "Saving..." : "Save settings" }),
165
161
  loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading..." }) : null
@@ -192,23 +188,16 @@ function AdditionalSettingsTab() {
192
188
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Skip Order Review Page" })
193
189
  ] }) }),
194
190
  /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Invoice prefix", children: /* @__PURE__ */ jsxRuntime.jsx("input", { value: form.invoicePrefix, onChange: (e) => setForm((p) => ({ ...p, invoicePrefix: e.target.value })), className: "w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive", placeholder: "WC-" }) }),
195
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Credit Card Statement Name", children: /* @__PURE__ */ jsxRuntime.jsx("input", { value: form.creditCardStatementName, onChange: (e) => setForm((p) => ({ ...p, creditCardStatementName: e.target.value })), className: "w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive", placeholder: "PayPal" }) }),
196
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Debug log", hint: /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
197
- "Log PayPal events such as Webhook, Payment, Refund. ",
198
- form.logPath ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
199
- "Log location: ",
200
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono", children: form.logPath })
201
- ] }) : null
202
- ] }), children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
203
- /* @__PURE__ */ jsxRuntime.jsx("input", { type: "checkbox", checked: form.enableLogging, onChange: (e) => setForm((p) => ({ ...p, enableLogging: e.target.checked })), className: "h-4 w-4 rounded border-ui-border-base" }),
204
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable logging" })
205
- ] }) })
191
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Credit Card Statement Name", children: /* @__PURE__ */ jsxRuntime.jsx("input", { value: form.creditCardStatementName, onChange: (e) => setForm((p) => ({ ...p, creditCardStatementName: e.target.value })), className: "w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive", placeholder: "PayPal" }) })
206
192
  ] })
207
193
  }
208
194
  )
209
195
  ] }) });
210
196
  }
211
- async function adminFetch$4(path, opts = {}) {
197
+ function PayPalGooglePayPage() {
198
+ return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
199
+ }
200
+ async function adminFetch$1(path, opts = {}) {
212
201
  var _a;
213
202
  const { method = "GET", body, query } = opts;
214
203
  let url = path;
@@ -301,7 +290,7 @@ function AdvancedCardPaymentsTab() {
301
290
  (async () => {
302
291
  try {
303
292
  setLoading(true);
304
- const json = await adminFetch$4("/admin/paypal/settings");
293
+ const json = await adminFetch$1("/admin/paypal/settings");
305
294
  const payload = (json == null ? void 0 : json.data) ?? json;
306
295
  const saved = payload == null ? void 0 : payload.advanced_card_payments;
307
296
  if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
@@ -314,7 +303,7 @@ function AdvancedCardPaymentsTab() {
314
303
  async function onSave() {
315
304
  try {
316
305
  setSaving(true);
317
- const json = await adminFetch$4("/admin/paypal/settings", { method: "POST", body: { advanced_card_payments: form } });
306
+ const json = await adminFetch$1("/admin/paypal/settings", { method: "POST", body: { advanced_card_payments: form } });
318
307
  const payload = (json == null ? void 0 : json.data) ?? json;
319
308
  const saved = payload == null ? void 0 : payload.advanced_card_payments;
320
309
  if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
@@ -379,9 +368,6 @@ function AdvancedCardPaymentsTab() {
379
368
  )
380
369
  ] }) });
381
370
  }
382
- function PayPalApplePayPage() {
383
- return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
384
- }
385
371
  const config = adminSdk.defineRouteConfig({
386
372
  label: "PayPal Connection",
387
373
  hide: true
@@ -966,373 +952,12 @@ function PayPalConnectionPage() {
966
952
  ` })
967
953
  ] });
968
954
  }
969
- async function adminFetch$3(path, opts = {}) {
970
- var _a;
971
- const { method = "GET", body, query } = opts;
972
- let url = path;
973
- if (query && Object.keys(query).length > 0) {
974
- const params = new URLSearchParams(query);
975
- url = `${path}?${params.toString()}`;
976
- }
977
- const headers = { Accept: "application/json" };
978
- if (body !== void 0) headers["Content-Type"] = "application/json";
979
- if (typeof window !== "undefined") {
980
- const token = (_a = window.__medusa__) == null ? void 0 : _a.token;
981
- if (token) headers["Authorization"] = `Bearer ${token}`;
982
- }
983
- const res = await fetch(url, {
984
- method,
985
- headers,
986
- credentials: "include",
987
- body: body !== void 0 ? JSON.stringify(body) : void 0
988
- });
989
- const text = await res.text().catch(() => "");
990
- if (!res.ok) {
991
- if (res.status === 401) throw new Error("Unauthorized (401) - session may have expired. Please reload and log in again.");
992
- if (res.status === 403) throw new Error("Forbidden (403) - you do not have permission to perform this action.");
993
- throw new Error(text || `Request failed with status ${res.status}`);
994
- }
995
- if (!text) return {};
996
- try {
997
- return JSON.parse(text);
998
- } catch {
999
- return {};
1000
- }
1001
- }
1002
- const EMPTY_FILTERS = { dispute_id: "", status: "", order_id: "", cart_id: "" };
1003
- function formatDate$2(value) {
1004
- if (!value) return "";
1005
- const parsed = new Date(value);
1006
- if (Number.isNaN(parsed.getTime())) return value;
1007
- return parsed.toLocaleString();
1008
- }
1009
- function PayPalDisputesPage() {
1010
- const [filters, setFilters] = react.useState({ ...EMPTY_FILTERS });
1011
- const [disputes, setDisputes] = react.useState([]);
1012
- const [loading, setLoading] = react.useState(false);
1013
- const [error, setError] = react.useState(null);
1014
- const queryString = react.useMemo(() => {
1015
- const params = new URLSearchParams();
1016
- Object.entries(filters).forEach(([key, value]) => {
1017
- if (value.trim()) params.set(key, value.trim());
1018
- });
1019
- const qs = params.toString();
1020
- return qs ? `?${qs}` : "";
1021
- }, [filters]);
1022
- const fetchDisputes = react.useCallback(async (source) => {
1023
- try {
1024
- setLoading(true);
1025
- setError(null);
1026
- const query = {};
1027
- Object.entries(source).forEach(([key, value]) => {
1028
- if (value.trim()) query[key] = value.trim();
1029
- });
1030
- const json = await adminFetch$3("/admin/paypal/disputes", { query });
1031
- setDisputes((json == null ? void 0 : json.disputes) ?? []);
1032
- } catch (fetchError) {
1033
- setError(fetchError instanceof Error ? fetchError.message : "Failed to load disputes");
1034
- setDisputes([]);
1035
- } finally {
1036
- setLoading(false);
1037
- }
1038
- }, []);
1039
- react.useEffect(() => {
1040
- fetchDisputes(EMPTY_FILTERS);
1041
- }, [fetchDisputes]);
1042
- const onSubmit = (event) => {
1043
- event.preventDefault();
1044
- fetchDisputes(filters);
1045
- };
1046
- const onReset = () => {
1047
- setFilters({ ...EMPTY_FILTERS });
1048
- fetchDisputes(EMPTY_FILTERS);
1049
- };
1050
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
1051
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1052
- /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Disputes" }),
1053
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-ui-fg-subtle", children: "Review PayPal dispute activity tied to your Medusa orders. This view is read-only." })
1054
- ] }),
1055
- /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
1056
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
1057
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-b border-ui-border-base p-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: "Filters" }) }),
1058
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, className: "flex flex-col gap-4", children: [
1059
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-4", children: [
1060
- /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1061
- "Dispute ID",
1062
- /* @__PURE__ */ jsxRuntime.jsx("input", { className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base", value: filters.dispute_id, onChange: (e) => setFilters((p) => ({ ...p, dispute_id: e.target.value })), placeholder: "PP-D-123" })
1063
- ] }),
1064
- /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1065
- "Status",
1066
- /* @__PURE__ */ jsxRuntime.jsx("input", { className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base", value: filters.status, onChange: (e) => setFilters((p) => ({ ...p, status: e.target.value })), placeholder: "OPEN" })
1067
- ] }),
1068
- /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1069
- "Order ID",
1070
- /* @__PURE__ */ jsxRuntime.jsx("input", { className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base", value: filters.order_id, onChange: (e) => setFilters((p) => ({ ...p, order_id: e.target.value })), placeholder: "order_..." })
1071
- ] }),
1072
- /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1073
- "Cart ID",
1074
- /* @__PURE__ */ jsxRuntime.jsx("input", { className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base", value: filters.cart_id, onChange: (e) => setFilters((p) => ({ ...p, cart_id: e.target.value })), placeholder: "cart_..." })
1075
- ] })
1076
- ] }),
1077
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-3", children: [
1078
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", className: "rounded-md bg-ui-fg-base px-4 py-2 text-sm font-medium text-ui-bg-base", disabled: loading, children: loading ? "Loading..." : "Apply filters" }),
1079
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "rounded-md border border-ui-border-base px-4 py-2 text-sm text-ui-fg-base", onClick: onReset, disabled: loading, children: "Reset" }),
1080
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-sm text-ui-fg-subtle", children: [
1081
- "Showing ",
1082
- disputes.length,
1083
- " dispute",
1084
- disputes.length === 1 ? "" : "s",
1085
- queryString ? " (filtered)" : ""
1086
- ] })
1087
- ] })
1088
- ] }) })
1089
- ] }),
1090
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
1091
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-b border-ui-border-base p-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: "Dispute Records" }) }),
1092
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base text-sm", children: [
1093
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "text-left text-ui-fg-subtle", children: [
1094
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Dispute" }),
1095
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Status" }),
1096
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Reason" }),
1097
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Stage" }),
1098
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Amount" }),
1099
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Order" }),
1100
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Cart" }),
1101
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Updated" })
1102
- ] }) }),
1103
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-base text-ui-fg-base", children: disputes.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-6 text-center text-ui-fg-subtle", colSpan: 8, children: loading ? "Loading disputes..." : "No disputes found." }) }) : disputes.map((dispute) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1104
- /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-3", children: [
1105
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium text-ui-fg-base", children: dispute.dispute_id }),
1106
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-ui-fg-subtle", children: dispute.transaction_id || "No transaction" })
1107
- ] }),
1108
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.status || "Unknown" }),
1109
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.reason || "-" }),
1110
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.stage || "-" }),
1111
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.amount ? `${dispute.amount} ${dispute.currency_code || ""}` : "-" }),
1112
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.order_id || "-" }),
1113
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.cart_id || "-" }),
1114
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3 text-ui-fg-subtle", children: formatDate$2(dispute.updated_at || dispute.created_at) })
1115
- ] }, dispute.id)) })
1116
- ] }) }),
1117
- error ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-t border-ui-border-base px-4 py-3 text-sm text-ui-fg-error", children: error }) : null
1118
- ] })
1119
- ] }) });
1120
- }
1121
- async function adminFetch$2(path, opts = {}) {
1122
- var _a;
1123
- const { method = "GET", body, query } = opts;
1124
- let url = path;
1125
- if (query && Object.keys(query).length > 0) {
1126
- const params = new URLSearchParams(query);
1127
- url = `${path}?${params.toString()}`;
1128
- }
1129
- const headers = { Accept: "application/json" };
1130
- if (body !== void 0) headers["Content-Type"] = "application/json";
1131
- if (typeof window !== "undefined") {
1132
- const token = (_a = window.__medusa__) == null ? void 0 : _a.token;
1133
- if (token) headers["Authorization"] = `Bearer ${token}`;
1134
- }
1135
- const res = await fetch(url, {
1136
- method,
1137
- headers,
1138
- credentials: "include",
1139
- body: body !== void 0 ? JSON.stringify(body) : void 0
1140
- });
1141
- const text = await res.text().catch(() => "");
1142
- if (!res.ok) {
1143
- if (res.status === 401) throw new Error("Unauthorized (401) - session may have expired. Please reload and log in again.");
1144
- if (res.status === 403) throw new Error("Forbidden (403) - you do not have permission to perform this action.");
1145
- throw new Error(text || `Request failed with status ${res.status}`);
1146
- }
1147
- if (!text) return {};
1148
- try {
1149
- return JSON.parse(text);
1150
- } catch {
1151
- return {};
1152
- }
1153
- }
1154
- function formatDate$1(value) {
1155
- if (!value) return "";
1156
- const parsed = new Date(value);
1157
- if (Number.isNaN(parsed.getTime())) return value;
1158
- return parsed.toLocaleString();
1159
- }
1160
- function PayPalAuditLogsPage() {
1161
- const [logs, setLogs] = react.useState([]);
1162
- const [loading, setLoading] = react.useState(false);
1163
- const [error, setError] = react.useState(null);
1164
- const fetchLogs = react.useCallback(async () => {
1165
- try {
1166
- setLoading(true);
1167
- setError(null);
1168
- const data = await adminFetch$2("/admin/paypal/audit-logs", { query: { limit: "50" } });
1169
- setLogs((data == null ? void 0 : data.logs) ?? []);
1170
- } catch (fetchError) {
1171
- setError(fetchError instanceof Error ? fetchError.message : "Failed to load audit logs.");
1172
- setLogs([]);
1173
- } finally {
1174
- setLoading(false);
1175
- }
1176
- }, []);
1177
- react.useEffect(() => {
1178
- fetchLogs();
1179
- }, [fetchLogs]);
1180
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
1181
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1182
- /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Audit Logs" }),
1183
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-ui-fg-subtle", children: "Track administrative changes and credential events for PayPal configuration." })
1184
- ] }),
1185
- /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
1186
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
1187
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-b border-ui-border-base p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-4", children: [
1188
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: "Latest events" }),
1189
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: fetchLogs, className: "rounded-md border border-ui-border-base px-3 py-2 text-sm text-ui-fg-base", disabled: loading, children: loading ? "Refreshing..." : "Refresh" })
1190
- ] }) }),
1191
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-4", children: [
1192
- error ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-600", children: error }) : null,
1193
- !error && logs.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm text-ui-fg-subtle", children: loading ? "Loading audit logs..." : "No audit log entries found yet." }) : null,
1194
- logs.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full text-left text-sm", children: [
1195
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "text-ui-fg-muted", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1196
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "pb-2 pr-4 font-medium", children: "Timestamp" }),
1197
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "pb-2 pr-4 font-medium", children: "Event" }),
1198
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "pb-2 font-medium", children: "Details" })
1199
- ] }) }),
1200
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: logs.map((entry) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "border-t border-ui-border-base", children: [
1201
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "py-3 pr-4 text-ui-fg-base", children: formatDate$1(entry.created_at) || "—" }),
1202
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "py-3 pr-4 text-ui-fg-base", children: entry.event_type || "—" }),
1203
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "py-3 text-ui-fg-subtle", children: /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap rounded-md bg-ui-bg-subtle p-2 text-xs text-ui-fg-subtle", children: JSON.stringify(entry.metadata || {}, null, 2) }) })
1204
- ] }, entry.id)) })
1205
- ] }) }) : null
1206
- ] })
1207
- ] })
1208
- ] }) });
1209
- }
1210
- function PayPalGooglePayPage() {
955
+ function PayPalApplePayPage() {
1211
956
  return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
1212
957
  }
1213
958
  function PayPalPayLaterMessagingPage() {
1214
959
  return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
1215
960
  }
1216
- async function adminFetch$1(path, opts = {}) {
1217
- var _a;
1218
- const { method = "GET", body, query } = opts;
1219
- let url = path;
1220
- if (query && Object.keys(query).length > 0) {
1221
- const params = new URLSearchParams(query);
1222
- url = `${path}?${params.toString()}`;
1223
- }
1224
- const headers = { Accept: "application/json" };
1225
- if (body !== void 0) headers["Content-Type"] = "application/json";
1226
- if (typeof window !== "undefined") {
1227
- const token = (_a = window.__medusa__) == null ? void 0 : _a.token;
1228
- if (token) headers["Authorization"] = `Bearer ${token}`;
1229
- }
1230
- const res = await fetch(url, {
1231
- method,
1232
- headers,
1233
- credentials: "include",
1234
- body: body !== void 0 ? JSON.stringify(body) : void 0
1235
- });
1236
- const text = await res.text().catch(() => "");
1237
- if (!res.ok) {
1238
- if (res.status === 401) throw new Error("Unauthorized (401) - session may have expired. Please reload and log in again.");
1239
- if (res.status === 403) throw new Error("Forbidden (403) - you do not have permission to perform this action.");
1240
- throw new Error(text || `Request failed with status ${res.status}`);
1241
- }
1242
- if (!text) return {};
1243
- try {
1244
- return JSON.parse(text);
1245
- } catch {
1246
- return {};
1247
- }
1248
- }
1249
- function formatDate(value) {
1250
- if (!value) return "—";
1251
- const parsed = new Date(value);
1252
- if (Number.isNaN(parsed.getTime())) return value;
1253
- return parsed.toLocaleString();
1254
- }
1255
- function PayPalReconciliationStatusPage() {
1256
- const [status, setStatus] = react.useState({});
1257
- const [loading, setLoading] = react.useState(false);
1258
- const [error, setError] = react.useState(null);
1259
- const fetchStatus = react.useCallback(async () => {
1260
- try {
1261
- setLoading(true);
1262
- setError(null);
1263
- const data = await adminFetch$1("/admin/paypal/reconciliation-status");
1264
- setStatus((data == null ? void 0 : data.status) ?? {});
1265
- } catch (fetchError) {
1266
- setError(fetchError instanceof Error ? fetchError.message : "Failed to load reconciliation status.");
1267
- setStatus({});
1268
- } finally {
1269
- setLoading(false);
1270
- }
1271
- }, []);
1272
- react.useEffect(() => {
1273
- fetchStatus();
1274
- }, [fetchStatus]);
1275
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
1276
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1277
- /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Reconciliation Status" }),
1278
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-ui-fg-subtle", children: "Monitor reconciliation health and drift detection for PayPal payment sessions." })
1279
- ] }),
1280
- /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
1281
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
1282
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-b border-ui-border-base p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-4", children: [
1283
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: "Latest reconciliation run" }),
1284
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: fetchStatus, className: "rounded-md border border-ui-border-base px-3 py-2 text-sm text-ui-fg-base", disabled: loading, children: loading ? "Refreshing..." : "Refresh" })
1285
- ] }) }),
1286
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-4", children: [
1287
- error ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-600", children: error }) : null,
1288
- !error && Object.keys(status).length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm text-ui-fg-subtle", children: loading ? "Loading reconciliation status..." : "No reconciliation data yet." }) : null,
1289
- Object.keys(status).length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-4 text-sm text-ui-fg-base md:grid-cols-2", children: [
1290
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1291
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last run" }),
1292
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: formatDate(status.last_run_at) })
1293
- ] }),
1294
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1295
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last run status" }),
1296
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium capitalize", children: status.last_run_status || "—" })
1297
- ] }),
1298
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1299
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last success" }),
1300
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: formatDate(status.last_success_at) })
1301
- ] }),
1302
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1303
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last failure" }),
1304
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: formatDate(status.last_failure_at) })
1305
- ] }),
1306
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1307
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Sessions checked" }),
1308
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.sessions_checked ?? 0 })
1309
- ] }),
1310
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1311
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Sessions updated" }),
1312
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.sessions_updated ?? 0 })
1313
- ] }),
1314
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1315
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Drift detections" }),
1316
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.drift_count ?? 0 })
1317
- ] }),
1318
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1319
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last drift order" }),
1320
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.last_drift_order_id || "—" }),
1321
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 text-xs text-ui-fg-subtle", children: formatDate(status.last_drift_at) })
1322
- ] }),
1323
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3 md:col-span-2", children: [
1324
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last error" }),
1325
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.last_error || "No errors recorded." })
1326
- ] }),
1327
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3 md:col-span-2", children: [
1328
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Total runs" }),
1329
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.runs ?? 0 })
1330
- ] })
1331
- ] }) : null
1332
- ] })
1333
- ] })
1334
- ] }) });
1335
- }
1336
961
  async function adminFetch(path, opts = {}) {
1337
962
  var _a;
1338
963
  const { method = "GET", body, query } = opts;
@@ -1808,37 +1433,25 @@ const routeModule = {
1808
1433
  path: "/settings/paypal/additional-settings"
1809
1434
  },
1810
1435
  {
1811
- Component: AdvancedCardPaymentsTab,
1812
- path: "/settings/paypal/advanced-card-payments"
1436
+ Component: PayPalGooglePayPage,
1437
+ path: "/settings/paypal/google-pay"
1813
1438
  },
1814
1439
  {
1815
- Component: PayPalApplePayPage,
1816
- path: "/settings/paypal/apple-pay"
1440
+ Component: AdvancedCardPaymentsTab,
1441
+ path: "/settings/paypal/advanced-card-payments"
1817
1442
  },
1818
1443
  {
1819
1444
  Component: PayPalConnectionPage,
1820
1445
  path: "/settings/paypal/connection"
1821
1446
  },
1822
1447
  {
1823
- Component: PayPalDisputesPage,
1824
- path: "/settings/paypal/disputes"
1825
- },
1826
- {
1827
- Component: PayPalAuditLogsPage,
1828
- path: "/settings/paypal/audit-logs"
1829
- },
1830
- {
1831
- Component: PayPalGooglePayPage,
1832
- path: "/settings/paypal/google-pay"
1448
+ Component: PayPalApplePayPage,
1449
+ path: "/settings/paypal/apple-pay"
1833
1450
  },
1834
1451
  {
1835
1452
  Component: PayPalPayLaterMessagingPage,
1836
1453
  path: "/settings/paypal/pay-later-messaging"
1837
1454
  },
1838
- {
1839
- Component: PayPalReconciliationStatusPage,
1840
- path: "/settings/paypal/reconciliation-status"
1841
- },
1842
1455
  {
1843
1456
  Component: PayPalSettingsTab,
1844
1457
  path: "/settings/paypal/paypal-settings"