@easypayment/medusa-payment-paypal 1.3.5 → 1.3.7
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/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts +16 -2
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js +73 -2
- package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/request-logger.d.ts +2 -0
- package/.medusa/server/src/modules/paypal/utils/request-logger.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/request-logger.js +9 -1
- package/.medusa/server/src/modules/paypal/utils/request-logger.js.map +1 -1
- package/CHANGELOG.md +39 -0
- package/package.json +1 -1
- package/src/admin/routes/settings/paypal/connection/page.tsx +148 -58
- package/src/modules/paypal/utils/paypal-fetch.ts +78 -2
- package/src/modules/paypal/utils/request-logger.ts +43 -43
|
@@ -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
|
-
|
|
446
|
+
const DEFAULT_FORM = {
|
|
447
|
+
enabled: true,
|
|
448
|
+
title: "Credit or Debit Card",
|
|
449
|
+
threeDS: "when_required"
|
|
450
|
+
};
|
|
451
|
+
function mergeWithDefaults(saved) {
|
|
452
|
+
if (!saved) return { ...DEFAULT_FORM };
|
|
453
|
+
const entries = Object.entries(saved).filter(
|
|
454
|
+
([, value]) => value !== void 0
|
|
455
|
+
);
|
|
456
|
+
return {
|
|
457
|
+
...DEFAULT_FORM,
|
|
458
|
+
...Object.fromEntries(entries)
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
const THREE_DS_OPTIONS = [
|
|
462
|
+
{
|
|
463
|
+
value: "when_required",
|
|
464
|
+
label: "3D Secure when required",
|
|
465
|
+
hint: "Triggers 3DS only when the card / issuer requires it."
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
value: "sli",
|
|
469
|
+
label: "3D Secure (SCA) / liability shift (recommended)",
|
|
470
|
+
hint: "Attempts to optimize for liability shift while remaining compliant."
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
value: "always",
|
|
474
|
+
label: "Always request 3D Secure",
|
|
475
|
+
hint: "Forces 3DS challenge whenever possible (may reduce conversion)."
|
|
476
|
+
}
|
|
477
|
+
];
|
|
478
|
+
function AdvancedCardPaymentsTab() {
|
|
479
|
+
var _a, _b;
|
|
480
|
+
const [form, setForm] = useState(() => ({
|
|
481
|
+
...DEFAULT_FORM
|
|
482
|
+
}));
|
|
483
|
+
const [loading, setLoading] = useState(false);
|
|
484
|
+
const [saving, setSaving] = useState(false);
|
|
485
|
+
const [toast, setToast] = useState(null);
|
|
486
|
+
const didInit = useRef(false);
|
|
487
|
+
const dismissToast = useCallback(() => setToast(null), []);
|
|
488
|
+
useEffect(() => {
|
|
489
|
+
if (didInit.current) return;
|
|
490
|
+
didInit.current = true;
|
|
491
|
+
(async () => {
|
|
492
|
+
try {
|
|
493
|
+
setLoading(true);
|
|
494
|
+
const json = await adminFetch("/admin/paypal/settings");
|
|
495
|
+
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
496
|
+
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
497
|
+
if (saved && typeof saved === "object")
|
|
498
|
+
setForm(mergeWithDefaults(saved));
|
|
499
|
+
} catch {
|
|
500
|
+
} finally {
|
|
501
|
+
setLoading(false);
|
|
502
|
+
}
|
|
503
|
+
})();
|
|
504
|
+
}, []);
|
|
505
|
+
async function onSave() {
|
|
506
|
+
try {
|
|
507
|
+
setSaving(true);
|
|
508
|
+
const json = await adminFetch("/admin/paypal/settings", {
|
|
509
|
+
method: "POST",
|
|
510
|
+
body: {
|
|
511
|
+
advanced_card_payments: form
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
515
|
+
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
516
|
+
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
|
|
517
|
+
setToast({ kind: "success", message: "Settings saved" });
|
|
518
|
+
} catch (e) {
|
|
519
|
+
setToast({
|
|
520
|
+
kind: "error",
|
|
521
|
+
message: (e instanceof Error ? e.message : "") || "Failed to save settings."
|
|
522
|
+
});
|
|
523
|
+
} finally {
|
|
524
|
+
setSaving(false);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
528
|
+
/* @__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" }) }) }),
|
|
529
|
+
/* @__PURE__ */ jsx(PayPalTabs, {}),
|
|
530
|
+
/* @__PURE__ */ jsx(Toast, { toast, onClose: dismissToast }),
|
|
531
|
+
/* @__PURE__ */ jsx(
|
|
532
|
+
SectionCard,
|
|
533
|
+
{
|
|
534
|
+
title: "Advanced Card Payments",
|
|
535
|
+
description: "Control card checkout settings and 3D Secure behavior.",
|
|
536
|
+
right: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
537
|
+
/* @__PURE__ */ jsx(
|
|
538
|
+
"button",
|
|
539
|
+
{
|
|
540
|
+
type: "button",
|
|
541
|
+
onClick: onSave,
|
|
542
|
+
disabled: saving || loading,
|
|
543
|
+
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",
|
|
544
|
+
children: saving ? "Saving..." : "Save settings"
|
|
545
|
+
}
|
|
546
|
+
),
|
|
547
|
+
loading ? /* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading…" }) : null
|
|
548
|
+
] }),
|
|
549
|
+
children: /* @__PURE__ */ jsxs("div", { className: "divide-y divide-ui-border-base", children: [
|
|
550
|
+
/* @__PURE__ */ jsx(FieldRow, { label: "Enable/Disable", children: /* @__PURE__ */ jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
551
|
+
/* @__PURE__ */ jsx(
|
|
552
|
+
"input",
|
|
553
|
+
{
|
|
554
|
+
type: "checkbox",
|
|
555
|
+
checked: form.enabled,
|
|
556
|
+
onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })),
|
|
557
|
+
className: "h-4 w-4 rounded border-ui-border-base"
|
|
558
|
+
}
|
|
559
|
+
),
|
|
560
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
|
|
561
|
+
] }) }),
|
|
562
|
+
/* @__PURE__ */ jsx(FieldRow, { label: "Title", htmlFor: "acp-title", children: /* @__PURE__ */ jsx(
|
|
563
|
+
"input",
|
|
564
|
+
{
|
|
565
|
+
id: "acp-title",
|
|
566
|
+
value: form.title,
|
|
567
|
+
onChange: (e) => setForm((p) => ({ ...p, title: e.target.value })),
|
|
568
|
+
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",
|
|
569
|
+
placeholder: "Credit or Debit Card"
|
|
570
|
+
}
|
|
571
|
+
) }),
|
|
572
|
+
/* @__PURE__ */ jsx(
|
|
573
|
+
FieldRow,
|
|
574
|
+
{
|
|
575
|
+
label: "Contingency for 3D Secure",
|
|
576
|
+
hint: "Choose when 3D Secure should be triggered during card payments.",
|
|
577
|
+
htmlFor: "acp-threeds",
|
|
578
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
579
|
+
/* @__PURE__ */ jsx(
|
|
580
|
+
"select",
|
|
581
|
+
{
|
|
582
|
+
id: "acp-threeds",
|
|
583
|
+
value: form.threeDS,
|
|
584
|
+
onChange: (e) => setForm((p) => ({
|
|
585
|
+
...p,
|
|
586
|
+
threeDS: e.target.value
|
|
587
|
+
})),
|
|
588
|
+
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",
|
|
589
|
+
children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, o.value))
|
|
590
|
+
}
|
|
591
|
+
),
|
|
592
|
+
((_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
|
|
593
|
+
] })
|
|
594
|
+
}
|
|
595
|
+
)
|
|
596
|
+
] })
|
|
597
|
+
}
|
|
598
|
+
)
|
|
599
|
+
] }) });
|
|
600
|
+
}
|
|
601
|
+
function PayPalApplePayPage() {
|
|
602
602
|
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
603
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: AdvancedCardPaymentsTab,
|
|
1634
|
+
path: "/settings/paypal/advanced-card-payments"
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
Component: PayPalApplePayPage,
|
|
1638
|
+
path: "/settings/paypal/apple-pay"
|
|
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,
|
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
* Outbound HTTP for PayPal API calls with timeout, circuit breaker, and
|
|
3
3
|
* optional retry for critical payment operations.
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Guarantee the BN code on every request to PayPal.
|
|
7
|
+
*
|
|
8
|
+
* Call sites used to add the header themselves, and several (order lookups,
|
|
9
|
+
* webhook verification, the invoice subscriber) did not, so those calls went
|
|
10
|
+
* out unattributed. Enforcing it here means a new call site cannot forget.
|
|
11
|
+
* A header the caller already set is kept, and non-PayPal hosts (the partner
|
|
12
|
+
* onboarding service, alert webhooks) are left alone. The original shape of
|
|
13
|
+
* `headers` is preserved so the request log shows them as the caller wrote
|
|
14
|
+
* them.
|
|
15
|
+
*/
|
|
16
|
+
export declare function withPartnerAttribution(input: string | URL, init?: RequestInit): RequestInit;
|
|
5
17
|
export declare const PAYPAL_HTTP_TIMEOUT_MS: number;
|
|
6
18
|
export declare class CircuitOpenError extends Error {
|
|
7
19
|
constructor();
|
|
@@ -10,9 +22,11 @@ export declare class CircuitOpenError extends Error {
|
|
|
10
22
|
* `fetch` with a default timeout (`PAYPAL_HTTP_TIMEOUT_MS`) and a per-host
|
|
11
23
|
* circuit breaker. 5xx responses and network/timeout errors count as failures;
|
|
12
24
|
* once the breaker opens, calls to that host reject immediately with
|
|
13
|
-
* `CircuitOpenError` until the half-open probe succeeds.
|
|
25
|
+
* `CircuitOpenError` until the half-open probe succeeds. Requests to PayPal
|
|
26
|
+
* always carry the partner attribution (BN) header: see
|
|
27
|
+
* `withPartnerAttribution`.
|
|
14
28
|
*/
|
|
15
|
-
export declare function paypalFetch(input: string | URL,
|
|
29
|
+
export declare function paypalFetch(input: string | URL, requestInit?: RequestInit): Promise<Response>;
|
|
16
30
|
/**
|
|
17
31
|
* `paypalFetch` with bounded exponential-backoff retries on 5xx/429, timeouts,
|
|
18
32
|
* and an open circuit. Only use for calls that are idempotent on PayPal's side
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paypal-fetch.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/paypal-fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"paypal-fetch.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/paypal/utils/paypal-fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,GAAG,GAAG,EACnB,IAAI,GAAE,WAAgB,GACrB,WAAW,CAwCb;AAED,eAAO,MAAM,sBAAsB,QAG/B,CAAA;AAsFJ,qBAAa,gBAAiB,SAAQ,KAAK;;CAO1C;AAMD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,GAAG,GAAG,EACnB,WAAW,GAAE,WAAgB,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAoEnB;AA2CD;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,MAAM,GAAG,GAAG,EACnB,IAAI,GAAE,WAAgB,GACrB,OAAO,CAAC,QAAQ,CAAC,CA0BnB"}
|