@easypayment/medusa-payment-paypal 1.3.5 → 1.3.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.
@@ -155,161 +155,6 @@ async function adminFetch(path, opts = {}) {
155
155
  }
156
156
  }
157
157
  const DEFAULT_FORM$1 = {
158
- enabled: true,
159
- title: "Credit or Debit Card",
160
- threeDS: "when_required"
161
- };
162
- function mergeWithDefaults$1(saved) {
163
- if (!saved) return { ...DEFAULT_FORM$1 };
164
- const entries = Object.entries(saved).filter(
165
- ([, value]) => value !== void 0
166
- );
167
- return {
168
- ...DEFAULT_FORM$1,
169
- ...Object.fromEntries(entries)
170
- };
171
- }
172
- const THREE_DS_OPTIONS = [
173
- {
174
- value: "when_required",
175
- label: "3D Secure when required",
176
- hint: "Triggers 3DS only when the card / issuer requires it."
177
- },
178
- {
179
- value: "sli",
180
- label: "3D Secure (SCA) / liability shift (recommended)",
181
- hint: "Attempts to optimize for liability shift while remaining compliant."
182
- },
183
- {
184
- value: "always",
185
- label: "Always request 3D Secure",
186
- hint: "Forces 3DS challenge whenever possible (may reduce conversion)."
187
- }
188
- ];
189
- function AdvancedCardPaymentsTab() {
190
- var _a, _b;
191
- const [form, setForm] = react.useState(() => ({
192
- ...DEFAULT_FORM$1
193
- }));
194
- const [loading, setLoading] = react.useState(false);
195
- const [saving, setSaving] = react.useState(false);
196
- const [toast, setToast] = react.useState(null);
197
- const didInit = react.useRef(false);
198
- const dismissToast = react.useCallback(() => setToast(null), []);
199
- react.useEffect(() => {
200
- if (didInit.current) return;
201
- didInit.current = true;
202
- (async () => {
203
- try {
204
- setLoading(true);
205
- const json = await adminFetch("/admin/paypal/settings");
206
- const payload = (json == null ? void 0 : json.data) ?? json;
207
- const saved = payload == null ? void 0 : payload.advanced_card_payments;
208
- if (saved && typeof saved === "object")
209
- setForm(mergeWithDefaults$1(saved));
210
- } catch {
211
- } finally {
212
- setLoading(false);
213
- }
214
- })();
215
- }, []);
216
- async function onSave() {
217
- try {
218
- setSaving(true);
219
- const json = await adminFetch("/admin/paypal/settings", {
220
- method: "POST",
221
- body: {
222
- advanced_card_payments: form
223
- }
224
- });
225
- const payload = (json == null ? void 0 : json.data) ?? json;
226
- const saved = payload == null ? void 0 : payload.advanced_card_payments;
227
- if (saved && typeof saved === "object") setForm(mergeWithDefaults$1(saved));
228
- setToast({ kind: "success", message: "Settings saved" });
229
- } catch (e) {
230
- setToast({
231
- kind: "error",
232
- message: (e instanceof Error ? e.message : "") || "Failed to save settings."
233
- });
234
- } finally {
235
- setSaving(false);
236
- }
237
- }
238
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
239
- /* @__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" }) }) }),
240
- /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
241
- /* @__PURE__ */ jsxRuntime.jsx(Toast, { toast, onClose: dismissToast }),
242
- /* @__PURE__ */ jsxRuntime.jsx(
243
- SectionCard,
244
- {
245
- title: "Advanced Card Payments",
246
- description: "Control card checkout settings and 3D Secure behavior.",
247
- right: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
248
- /* @__PURE__ */ jsxRuntime.jsx(
249
- "button",
250
- {
251
- type: "button",
252
- onClick: onSave,
253
- disabled: saving || loading,
254
- 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",
255
- children: saving ? "Saving..." : "Save settings"
256
- }
257
- ),
258
- loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading…" }) : null
259
- ] }),
260
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y divide-ui-border-base", children: [
261
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Enable/Disable", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
262
- /* @__PURE__ */ jsxRuntime.jsx(
263
- "input",
264
- {
265
- type: "checkbox",
266
- checked: form.enabled,
267
- onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })),
268
- className: "h-4 w-4 rounded border-ui-border-base"
269
- }
270
- ),
271
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
272
- ] }) }),
273
- /* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Title", htmlFor: "acp-title", children: /* @__PURE__ */ jsxRuntime.jsx(
274
- "input",
275
- {
276
- id: "acp-title",
277
- value: form.title,
278
- onChange: (e) => setForm((p) => ({ ...p, title: e.target.value })),
279
- 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",
280
- placeholder: "Credit or Debit Card"
281
- }
282
- ) }),
283
- /* @__PURE__ */ jsxRuntime.jsx(
284
- FieldRow,
285
- {
286
- label: "Contingency for 3D Secure",
287
- hint: "Choose when 3D Secure should be triggered during card payments.",
288
- htmlFor: "acp-threeds",
289
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
290
- /* @__PURE__ */ jsxRuntime.jsx(
291
- "select",
292
- {
293
- id: "acp-threeds",
294
- value: form.threeDS,
295
- onChange: (e) => setForm((p) => ({
296
- ...p,
297
- threeDS: e.target.value
298
- })),
299
- 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",
300
- children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o.value, children: o.label }, o.value))
301
- }
302
- ),
303
- ((_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
304
- ] })
305
- }
306
- )
307
- ] })
308
- }
309
- )
310
- ] }) });
311
- }
312
- const DEFAULT_FORM = {
313
158
  paymentAction: "capture",
314
159
  brandName: "PayPal",
315
160
  landingPage: "no_preference",
@@ -319,19 +164,19 @@ const DEFAULT_FORM = {
319
164
  creditCardStatementName: "PayPal",
320
165
  debugLogging: false
321
166
  };
322
- function mergeWithDefaults(saved) {
323
- if (!saved) return { ...DEFAULT_FORM };
167
+ function mergeWithDefaults$1(saved) {
168
+ if (!saved) return { ...DEFAULT_FORM$1 };
324
169
  const entries = Object.entries(saved).filter(
325
170
  ([, value]) => value !== void 0
326
171
  );
327
172
  return {
328
- ...DEFAULT_FORM,
173
+ ...DEFAULT_FORM$1,
329
174
  ...Object.fromEntries(entries)
330
175
  };
331
176
  }
332
177
  function AdditionalSettingsTab() {
333
178
  const [form, setForm] = react.useState(() => ({
334
- ...DEFAULT_FORM
179
+ ...DEFAULT_FORM$1
335
180
  }));
336
181
  const [loading, setLoading] = react.useState(false);
337
182
  const [saving, setSaving] = react.useState(false);
@@ -392,7 +237,7 @@ function AdditionalSettingsTab() {
392
237
  const payload = (json == null ? void 0 : json.data) ?? json;
393
238
  const saved = payload == null ? void 0 : payload.additional_settings;
394
239
  if (saved && typeof saved === "object")
395
- setForm(mergeWithDefaults(saved));
240
+ setForm(mergeWithDefaults$1(saved));
396
241
  } catch {
397
242
  } finally {
398
243
  setLoading(false);
@@ -411,7 +256,7 @@ function AdditionalSettingsTab() {
411
256
  });
412
257
  const payload = (json == null ? void 0 : json.data) ?? json;
413
258
  const saved = payload == null ? void 0 : payload.additional_settings;
414
- if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
259
+ if (saved && typeof saved === "object") setForm(mergeWithDefaults$1(saved));
415
260
  setToast({ kind: "success", message: "Settings saved" });
416
261
  } catch (e) {
417
262
  setToast({
@@ -599,13 +444,218 @@ function AdditionalSettingsTab() {
599
444
  )
600
445
  ] }) });
