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