@easypayment/medusa-paypal 0.1.5 → 0.1.6

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 (32) hide show
  1. package/.medusa/server/src/admin/index.js +582 -582
  2. package/.medusa/server/src/admin/index.mjs +582 -582
  3. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
  4. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js +10 -33
  5. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js.map +1 -1
  6. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
  7. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js +10 -35
  8. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js.map +1 -1
  9. package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
  10. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +1 -1
  11. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
  12. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
  13. package/.medusa/server/src/modules/paypal/payment-provider/service.js +3 -16
  14. package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
  15. package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts +0 -5
  16. package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts.map +1 -1
  17. package/.medusa/server/src/modules/paypal/utils/provider-ids.js +1 -57
  18. package/.medusa/server/src/modules/paypal/utils/provider-ids.js.map +1 -1
  19. package/LICENSE +21 -21
  20. package/README.md +102 -102
  21. package/package.json +75 -76
  22. package/src/admin/routes/settings/paypal/page.tsx +17 -17
  23. package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +11 -39
  24. package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +12 -45
  25. package/src/index.ts +1 -1
  26. package/src/modules/paypal/payment-provider/card-service.ts +1 -1
  27. package/src/modules/paypal/payment-provider/service.ts +1016 -1036
  28. package/src/modules/paypal/utils/provider-ids.ts +0 -70
  29. package/src/providers/paypal/index.ts +10 -10
  30. package/src/providers/paypal_card/index.ts +10 -10
  31. package/tsconfig.json +30 -30
  32. package/postcss.config.cjs +0 -3
@@ -41,17 +41,11 @@ function PayPalTabs() {
41
41
  }) }) });
42
42
  }
43
43
  const DEFAULT_FORM$1 = {
44
- paymentAction: "capture",
45
- brandName: "PayPal",
46
- landingPage: "no_preference",
47
- requireInstantPayment: false,
48
- useShippingAsBilling: true,
49
- sendItemDetails: true,
50
- skipOrderReviewPage: true,
51
- invoicePrefix: "WC-",
52
- creditCardStatementName: "PayPal",
53
- enableLogging: true,
54
- logPath: "/uploads/wc-logs/"
44
+ enabled: true,
45
+ title: "Credit or Debit Card",
46
+ disabledCards: [],
47
+ threeDS: "when_required",
48
+ cardSaveEnabled: false
55
49
  };
56
50
  function mergeWithDefaults$1(saved) {
57
51
  if (!saved) return { ...DEFAULT_FORM$1 };
@@ -61,6 +55,53 @@ function mergeWithDefaults$1(saved) {
61
55
  ...Object.fromEntries(entries)
62
56
  };
63
57
  }
58
+ const CARD_BRANDS = [
59
+ { value: "visa", label: "Visa" },
60
+ { value: "mastercard", label: "Mastercard" },
61
+ { value: "amex", label: "American Express" },
62
+ { value: "discover", label: "Discover" },
63
+ { value: "diners", label: "Diners Club" },
64
+ { value: "jcb", label: "JCB" },
65
+ { value: "unionpay", label: "UnionPay" }
66
+ ];
67
+ const THREE_DS_OPTIONS = [
68
+ {
69
+ value: "when_required",
70
+ label: "3D Secure when required",
71
+ hint: "Triggers 3DS only when the card / issuer requires it."
72
+ },
73
+ {
74
+ value: "sli",
75
+ label: "3D Secure (SCA) / liability shift (recommended)",
76
+ hint: "Attempts to optimize for liability shift while remaining compliant."
77
+ },
78
+ {
79
+ value: "always",
80
+ label: "Always request 3D Secure",
81
+ hint: "Forces 3DS challenge whenever possible (may reduce conversion)."
82
+ }
83
+ ];
84
+ function cx$1(...parts) {
85
+ return parts.filter(Boolean).join(" ");
86
+ }
87
+ function Pill$1({
88
+ children,
89
+ onRemove
90
+ }) {
91
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1 rounded-md border border-ui-border-base bg-ui-bg-base px-2 py-1 text-sm text-ui-fg-base", children: [
92
+ children,
93
+ onRemove ? /* @__PURE__ */ jsxRuntime.jsx(
94
+ "button",
95
+ {
96
+ type: "button",
97
+ onClick: onRemove,
98
+ className: "ml-1 rounded px-1 text-ui-fg-subtle hover:text-ui-fg-base",
99
+ "aria-label": "Remove",
100
+ children: "×"
101
+ }
102
+ ) : null
103
+ ] });
104
+ }
64
105
  function SectionCard$2({
65
106
  title,
66
107
  description,
@@ -91,10 +132,12 @@ function FieldRow$2({
91
132
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12 md:col-span-8", children })
92
133
  ] });
93
134
  }
