@easypayment/medusa-payment-paypal 0.7.8 → 0.8.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.
@@ -180,6 +180,148 @@ function AdditionalSettingsTab() {
180
180
  )
181
181
  ] }) });
182
182
  }
183
+ function PayPalApplePayPage() {
184
+ return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
185
+ }
186
+ async function adminFetch$1(path, opts = {}) {
187
+ var _a;
188
+ const { method = "GET", body, query } = opts;
189
+ let url = path;
190
+ if (query && Object.keys(query).length > 0) {
191
+ const params = new URLSearchParams(query);
192
+ url = `${path}?${params.toString()}`;
193
+ }
194
+ const headers = { Accept: "application/json" };
195
+ if (body !== void 0) headers["Content-Type"] = "application/json";
196
+ if (typeof window !== "undefined") {
197
+ const token = (_a = window.__medusa__) == null ? void 0 : _a.token;
198
+ if (token) headers["Authorization"] = `Bearer ${token}`;
199
+ }
200
+ const res = await fetch(url, {
201
+ method,
202
+ headers,
203
+ credentials: "include",
204
+ body: body !== void 0 ? JSON.stringify(body) : void 0
205
+ });
206
+ const text = await res.text().catch(() => "");
207
+ if (!res.ok) {
208
+ if (res.status === 401) throw new Error("Unauthorized (401) - session may have expired. Please reload and log in again.");
209
+ if (res.status === 403) throw new Error("Forbidden (403) - you do not have permission to perform this action.");
210
+ throw new Error(text || `Request failed with status ${res.status}`);
211
+ }
212
+ if (!text) return {};
213
+ try {
214
+ return JSON.parse(text);
215
+ } catch {
216
+ return {};
217
+ }
218
+ }
219
+ const DEFAULT_FORM = {
220
+ enabled: true,
221
+ title: "Credit or Debit Card",
222
+ threeDS: "when_required"
223
+ };
224
+ function mergeWithDefaults(saved) {
225
+ if (!saved) return { ...DEFAULT_FORM };
226
+ const entries = Object.entries(saved).filter(([, value]) => value !== void 0);
227
+ return { ...DEFAULT_FORM, ...Object.fromEntries(entries) };
228
+ }
229
+ const THREE_DS_OPTIONS = [
230
+ { value: "when_required", label: "3D Secure when required", hint: "Triggers 3DS only when the card / issuer requires it." },
231
+ { value: "sli", label: "3D Secure (SCA) / liability shift (recommended)", hint: "Attempts to optimize for liability shift while remaining compliant." },
232
+ { value: "always", label: "Always request 3D Secure", hint: "Forces 3DS challenge whenever possible (may reduce conversion)." }
233
+ ];
234
+ function SectionCard$1({ title, description, right, children }) {
235
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
236
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-4 border-b border-ui-border-base p-4", children: [
237
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
238
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: title }),
239
+ description ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 text-sm text-ui-fg-subtle", children: description }) : null
240
+ ] }),
241
+ right
242
+ ] }),
243
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children })
244
+ ] });
245
+ }
246
+ function FieldRow$1({ label, hint, children }) {
247
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 items-start gap-4 py-3", children: [
248
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
249
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-ui-fg-base", children: label }),
250
+ hint ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 text-xs text-ui-fg-subtle", children: hint }) : null
251
+ ] }),
252
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12 md:col-span-8", children })
253
+ ] });
254
+ }
255
+ function AdvancedCardPaymentsTab() {
256
+ var _a, _b;
257
+ const [form, setForm] = react.useState(() => ({ ...DEFAULT_FORM }));
258
+ const [loading, setLoading] = react.useState(false);
259
+ const [saving, setSaving] = react.useState(false);
260
+ const [toast, setToast] = react.useState(null);
261
+ const didInit = react.useRef(false);
262
+ react.useEffect(() => {
263
+ if (didInit.current) return;
264
+ didInit.current = true;
265
+ (async () => {
266
+ try {
267
+ setLoading(true);
268
+ const json = await adminFetch$1("/admin/paypal/settings");
269
+ const payload = (json == null ? void 0 : json.data) ?? json;
270
+ const saved = payload == null ? void 0 : payload.advanced_card_payments;
271
+ if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
272
+ } catch {
273
+ } finally {
274
+ setLoading(false);
275
+ }
276
+ })();
277
+ }, []);
278
+ async function onSave() {
279
+ try {
280
+ setSaving(true);
281
+ const json = await adminFetch$1("/admin/paypal/settings", {
282
+ method: "POST",
283
+ body: { advanced_card_payments: form }
284
+ });
285
+ const payload = (json == null ? void 0 : json.data) ?? json;
286
+ const saved = payload == null ? void 0 : payload.advanced_card_payments;
287
+ if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
288
+ setToast({ type: "success", message: "Settings saved" });
289
+ window.setTimeout(() => setToast(null), 2500);
290
+ } catch (e) {
291
+ setToast({ type: "error", message: (e instanceof Error ? e.message : "") || "Failed to save settings." });
292
+ window.setTimeout(() => setToast(null), 3500);
293
+ } finally {
294
+ setSaving(false);
295
+ }
296
+ }
297
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
298
+ /* @__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" }) }) }),
299
+ /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
300
+ toast ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "fixed right-6 top-6 z-50 rounded-md border border-ui-border-base bg-ui-bg-base px-4 py-3 text-sm shadow-lg", role: "status", "aria-live": "polite", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: toast.type === "success" ? "text-ui-fg-base" : "text-ui-fg-error", children: toast.message }) }) : null,
301
+ /* @__PURE__ */ jsxRuntime.jsx(
302
+ SectionCard$1,
303
+ {
304
+ title: "Advanced Card Payments",
305
+ description: "Control card checkout settings and 3D Secure behavior.",
306
+ right: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
307
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onSave, disabled: saving || loading, className: "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5", children: saving ? "Saving..." : "Save settings" }),
308
+ loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading..." }) : null
309
+ ] }),
310
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y divide-ui-border-base", children: [
311
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Enable/Disable", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
312
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "checkbox", checked: form.enabled, onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })), className: "h-4 w-4 rounded border-ui-border-base" }),
313
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
314
+ ] }) }),
315
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Title", children: /* @__PURE__ */ jsxRuntime.jsx("input", { value: form.title, onChange: (e) => setForm((p) => ({ ...p, title: 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: "Credit or Debit Card" }) }),
316
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Contingency for 3D Secure", hint: "Choose when 3D Secure should be triggered during card payments.", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
317
+ /* @__PURE__ */ jsxRuntime.jsx("select", { value: form.threeDS, onChange: (e) => setForm((p) => ({ ...p, threeDS: 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", children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o.value, children: o.label }, o.value)) }),
318
+ ((_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
319
+ ] }) })
320
+ ] })
321
+ }
322
+ )
323
+ ] }) });
324
+ }
183
325
  const config = adminSdk.defineRouteConfig({
184
326
  label: "PayPal Connection",
185
327
  hide: true
@@ -773,148 +915,6 @@ function PayPalConnectionPage() {
773
915
  ` })
774
916
  ] });
775
917
  }
776
- async function adminFetch$1(path, opts = {}) {
777
- var _a;
778
- const { method = "GET", body, query } = opts;
779
- let url = path;
780
- if (query && Object.keys(query).length > 0) {
781
- const params = new URLSearchParams(query);
782
- url = `${path}?${params.toString()}`;
783
- }
784
- const headers = { Accept: "application/json" };
785
- if (body !== void 0) headers["Content-Type"] = "application/json";
786
- if (typeof window !== "undefined") {
787
- const token = (_a = window.__medusa__) == null ? void 0 : _a.token;
788
- if (token) headers["Authorization"] = `Bearer ${token}`;
789
- }
790
- const res = await fetch(url, {
791
- method,
792
- headers,
793
- credentials: "include",
794
- body: body !== void 0 ? JSON.stringify(body) : void 0
795
- });
796
- const text = await res.text().catch(() => "");
797
- if (!res.ok) {
798
- if (res.status === 401) throw new Error("Unauthorized (401) - session may have expired. Please reload and log in again.");
799
- if (res.status === 403) throw new Error("Forbidden (403) - you do not have permission to perform this action.");
800
- throw new Error(text || `Request failed with status ${res.status}`);
801
- }
802
- if (!text) return {};
803
- try {
804
- return JSON.parse(text);
805
- } catch {
806
- return {};
807
- }
808
- }
809
- const DEFAULT_FORM = {
810
- enabled: true,
811
- title: "Credit or Debit Card",
812
- threeDS: "when_required"
813
- };
814
- function mergeWithDefaults(saved) {
815
- if (!saved) return { ...DEFAULT_FORM };
816
- const entries = Object.entries(saved).filter(([, value]) => value !== void 0);
817
- return { ...DEFAULT_FORM, ...Object.fromEntries(entries) };
818
- }
819
- const THREE_DS_OPTIONS = [
820
- { value: "when_required", label: "3D Secure when required", hint: "Triggers 3DS only when the card / issuer requires it." },
821
- { value: "sli", label: "3D Secure (SCA) / liability shift (recommended)", hint: "Attempts to optimize for liability shift while remaining compliant." },
822
- { value: "always", label: "Always request 3D Secure", hint: "Forces 3DS challenge whenever possible (may reduce conversion)." }
823
- ];
824
- function SectionCard$1({ title, description, right, children }) {
825
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
826
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-4 border-b border-ui-border-base p-4", children: [
827
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
828
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: title }),
829
- description ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 text-sm text-ui-fg-subtle", children: description }) : null
830
- ] }),
831
- right
832
- ] }),
833
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children })
834
- ] });
835
- }
836
- function FieldRow$1({ label, hint, children }) {
837
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 items-start gap-4 py-3", children: [
838
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
839
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-ui-fg-base", children: label }),
840
- hint ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 text-xs text-ui-fg-subtle", children: hint }) : null
841
- ] }),
842
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12 md:col-span-8", children })
843
- ] });
844
- }
845
- function AdvancedCardPaymentsTab() {
846
- var _a, _b;
847
- const [form, setForm] = react.useState(() => ({ ...DEFAULT_FORM }));
848
- const [loading, setLoading] = react.useState(false);
849
- const [saving, setSaving] = react.useState(false);
850
- const [toast, setToast] = react.useState(null);
851
- const didInit = react.useRef(false);
852
- react.useEffect(() => {
853
- if (didInit.current) return;
854
- didInit.current = true;
855
- (async () => {
856
- try {
857
- setLoading(true);
858
- const json = await adminFetch$1("/admin/paypal/settings");
859
- const payload = (json == null ? void 0 : json.data) ?? json;
860
- const saved = payload == null ? void 0 : payload.advanced_card_payments;
861
- if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
862
- } catch {
863
- } finally {
864
- setLoading(false);
865
- }
866
- })();
867
- }, []);
868
- async function onSave() {
869
- try {
870
- setSaving(true);
871
- const json = await adminFetch$1("/admin/paypal/settings", {
872
- method: "POST",
873
- body: { advanced_card_payments: form }
874
- });
875
- const payload = (json == null ? void 0 : json.data) ?? json;
876
- const saved = payload == null ? void 0 : payload.advanced_card_payments;
877
- if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
878
- setToast({ type: "success", message: "Settings saved" });
879
- window.setTimeout(() => setToast(null), 2500);
880
- } catch (e) {
881
- setToast({ type: "error", message: (e instanceof Error ? e.message : "") || "Failed to save settings." });
882
- window.setTimeout(() => setToast(null), 3500);
883
- } finally {
884
- setSaving(false);
885
- }
886
- }
887
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
888
- /* @__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" }) }) }),
889
- /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
890
- toast ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "fixed right-6 top-6 z-50 rounded-md border border-ui-border-base bg-ui-bg-base px-4 py-3 text-sm shadow-lg", role: "status", "aria-live": "polite", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: toast.type === "success" ? "text-ui-fg-base" : "text-ui-fg-error", children: toast.message }) }) : null,
891
- /* @__PURE__ */ jsxRuntime.jsx(
892
- SectionCard$1,
893
- {
894
- title: "Advanced Card Payments",
895
- description: "Control card checkout settings and 3D Secure behavior.",
896
- right: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
897
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onSave, disabled: saving || loading, className: "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5", children: saving ? "Saving..." : "Save settings" }),
898
- loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading..." }) : null
899
- ] }),
900
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y divide-ui-border-base", children: [
901
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Enable/Disable", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
902
- /* @__PURE__ */ jsxRuntime.jsx("input", { type: "checkbox", checked: form.enabled, onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })), className: "h-4 w-4 rounded border-ui-border-base" }),
903
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
904
- ] }) }),
905
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Title", children: /* @__PURE__ */ jsxRuntime.jsx("input", { value: form.title, onChange: (e) => setForm((p) => ({ ...p, title: 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: "Credit or Debit Card" }) }),
906
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow$1, { label: "Contingency for 3D Secure", hint: "Choose when 3D Secure should be triggered during card payments.", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
907
- /* @__PURE__ */ jsxRuntime.jsx("select", { value: form.threeDS, onChange: (e) => setForm((p) => ({ ...p, threeDS: 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", children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o.value, children: o.label }, o.value)) }),
908
- ((_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
909
- ] }) })
910
- ] })
911
- }
912
- )
913
- ] }) });
914
- }
915
- function PayPalApplePayPage() {
916
- return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
917
- }
918
918
  function PayPalGooglePayPage() {
919
919
  return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
920
920
  }
@@ -1206,16 +1206,16 @@ const routeModule = {
1206
1206
  path: "/settings/paypal/additional-settings"
1207
1207
  },
1208
1208
  {
1209
- Component: PayPalConnectionPage,
1210
- path: "/settings/paypal/connection"
1209
+ Component: PayPalApplePayPage,
1210
+ path: "/settings/paypal/apple-pay"
1211
1211
  },
1212
1212
  {
1213
1213
  Component: AdvancedCardPaymentsTab,
1214
1214
  path: "/settings/paypal/advanced-card-payments"
1215
1215
  },
1216
1216
  {
1217
- Component: PayPalApplePayPage,
1218
- path: "/settings/paypal/apple-pay"
1217
+ Component: PayPalConnectionPage,
1218
+ path: "/settings/paypal/connection"
1219
1219
  },
1220
1220
  {
1221
1221
  Component: PayPalGooglePayPage,
@@ -179,6 +179,148 @@ function AdditionalSettingsTab() {
179
179
  )
180
180
  ] }) });
181
181
  }
182
+ function PayPalApplePayPage() {
183
+ return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
184
+ }
185
+ async function adminFetch$1(path, opts = {}) {
186
+ var _a;
187
+ const { method = "GET", body, query } = opts;
188
+ let url = path;
189
+ if (query && Object.keys(query).length > 0) {
190
+ const params = new URLSearchParams(query);
191
+ url = `${path}?${params.toString()}`;
192
+ }
193
+ const headers = { Accept: "application/json" };
194
+ if (body !== void 0) headers["Content-Type"] = "application/json";
195
+ if (typeof window !== "undefined") {
196
+ const token = (_a = window.__medusa__) == null ? void 0 : _a.token;
197
+ if (token) headers["Authorization"] = `Bearer ${token}`;
198
+ }
199
+ const res = await fetch(url, {
200
+ method,
201
+ headers,
202
+ credentials: "include",
203
+ body: body !== void 0 ? JSON.stringify(body) : void 0
204
+ });
205
+ const text = await res.text().catch(() => "");
206
+ if (!res.ok) {
207
+ if (res.status === 401) throw new Error("Unauthorized (401) - session may have expired. Please reload and log in again.");
208
+ if (res.status === 403) throw new Error("Forbidden (403) - you do not have permission to perform this action.");
209
+ throw new Error(text || `Request failed with status ${res.status}`);
210
+ }
211
+ if (!text) return {};
212
+ try {
213
+ return JSON.parse(text);
214
+ } catch {
215
+ return {};
216
+ }
217
+ }
218
+ const DEFAULT_FORM = {
219
+ enabled: true,
220
+ title: "Credit or Debit Card",
221
+ threeDS: "when_required"
222
+ };
223
+ function mergeWithDefaults(saved) {
224
+ if (!saved) return { ...DEFAULT_FORM };
225
+ const entries = Object.entries(saved).filter(([, value]) => value !== void 0);
226
+ return { ...DEFAULT_FORM, ...Object.fromEntries(entries) };
227
+ }
228
+ const THREE_DS_OPTIONS = [
229
+ { value: "when_required", label: "3D Secure when required", hint: "Triggers 3DS only when the card / issuer requires it." },
230
+ { value: "sli", label: "3D Secure (SCA) / liability shift (recommended)", hint: "Attempts to optimize for liability shift while remaining compliant." },
231
+ { value: "always", label: "Always request 3D Secure", hint: "Forces 3DS challenge whenever possible (may reduce conversion)." }
232
+ ];
233
+ function SectionCard$1({ title, description, right, children }) {
234
+ return /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
235
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4 border-b border-ui-border-base p-4", children: [
236
+ /* @__PURE__ */ jsxs("div", { children: [
237
+ /* @__PURE__ */ jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: title }),
238
+ description ? /* @__PURE__ */ jsx("div", { className: "mt-1 text-sm text-ui-fg-subtle", children: description }) : null
239
+ ] }),
240
+ right
241
+ ] }),
242
+ /* @__PURE__ */ jsx("div", { className: "p-4", children })
243
+ ] });
244
+ }
245
+ function FieldRow$1({ label, hint, children }) {
246
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-12 items-start gap-4 py-3", children: [
247
+ /* @__PURE__ */ jsxs("div", { className: "col-span-12 md:col-span-4", children: [
248
+ /* @__PURE__ */ jsx("div", { className: "text-sm font-medium text-ui-fg-base", children: label }),
249
+ hint ? /* @__PURE__ */ jsx("div", { className: "mt-1 text-xs text-ui-fg-subtle", children: hint }) : null
250
+ ] }),
251
+ /* @__PURE__ */ jsx("div", { className: "col-span-12 md:col-span-8", children })
252
+ ] });
253
+ }
254
+ function AdvancedCardPaymentsTab() {
255
+ var _a, _b;
256
+ const [form, setForm] = useState(() => ({ ...DEFAULT_FORM }));
257
+ const [loading, setLoading] = useState(false);
258
+ const [saving, setSaving] = useState(false);
259
+ const [toast, setToast] = useState(null);
260
+ const didInit = useRef(false);
261
+ useEffect(() => {
262
+ if (didInit.current) return;
263
+ didInit.current = true;
264
+ (async () => {
265
+ try {
266
+ setLoading(true);
267
+ const json = await adminFetch$1("/admin/paypal/settings");
268
+ const payload = (json == null ? void 0 : json.data) ?? json;
269
+ const saved = payload == null ? void 0 : payload.advanced_card_payments;
270
+ if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
271
+ } catch {
272
+ } finally {
273
+ setLoading(false);
274
+ }
275
+ })();
276
+ }, []);
277
+ async function onSave() {
278
+ try {
279
+ setSaving(true);
280
+ const json = await adminFetch$1("/admin/paypal/settings", {
281
+ method: "POST",
282
+ body: { advanced_card_payments: form }
283
+ });
284
+ const payload = (json == null ? void 0 : json.data) ?? json;
285
+ const saved = payload == null ? void 0 : payload.advanced_card_payments;
286
+ if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
287
+ setToast({ type: "success", message: "Settings saved" });
288
+ window.setTimeout(() => setToast(null), 2500);
289
+ } catch (e) {
290
+ setToast({ type: "error", message: (e instanceof Error ? e.message : "") || "Failed to save settings." });
291
+ window.setTimeout(() => setToast(null), 3500);
292
+ } finally {
293
+ setSaving(false);
294
+ }
295
+ }
296
+ return /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
297
+ /* @__PURE__ */ jsx("div", { className: "flex items-start justify-between gap-4", children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Gateway By Easy Payment" }) }) }),
298
+ /* @__PURE__ */ jsx(PayPalTabs, {}),
299
+ toast ? /* @__PURE__ */ jsx("div", { className: "fixed right-6 top-6 z-50 rounded-md border border-ui-border-base bg-ui-bg-base px-4 py-3 text-sm shadow-lg", role: "status", "aria-live": "polite", children: /* @__PURE__ */ jsx("span", { className: toast.type === "success" ? "text-ui-fg-base" : "text-ui-fg-error", children: toast.message }) }) : null,
300
+ /* @__PURE__ */ jsx(
301
+ SectionCard$1,
302
+ {
303
+ title: "Advanced Card Payments",
304
+ description: "Control card checkout settings and 3D Secure behavior.",
305
+ right: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
306
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: onSave, disabled: saving || loading, className: "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5", children: saving ? "Saving..." : "Save settings" }),
307
+ loading ? /* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading..." }) : null
308
+ ] }),
309
+ children: /* @__PURE__ */ jsxs("div", { className: "divide-y divide-ui-border-base", children: [
310
+ /* @__PURE__ */ jsx(FieldRow$1, { label: "Enable/Disable", children: /* @__PURE__ */ jsxs("label", { className: "inline-flex items-center gap-2", children: [
311
+ /* @__PURE__ */ jsx("input", { type: "checkbox", checked: form.enabled, onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })), className: "h-4 w-4 rounded border-ui-border-base" }),
312
+ /* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
313
+ ] }) }),
314
+ /* @__PURE__ */ jsx(FieldRow$1, { label: "Title", children: /* @__PURE__ */ jsx("input", { value: form.title, onChange: (e) => setForm((p) => ({ ...p, title: 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: "Credit or Debit Card" }) }),
315
+ /* @__PURE__ */ jsx(FieldRow$1, { label: "Contingency for 3D Secure", hint: "Choose when 3D Secure should be triggered during card payments.", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
316
+ /* @__PURE__ */ jsx("select", { value: form.threeDS, onChange: (e) => setForm((p) => ({ ...p, threeDS: 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", children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, o.value)) }),
317
+ ((_a = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _a.hint) ? /* @__PURE__ */ 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
318
+ ] }) })
319
+ ] })
320
+ }
321
+ )
322
+ ] }) });
323
+ }
182
324
  const config = defineRouteConfig({
183
325
  label: "PayPal Connection",
184
326
  hide: true
@@ -772,148 +914,6 @@ function PayPalConnectionPage() {
772
914
  ` })
773
915
  ] });