601
446
  }
602
- function PayPalGooglePayPage() {
447
+ function PayPalApplePayPage() {
603
448
  return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
604
449
  }
450
+ const DEFAULT_FORM = {
451
+ enabled: true,
452
+ title: "Credit or Debit Card",
453
+ threeDS: "when_required"
454
+ };
455
+ function mergeWithDefaults(saved) {
456
+ if (!saved) return { ...DEFAULT_FORM };
457
+ const entries = Object.entries(saved).filter(
458
+ ([, value]) => value !== void 0
459
+ );
460
+ return {
461
+ ...DEFAULT_FORM,
462
+ ...Object.fromEntries(entries)
463
+ };
464
+ }
465
+ const THREE_DS_OPTIONS = [
466
+ {
467
+ value: "when_required",
468
+ label: "3D Secure when required",
469
+ hint: "Triggers 3DS only when the card / issuer requires it."
470
+ },
471
+ {
472
+ value: "sli",
473
+ label: "3D Secure (SCA) / liability shift (recommended)",
474
+ hint: "Attempts to optimize for liability shift while remaining compliant."
475
+ },
476
+ {
477
+ value: "always",
478
+ label: "Always request 3D Secure",
479
+ hint: "Forces 3DS challenge whenever possible (may reduce conversion)."
480
+ }
481
+ ];
482
+ function AdvancedCardPaymentsTab() {
483
+ var _a, _b;
484
+ const [form, setForm] = react.useState(() => ({
485
+ ...DEFAULT_FORM
486
+ }));
487
+ const [loading, setLoading] = react.useState(false);
488
+ const [saving, setSaving] = react.useState(false);
489
+ const [toast, setToast] = react.useState(null);
490
+ const didInit = react.useRef(false);
491
+ const dismissToast = react.useCallback(() => setToast(null), []);
492
+ react.useEffect(() => {
493
+ if (didInit.current) return;
494
+ didInit.current = true;
495
+ (async () => {
496
+ try {
497
+ setLoading(true);
498
+ const json = await adminFetch("/admin/paypal/settings");
499
+ const payload = (json == null ? void 0 : json.data) ?? json;
500
+ const saved = payload == null ? void 0 : payload.advanced_card_payments;
501
+ if (saved && typeof saved === "object")
502
+ setForm(mergeWithDefaults(saved));
503
+ } catch {
504
+ } finally {
505
+ setLoading(false);
506
+ }
507
+ })();
508
+ }, []);
509
+ async function onSave() {
510
+ try {
511
+ setSaving(true);
512
+ const json = await adminFetch("/admin/paypal/settings", {
513
+ method: "POST",
514
+ body: {
515
+ advanced_card_payments: form
516
+ }
517
+ });
518
+ const payload = (json == null ? void 0 : json.data) ?? json;
519
+ const saved = payload == null ? void 0 : payload.advanced_card_payments;
520
+ if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
521
+ setToast({ kind: "success", message: "Settings saved" });
522
+ } catch (e) {
523
+ setToast({
524
+ kind: "error",
525
+ message: (e instanceof Error ? e.message : "") || "Failed to save settings."
526
+ });
527
+ } finally {
528
+ setSaving(false);
529
+ }
530
+ }
531
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
532
+ /* @__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" }) }) }),
533
+ /* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
534
+ /* @__PURE__ */ jsxRuntime.jsx(Toast, { toast, onClose: dismissToast }),
535
+ /* @__PURE__ */ jsxRuntime.jsx(
536
+ SectionCard,
537
+ {
538
+ title: "Advanced Card Payments",
539
+ description: "Control card checkout settings and 3D Secure behavior.",
540
+ right: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
541
+ /* @__PURE__ */ jsxRuntime.jsx(
542
+ "button",
543
+ {
544
+ type: "button",
545
+ onClick: onSave,
546
+ disabled: saving || loading,
547
+ 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",
548
+ children: saving ? "Saving..." : "Save settings"
549
+ }
550
+ ),
551
+ loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading…" }) : null
552
+ ] }),
553
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y divide-ui-border-base", children: [
554
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Enable/Disable", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
555
+ /* @__PURE__ */ jsxRuntime.jsx(
556
+ "input",
557
+ {
558
+ type: "checkbox",
559
+ checked: form.enabled,
560
+ onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })),
561
+ className: "h-4 w-4 rounded border-ui-border-base"
562
+ }
563
+ ),
564
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
565
+ ] }) }),
566
+ /* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Title", htmlFor: "acp-title", children: /* @__PURE__ */ jsxRuntime.jsx(
567
+ "input",
568
+ {
569
+ id: "acp-title",
570
+ value: form.title,
571
+ onChange: (e) => setForm((p) => ({ ...p, title: e.target.value })),
572
+ 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",
573
+ placeholder: "Credit or Debit Card"
574
+ }
575
+ ) }),
576
+ /* @__PURE__ */ jsxRuntime.jsx(
577
+ FieldRow,
578
+ {
579
+ label: "Contingency for 3D Secure",
580
+ hint: "Choose when 3D Secure should be triggered during card payments.",
581
+ htmlFor: "acp-threeds",
582
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
583
+ /* @__PURE__ */ jsxRuntime.jsx(
584
+ "select",
585
+ {
586
+ id: "acp-threeds",
587
+ value: form.threeDS,
588
+ onChange: (e) => setForm((p) => ({
589
+ ...p,
590
+ threeDS: e.target.value
591
+ })),
592
+ 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",
593
+ children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o.value, children: o.label }, o.value))
594
+ }
595
+ ),
596
+ ((_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
597
+ ] })
598
+ }
599
+ )
600
+ ] })
601
+ }
602
+ )
603
+ ] }) });
604
+ }
605
605
  const config = adminSdk.defineRouteConfig({
606
606
  label: "PayPal Connection"
607
607
  });