94
- function AdditionalSettingsTab() {
135
+ function AdvancedCardPaymentsTab() {
136
+ var _a, _b;
95
137
  const [form, setForm] = react.useState(() => ({ ...DEFAULT_FORM$1 }));
96
138
  const [loading, setLoading] = react.useState(false);
97
139
  const [saving, setSaving] = react.useState(false);
140
+ const [toast, setToast] = react.useState(null);
98
141
  const didInit = react.useRef(false);
99
142
  react.useEffect(() => {
100
143
  if (didInit.current) return;
@@ -109,7 +152,7 @@ function AdditionalSettingsTab() {
109
152
  if (!r.ok) return;
110
153
  const json = await r.json();
111
154
  const payload = (json == null ? void 0 : json.data) ?? json;
112
- const saved = payload == null ? void 0 : payload.additional_settings;
155
+ const saved = payload == null ? void 0 : payload.advanced_card_payments;
113
156
  if (saved && typeof saved === "object") {
114
157
  setForm(mergeWithDefaults$1(saved));
115
158
  }
@@ -118,11 +161,9 @@ function AdditionalSettingsTab() {
118
161
  }
119
162
  })();
120
163
  }, []);
121
- const [toast, setToast] = react.useState(null);
122
164
  async function onSave() {
123
165
  try {
124
166
  setSaving(true);
125
- setToast(null);
126
167
  const r = await fetch("/admin/paypal/settings", {
127
168
  method: "POST",
128
169
  credentials: "include",
@@ -130,29 +171,42 @@ function AdditionalSettingsTab() {
130
171
  "Content-Type": "application/json",
131
172
  "Accept": "application/json"
132
173
  },
133
- body: JSON.stringify({
134
- additional_settings: form
135
- })
174
+ body: JSON.stringify({ advanced_card_payments: form })
136
175
  });
137
176
  if (!r.ok) {
138
- const errText = await r.text().catch(() => "");
139
- throw new Error(errText || "Failed to save settings");
177
+ const t = await r.text();
178
+ setToast({ type: "error", message: "Failed to save settings. " + t });
179
+ window.setTimeout(() => setToast(null), 3500);
180
+ return;
140
181
  }
141
- const json = await r.json().catch(() => ({}));
182
+ const json = await r.json().catch(() => null);
142
183
  const payload = (json == null ? void 0 : json.data) ?? json;
143
- const saved = payload == null ? void 0 : payload.additional_settings;
184
+ const saved = payload == null ? void 0 : payload.advanced_card_payments;
144
185
  if (saved && typeof saved === "object") {
145
186
  setForm(mergeWithDefaults$1(saved));
146
187
  }
147
188
  setToast({ type: "success", message: "Settings saved" });
148
189
  window.setTimeout(() => setToast(null), 2500);
149
- } catch (e) {
150
- setToast({ type: "error", message: (e == null ? void 0 : e.message) || "Failed to save settings" });
151
- window.setTimeout(() => setToast(null), 3500);
152
190
  } finally {
153
191
  setSaving(false);
154
192
  }
155
193
  }
194
+ const disabledSet = react.useMemo(() => new Set(form.disabledCards), [form.disabledCards]);
195
+ function toggleDisabledCard(value) {
196
+ setForm((prev) => {
197
+ const exists = prev.disabledCards.includes(value);
198
+ return {
199
+ ...prev,
200
+ disabledCards: exists ? prev.disabledCards.filter((v) => v !== value) : [...prev.disabledCards, value]
201
+ };
202
+ });
203
+ }
204
+ function removeDisabledCard(value) {
205
+ setForm((prev) => ({
206
+ ...prev,
207
+ disabledCards: prev.disabledCards.filter((v) => v !== value)
208
+ }));
209
+ }
156
210
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
157
211
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-start justify-between gap-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Gateway By Easy Payment" }) }) }),
158
212
  /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
@@ -168,8 +222,8 @@ function AdditionalSettingsTab() {
168
222
  /* @__PURE__ */ jsxRuntime.jsx(
169
223
  SectionCard$2,
170
224
  {
171
- title: "Additional Settings",
172
- description: "These settings control checkout behavior, PayPal experience, and logging.",
225
+ title: "Advanced Card Payments",
226
+ description: "Control card checkout settings, 3D Secure behavior, and card saving.",
173
227
  right: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
174
228
  /* @__PURE__ */ jsxRuntime.jsx(
175
229
  "button",
@@ -184,161 +238,102 @@ function AdditionalSettingsTab() {
184
238
  loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading…" }) : null
185
239
  ] }),
186
240
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y divide-ui-border-base", children: [
187
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Payment action", children: /* @__PURE__ */ jsxRuntime.jsxs(
188
- "select",
189
- {
190
- value: form.paymentAction,
191
- onChange: (e) => setForm((p) => ({ ...p, paymentAction: e.target.value })),
192
- 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",
193
- children: [
194
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "capture", children: "Capture" }),
195
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorize", children: "Authorize" })
196
- ]
197
- }
198
- ) }),
199
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Brand Name", children: /* @__PURE__ */ jsxRuntime.jsx(
200
- "input",
201
- {
202
- value: form.brandName,
203
- onChange: (e) => setForm((p) => ({ ...p, brandName: e.target.value })),
204
- 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",
205
- placeholder: "PayPal"
206
- }
207
- ) }),
208
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Landing Page", children: /* @__PURE__ */ jsxRuntime.jsxs(
209
- "select",
210
- {
211
- value: form.landingPage,
212
- onChange: (e) => setForm((p) => ({ ...p, landingPage: e.target.value })),
213
- 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",
214
- children: [
215
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "no_preference", children: "No Preference" }),
216
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "login", children: "Login" }),
217
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "billing", children: "Billing" })
218
- ]
219
- }
220
- ) }),
221
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Instant Payments", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
241
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Enable/Disable", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
222
242
  /* @__PURE__ */ jsxRuntime.jsx(
223
243
  "input",
224
244
  {
225
245
  type: "checkbox",
226
- checked: form.requireInstantPayment,
227
- onChange: (e) => setForm((p) => ({ ...p, requireInstantPayment: e.target.checked })),
246
+ checked: form.enabled,
247
+ onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })),
228
248
  className: "h-4 w-4 rounded border-ui-border-base"
229
249
  }
230
250
  ),
231
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Require Instant Payment" })
251
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
232
252
  ] }) }),
233
- /* @__PURE__ */ jsxRuntime.jsx(
234
- FieldRow$2,
253
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Title", children: /* @__PURE__ */ jsxRuntime.jsx(
254
+ "input",
235
255
  {
236
- label: "Billing Address",
237
- hint: "If the billing address is empty and PayPal provides a shipping address, the order will use the shipping address as the billing address.",
238
- children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
239
- /* @__PURE__ */ jsxRuntime.jsx(
240
- "input",
241
- {
242
- type: "checkbox",
243
- checked: form.useShippingAsBilling,
244
- onChange: (e) => setForm((p) => ({ ...p, useShippingAsBilling: e.target.checked })),
245
- className: "h-4 w-4 rounded border-ui-border-base"
246
- }
247
- ),
248
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Use PayPal Shipping Address as Billing" })
249
- ] })
256
+ value: form.title,
257
+ onChange: (e) => setForm((p) => ({ ...p, title: e.target.value })),
258
+ 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",
259
+ placeholder: "Credit or Debit Card"
250
260
  }
251
- ),
261
+ ) }),
252
262
  /* @__PURE__ */ jsxRuntime.jsx(
253
263
  FieldRow$2,
254
264
  {
255
- label: "Send Item Details",
256
- hint: "Include all line item details in the payment request to PayPal so that they can be seen from the PayPal transaction details page.",
257
- children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
258
- /* @__PURE__ */ jsxRuntime.jsx(
259
- "input",
260
- {
261
- type: "checkbox",
262
- checked: form.sendItemDetails,
263
- onChange: (e) => setForm((p) => ({ ...p, sendItemDetails: e.target.checked })),
264
- className: "h-4 w-4 rounded border-ui-border-base"
265
- }
266
- ),
267
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Send line item details to PayPal" })
265
+ label: "Disable specific credit cards",
266
+ hint: "Select card brands to hide from the card form.",
267
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
268
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: form.disabledCards.length ? form.disabledCards.map((v) => {
269
+ var _a2;
270
+ const label = ((_a2 = CARD_BRANDS.find((b) => b.value === v)) == null ? void 0 : _a2.label) ?? v;
271
+ return /* @__PURE__ */ jsxRuntime.jsx(Pill$1, { onRemove: () => removeDisabledCard(v), children: label }, v);
272
+ }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "No card brands disabled." }) }),
273
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md border border-ui-border-base p-3", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid gap-2 md:grid-cols-2", children: CARD_BRANDS.map((b) => {
274
+ const checked = disabledSet.has(b.value);
275
+ return /* @__PURE__ */ jsxRuntime.jsxs(
276
+ "label",
277
+ {
278
+ className: cx$1(
279
+ "flex items-center gap-2 rounded-md p-2",
280
+ "hover:bg-ui-bg-subtle"
281
+ ),
282
+ children: [
283
+ /* @__PURE__ */ jsxRuntime.jsx(
284
+ "input",
285
+ {
286
+ type: "checkbox",
287
+ checked,
288
+ onChange: () => toggleDisabledCard(b.value),
289
+ className: "h-4 w-4 rounded border-ui-border-base"
290
+ }
291
+ ),
292
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: b.label })
293
+ ]
294
+ },
295
+ b.value
296
+ );
297
+ }) }) })
268
298
  ] })
269
299
  }
270
300
  ),
271
301
  /* @__PURE__ */ jsxRuntime.jsx(
272
302
  FieldRow$2,
273
303
  {
274
- label: "Order Review Page",
275
- hint: "Payments from the Product or Cart page skip the review step and go straight to the Thank You page.",
276
- children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
304
+ label: "Contingency for 3D Secure",
305
+ hint: "Choose when 3D Secure should be triggered during card payments.",
306
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
277
307
  /* @__PURE__ */ jsxRuntime.jsx(
278
- "input",
308
+ "select",
279
309
  {
280
- type: "checkbox",
281
- checked: form.skipOrderReviewPage,
282
- onChange: (e) => setForm((p) => ({ ...p, skipOrderReviewPage: e.target.checked })),
283
- className: "h-4 w-4 rounded border-ui-border-base"
310
+ value: form.threeDS,
311
+ onChange: (e) => setForm((p) => ({ ...p, threeDS: e.target.value })),
312
+ 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",
313
+ children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o.value, children: o.label }, o.value))
284
314
  }
