@easypayment/medusa-payment-paypal 1.3.8 → 1.3.10
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 +261 -94
- package/.medusa/server/src/admin/index.mjs +196 -31
- package/.medusa/server/src/api/admin/paypal/merchant-status/route.d.ts +11 -0
- package/.medusa/server/src/api/admin/paypal/merchant-status/route.d.ts.map +1 -0
- package/.medusa/server/src/api/admin/paypal/merchant-status/route.js +32 -0
- package/.medusa/server/src/api/admin/paypal/merchant-status/route.js.map +1 -0
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +4 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/create-order/route.js +113 -108
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
- package/.medusa/server/src/api/utils/request-logger.d.ts.map +1 -1
- package/.medusa/server/src/api/utils/request-logger.js +4 -2
- package/.medusa/server/src/api/utils/request-logger.js.map +1 -1
- package/.medusa/server/src/modules/paypal/service.d.ts +33 -0
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +138 -34
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +2 -1
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/merchant-status.d.ts +48 -0
- package/.medusa/server/src/modules/paypal/utils/merchant-status.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/merchant-status.js +106 -0
- package/.medusa/server/src/modules/paypal/utils/merchant-status.js.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/order-context.d.ts +61 -0
- package/.medusa/server/src/modules/paypal/utils/order-context.d.ts.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/order-context.js +127 -0
- package/.medusa/server/src/modules/paypal/utils/order-context.js.map +1 -0
- package/.medusa/server/src/modules/paypal/utils/request-logger.d.ts +12 -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 +26 -2
- package/.medusa/server/src/modules/paypal/utils/request-logger.js.map +1 -1
- package/CHANGELOG.md +102 -0
- package/README.md +4 -4
- package/package.json +1 -1
- package/src/admin/routes/settings/paypal/_components/MerchantStatusNotices.tsx +116 -0
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +54 -12
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +2 -0
- package/src/admin/routes/settings/paypal/connection/page.tsx +73 -6
- package/src/api/admin/paypal/merchant-status/route.ts +36 -0
- package/src/api/store/paypal/create-order/route.ts +191 -165
- package/src/api/utils/request-logger.ts +7 -3
- package/src/modules/paypal/service.ts +192 -43
- package/src/modules/paypal/types/config.ts +3 -2
- package/src/modules/paypal/utils/merchant-status.ts +187 -0
- package/src/modules/paypal/utils/order-context.ts +163 -0
- package/src/modules/paypal/utils/request-logger.ts +30 -2
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
const jsxRuntime = require("react/jsx-runtime");
|
|
3
3
|
const adminSdk = require("@medusajs/admin-sdk");
|
|
4
4
|
const reactRouterDom = require("react-router-dom");
|
|
5
|
-
const
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
7
|
+
const React__default = /* @__PURE__ */ _interopDefault(React);
|
|
6
8
|
const config$1 = adminSdk.defineRouteConfig({
|
|
7
9
|
label: "PayPal"
|
|
8
10
|
});
|
|
@@ -73,7 +75,7 @@ function FieldRow({
|
|
|
73
75
|
] });
|
|
74
76
|
}
|
|
75
77
|
function Toast({ toast, onClose }) {
|
|
76
|
-
|
|
78
|
+
React.useEffect(() => {
|
|
77
79
|
if (!toast) return;
|
|
78
80
|
const duration = toast.kind === "error" ? 5e3 : 2500;
|
|
79
81
|
const t = setTimeout(() => onClose(), duration);
|
|
@@ -156,34 +158,44 @@ async function adminFetch(path, opts = {}) {
|
|
|
156
158
|
}
|
|
157
159
|
const DEFAULT_FORM$1 = {
|
|
158
160
|
paymentAction: "capture",
|
|
159
|
-
brandName: "
|
|
160
|
-
landingPage: "
|
|
161
|
+
brandName: "",
|
|
162
|
+
landingPage: "login",
|
|
161
163
|
requireInstantPayment: false,
|
|
162
164
|
sendItemDetails: true,
|
|
165
|
+
sendShippingAddress: true,
|
|
163
166
|
invoicePrefix: "PP-",
|
|
164
|
-
creditCardStatementName: "
|
|
167
|
+
creditCardStatementName: "",
|
|
165
168
|
debugLogging: false
|
|
166
169
|
};
|
|
170
|
+
function isPlaceholderName(value) {
|
|
171
|
+
return typeof value === "string" && value.trim().toLowerCase() === "paypal";
|
|
172
|
+
}
|
|
167
173
|
function mergeWithDefaults$1(saved) {
|
|
168
174
|
if (!saved) return { ...DEFAULT_FORM$1 };
|
|
169
175
|
const entries = Object.entries(saved).filter(
|
|
170
176
|
([, value]) => value !== void 0
|
|
171
177
|
);
|
|
172
|
-
|
|
178
|
+
const merged = {
|
|
173
179
|
...DEFAULT_FORM$1,
|
|
174
180
|
...Object.fromEntries(entries)
|
|
175
181
|
};
|
|
182
|
+
if (merged.landingPage !== "billing") merged.landingPage = "login";
|
|
183
|
+
if (isPlaceholderName(merged.brandName)) merged.brandName = "";
|
|
184
|
+
if (isPlaceholderName(merged.creditCardStatementName)) {
|
|
185
|
+
merged.creditCardStatementName = "";
|
|
186
|
+
}
|
|
187
|
+
return merged;
|
|
176
188
|
}
|
|
177
189
|
function AdditionalSettingsTab() {
|
|
178
|
-
const [form, setForm] =
|
|
190
|
+
const [form, setForm] = React.useState(() => ({
|
|
179
191
|
...DEFAULT_FORM$1
|
|
180
192
|
}));
|
|
181
|
-
const [loading, setLoading] =
|
|
182
|
-
const [saving, setSaving] =
|
|
183
|
-
const [downloading, setDownloading] =
|
|
184
|
-
const [toast, setToast] =
|
|
185
|
-
const didInit =
|
|
186
|
-
const dismissToast =
|
|
193
|
+
const [loading, setLoading] = React.useState(false);
|
|
194
|
+
const [saving, setSaving] = React.useState(false);
|
|
195
|
+
const [downloading, setDownloading] = React.useState(false);
|
|
196
|
+
const [toast, setToast] = React.useState(null);
|
|
197
|
+
const didInit = React.useRef(false);
|
|
198
|
+
const dismissToast = React.useCallback(() => setToast(null), []);
|
|
187
199
|
async function onDownloadLog() {
|
|
188
200
|
var _a;
|
|
189
201
|
try {
|
|
@@ -227,7 +239,7 @@ function AdditionalSettingsTab() {
|
|
|
227
239
|
setDownloading(false);
|
|
228
240
|
}
|
|
229
241
|
}
|
|
230
|
-
|
|
242
|
+
React.useEffect(() => {
|
|
231
243
|
if (didInit.current) return;
|
|
232
244
|
didInit.current = true;
|
|
233
245
|
(async () => {
|
|
@@ -306,16 +318,24 @@ function AdditionalSettingsTab() {
|
|
|
306
318
|
]
|
|
307
319
|
}
|
|
308
320
|
) }),
|
|
309
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
310
|
-
|
|
321
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
322
|
+
FieldRow,
|
|
311
323
|
{
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
324
|
+
label: "Brand Name",
|
|
325
|
+
htmlFor: "as-brand-name",
|
|
326
|
+
hint: "The business name customers see in the PayPal checkout. Leave empty to use your store's name.",
|
|
327
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
328
|
+
"input",
|
|
329
|
+
{
|
|
330
|
+
id: "as-brand-name",
|
|
331
|
+
value: form.brandName,
|
|
332
|
+
onChange: (e) => setForm((p) => ({ ...p, brandName: e.target.value })),
|
|
333
|
+
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",
|
|
334
|
+
placeholder: "Your store name"
|
|
335
|
+
}
|
|
336
|
+
)
|
|
317
337
|
}
|
|
318
|
-
)
|
|
338
|
+
),
|
|
319
339
|
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Landing Page", htmlFor: "as-landing-page", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
320
340
|
"select",
|
|
321
341
|
{
|
|
@@ -327,9 +347,8 @@ function AdditionalSettingsTab() {
|
|
|
327
347
|
})),
|
|
328
348
|
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",
|
|
329
349
|
children: [
|
|
330
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "
|
|
331
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "
|
|
332
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "billing", children: "Billing" })
|
|
350
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "login", children: "Login (PayPal account)" }),
|
|
351
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "billing", children: "Guest checkout (card form)" })
|
|
333
352
|
]
|
|
334
353
|
}
|
|
335
354
|
) }),
|
|
@@ -370,6 +389,28 @@ function AdditionalSettingsTab() {
|
|
|
370
389
|
] })
|
|
371
390
|
}
|
|
372
391
|
),
|
|
392
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
393
|
+
FieldRow,
|
|
394
|
+
{
|
|
395
|
+
label: "Send Shipping Address",
|
|
396
|
+
hint: "Send the shipping address the customer entered at checkout to PayPal, so PayPal shows that address instead of the ones saved on the customer's PayPal account. Needed for PayPal Seller Protection.",
|
|
397
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
398
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
399
|
+
"input",
|
|
400
|
+
{
|
|
401
|
+
type: "checkbox",
|
|
402
|
+
checked: form.sendShippingAddress,
|
|
403
|
+
onChange: (e) => setForm((p) => ({
|
|
404
|
+
...p,
|
|
405
|
+
sendShippingAddress: e.target.checked
|
|
406
|
+
})),
|
|
407
|
+
className: "h-4 w-4 rounded border-ui-border-base"
|
|
408
|
+
}
|
|
409
|
+
),
|
|
410
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Send the checkout shipping address to PayPal" })
|
|
411
|
+
] })
|
|
412
|
+
}
|
|
413
|
+
),
|
|
373
414
|
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Invoice prefix", htmlFor: "as-invoice-prefix", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
374
415
|
"input",
|
|
375
416
|
{
|
|
@@ -385,6 +426,7 @@ function AdditionalSettingsTab() {
|
|
|
385
426
|
{
|
|
386
427
|
label: "Credit Card Statement Name",
|
|
387
428
|
htmlFor: "as-cc-statement",
|
|
429
|
+
hint: "Shown on the customer's card statement (up to 22 characters). Leave empty to use the name on your PayPal account.",
|
|
388
430
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
389
431
|
"input",
|
|
390
432
|
{
|
|
@@ -395,7 +437,8 @@ function AdditionalSettingsTab() {
|
|
|
395
437
|
creditCardStatementName: e.target.value
|
|
396
438
|
})),
|
|
397
439
|
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",
|
|
398
|
-
placeholder: "
|
|
440
|
+
placeholder: "Your business name",
|
|
441
|
+
maxLength: 22
|
|
399
442
|
}
|
|
400
443
|
)
|
|
401
444
|
}
|
|
@@ -422,7 +465,7 @@ function AdditionalSettingsTab() {
|
|
|
422
465
|
FieldRow,
|
|
423
466
|
{
|
|
424
467
|
label: "Request/response logging",
|
|
425
|
-
hint: "When enabled, the plugin appends each request and response to logs/paypal-requests-YYYY-MM-DD.log (path configurable via PAYPAL_LOG_DIR). Remember to save after toggling.",
|
|
468
|
+
hint: "When enabled, the plugin appends each request and response to .medusa/paypal-logs/paypal-requests-YYYY-MM-DD.log in your project (path configurable via PAYPAL_LOG_DIR). Remember to save after toggling.",
|
|
426
469
|
children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
427
470
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
428
471
|
"input",
|
|
@@ -444,6 +487,71 @@ function AdditionalSettingsTab() {
|
|
|
444
487
|
)
|
|
445
488
|
] }) });
|
|
446
489
|
}
|
|
490
|
+
function PayPalApplePayPage() {
|
|
491
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
492
|
+
}
|
|
493
|
+
const URL_RE = /(https?:\/\/[^\s]+[^\s.,!?])/g;
|
|
494
|
+
function NoticeText({ message }) {
|
|
495
|
+
const parts = message.split(URL_RE);
|
|
496
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: parts.map(
|
|
497
|
+
(part, i) => /^https?:\/\//.test(part) ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
498
|
+
"a",
|
|
499
|
+
{
|
|
500
|
+
href: part,
|
|
501
|
+
target: "_blank",
|
|
502
|
+
rel: "noopener noreferrer",
|
|
503
|
+
className: "underline",
|
|
504
|
+
children: part
|
|
505
|
+
},
|
|
506
|
+
i
|
|
507
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(React__default.default.Fragment, { children: part }, i)
|
|
508
|
+
) });
|
|
509
|
+
}
|
|
510
|
+
function MerchantStatusNotices({
|
|
511
|
+
environment,
|
|
512
|
+
only,
|
|
513
|
+
reloadKey
|
|
514
|
+
}) {
|
|
515
|
+
const [notices, setNotices] = React.useState([]);
|
|
516
|
+
React.useEffect(() => {
|
|
517
|
+
let cancelled = false;
|
|
518
|
+
setNotices([]);
|
|
519
|
+
(async () => {
|
|
520
|
+
try {
|
|
521
|
+
const json = await adminFetch(
|
|
522
|
+
"/admin/paypal/merchant-status",
|
|
523
|
+
environment ? { query: { environment } } : {}
|
|
524
|
+
);
|
|
525
|
+
if (cancelled) return;
|
|
526
|
+
setNotices(Array.isArray(json == null ? void 0 : json.notices) ? json.notices : []);
|
|
527
|
+
} catch {
|
|
528
|
+
}
|
|
529
|
+
})();
|
|
530
|
+
return () => {
|
|
531
|
+
cancelled = true;
|
|
532
|
+
};
|
|
533
|
+
}, [environment, reloadKey]);
|
|
534
|
+
const visible = only ? notices.filter((notice) => only.includes(notice.code)) : notices;
|
|
535
|
+
if (visible.length === 0) return null;
|
|
536
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", "data-testid": "paypal-merchant-notices", children: visible.map((notice) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
537
|
+
"div",
|
|
538
|
+
{
|
|
539
|
+
role: "alert",
|
|
540
|
+
className: "rounded border p-3 text-sm",
|
|
541
|
+
style: notice.level === "error" ? {
|
|
542
|
+
background: "#fef2f2",
|
|
543
|
+
borderColor: "#fecaca",
|
|
544
|
+
color: "#b91c1c"
|
|
545
|
+
} : {
|
|
546
|
+
background: "#fffbeb",
|
|
547
|
+
borderColor: "#fde68a",
|
|
548
|
+
color: "#92400e"
|
|
549
|
+
},
|
|
550
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(NoticeText, { message: notice.message })
|
|
551
|
+
},
|
|
552
|
+
notice.code
|
|
553
|
+
)) });
|
|
554
|
+
}
|
|
447
555
|
const DEFAULT_FORM = {
|
|
448
556
|
enabled: true,
|
|
449
557
|
title: "Credit or Debit Card",
|
|
@@ -478,15 +586,15 @@ const THREE_DS_OPTIONS = [
|
|
|
478
586
|
];
|
|
479
587
|
function AdvancedCardPaymentsTab() {
|
|
480
588
|
var _a, _b;
|
|
481
|
-
const [form, setForm] =
|
|
589
|
+
const [form, setForm] = React.useState(() => ({
|
|
482
590
|
...DEFAULT_FORM
|
|
483
591
|
}));
|
|
484
|
-
const [loading, setLoading] =
|
|
485
|
-
const [saving, setSaving] =
|
|
486
|
-
const [toast, setToast] =
|
|
487
|
-
const didInit =
|
|
488
|
-
const dismissToast =
|
|
489
|
-
|
|
592
|
+
const [loading, setLoading] = React.useState(false);
|
|
593
|
+
const [saving, setSaving] = React.useState(false);
|
|
594
|
+
const [toast, setToast] = React.useState(null);
|
|
595
|
+
const didInit = React.useRef(false);
|
|
596
|
+
const dismissToast = React.useCallback(() => setToast(null), []);
|
|
597
|
+
React.useEffect(() => {
|
|
490
598
|
if (didInit.current) return;
|
|
491
599
|
didInit.current = true;
|
|
492
600
|
(async () => {
|
|
@@ -529,6 +637,7 @@ function AdvancedCardPaymentsTab() {
|
|
|
529
637
|
/* @__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" }) }) }),
|
|
530
638
|
/* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
|
|
531
639
|
/* @__PURE__ */ jsxRuntime.jsx(Toast, { toast, onClose: dismissToast }),
|
|
640
|
+
/* @__PURE__ */ jsxRuntime.jsx(MerchantStatusNotices, { only: ["card_payments_not_enabled"] }),
|
|
532
641
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
533
642
|
SectionCard,
|
|
534
643
|
{
|
|
@@ -602,12 +711,21 @@ function AdvancedCardPaymentsTab() {
|
|
|
602
711
|
function PayPalGooglePayPage() {
|
|
603
712
|
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
604
713
|
}
|
|
605
|
-
function PayPalApplePayPage() {
|
|
606
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
607
|
-
}
|
|
608
714
|
const config = adminSdk.defineRouteConfig({
|
|
609
715
|
label: "PayPal Connection"
|
|
610
716
|
});
|
|
717
|
+
const SESSION_EXPIRED_MESSAGE = "Your admin session has expired. Reload this page and log in again.";
|
|
718
|
+
function describeFailure(status, body, fallback) {
|
|
719
|
+
var _a;
|
|
720
|
+
if (status === 401) return SESSION_EXPIRED_MESSAGE;
|
|
721
|
+
try {
|
|
722
|
+
const message = (_a = JSON.parse(body)) == null ? void 0 : _a.message;
|
|
723
|
+
if (typeof message === "string" && message.trim()) return message.trim();
|
|
724
|
+
} catch {
|
|
725
|
+
}
|
|
726
|
+
const text = body.trim();
|
|
727
|
+
return text && !text.startsWith("<") ? text.slice(0, 300) : fallback;
|
|
728
|
+
}
|
|
611
729
|
const PARTNER_JS_URL = "https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js";
|
|
612
730
|
const PARTNER_SCRIPT_ID = "paypal-partner-js";
|
|
613
731
|
const PARTNER_HELPER_SCRIPT_IDS = [
|
|
@@ -702,39 +820,39 @@ function clearCachedUrl(env) {
|
|
|
702
820
|
}
|
|
703
821
|
}
|
|
704
822
|
function PayPalConnectionPage() {
|
|
705
|
-
const [env, setEnv] =
|
|
706
|
-
const [envReady, setEnvReady] =
|
|
707
|
-
const [connState, setConnState] =
|
|
708
|
-
const [error, setError] =
|
|
709
|
-
const [finalUrl, setFinalUrl] =
|
|
710
|
-
const [showManual, setShowManual] =
|
|
711
|
-
const [clientId, setClientId] =
|
|
712
|
-
const [secret, setSecret] =
|
|
713
|
-
const [statusInfo, setStatusInfo] =
|
|
714
|
-
const [onboardingInProgress, setOnboardingInProgress] =
|
|
715
|
-
const initLoaderRef =
|
|
716
|
-
const paypalButtonRef =
|
|
717
|
-
const errorLogRef =
|
|
718
|
-
const runIdRef =
|
|
719
|
-
const currentRunId =
|
|
720
|
-
const completedRef =
|
|
721
|
-
const boundButtonsRef =
|
|
823
|
+
const [env, setEnv] = React.useState("live");
|
|
824
|
+
const [envReady, setEnvReady] = React.useState(false);
|
|
825
|
+
const [connState, setConnState] = React.useState("loading");
|
|
826
|
+
const [error, setError] = React.useState(null);
|
|
827
|
+
const [finalUrl, setFinalUrl] = React.useState("");
|
|
828
|
+
const [showManual, setShowManual] = React.useState(false);
|
|
829
|
+
const [clientId, setClientId] = React.useState("");
|
|
830
|
+
const [secret, setSecret] = React.useState("");
|
|
831
|
+
const [statusInfo, setStatusInfo] = React.useState(null);
|
|
832
|
+
const [onboardingInProgress, setOnboardingInProgress] = React.useState(false);
|
|
833
|
+
const initLoaderRef = React.useRef(null);
|
|
834
|
+
const paypalButtonRef = React.useRef(null);
|
|
835
|
+
const errorLogRef = React.useRef(null);
|
|
836
|
+
const runIdRef = React.useRef(0);
|
|
837
|
+
const currentRunId = React.useRef(0);
|
|
838
|
+
const completedRef = React.useRef(false);
|
|
839
|
+
const boundButtonsRef = React.useRef(
|
|
722
840
|
/* @__PURE__ */ new WeakMap()
|
|
723
841
|
);
|
|
724
|
-
const envRef =
|
|
842
|
+
const envRef = React.useRef(env);
|
|
725
843
|
envRef.current = env;
|
|
726
|
-
const pollTimerRef =
|
|
727
|
-
const pollAttemptsRef =
|
|
728
|
-
const ppBtnMeasureRef =
|
|
729
|
-
const [ppBtnWidth, setPpBtnWidth] =
|
|
730
|
-
const canSaveManual =
|
|
844
|
+
const pollTimerRef = React.useRef(null);
|
|
845
|
+
const pollAttemptsRef = React.useRef(0);
|
|
846
|
+
const ppBtnMeasureRef = React.useRef(null);
|
|
847
|
+
const [ppBtnWidth, setPpBtnWidth] = React.useState(null);
|
|
848
|
+
const canSaveManual = React.useMemo(() => {
|
|
731
849
|
return clientId.trim().length > 0 && secret.trim().length > 0;
|
|
732
850
|
}, [clientId, secret]);
|
|
733
|
-
const showError =
|
|
851
|
+
const showError = React.useCallback((msg) => {
|
|
734
852
|
setConnState("error");
|
|
735
853
|
setError(msg);
|
|
736
854
|
}, []);
|
|
737
|
-
const closeMiniBrowser =
|
|
855
|
+
const closeMiniBrowser = React.useCallback(() => {
|
|
738
856
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
739
857
|
try {
|
|
740
858
|
const close1 = (_d = (_c = (_b = (_a = window.PAYPAL) == null ? void 0 : _a.apps) == null ? void 0 : _b.Signup) == null ? void 0 : _c.MiniBrowser) == null ? void 0 : _d.closeFlow;
|
|
@@ -747,14 +865,14 @@ function PayPalConnectionPage() {
|
|
|
747
865
|
} catch {
|
|
748
866
|
}
|
|
749
867
|
}, []);
|
|
750
|
-
const stopStatusPolling =
|
|
868
|
+
const stopStatusPolling = React.useCallback(() => {
|
|
751
869
|
if (pollTimerRef.current) {
|
|
752
870
|
clearTimeout(pollTimerRef.current);
|
|
753
871
|
pollTimerRef.current = null;
|
|
754
872
|
}
|
|
755
873
|
pollAttemptsRef.current = 0;
|
|
756
874
|
}, []);
|
|
757
|
-
const refreshStatusAndMaybeConnect =
|
|
875
|
+
const refreshStatusAndMaybeConnect = React.useCallback(
|
|
758
876
|
async (activeEnv) => {
|
|
759
877
|
try {
|
|
760
878
|
const res = await fetch(`${STATUS_ENDPOINT}?environment=${activeEnv}`, {
|
|
@@ -780,7 +898,7 @@ function PayPalConnectionPage() {
|
|
|
780
898
|
},
|
|
781
899
|
[closeMiniBrowser, stopStatusPolling]
|
|
782
900
|
);
|
|
783
|
-
const startStatusPolling =
|
|
901
|
+
const startStatusPolling = React.useCallback(() => {
|
|
784
902
|
stopStatusPolling();
|
|
785
903
|
const MAX_ATTEMPTS = 100;
|
|
786
904
|
const tick = async () => {
|
|
@@ -795,7 +913,7 @@ function PayPalConnectionPage() {
|
|
|
795
913
|
};
|
|
796
914
|
pollTimerRef.current = setTimeout(tick, 3e3);
|
|
797
915
|
}, [refreshStatusAndMaybeConnect, stopStatusPolling]);
|
|
798
|
-
const completeOnboarding =
|
|
916
|
+
const completeOnboarding = React.useCallback(
|
|
799
917
|
async (authCode, sharedId) => {
|
|
800
918
|
if (!authCode || !sharedId) return;
|
|
801
919
|
if (completedRef.current) return;
|
|
@@ -817,7 +935,13 @@ function PayPalConnectionPage() {
|
|
|
817
935
|
});
|
|
818
936
|
if (!res.ok) {
|
|
819
937
|
const txt = await res.text().catch(() => "");
|
|
820
|
-
throw new Error(
|
|
938
|
+
throw new Error(
|
|
939
|
+
describeFailure(
|
|
940
|
+
res.status,
|
|
941
|
+
txt,
|
|
942
|
+
`Onboarding exchange failed (${res.status})`
|
|
943
|
+
)
|
|
944
|
+
);
|
|
821
945
|
}
|
|
822
946
|
closeMiniBrowser();
|
|
823
947
|
clearCachedUrl(activeEnv);
|
|
@@ -844,12 +968,12 @@ function PayPalConnectionPage() {
|
|
|
844
968
|
},
|
|
845
969
|
[closeMiniBrowser, stopStatusPolling]
|
|
846
970
|
);
|
|
847
|
-
const isConnectButtonBound =
|
|
971
|
+
const isConnectButtonBound = React.useCallback(() => {
|
|
848
972
|
const anchor = paypalButtonRef.current;
|
|
849
973
|
const mb = getMiniBrowser();
|
|
850
974
|
return !!anchor && !!mb && isMiniBrowserReady() && boundButtonsRef.current.get(anchor) === mb;
|
|
851
975
|
}, []);
|
|
852
|
-
const initPartner =
|
|
976
|
+
const initPartner = React.useCallback(() => {
|
|
853
977
|
const anchor = paypalButtonRef.current;
|
|
854
978
|
const mb = getMiniBrowser();
|
|
855
979
|
if (!anchor || !mb || !isMiniBrowserReady()) return false;
|
|
@@ -864,10 +988,10 @@ function PayPalConnectionPage() {
|
|
|
864
988
|
return false;
|
|
865
989
|
}
|
|
866
990
|
}, []);
|
|
867
|
-
|
|
991
|
+
React.useEffect(() => {
|
|
868
992
|
void loadMiniBrowser();
|
|
869
993
|
}, []);
|
|
870
|
-
const activatePayPal =
|
|
994
|
+
const activatePayPal = React.useCallback(
|
|
871
995
|
(url, runId) => {
|
|
872
996
|
if (paypalButtonRef.current) {
|
|
873
997
|
paypalButtonRef.current.href = url;
|
|
@@ -888,7 +1012,7 @@ function PayPalConnectionPage() {
|
|
|
888
1012
|
},
|
|
889
1013
|
[initPartner, showError]
|
|
890
1014
|
);
|
|
891
|
-
const fetchFreshLink =
|
|
1015
|
+
const fetchFreshLink = React.useCallback(
|
|
892
1016
|
async (targetEnv, runId) => {
|
|
893
1017
|
if (initLoaderRef.current) {
|
|
894
1018
|
const loaderText = initLoaderRef.current.querySelector("#loader-text");
|
|
@@ -922,7 +1046,7 @@ function PayPalConnectionPage() {
|
|
|
922
1046
|
},
|
|
923
1047
|
[activatePayPal, showError]
|
|
924
1048
|
);
|
|
925
|
-
|
|
1049
|
+
React.useEffect(() => {
|
|
926
1050
|
let alive = true;
|
|
927
1051
|
fetch(ENVIRONMENT_ENDPOINT, { method: "GET", credentials: "include" }).then((r) => r.json()).then((d) => {
|
|
928
1052
|
if (!alive) return;
|
|
@@ -935,7 +1059,7 @@ function PayPalConnectionPage() {
|
|
|
935
1059
|
alive = false;
|
|
936
1060
|
};
|
|
937
1061
|
}, []);
|
|
938
|
-
|
|
1062
|
+
React.useEffect(() => {
|
|
939
1063
|
if (!envReady) return;
|
|
940
1064
|
currentRunId.current = ++runIdRef.current;
|
|
941
1065
|
const runId = currentRunId.current;
|
|
@@ -975,7 +1099,7 @@ function PayPalConnectionPage() {
|
|
|
975
1099
|
cancelled = true;
|
|
976
1100
|
};
|
|
977
1101
|
}, [env, envReady, fetchFreshLink, activatePayPal]);
|
|
978
|
-
|
|
1102
|
+
React.useLayoutEffect(() => {
|
|
979
1103
|
window.onboardingCallback = (authCode, sharedId) => {
|
|
980
1104
|
void completeOnboarding(authCode, sharedId);
|
|
981
1105
|
};
|
|
@@ -983,7 +1107,7 @@ function PayPalConnectionPage() {
|
|
|
983
1107
|
window.onboardingCallback = void 0;
|
|
984
1108
|
};
|
|
985
1109
|
}, [completeOnboarding]);
|
|
986
|
-
|
|
1110
|
+
React.useEffect(() => {
|
|
987
1111
|
const onMessage = (event) => {
|
|
988
1112
|
const data = event == null ? void 0 : event.data;
|
|
989
1113
|
if (!data || data.source !== "paypal-onboarding-return") return;
|
|
@@ -1001,8 +1125,8 @@ function PayPalConnectionPage() {
|
|
|
1001
1125
|
window.addEventListener("message", onMessage);
|
|
1002
1126
|
return () => window.removeEventListener("message", onMessage);
|
|
1003
1127
|
}, [completeOnboarding, refreshStatusAndMaybeConnect]);
|
|
1004
|
-
|
|
1005
|
-
|
|
1128
|
+
React.useEffect(() => stopStatusPolling, [stopStatusPolling]);
|
|
1129
|
+
React.useLayoutEffect(() => {
|
|
1006
1130
|
const el = ppBtnMeasureRef.current;
|
|
1007
1131
|
if (!el) return;
|
|
1008
1132
|
const update = () => {
|
|
@@ -1055,7 +1179,13 @@ function PayPalConnectionPage() {
|
|
|
1055
1179
|
});
|
|
1056
1180
|
if (!res.ok) {
|
|
1057
1181
|
const txt = await res.text().catch(() => "");
|
|
1058
|
-
throw new Error(
|
|
1182
|
+
throw new Error(
|
|
1183
|
+
describeFailure(
|
|
1184
|
+
res.status,
|
|
1185
|
+
txt,
|
|
1186
|
+
`Save credentials failed (${res.status})`
|
|
1187
|
+
)
|
|
1188
|
+
);
|
|
1059
1189
|
}
|
|
1060
1190
|
const statusRes = await fetch(`${STATUS_ENDPOINT}?environment=${env}`, {
|
|
1061
1191
|
method: "GET",
|
|
@@ -1093,7 +1223,9 @@ function PayPalConnectionPage() {
|
|
|
1093
1223
|
});
|
|
1094
1224
|
if (!res.ok) {
|
|
1095
1225
|
const t = await res.text().catch(() => "");
|
|
1096
|
-
throw new Error(
|
|
1226
|
+
throw new Error(
|
|
1227
|
+
describeFailure(res.status, t, `Disconnect failed (${res.status})`)
|
|
1228
|
+
);
|
|
1097
1229
|
}
|
|
1098
1230
|
clearCachedUrl(env);
|
|
1099
1231
|
completedRef.current = false;
|
|
@@ -1101,7 +1233,8 @@ function PayPalConnectionPage() {
|
|
|
1101
1233
|
await fetchFreshLink(env, currentRunId.current);
|
|
1102
1234
|
} catch (e) {
|
|
1103
1235
|
console.error(e);
|
|
1104
|
-
|
|
1236
|
+
const stillConnected = await refreshStatusAndMaybeConnect(env);
|
|
1237
|
+
if (!stillConnected) setConnState("error");
|
|
1105
1238
|
setError((e == null ? void 0 : e.message) || "Failed to disconnect.");
|
|
1106
1239
|
} finally {
|
|
1107
1240
|
setOnboardingInProgress(false);
|
|
@@ -1146,8 +1279,27 @@ function PayPalConnectionPage() {
|
|
|
1146
1279
|
) }),
|
|
1147
1280
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium pt-2", children: env === "sandbox" ? "Connect to PayPal (Sandbox)" : "Connect to PayPal" }),
|
|
1148
1281
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-xl", children: connState === "connected" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1149
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm text-green-600 bg-green-50 p-3 rounded border border-green-200", children: [
|
|
1150
|
-
|
|
1282
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded border border-green-200", children: [
|
|
1283
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1284
|
+
"svg",
|
|
1285
|
+
{
|
|
1286
|
+
width: "16",
|
|
1287
|
+
height: "16",
|
|
1288
|
+
viewBox: "0 0 24 24",
|
|
1289
|
+
fill: "none",
|
|
1290
|
+
stroke: "currentColor",
|
|
1291
|
+
strokeWidth: "2.5",
|
|
1292
|
+
strokeLinecap: "round",
|
|
1293
|
+
strokeLinejoin: "round",
|
|
1294
|
+
"aria-hidden": "true",
|
|
1295
|
+
style: { flexShrink: 0 },
|
|
1296
|
+
children: [
|
|
1297
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1298
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "m8 12 3 3 5-6" })
|
|
1299
|
+
]
|
|
1300
|
+
}
|
|
1301
|
+
),
|
|
1302
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "Successfully connected to PayPal" }),
|
|
1151
1303
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1152
1304
|
"a",
|
|
1153
1305
|
{
|
|
@@ -1159,6 +1311,13 @@ function PayPalConnectionPage() {
|
|
|
1159
1311
|
}
|
|
1160
1312
|
)
|
|
1161
1313
|
] }),
|
|
1314
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1315
|
+
MerchantStatusNotices,
|
|
1316
|
+
{
|
|
1317
|
+
environment: env,
|
|
1318
|
+
reloadKey: (statusInfo == null ? void 0 : statusInfo.seller_client_id_masked) || ""
|
|
1319
|
+
}
|
|
1320
|
+
) }),
|
|
1162
1321
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-3 rounded-md border border-ui-border-base bg-ui-bg-subtle p-3 text-xs text-ui-fg-subtle", children: [
|
|
1163
1322
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium text-ui-fg-base", children: "Connected PayPal account" }),
|
|
1164
1323
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1", children: [
|
|
@@ -1167,6 +1326,14 @@ function PayPalConnectionPage() {
|
|
|
1167
1326
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono text-ui-fg-base", children: (statusInfo == null ? void 0 : statusInfo.seller_email) || "Unavailable" })
|
|
1168
1327
|
] })
|
|
1169
1328
|
] }),
|
|
1329
|
+
error ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1330
|
+
"div",
|
|
1331
|
+
{
|
|
1332
|
+
role: "alert",
|
|
1333
|
+
className: "mt-3 text-left text-xs bg-red-50 text-red-600 p-3 border border-red-200 rounded",
|
|
1334
|
+
children: error
|
|
1335
|
+
}
|
|
1336
|
+
) : null,
|
|
1170
1337
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 flex items-center gap-2", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1171
1338
|
"button",
|
|
1172
1339
|
{
|
|
@@ -1428,7 +1595,7 @@ const LABEL_OPTIONS = [
|
|
|
1428
1595
|
{ value: "pay", label: "Pay" }
|
|
1429
1596
|
];
|
|
1430
1597
|
function PayPalSettingsTab() {
|
|
1431
|
-
const [form, setForm] =
|
|
1598
|
+
const [form, setForm] = React.useState({
|
|
1432
1599
|
enabled: true,
|
|
1433
1600
|
title: "PayPal",
|
|
1434
1601
|
description: "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account",
|
|
@@ -1438,12 +1605,12 @@ function PayPalSettingsTab() {
|
|
|
1438
1605
|
buttonHeight: 48,
|
|
1439
1606
|
buttonLabel: "paypal"
|
|
1440
1607
|
});
|
|
1441
|
-
const [loading, setLoading] =
|
|
1442
|
-
const [saving, setSaving] =
|
|
1443
|
-
const [toast, setToast] =
|
|
1444
|
-
const didInit =
|
|
1445
|
-
const dismissToast =
|
|
1446
|
-
|
|
1608
|
+
const [loading, setLoading] = React.useState(false);
|
|
1609
|
+
const [saving, setSaving] = React.useState(false);
|
|
1610
|
+
const [toast, setToast] = React.useState(null);
|
|
1611
|
+
const didInit = React.useRef(false);
|
|
1612
|
+
const dismissToast = React.useCallback(() => setToast(null), []);
|
|
1613
|
+
React.useEffect(() => {
|
|
1447
1614
|
if (didInit.current) return;
|
|
1448
1615
|
didInit.current = true;
|
|
1449
1616
|
(async () => {
|
|
@@ -1630,6 +1797,10 @@ const routeModule = {
|
|
|
1630
1797
|
Component: AdditionalSettingsTab,
|
|
1631
1798
|
path: "/settings/paypal/additional-settings"
|
|
1632
1799
|
},
|
|
1800
|
+
{
|
|
1801
|
+
Component: PayPalApplePayPage,
|
|
1802
|
+
path: "/settings/paypal/apple-pay"
|
|
1803
|
+
},
|
|
1633
1804
|
{
|
|
1634
1805
|
Component: AdvancedCardPaymentsTab,
|
|
1635
1806
|
path: "/settings/paypal/advanced-card-payments"
|
|
@@ -1638,10 +1809,6 @@ const routeModule = {
|
|
|
1638
1809
|
Component: PayPalGooglePayPage,
|
|
1639
1810
|
path: "/settings/paypal/google-pay"
|
|
1640
1811
|
},
|
|
1641
|
-
{
|
|
1642
|
-
Component: PayPalApplePayPage,
|
|
1643
|
-
path: "/settings/paypal/apple-pay"
|
|
1644
|
-
},
|
|
1645
1812
|
{
|
|
1646
1813
|
Component: PayPalConnectionPage,
|
|
1647
1814
|
path: "/settings/paypal/connection"
|