608
608
  const PARTNER_JS_URL = "https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js";
609
+ const PARTNER_SCRIPT_ID = "paypal-partner-js";
610
+ const PARTNER_HELPER_SCRIPT_IDS = [
611
+ "rampConfig-js",
612
+ "signup-js",
613
+ "zoidMiniBrowser-js"
614
+ ];
615
+ const MINI_BROWSER_POLL_MS = 50;
616
+ const MINI_BROWSER_POLL_ATTEMPTS = 200;
617
+ function getMiniBrowser() {
618
+ var _a, _b;
619
+ const signup = (_b = (_a = window.PAYPAL) == null ? void 0 : _a.apps) == null ? void 0 : _b.Signup;
620
+ return (signup == null ? void 0 : signup.MiniBrowser) || (signup == null ? void 0 : signup.miniBrowser);
621
+ }
622
+ function isMiniBrowserReady() {
623
+ const mb = getMiniBrowser();
624
+ return typeof (mb == null ? void 0 : mb.startFlow) === "function" || !!(mb == null ? void 0 : mb.component);
625
+ }
626
+ let miniBrowserLoad = null;
627
+ function loadMiniBrowser() {
628
+ if (isMiniBrowserReady()) return Promise.resolve(true);
629
+ if (miniBrowserLoad) return miniBrowserLoad;
630
+ miniBrowserLoad = new Promise((resolve) => {
631
+ var _a;
632
+ for (const id of [PARTNER_SCRIPT_ID, ...PARTNER_HELPER_SCRIPT_IDS]) {
633
+ (_a = document.getElementById(id)) == null ? void 0 : _a.remove();
634
+ }
635
+ const script = document.createElement("script");
636
+ script.id = PARTNER_SCRIPT_ID;
637
+ script.src = PARTNER_JS_URL;
638
+ script.async = true;
639
+ document.head.appendChild(script);
640
+ let attempts = 0;
641
+ const poll = () => {
642
+ if (isMiniBrowserReady()) {
643
+ miniBrowserLoad = null;
644
+ resolve(true);
645
+ return;
646
+ }
647
+ attempts++;
648
+ if (attempts >= MINI_BROWSER_POLL_ATTEMPTS) {
649
+ miniBrowserLoad = null;
650
+ resolve(false);
651
+ return;
652
+ }
653
+ setTimeout(poll, MINI_BROWSER_POLL_MS);
654
+ };
655
+ poll();
656
+ });
657
+ return miniBrowserLoad;
658
+ }
609
659
  const SERVICE_URL = "/admin/paypal/onboarding-link";