285
315
  ),
286
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Skip Order Review Page" })
316
+ ((_a = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _a.hint) ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-ui-fg-subtle", children: (_b = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _b.hint }) : null
287
317
  ] })
288
318
  }
289
319
  ),
290
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Invoice prefix", children: /* @__PURE__ */ jsxRuntime.jsx(
291
- "input",
292
- {
293
- value: form.invoicePrefix,
294
- onChange: (e) => setForm((p) => ({ ...p, invoicePrefix: e.target.value })),
295
- 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",
296
- placeholder: "WC-"
297
- }
298
- ) }),
299
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Credit Card Statement Name", children: /* @__PURE__ */ jsxRuntime.jsx(
300
- "input",
301
- {
302
- value: form.creditCardStatementName,
303
- onChange: (e) => setForm((p) => ({ ...p, creditCardStatementName: e.target.value })),
304
- 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",
305
- placeholder: "PayPal"
306
- }
307
- ) }),
308
- /* @__PURE__ */ jsxRuntime.jsx(
309
- FieldRow$2,
310
- {
311
- label: "Debug log",
312
- hint: /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
313
- "Log PayPal events such as Webhook, Payment, Refund.",
314
- " ",
315
- form.logPath ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
316
- "Log location: ",
317
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono", children: form.logPath })
318
- ] }) : null
319
- ] }),
320
- children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
321
- /* @__PURE__ */ jsxRuntime.jsx(
322
- "input",
323
- {
324
- type: "checkbox",
325
- checked: form.enableLogging,
326
- onChange: (e) => setForm((p) => ({ ...p, enableLogging: e.target.checked })),
327
- className: "h-4 w-4 rounded border-ui-border-base"
328
- }
329
- ),
330
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable logging" })
331
- ] })
332
- }
333
- )
320
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$2, { label: "Card Save Enabled", hint: "Allow customers to save a card at checkout for future use.", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
321
+ /* @__PURE__ */ jsxRuntime.jsx(
322
+ "input",
323
+ {
324
+ type: "checkbox",
325
+ checked: form.cardSaveEnabled,
326
+ onChange: (e) => setForm((p) => ({ ...p, cardSaveEnabled: e.target.checked })),
327
+ className: "h-4 w-4 rounded border-ui-border-base"
328
+ }
329
+ ),
330
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable card saving at checkout" })
331
+ ] }) })
334
332
  ] })
335
333
  }
336
334
  )
337
335
  ] }) });
338
336
  }