774
916
  }
775
- async function adminFetch$1(path, opts = {}) {
776
- var _a;
777
- const { method = "GET", body, query } = opts;
778
- let url = path;
779
- if (query && Object.keys(query).length > 0) {
780
- const params = new URLSearchParams(query);
781
- url = `${path}?${params.toString()}`;
782
- }
783
- const headers = { Accept: "application/json" };
784
- if (body !== void 0) headers["Content-Type"] = "application/json";
785
- if (typeof window !== "undefined") {
786
- const token = (_a = window.__medusa__) == null ? void 0 : _a.token;
787
- if (token) headers["Authorization"] = `Bearer ${token}`;
788
- }
789
- const res = await fetch(url, {
790
- method,
791
- headers,
792
- credentials: "include",
793
- body: body !== void 0 ? JSON.stringify(body) : void 0
794
- });
795
- const text = await res.text().catch(() => "");
796
- if (!res.ok) {
797
- if (res.status === 401) throw new Error("Unauthorized (401) - session may have expired. Please reload and log in again.");
798
- if (res.status === 403) throw new Error("Forbidden (403) - you do not have permission to perform this action.");
799
- throw new Error(text || `Request failed with status ${res.status}`);
800
- }
801
- if (!text) return {};
802
- try {
803
- return JSON.parse(text);
804
- } catch {
805
- return {};
806
- }
807
- }
808
- const DEFAULT_FORM = {
809
- enabled: true,
810
- title: "Credit or Debit Card",
811
- threeDS: "when_required"
812
- };
813
- function mergeWithDefaults(saved) {
814
- if (!saved) return { ...DEFAULT_FORM };
815
- const entries = Object.entries(saved).filter(([, value]) => value !== void 0);
816
- return { ...DEFAULT_FORM, ...Object.fromEntries(entries) };
817
- }
818
- const THREE_DS_OPTIONS = [
819
- { value: "when_required", label: "3D Secure when required", hint: "Triggers 3DS only when the card / issuer requires it." },
820
- { value: "sli", label: "3D Secure (SCA) / liability shift (recommended)", hint: "Attempts to optimize for liability shift while remaining compliant." },
821
- { value: "always", label: "Always request 3D Secure", hint: "Forces 3DS challenge whenever possible (may reduce conversion)." }
822
- ];
823
- function SectionCard$1({ title, description, right, children }) {
824
- return /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm", children: [
825
- /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4 border-b border-ui-border-base p-4", children: [
826
- /* @__PURE__ */ jsxs("div", { children: [
827
- /* @__PURE__ */ jsx("div", { className: "text-base font-semibold text-ui-fg-base", children: title }),
828
- description ? /* @__PURE__ */ jsx("div", { className: "mt-1 text-sm text-ui-fg-subtle", children: description }) : null
829
- ] }),
830
- right
831
- ] }),
832
- /* @__PURE__ */ jsx("div", { className: "p-4", children })
833
- ] });
834
- }
835
- function FieldRow$1({ label, hint, children }) {
836
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-12 items-start gap-4 py-3", children: [
837
- /* @__PURE__ */ jsxs("div", { className: "col-span-12 md:col-span-4", children: [
838
- /* @__PURE__ */ jsx("div", { className: "text-sm font-medium text-ui-fg-base", children: label }),
839
- hint ? /* @__PURE__ */ jsx("div", { className: "mt-1 text-xs text-ui-fg-subtle", children: hint }) : null
840
- ] }),
841
- /* @__PURE__ */ jsx("div", { className: "col-span-12 md:col-span-8", children })
842
- ] });
843
- }
844
- function AdvancedCardPaymentsTab() {
845
- var _a, _b;
846
- const [form, setForm] = useState(() => ({ ...DEFAULT_FORM }));
847
- const [loading, setLoading] = useState(false);
848
- const [saving, setSaving] = useState(false);
849
- const [toast, setToast] = useState(null);
850
- const didInit = useRef(false);
851
- useEffect(() => {
852
- if (didInit.current) return;
853
- didInit.current = true;
854
- (async () => {
855
- try {
856
- setLoading(true);
857
- const json = await adminFetch$1("/admin/paypal/settings");
858
- const payload = (json == null ? void 0 : json.data) ?? json;
859
- const saved = payload == null ? void 0 : payload.advanced_card_payments;
860
- if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
861
- } catch {
862
- } finally {
863
- setLoading(false);
864
- }
865
- })();
866
- }, []);
867
- async function onSave() {
868
- try {
869
- setSaving(true);
870
- const json = await adminFetch$1("/admin/paypal/settings", {
871
- method: "POST",
872
- body: { advanced_card_payments: form }
873
- });
874
- const payload = (json == null ? void 0 : json.data) ?? json;
875
- const saved = payload == null ? void 0 : payload.advanced_card_payments;
876
- if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
877
- setToast({ type: "success", message: "Settings saved" });
878
- window.setTimeout(() => setToast(null), 2500);
879
- } catch (e) {
880
- setToast({ type: "error", message: (e instanceof Error ? e.message : "") || "Failed to save settings." });
881
- window.setTimeout(() => setToast(null), 3500);
882
- } finally {
883
- setSaving(false);
884
- }
885
- }
886
- return /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
887
- /* @__PURE__ */ jsx("div", { className: "flex items-start justify-between gap-4", children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("h1", { className: "text-xl font-semibold text-ui-fg-base", children: "PayPal Gateway By Easy Payment" }) }) }),
888
- /* @__PURE__ */ jsx(PayPalTabs, {}),
889
- toast ? /* @__PURE__ */ jsx("div", { className: "fixed right-6 top-6 z-50 rounded-md border border-ui-border-base bg-ui-bg-base px-4 py-3 text-sm shadow-lg", role: "status", "aria-live": "polite", children: /* @__PURE__ */ jsx("span", { className: toast.type === "success" ? "text-ui-fg-base" : "text-ui-fg-error", children: toast.message }) }) : null,
890
- /* @__PURE__ */ jsx(
891
- SectionCard$1,
892
- {
893
- title: "Advanced Card Payments",
894
- description: "Control card checkout settings and 3D Secure behavior.",
895
- right: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
896
- /* @__PURE__ */ jsx("button", { type: "button", onClick: onSave, disabled: saving || loading, className: "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5", children: saving ? "Saving..." : "Save settings" }),
897
- loading ? /* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading..." }) : null
898
- ] }),
899
- children: /* @__PURE__ */ jsxs("div", { className: "divide-y divide-ui-border-base", children: [
900
- /* @__PURE__ */ jsx(FieldRow$1, { label: "Enable/Disable", children: /* @__PURE__ */ jsxs("label", { className: "inline-flex items-center gap-2", children: [
901
- /* @__PURE__ */ jsx("input", { type: "checkbox", checked: form.enabled, onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })), className: "h-4 w-4 rounded border-ui-border-base" }),
902
- /* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
903
- ] }) }),
904
- /* @__PURE__ */ jsx(FieldRow$1, { label: "Title", children: /* @__PURE__ */ jsx("input", { value: form.title, onChange: (e) => setForm((p) => ({ ...p, title: 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: "Credit or Debit Card" }) }),
905
- /* @__PURE__ */ jsx(FieldRow$1, { label: "Contingency for 3D Secure", hint: "Choose when 3D Secure should be triggered during card payments.", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
906
- /* @__PURE__ */ jsx("select", { value: form.threeDS, onChange: (e) => setForm((p) => ({ ...p, threeDS: 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", children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, o.value)) }),
907
- ((_a = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _a.hint) ? /* @__PURE__ */ 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
908
- ] }) })
909
- ] })
910
- }
911
- )
912
- ] }) });
913
- }
914
- function PayPalApplePayPage() {
915
- return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
916
- }
917
917
  function PayPalGooglePayPage() {
918
918
  return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
919
919
  }
@@ -1205,16 +1205,16 @@ const routeModule = {
1205
1205
  path: "/settings/paypal/additional-settings"
1206
1206
  },
1207
1207
  {
1208
- Component: PayPalConnectionPage,
1209
- path: "/settings/paypal/connection"
1208
+ Component: PayPalApplePayPage,
1209
+ path: "/settings/paypal/apple-pay"
1210
1210
  },
1211
1211
  {
1212
1212
  Component: AdvancedCardPaymentsTab,
1213
1213
  path: "/settings/paypal/advanced-card-payments"
1214
1214
  },
1215
1215
  {
1216
- Component: PayPalApplePayPage,
1217
- path: "/settings/paypal/apple-pay"
1216
+ Component: PayPalConnectionPage,
1217
+ path: "/settings/paypal/connection"
1218
1218
  },
1219
1219
  {
1220
1220
  Component: PayPalGooglePayPage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easypayment/medusa-payment-paypal",
3
- "version": "0.7.8",
3
+ "version": "0.8.0",
4
4
  "description": "PayPal integration for Medusa v2",
5
5
  "author": "EasyPayment Plugins",
6
6
  "license": "MIT",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "repository": {
66
66
  "type": "git",
67
- "url": "https://github.com/easypayment/medusa-paypal.git"
67
+ "url": "https://github.com/easypaymentplugins/medusa-paypal.git"
68
68
  },
69
69
  "keywords": [
70
70
  "medusa",