610
660
  const CACHE_PREFIX = "pp_onboard_cache";
611
661
  const CACHE_EXPIRY = 6 * 60 * 60 * 1e3;
@@ -665,6 +715,9 @@ function PayPalConnectionPage() {
665
715
  const runIdRef = react.useRef(0);
666
716
  const currentRunId = react.useRef(0);
667
717
  const completedRef = react.useRef(false);
718
+ const boundButtonsRef = react.useRef(
719
+ /* @__PURE__ */ new WeakMap()
720
+ );
668
721
  const envRef = react.useRef(env);
669
722
  envRef.current = env;
670
723
  const pollTimerRef = react.useRef(null);
@@ -788,40 +841,28 @@ function PayPalConnectionPage() {
788
841
  },
789
842
  [closeMiniBrowser, stopStatusPolling]
790
843
  );
844
+ const isConnectButtonBound = react.useCallback(() => {
845
+ const anchor = paypalButtonRef.current;
846
+ const mb = getMiniBrowser();
847
+ return !!anchor && !!mb && isMiniBrowserReady() && boundButtonsRef.current.get(anchor) === mb;
848
+ }, []);
791
849
  const initPartner = react.useCallback(() => {
792
- var _a, _b;
793
- const signup = (_b = (_a = window.PAYPAL) == null ? void 0 : _a.apps) == null ? void 0 : _b.Signup;
794
- const init = (signup == null ? void 0 : signup.miniBrowser) && signup.miniBrowser.init || (signup == null ? void 0 : signup.MiniBrowser) && signup.MiniBrowser.init;
795
- if (typeof init === "function") {
796
- try {
797
- init();
798
- } catch (e) {
799
- console.error("[paypal] partner.js init failed:", e);
800
- }
850
+ const anchor = paypalButtonRef.current;
851
+ const mb = getMiniBrowser();
852
+ if (!anchor || !mb || !isMiniBrowserReady()) return false;
853
+ if (boundButtonsRef.current.get(anchor) === mb) return true;
854
+ if (typeof mb.init !== "function") return false;
855
+ try {
856
+ mb.init();
857
+ boundButtonsRef.current.set(anchor, mb);
858
+ return true;
859
+ } catch (e) {
860
+ console.error("[paypal] partner.js init failed:", e);
861
+ return false;
801
862
  }
802
863
  }, []);
803
864
  react.useEffect(() => {
804
- const existingScript = document.getElementById("paypal-partner-js");
805
- if (existingScript) return;
806
- const preloadHref = PARTNER_JS_URL;
807
- let preloadLink = null;
808
- if (!document.head.querySelector(`link[rel="preload"][href="${preloadHref}"]`)) {
809
- preloadLink = document.createElement("link");
810
- preloadLink.rel = "preload";
811
- preloadLink.href = preloadHref;
812
- preloadLink.as = "script";
813
- document.head.appendChild(preloadLink);
814
- }
815
- const ppScript = document.createElement("script");
816
- ppScript.id = "paypal-partner-js";
817
- ppScript.src = preloadHref;
818
- ppScript.async = true;
819
- document.head.appendChild(ppScript);
820
- return () => {
821
- if (preloadLink == null ? void 0 : preloadLink.parentNode)
822
- preloadLink.parentNode.removeChild(preloadLink);
823
- if (ppScript.parentNode) ppScript.parentNode.removeChild(ppScript);
824
- };
865
+ void loadMiniBrowser();
825
866
  }, []);
826
867
  const activatePayPal = react.useCallback(
827
868
  (url, runId) => {
@@ -829,26 +870,18 @@ function PayPalConnectionPage() {
829
870
  paypalButtonRef.current.href = url;
830
871
  }
831
872
  setFinalUrl(url);
832
- let attempts = 0;
833
- const MAX_ATTEMPTS = 200;
834
- const tryInit = () => {
835
- var _a, _b;
873
+ void (async () => {
874
+ const loaded = await loadMiniBrowser() || await loadMiniBrowser();
836
875
  if (runId !== currentRunId.current) return;
837
- if ((_b = (_a = window.PAYPAL) == null ? void 0 : _a.apps) == null ? void 0 : _b.Signup) {
838
- initPartner();
839
- setConnState("ready");
840
- return;
841
- }
842
- attempts++;
843
- if (attempts >= MAX_ATTEMPTS) {
876
+ if (!paypalButtonRef.current) return;
877
+ if (!loaded || !initPartner()) {
844
878
  showError(
845
879
  "PayPal partner script failed to load. Please refresh and try again."
846
880
  );
847
881
  return;
848
882
  }
849
- setTimeout(tryInit, 50);
850
- };
851
- tryInit();
883
+ setConnState("ready");
884
+ })();
852
885
  },
853
886
  [initPartner, showError]
854
887
  );
@@ -991,6 +1024,13 @@ function PayPalConnectionPage() {
991
1024
  e.preventDefault();
992
1025
  return;
993
1026
  }
1027
+ if (!isConnectButtonBound()) {
1028
+ e.preventDefault();
1029
+ currentRunId.current = ++runIdRef.current;
1030
+ setConnState("loading");
1031
+ activatePayPal(finalUrl, currentRunId.current);
1032
+ return;
1033
+ }
994
1034
  completedRef.current = false;
995
1035
  startStatusPolling();
996
1036
  };
@@ -1357,7 +1397,7 @@ function PayPalConnectionPage() {
1357
1397
  ` })
1358
1398
  ] });
1359
1399
  }
1360
- function PayPalApplePayPage() {
1400
+ function PayPalGooglePayPage() {
1361
1401
  return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
1362
1402
  }
1363
1403
  function PayPalPayLaterMessagingPage() {
@@ -1586,25 +1626,25 @@ const routeModule = {
1586
1626
  Component: PayPalSettingsIndexRoute,
1587
1627
  path: "/settings/paypal"
1588
1628
  },
1589
- {
1590
- Component: AdvancedCardPaymentsTab,
1591
- path: "/settings/paypal/advanced-card-payments"
1592
- },
1593
1629
  {
1594
1630
  Component: AdditionalSettingsTab,
1595
1631
  path: "/settings/paypal/additional-settings"
1596
1632
  },
1597
1633
  {
1598
- Component: PayPalGooglePayPage,
1599
- path: "/settings/paypal/google-pay"
1634
+ Component: PayPalApplePayPage,
1635
+ path: "/settings/paypal/apple-pay"
1636
+ },
1637
+ {
1638
+ Component: AdvancedCardPaymentsTab,
1639
+ path: "/settings/paypal/advanced-card-payments"
1600
1640
  },
1601
1641
  {
1602
1642
  Component: PayPalConnectionPage,
1603
1643
  path: "/settings/paypal/connection"
1604
1644
  },
1605
1645
  {
1606
- Component: PayPalApplePayPage,
1607
- path: "/settings/paypal/apple-pay"
1646
+ Component: PayPalGooglePayPage,
1647
+ path: "/settings/paypal/google-pay"
1608
1648
  },
1609
1649
  {
1610
1650
  Component: PayPalPayLaterMessagingPage,