339
- function PayPalApplePayPage() {
340
- return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
341
- }
342
337
  const config = adminSdk.defineRouteConfig({
343
338
  label: "PayPal Connection",
344
339
  hide: true
@@ -923,6 +918,12 @@ function PayPalConnectionPage() {
923
918
  ` })
924
919
  ] });
925
920
  }
921
+ const EMPTY_FILTERS = {
922
+ dispute_id: "",
923
+ status: "",
924
+ order_id: "",
925
+ cart_id: ""
926
+ };
926
927
  function formatDate$2(value) {
927
928
  if (!value) {
928
929
  return "";
@@ -933,6 +934,195 @@ function formatDate$2(value) {
933
934
  }
934
935
  return parsed.toLocaleString();
935
936
  }
937
+ function PayPalDisputesPage() {
938
+ const [filters, setFilters] = react.useState({ ...EMPTY_FILTERS });
939
+ const [disputes, setDisputes] = react.useState([]);
940
+ const [loading, setLoading] = react.useState(false);
941
+ const [error, setError] = react.useState(null);
942
+ const queryString = react.useMemo(() => {
943
+ const params = new URLSearchParams();
944
+ Object.entries(filters).forEach(([key, value]) => {
945
+ if (value.trim()) {
946
+ params.set(key, value.trim());
947
+ }
948
+ });
949
+ const qs = params.toString();
950
+ return qs ? `?${qs}` : "";
951
+ }, [filters]);
952
+ const fetchDisputes = react.useCallback(async (source) => {
953
+ try {
954
+ setLoading(true);
955
+ setError(null);
956
+ const params = new URLSearchParams();
957
+ Object.entries(source).forEach(([key, value]) => {
958
+ if (value.trim()) {
959
+ params.set(key, value.trim());
960
+ }
961
+ });
962
+ const qs = params.toString();
963
+ const resp = await fetch(`/admin/paypal/disputes${qs ? `?${qs}` : ""}`, {
964
+ credentials: "include",
965
+ headers: {
966
+ Accept: "application/json"
967
+ }
968
+ });
969
+ if (!resp.ok) {
970
+ const message = await resp.text().catch(() => "");
971
+ throw new Error(message || "Failed to load disputes");
972
+ }
973
+ const json = await resp.json().catch(() => ({}));
974
+ setDisputes((json == null ? void 0 : json.disputes) || []);
975
+ } catch (fetchError) {
976
+ setError((fetchError == null ? void 0 : fetchError.message) || "Failed to load disputes");
977
+ setDisputes([]);
978
+ } finally {
979
+ setLoading(false);
980
+ }
981
+ }, []);
982
+ react.useEffect(() => {
983
+ fetchDisputes(EMPTY_FILTERS);
984
+ }, [fetchDisputes]);
985
+ const onSubmit = (event) => {
986
+ event.preventDefault();
987
+ fetchDisputes(filters);
988
+ };
989
+ const onReset = () => {
990
+ setFilters({ ...EMPTY_FILTERS });
991
+ fetchDisputes(EMPTY_FILTERS);
992
+ };
993
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
994
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
995
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Disputes" }),
996
+ /* @__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." })
997
+ ] }),
998
+ /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
999
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
1000
+ /* @__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" }) }),
1001
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, className: "flex flex-col gap-4", children: [
1002
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-4", children: [
1003
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1004
+ "Dispute ID",
1005
+ /* @__PURE__ */ jsxRuntime.jsx(
1006
+ "input",
1007
+ {
1008
+ className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base",
1009
+ value: filters.dispute_id,
1010
+ onChange: (event) => setFilters((prev) => ({ ...prev, dispute_id: event.target.value })),
1011
+ placeholder: "PP-D-123"
1012
+ }
1013
+ )
1014
+ ] }),
1015
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1016
+ "Status",
1017
+ /* @__PURE__ */ jsxRuntime.jsx(
1018
+ "input",
1019
+ {
1020
+ className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base",
1021
+ value: filters.status,
1022
+ onChange: (event) => setFilters((prev) => ({ ...prev, status: event.target.value })),
1023
+ placeholder: "OPEN"
1024
+ }
1025
+ )
1026
+ ] }),
1027
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1028
+ "Order ID",
1029
+ /* @__PURE__ */ jsxRuntime.jsx(
1030
+ "input",
1031
+ {
1032
+ className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base",
1033
+ value: filters.order_id,
1034
+ onChange: (event) => setFilters((prev) => ({ ...prev, order_id: event.target.value })),
1035
+ placeholder: "order_..."
1036
+ }
1037
+ )
1038
+ ] }),
1039
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1040
+ "Cart ID",
1041
+ /* @__PURE__ */ jsxRuntime.jsx(
1042
+ "input",
1043
+ {
1044
+ className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base",
1045
+ value: filters.cart_id,
1046
+ onChange: (event) => setFilters((prev) => ({ ...prev, cart_id: event.target.value })),
1047
+ placeholder: "cart_..."
1048
+ }
1049
+ )
1050
+ ] })
1051
+ ] }),
1052
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-3", children: [
1053
+ /* @__PURE__ */ jsxRuntime.jsx(
1054
+ "button",
1055
+ {
1056
+ type: "submit",
1057
+ className: "rounded-md bg-ui-fg-base px-4 py-2 text-sm font-medium text-ui-bg-base",
1058
+ disabled: loading,
1059
+ children: loading ? "Loading..." : "Apply filters"
1060
+ }
1061
+ ),
1062
+ /* @__PURE__ */ jsxRuntime.jsx(
1063
+ "button",
1064
+ {
1065
+ type: "button",
1066
+ className: "rounded-md border border-ui-border-base px-4 py-2 text-sm text-ui-fg-base",
1067
+ onClick: onReset,
1068
+ disabled: loading,
1069
+ children: "Reset"
1070
+ }
1071
+ ),
1072
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-sm text-ui-fg-subtle", children: [
1073
+ "Showing ",
1074
+ disputes.length,
1075
+ " dispute",
1076
+ disputes.length === 1 ? "" : "s",
1077
+ queryString ? " (filtered)" : ""
1078
+ ] })
1079
+ ] })
1080
+ ] }) })
1081
+ ] }),
1082
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
1083
+ /* @__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" }) }),
1084
+ /* @__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: [
1085
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "text-left text-ui-fg-subtle", children: [
1086
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Dispute" }),
1087
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Status" }),
1088
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Reason" }),
1089
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Stage" }),
1090
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Amount" }),
1091
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Order" }),
1092
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Cart" }),
1093
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Updated" })
1094
+ ] }) }),
1095
+ /* @__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: [
1096
+ /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-3", children: [
1097
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium text-ui-fg-base", children: dispute.dispute_id }),
1098
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-ui-fg-subtle", children: dispute.transaction_id || "No transaction" })
1099
+ ] }),
1100
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.status || "Unknown" }),
1101
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.reason || "-" }),
1102
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.stage || "-" }),
1103
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.amount ? `${dispute.amount} ${dispute.currency_code || ""}` : "-" }),
1104
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.order_id || "-" }),
1105
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.cart_id || "-" }),
1106
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3 text-ui-fg-subtle", children: formatDate$2(dispute.updated_at || dispute.created_at) })
1107
+ ] }, dispute.id)) })
1108
+ ] }) }),
1109
+ 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
1110
+ ] })
1111
+ ] }) });
1112
+ }
1113
+ function PayPalApplePayPage() {
1114
+ return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
1115
+ }
1116
+ function formatDate$1(value) {
1117
+ if (!value) {
1118
+ return "";
1119
+ }
1120
+ const parsed = new Date(value);
1121
+ if (Number.isNaN(parsed.getTime())) {
1122
+ return value;
1123
+ }
1124
+ return parsed.toLocaleString();
1125
+ }
936
1126
  function PayPalAuditLogsPage() {
937
1127
  const [logs, setLogs] = react.useState([]);
938
1128
  const [loading, setLoading] = react.useState(false);
@@ -993,7 +1183,7 @@ function PayPalAuditLogsPage() {
993
1183
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "pb-2 font-medium", children: "Details" })
994
1184
  ] }) }),
995
1185
  /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: logs.map((entry) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "border-t border-ui-border-base", children: [
996
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "py-3 pr-4 text-ui-fg-base", children: formatDate$2(entry.created_at) || "—" }),
1186
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "py-3 pr-4 text-ui-fg-base", children: formatDate$1(entry.created_at) || "—" }),
997
1187
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "py-3 pr-4 text-ui-fg-base", children: entry.event_type || "—" }),
998
1188
  /* @__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) }) })
999
1189
  ] }, entry.id)) })
@@ -1002,12 +1192,21 @@ function PayPalAuditLogsPage() {
1002
1192
  ] })
1003
1193
  ] }) });
1004
1194
  }
1195
+ function PayPalGooglePayPage() {
1196
+ return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
1197
+ }
1005
1198
  const DEFAULT_FORM = {
1006
- enabled: true,
1007
- title: "Credit or Debit Card",
1008
- disabledCards: [],
1009
- threeDS: "when_required",
1010
- cardSaveEnabled: false
1199
+ paymentAction: "capture",
1200
+ brandName: "PayPal",
1201
+ landingPage: "no_preference",
1202
+ requireInstantPayment: false,
1203
+ useShippingAsBilling: true,
1204
+ sendItemDetails: true,
1205
+ skipOrderReviewPage: true,
1206
+ invoicePrefix: "WC-",
1207
+ creditCardStatementName: "PayPal",
1208
+ enableLogging: true,
1209
+ logPath: "/uploads/wc-logs/"
1011
1210
  };
1012
1211
  function mergeWithDefaults(saved) {
1013
1212
  if (!saved) return { ...DEFAULT_FORM };
@@ -1017,53 +1216,6 @@ function mergeWithDefaults(saved) {
1017
1216
  ...Object.fromEntries(entries)
1018
1217
  };
1019
1218
  }
1020
- const CARD_BRANDS = [
1021
- { value: "visa", label: "Visa" },
1022
- { value: "mastercard", label: "Mastercard" },
1023
- { value: "amex", label: "American Express" },
1024
- { value: "discover", label: "Discover" },
1025
- { value: "diners", label: "Diners Club" },
1026
- { value: "jcb", label: "JCB" },
1027
- { value: "unionpay", label: "UnionPay" }
1028
- ];
1029
- const THREE_DS_OPTIONS = [
1030
- {
1031
- value: "when_required",
1032
- label: "3D Secure when required",
1033
- hint: "Triggers 3DS only when the card / issuer requires it."
1034
- },
1035
- {
1036
- value: "sli",
1037
- label: "3D Secure (SCA) / liability shift (recommended)",
1038
- hint: "Attempts to optimize for liability shift while remaining compliant."
1039
- },
1040
- {
1041
- value: "always",
1042
- label: "Always request 3D Secure",
1043
- hint: "Forces 3DS challenge whenever possible (may reduce conversion)."
1044
- }
1045
- ];
1046
- function cx$1(...parts) {
1047
- return parts.filter(Boolean).join(" ");
1048
- }
1049
- function Pill$1({
1050
- children,
1051
- onRemove
1052
- }) {
1053
- return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1 rounded-md border border-ui-border-base bg-ui-bg-base px-2 py-1 text-sm text-ui-fg-base", children: [
1054
- children,
1055
- onRemove ? /* @__PURE__ */ jsxRuntime.jsx(
1056
- "button",
1057
- {
1058
- type: "button",
1059
- onClick: onRemove,
1060
- className: "ml-1 rounded px-1 text-ui-fg-subtle hover:text-ui-fg-base",
1061
- "aria-label": "Remove",
1062
- children: "×"
1063
- }
1064
- ) : null
1065
- ] });
1066
- }
1067
1219
  function SectionCard$1({
1068
1220
  title,
1069
1221
  description,
@@ -1094,12 +1246,10 @@ function FieldRow$1({
1094
1246
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12 md:col-span-8", children })
1095
1247
  ] });
1096
1248
  }
1097
- function AdvancedCardPaymentsTab() {
1098
- var _a, _b;
1249
+ function AdditionalSettingsTab() {
1099
1250
  const [form, setForm] = react.useState(() => ({ ...DEFAULT_FORM }));
1100
1251
  const [loading, setLoading] = react.useState(false);
1101
1252
  const [saving, setSaving] = react.useState(false);
1102
- const [toast, setToast] = react.useState(null);
1103
1253
  const didInit = react.useRef(false);
1104
1254
  react.useEffect(() => {
1105
1255
  if (didInit.current) return;
@@ -1114,7 +1264,7 @@ function AdvancedCardPaymentsTab() {
1114
1264
  if (!r.ok) return;
1115
1265
  const json = await r.json();
1116
1266
  const payload = (json == null ? void 0 : json.data) ?? json;
1117
- const saved = payload == null ? void 0 : payload.advanced_card_payments;
1267
+ const saved = payload == null ? void 0 : payload.additional_settings;
1118
1268
  if (saved && typeof saved === "object") {
1119
1269
  setForm(mergeWithDefaults(saved));
1120
1270
  }
@@ -1123,9 +1273,11 @@ function AdvancedCardPaymentsTab() {
1123
1273
  }
1124
1274
  })();
1125
1275
  }, []);
1276
+ const [toast, setToast] = react.useState(null);
1126
1277
  async function onSave() {
1127
1278
  try {
1128
1279
  setSaving(true);
1280
+ setToast(null);
1129
1281
  const r = await fetch("/admin/paypal/settings", {
1130
1282
  method: "POST",
1131
1283
  credentials: "include",
@@ -1133,42 +1285,29 @@ function AdvancedCardPaymentsTab() {
1133
1285
  "Content-Type": "application/json",
1134
1286
  "Accept": "application/json"
1135
1287
  },
1136
- body: JSON.stringify({ advanced_card_payments: form })
1288
+ body: JSON.stringify({
1289
+ additional_settings: form
1290
+ })
1137
1291
  });
1138
1292
  if (!r.ok) {
1139
- const t = await r.text();
1140
- setToast({ type: "error", message: "Failed to save settings. " + t });
1141
- window.setTimeout(() => setToast(null), 3500);
1142
- return;
1293
+ const errText = await r.text().catch(() => "");
1294
+ throw new Error(errText || "Failed to save settings");
1143
1295
  }
1144
- const json = await r.json().catch(() => null);
1296
+ const json = await r.json().catch(() => ({}));
1145
1297
  const payload = (json == null ? void 0 : json.data) ?? json;
1146
- const saved = payload == null ? void 0 : payload.advanced_card_payments;
1298
+ const saved = payload == null ? void 0 : payload.additional_settings;
1147
1299
  if (saved && typeof saved === "object") {
1148
1300
  setForm(mergeWithDefaults(saved));
1149
1301
  }
1150
1302
  setToast({ type: "success", message: "Settings saved" });
1151
1303
  window.setTimeout(() => setToast(null), 2500);
1304
+ } catch (e) {
1305
+ setToast({ type: "error", message: (e == null ? void 0 : e.message) || "Failed to save settings" });
1306
+ window.setTimeout(() => setToast(null), 3500);
1152
1307
  } finally {
1153
1308
  setSaving(false);
1154
1309
  }
1155
1310
  }
1156
- const disabledSet = react.useMemo(() => new Set(form.disabledCards), [form.disabledCards]);
1157
- function toggleDisabledCard(value) {
1158
- setForm((prev) => {
1159
- const exists = prev.disabledCards.includes(value);
1160
- return {
1161
- ...prev,
1162
- disabledCards: exists ? prev.disabledCards.filter((v) => v !== value) : [...prev.disabledCards, value]
1163
- };
1164
- });
1165
- }
1166
- function removeDisabledCard(value) {
1167
- setForm((prev) => ({
1168
- ...prev,
1169
- disabledCards: prev.disabledCards.filter((v) => v !== value)
1170
- }));
1171
- }
1172
1311
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
1173
1312
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-start justify-between gap-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Gateway By Easy Payment" }) }) }),
1174
1313
  /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
@@ -1184,8 +1323,8 @@ function AdvancedCardPaymentsTab() {
1184
1323
  /* @__PURE__ */ jsxRuntime.jsx(
1185
1324
  SectionCard$1,
1186
1325
  {
1187
- title: "Advanced Card Payments",
1188
- description: "Control card checkout settings, 3D Secure behavior, and card saving.",
1326
+ title: "Additional Settings",
1327
+ description: "These settings control checkout behavior, PayPal experience, and logging.",
1189
1328
  right: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
1190
1329
  /* @__PURE__ */ jsxRuntime.jsx(
1191
1330
  "button",
@@ -1200,114 +1339,161 @@ function AdvancedCardPaymentsTab() {
1200
1339
  loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading…" }) : null
1201
1340
  ] }),
1202
1341
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y divide-ui-border-base", children: [
1203
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Enable/Disable", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
1342
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Payment action", children: /* @__PURE__ */ jsxRuntime.jsxs(
1343
+ "select",
1344
+ {
1345
+ value: form.paymentAction,
1346
+ onChange: (e) => setForm((p) => ({ ...p, paymentAction: e.target.value })),
1347
+ 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",
1348
+ children: [
1349
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "capture", children: "Capture" }),
1350
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorize", children: "Authorize" })
1351
+ ]
1352
+ }
1353
+ ) }),
1354
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Brand Name", children: /* @__PURE__ */ jsxRuntime.jsx(
1355
+ "input",
1356
+ {
1357
+ value: form.brandName,
1358
+ onChange: (e) => setForm((p) => ({ ...p, brandName: e.target.value })),
1359
+ 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",
1360
+ placeholder: "PayPal"
1361
+ }
1362
+ ) }),
1363
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Landing Page", children: /* @__PURE__ */ jsxRuntime.jsxs(
1364
+ "select",
1365
+ {
1366
+ value: form.landingPage,
1367
+ onChange: (e) => setForm((p) => ({ ...p, landingPage: e.target.value })),
1368
+ 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",
1369
+ children: [
1370
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "no_preference", children: "No Preference" }),
1371
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "login", children: "Login" }),
1372
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "billing", children: "Billing" })
1373
+ ]
1374
+ }
1375
+ ) }),
1376
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Instant Payments", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
1204
1377
  /* @__PURE__ */ jsxRuntime.jsx(
1205
1378
  "input",
1206
1379
  {
1207
1380
  type: "checkbox",
1208
- checked: form.enabled,
1209
- onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })),
1381
+ checked: form.requireInstantPayment,
1382
+ onChange: (e) => setForm((p) => ({ ...p, requireInstantPayment: e.target.checked })),
1210
1383
  className: "h-4 w-4 rounded border-ui-border-base"
1211
1384
  }
1212
1385
  ),
1213
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
1386
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Require Instant Payment" })
1214
1387
  ] }) }),
1215
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Title", children: /* @__PURE__ */ jsxRuntime.jsx(
1216
- "input",
1388
+ /* @__PURE__ */ jsxRuntime.jsx(
1389
+ FieldRow$1,
1217
1390
  {
1218
- value: form.title,
1219
- onChange: (e) => setForm((p) => ({ ...p, title: e.target.value })),
1220
- 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",
1221
- placeholder: "Credit or Debit Card"
1391
+ label: "Billing Address",
1392
+ hint: "If the billing address is empty and PayPal provides a shipping address, the order will use the shipping address as the billing address.",
1393
+ children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
1394
+ /* @__PURE__ */ jsxRuntime.jsx(
1395
+ "input",
1396
+ {
1397
+ type: "checkbox",
1398
+ checked: form.useShippingAsBilling,
1399
+ onChange: (e) => setForm((p) => ({ ...p, useShippingAsBilling: e.target.checked })),
1400
+ className: "h-4 w-4 rounded border-ui-border-base"
1401
+ }
1402
+ ),
1403
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Use PayPal Shipping Address as Billing" })
1404
+ ] })
1222
1405
  }
1223
- ) }),
1406
+ ),
1224
1407
  /* @__PURE__ */ jsxRuntime.jsx(
1225
1408
  FieldRow$1,
1226
1409
  {
1227
- label: "Disable specific credit cards",
1228
- hint: "Select card brands to hide from the card form.",
1229
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
1230
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: form.disabledCards.length ? form.disabledCards.map((v) => {
1231
- var _a2;
1232
- const label = ((_a2 = CARD_BRANDS.find((b) => b.value === v)) == null ? void 0 : _a2.label) ?? v;
1233
- return /* @__PURE__ */ jsxRuntime.jsx(Pill$1, { onRemove: () => removeDisabledCard(v), children: label }, v);
1234
- }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "No card brands disabled." }) }),
1235
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md border border-ui-border-base p-3", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid gap-2 md:grid-cols-2", children: CARD_BRANDS.map((b) => {
1236
- const checked = disabledSet.has(b.value);
1237
- return /* @__PURE__ */ jsxRuntime.jsxs(
1238
- "label",
1239
- {
1240
- className: cx$1(
1241
- "flex items-center gap-2 rounded-md p-2",
1242
- "hover:bg-ui-bg-subtle"
1243
- ),
1244
- children: [
1245
- /* @__PURE__ */ jsxRuntime.jsx(
1246
- "input",
1247
- {
1248
- type: "checkbox",
1249
- checked,
1250
- onChange: () => toggleDisabledCard(b.value),
1251
- className: "h-4 w-4 rounded border-ui-border-base"
1252
- }
1253
- ),
1254
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: b.label })
1255
- ]
1256
- },
1257
- b.value
1258
- );
1259
- }) }) })
1410
+ label: "Send Item Details",
1411
+ hint: "Include all line item details in the payment request to PayPal so that they can be seen from the PayPal transaction details page.",
1412
+ children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
1413
+ /* @__PURE__ */ jsxRuntime.jsx(
1414
+ "input",
1415
+ {
1416
+ type: "checkbox",
1417
+ checked: form.sendItemDetails,
1418
+ onChange: (e) => setForm((p) => ({ ...p, sendItemDetails: e.target.checked })),
1419
+ className: "h-4 w-4 rounded border-ui-border-base"
1420
+ }
1421
+ ),
1422
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Send line item details to PayPal" })
1260
1423
  ] })
1261
1424
  }
1262
1425
  ),
1263
1426
  /* @__PURE__ */ jsxRuntime.jsx(
1264
1427
  FieldRow$1,
1265
1428
  {
1266
- label: "Contingency for 3D Secure",
1267
- hint: "Choose when 3D Secure should be triggered during card payments.",
1268
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
1429
+ label: "Order Review Page",
1430
+ hint: "Payments from the Product or Cart page skip the review step and go straight to the Thank You page.",
1431
+ children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
1269
1432
  /* @__PURE__ */ jsxRuntime.jsx(
1270
- "select",
1433
+ "input",
1271
1434
  {
1272
- value: form.threeDS,
1273
- onChange: (e) => setForm((p) => ({ ...p, threeDS: e.target.value })),
1274
- 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",
1275
- children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o.value, children: o.label }, o.value))
1435
+ type: "checkbox",
1436
+ checked: form.skipOrderReviewPage,
1437
+ onChange: (e) => setForm((p) => ({ ...p, skipOrderReviewPage: e.target.checked })),
1438
+ className: "h-4 w-4 rounded border-ui-border-base"
1276
1439
  }
1277
1440
  ),
1278
- ((_a = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _a.hint) ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-ui-fg-subtle", children: (_b = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _b.hint }) : null
1441
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Skip Order Review Page" })
1279
1442
  ] })
1280
1443
  }
1281
1444
  ),
1282
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Card Save Enabled", hint: "Allow customers to save a card at checkout for future use.", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
1283
- /* @__PURE__ */ jsxRuntime.jsx(
1284
- "input",
1285
- {
1286
- type: "checkbox",
1287
- checked: form.cardSaveEnabled,
1288
- onChange: (e) => setForm((p) => ({ ...p, cardSaveEnabled: e.target.checked })),
1289
- className: "h-4 w-4 rounded border-ui-border-base"
1290
- }
1291
- ),
1292
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable card saving at checkout" })
1293
- ] }) })
1445
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Invoice prefix", children: /* @__PURE__ */ jsxRuntime.jsx(
1446
+ "input",
1447
+ {
1448
+ value: form.invoicePrefix,
1449
+ onChange: (e) => setForm((p) => ({ ...p, invoicePrefix: e.target.value })),
1450
+ 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",
1451
+ placeholder: "WC-"
1452
+ }
1453
+ ) }),
1454
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Credit Card Statement Name", children: /* @__PURE__ */ jsxRuntime.jsx(
1455
+ "input",
1456
+ {
1457
+ value: form.creditCardStatementName,
1458
+ onChange: (e) => setForm((p) => ({ ...p, creditCardStatementName: e.target.value })),
1459
+ 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",
1460
+ placeholder: "PayPal"
1461
+ }
1462
+ ) }),
1463
+ /* @__PURE__ */ jsxRuntime.jsx(
1464
+ FieldRow$1,
1465
+ {
1466
+ label: "Debug log",
1467
+ hint: /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
1468
+ "Log PayPal events such as Webhook, Payment, Refund.",
1469
+ " ",
1470
+ form.logPath ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1471
+ "Log location: ",
1472
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono", children: form.logPath })
1473
+ ] }) : null
1474
+ ] }),
1475
+ children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
1476
+ /* @__PURE__ */ jsxRuntime.jsx(
1477
+ "input",
1478
+ {
1479
+ type: "checkbox",
1480
+ checked: form.enableLogging,
1481
+ onChange: (e) => setForm((p) => ({ ...p, enableLogging: e.target.checked })),
1482
+ className: "h-4 w-4 rounded border-ui-border-base"
1483
+ }
1484
+ ),
1485
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable logging" })
1486
+ ] })
1487
+ }
1488
+ )
1294
1489
  ] })
1295
1490
  }
1296
1491
  )
1297
1492
  ] }) });
1298
1493
  }
1299
- function PayPalGooglePayPage() {
1300
- return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
1301
- }
1302
- const EMPTY_FILTERS = {
1303
- dispute_id: "",
1304
- status: "",
1305
- order_id: "",
1306
- cart_id: ""
1307
- };
1308
- function formatDate$1(value) {
1494
+ function formatDate(value) {
1309
1495
  if (!value) {
1310
- return "";
1496
+ return "";
1311
1497
  }
1312
1498
  const parsed = new Date(value);
1313
1499
  if (Number.isNaN(parsed.getTime())) {
@@ -1315,179 +1501,103 @@ function formatDate$1(value) {
1315
1501
  }
1316
1502
  return parsed.toLocaleString();
1317
1503
  }
1318
- function PayPalDisputesPage() {
1319
- const [filters, setFilters] = react.useState({ ...EMPTY_FILTERS });
1320
- const [disputes, setDisputes] = react.useState([]);
1504
+ function PayPalReconciliationStatusPage() {
1505
+ const [status, setStatus] = react.useState({});
1321
1506
  const [loading, setLoading] = react.useState(false);
1322
1507
  const [error, setError] = react.useState(null);
1323
- const queryString = react.useMemo(() => {
1324
- const params = new URLSearchParams();
1325
- Object.entries(filters).forEach(([key, value]) => {
1326
- if (value.trim()) {
1327
- params.set(key, value.trim());
1328
- }
1329
- });
1330
- const qs = params.toString();
1331
- return qs ? `?${qs}` : "";
1332
- }, [filters]);
1333
- const fetchDisputes = react.useCallback(async (source) => {
1508
+ const fetchStatus = react.useCallback(async () => {
1334
1509
  try {
1335
1510
  setLoading(true);
1336
1511
  setError(null);
1337
- const params = new URLSearchParams();
1338
- Object.entries(source).forEach(([key, value]) => {
1339
- if (value.trim()) {
1340
- params.set(key, value.trim());
1341
- }
1342
- });
1343
- const qs = params.toString();
1344
- const resp = await fetch(`/admin/paypal/disputes${qs ? `?${qs}` : ""}`, {
1512
+ const response = await fetch("/admin/paypal/reconciliation-status", {
1345
1513
  credentials: "include",
1346
1514
  headers: {
1347
1515
  Accept: "application/json"
1348
1516
  }
1349
1517
  });
1350
- if (!resp.ok) {
1351
- const message = await resp.text().catch(() => "");
1352
- throw new Error(message || "Failed to load disputes");
1518
+ if (!response.ok) {
1519
+ const message = await response.text().catch(() => "");
1520
+ throw new Error(message || "Failed to load reconciliation status.");
1353
1521
  }
1354
- const json = await resp.json().catch(() => ({}));
1355
- setDisputes((json == null ? void 0 : json.disputes) || []);
1522
+ const data = await response.json().catch(() => ({}));
1523
+ setStatus((data == null ? void 0 : data.status) || {});
1356
1524
  } catch (fetchError) {
1357
- setError((fetchError == null ? void 0 : fetchError.message) || "Failed to load disputes");
1358
- setDisputes([]);
1525
+ setError((fetchError == null ? void 0 : fetchError.message) || "Failed to load reconciliation status.");
1526
+ setStatus({});
1359
1527
  } finally {
1360
1528
  setLoading(false);
1361
1529
  }
1362
1530
  }, []);
1363
1531
  react.useEffect(() => {
1364
- fetchDisputes(EMPTY_FILTERS);
1365
- }, [fetchDisputes]);
1366
- const onSubmit = (event) => {
1367
- event.preventDefault();
1368
- fetchDisputes(filters);
1369
- };
1370
- const onReset = () => {
1371
- setFilters({ ...EMPTY_FILTERS });
1372
- fetchDisputes(EMPTY_FILTERS);
1373
- };
1532
+ fetchStatus();
1533
+ }, [fetchStatus]);
1374
1534
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
1375
1535
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1376
- /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Disputes" }),
1377
- /* @__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." })
1536
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Reconciliation Status" }),
1537
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-ui-fg-subtle", children: "Monitor reconciliation health and drift detection for PayPal payment sessions." })
1378
1538
  ] }),
1379
1539
  /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
1380
1540
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
1381
- /* @__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" }) }),
1382
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit, className: "flex flex-col gap-4", children: [
1383
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-4", children: [
1384
- /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1385
- "Dispute ID",
1386
- /* @__PURE__ */ jsxRuntime.jsx(
1387
- "input",
1388
- {
1389
- className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base",
1390
- value: filters.dispute_id,
1391
- onChange: (event) => setFilters((prev) => ({ ...prev, dispute_id: event.target.value })),
1392
- placeholder: "PP-D-123"
1393
- }
1394
- )
1541
+ /* @__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: [
1542
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: "Latest reconciliation run" }),
1543
+ /* @__PURE__ */ jsxRuntime.jsx(
1544
+ "button",
1545
+ {
1546
+ type: "button",
1547
+ onClick: fetchStatus,
1548
+ className: "rounded-md border border-ui-border-base px-3 py-2 text-sm text-ui-fg-base",
1549
+ disabled: loading,
1550
+ children: loading ? "Refreshing..." : "Refresh"
1551
+ }
1552
+ )
1553
+ ] }) }),
1554
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-4", children: [
1555
+ 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,
1556
+ !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,
1557
+ Object.keys(status).length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-4 text-sm text-ui-fg-base md:grid-cols-2", children: [
1558
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1559
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last run" }),
1560
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: formatDate(status.last_run_at) })
1561
+ ] }),
1562
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1563
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last run status" }),
1564
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium capitalize", children: status.last_run_status || "—" })
1565
+ ] }),
1566
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1567
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last success" }),
1568
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: formatDate(status.last_success_at) })
1569
+ ] }),
1570
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1571
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last failure" }),
1572
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: formatDate(status.last_failure_at) })
1573
+ ] }),
1574
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1575
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Sessions checked" }),
1576
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.sessions_checked ?? 0 })
1395
1577
  ] }),
1396
- /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1397
- "Status",
1398
- /* @__PURE__ */ jsxRuntime.jsx(
1399
- "input",
1400
- {
1401
- className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base",
1402
- value: filters.status,
1403
- onChange: (event) => setFilters((prev) => ({ ...prev, status: event.target.value })),
1404
- placeholder: "OPEN"
1405
- }
1406
- )
1578
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1579
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Sessions updated" }),
1580
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.sessions_updated ?? 0 })
1407
1581
  ] }),
1408
- /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1409
- "Order ID",
1410
- /* @__PURE__ */ jsxRuntime.jsx(
1411
- "input",
1412
- {
1413
- className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base",
1414
- value: filters.order_id,
1415
- onChange: (event) => setFilters((prev) => ({ ...prev, order_id: event.target.value })),
1416
- placeholder: "order_..."
1417
- }
1418
- )
1582
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1583
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Drift detections" }),
1584
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.drift_count ?? 0 })
1419
1585
  ] }),
1420
- /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex flex-col gap-1 text-sm text-ui-fg-subtle", children: [
1421
- "Cart ID",
1422
- /* @__PURE__ */ jsxRuntime.jsx(
1423
- "input",
1424
- {
1425
- className: "rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base",
1426
- value: filters.cart_id,
1427
- onChange: (event) => setFilters((prev) => ({ ...prev, cart_id: event.target.value })),
1428
- placeholder: "cart_..."
1429
- }
1430
- )
1431
- ] })
1432
- ] }),
1433
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-3", children: [
1434
- /* @__PURE__ */ jsxRuntime.jsx(
1435
- "button",
1436
- {
1437
- type: "submit",
1438
- className: "rounded-md bg-ui-fg-base px-4 py-2 text-sm font-medium text-ui-bg-base",
1439
- disabled: loading,
1440
- children: loading ? "Loading..." : "Apply filters"
1441
- }
1442
- ),
1443
- /* @__PURE__ */ jsxRuntime.jsx(
1444
- "button",
1445
- {
1446
- type: "button",
1447
- className: "rounded-md border border-ui-border-base px-4 py-2 text-sm text-ui-fg-base",
1448
- onClick: onReset,
1449
- disabled: loading,
1450
- children: "Reset"
1451
- }
1452
- ),
1453
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-sm text-ui-fg-subtle", children: [
1454
- "Showing ",
1455
- disputes.length,
1456
- " dispute",
1457
- disputes.length === 1 ? "" : "s",
1458
- queryString ? " (filtered)" : ""
1459
- ] })
1460
- ] })
1461
- ] }) })
1462
- ] }),
1463
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
1464
- /* @__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" }) }),
1465
- /* @__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: [
1466
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "text-left text-ui-fg-subtle", children: [
1467
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Dispute" }),
1468
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Status" }),
1469
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Reason" }),
1470
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Stage" }),
1471
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Amount" }),
1472
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Order" }),
1473
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Cart" }),
1474
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 font-medium", children: "Updated" })
1475
- ] }) }),
1476
- /* @__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: [
1477
- /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-3", children: [
1478
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium text-ui-fg-base", children: dispute.dispute_id }),
1479
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-ui-fg-subtle", children: dispute.transaction_id || "No transaction" })
1586
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1587
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last drift order" }),
1588
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.last_drift_order_id || "—" }),
1589
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 text-xs text-ui-fg-subtle", children: formatDate(status.last_drift_at) })
1480
1590
  ] }),
1481
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.status || "Unknown" }),
1482
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.reason || "-" }),
1483
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.stage || "-" }),
1484
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.amount ? `${dispute.amount} ${dispute.currency_code || ""}` : "-" }),
1485
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.order_id || "-" }),
1486
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3", children: dispute.cart_id || "-" }),
1487
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-3 text-ui-fg-subtle", children: formatDate$1(dispute.updated_at || dispute.created_at) })
1488
- ] }, dispute.id)) })
1489
- ] }) }),
1490
- 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
1591
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3 md:col-span-2", children: [
1592
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last error" }),
1593
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.last_error || "No errors recorded." })
1594
+ ] }),
1595
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3 md:col-span-2", children: [
1596
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Total runs" }),
1597
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.runs ?? 0 })
1598
+ ] })
1599
+ ] }) : null
1600
+ ] })
1491
1601
  ] })
1492
1602
  ] }) });
1493
1603
  }
@@ -1931,116 +2041,6 @@ function PayPalSettingsTab() {
1931
2041
  )
1932
2042
  ] }) });
1933
2043
  }
1934
- function formatDate(value) {
1935
- if (!value) {
1936
- return "—";
1937
- }
1938
- const parsed = new Date(value);
1939
- if (Number.isNaN(parsed.getTime())) {
1940
- return value;
1941
- }
1942
- return parsed.toLocaleString();
1943
- }
1944
- function PayPalReconciliationStatusPage() {
1945
- const [status, setStatus] = react.useState({});
1946
- const [loading, setLoading] = react.useState(false);
1947
- const [error, setError] = react.useState(null);
1948
- const fetchStatus = react.useCallback(async () => {
1949
- try {
1950
- setLoading(true);
1951
- setError(null);
1952
- const response = await fetch("/admin/paypal/reconciliation-status", {
1953
- credentials: "include",
1954
- headers: {
1955
- Accept: "application/json"
1956
- }
1957
- });
1958
- if (!response.ok) {
1959
- const message = await response.text().catch(() => "");
1960
- throw new Error(message || "Failed to load reconciliation status.");
1961
- }
1962
- const data = await response.json().catch(() => ({}));
1963
- setStatus((data == null ? void 0 : data.status) || {});
1964
- } catch (fetchError) {
1965
- setError((fetchError == null ? void 0 : fetchError.message) || "Failed to load reconciliation status.");
1966
- setStatus({});
1967
- } finally {
1968
- setLoading(false);
1969
- }
1970
- }, []);
1971
- react.useEffect(() => {
1972
- fetchStatus();
1973
- }, [fetchStatus]);
1974
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
1975
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1976
- /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Reconciliation Status" }),
1977
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-ui-fg-subtle", children: "Monitor reconciliation health and drift detection for PayPal payment sessions." })
1978
- ] }),
1979
- /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
1980
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
1981
- /* @__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: [
1982
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: "Latest reconciliation run" }),
1983
- /* @__PURE__ */ jsxRuntime.jsx(
1984
- "button",
1985
- {
1986
- type: "button",
1987
- onClick: fetchStatus,
1988
- className: "rounded-md border border-ui-border-base px-3 py-2 text-sm text-ui-fg-base",
1989
- disabled: loading,
1990
- children: loading ? "Refreshing..." : "Refresh"
1991
- }
1992
- )
1993
- ] }) }),
1994
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-4", children: [
1995
- 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,
1996
- !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,
1997
- Object.keys(status).length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-4 text-sm text-ui-fg-base md:grid-cols-2", children: [
1998
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
1999
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last run" }),
2000
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: formatDate(status.last_run_at) })
2001
- ] }),
2002
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
2003
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last run status" }),
2004
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium capitalize", children: status.last_run_status || "—" })
2005
- ] }),
2006
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
2007
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last success" }),
2008
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: formatDate(status.last_success_at) })
2009
- ] }),
2010
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
2011
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last failure" }),
2012
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: formatDate(status.last_failure_at) })
2013
- ] }),
2014
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
2015
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Sessions checked" }),
2016
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.sessions_checked ?? 0 })
2017
- ] }),
2018
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
2019
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Sessions updated" }),
2020
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.sessions_updated ?? 0 })
2021
- ] }),
2022
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
2023
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Drift detections" }),
2024
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.drift_count ?? 0 })
2025
- ] }),
2026
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3", children: [
2027
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last drift order" }),
2028
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.last_drift_order_id || "—" }),
2029
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 text-xs text-ui-fg-subtle", children: formatDate(status.last_drift_at) })
2030
- ] }),
2031
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3 md:col-span-2", children: [
2032
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Last error" }),
2033
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.last_error || "No errors recorded." })
2034
- ] }),
2035
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3 md:col-span-2", children: [
2036
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ui-fg-subtle", children: "Total runs" }),
2037
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 font-medium", children: status.runs ?? 0 })
2038
- ] })
2039
- ] }) : null
2040
- ] })
2041
- ] })
2042
- ] }) });
2043
- }
2044
2044
  const widgetModule = { widgets: [] };
2045
2045
  const routeModule = {
2046
2046
  routes: [
@@ -2049,32 +2049,36 @@ const routeModule = {
2049
2049
  path: "/settings/paypal"
2050
2050
  },
2051
2051
  {
2052
- Component: AdditionalSettingsTab,
2053
- path: "/settings/paypal/additional-settings"
2054
- },
2055
- {
2056
- Component: PayPalApplePayPage,
2057
- path: "/settings/paypal/apple-pay"
2052
+ Component: AdvancedCardPaymentsTab,
2053
+ path: "/settings/paypal/advanced-card-payments"
2058
2054
  },
2059
2055
  {
2060
2056
  Component: PayPalConnectionPage,
2061
2057
  path: "/settings/paypal/connection"
2062
2058
  },
2063
2059
  {
2064
- Component: PayPalAuditLogsPage,
2065
- path: "/settings/paypal/audit-logs"
2060
+ Component: PayPalDisputesPage,
2061
+ path: "/settings/paypal/disputes"
2066
2062
  },
2067
2063
  {
2068
- Component: AdvancedCardPaymentsTab,
2069
- path: "/settings/paypal/advanced-card-payments"
2064
+ Component: PayPalApplePayPage,
2065
+ path: "/settings/paypal/apple-pay"
2066
+ },
2067
+ {
2068
+ Component: PayPalAuditLogsPage,
2069
+ path: "/settings/paypal/audit-logs"
2070
2070
  },
2071
2071
  {
2072
2072
  Component: PayPalGooglePayPage,
2073
2073
  path: "/settings/paypal/google-pay"
2074
2074
  },
2075
2075
  {
2076
- Component: PayPalDisputesPage,
2077
- path: "/settings/paypal/disputes"
2076
+ Component: AdditionalSettingsTab,
2077
+ path: "/settings/paypal/additional-settings"
2078
+ },
2079
+ {
2080
+ Component: PayPalReconciliationStatusPage,
2081
+ path: "/settings/paypal/reconciliation-status"
2078
2082
  },
2079
2083
  {
2080
2084
  Component: PayPalPayLaterMessagingPage,
@@ -2083,10 +2087,6 @@ const routeModule = {
2083
2087
  {
2084
2088
  Component: PayPalSettingsTab,
2085
2089
  path: "/settings/paypal/paypal-settings"
2086
- },
2087
- {
2088
- Component: PayPalReconciliationStatusPage,
2089
- path: "/settings/paypal/reconciliation-status"
2090
2090
  }
2091
2091
  ]
2092
2092
  };