@easypayment/medusa-payment-paypal 1.3.7 → 1.3.9
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 +172 -76
- package/.medusa/server/src/admin/index.mjs +107 -13
- package/.medusa/server/src/api/admin/paypal/logs/route.d.ts.map +1 -1
- package/.medusa/server/src/api/admin/paypal/logs/route.js.map +1 -1
- 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 +101 -102
- package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
- package/.medusa/server/src/modules/paypal/service.d.ts +34 -0
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +161 -34
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.d.ts +12 -0
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +25 -1
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/merchant-status.d.ts +50 -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/CHANGELOG.md +78 -0
- package/README.md +108 -61
- package/package.json +2 -2
- package/src/admin/routes/settings/paypal/_components/MerchantStatusNotices.tsx +116 -0
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +32 -6
- package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +2 -0
- package/src/admin/routes/settings/paypal/connection/page.tsx +7 -0
- package/src/api/admin/paypal/logs/route.ts +1 -4
- package/src/api/admin/paypal/merchant-status/route.ts +36 -0
- package/src/api/store/paypal/create-order/route.ts +176 -157
- package/src/modules/paypal/service.ts +222 -43
- package/src/modules/paypal/types/config.ts +35 -2
- package/src/modules/paypal/utils/merchant-status.ts +185 -0
- package/src/modules/paypal/utils/order-context.ts +163 -0
|
@@ -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);
|
|
@@ -157,9 +159,10 @@ async function adminFetch(path, opts = {}) {
|
|
|
157
159
|
const DEFAULT_FORM$1 = {
|
|
158
160
|
paymentAction: "capture",
|
|
159
161
|
brandName: "PayPal",
|
|
160
|
-
landingPage: "
|
|
162
|
+
landingPage: "login",
|
|
161
163
|
requireInstantPayment: false,
|
|
162
164
|
sendItemDetails: true,
|
|
165
|
+
sendShippingAddress: true,
|
|
163
166
|
invoicePrefix: "PP-",
|
|
164
167
|
creditCardStatementName: "PayPal",
|
|
165
168
|
debugLogging: false
|
|
@@ -169,21 +172,23 @@ function mergeWithDefaults$1(saved) {
|
|
|
169
172
|
const entries = Object.entries(saved).filter(
|
|
170
173
|
([, value]) => value !== void 0
|
|
171
174
|
);
|
|
172
|
-
|
|
175
|
+
const merged = {
|
|
173
176
|
...DEFAULT_FORM$1,
|
|
174
177
|
...Object.fromEntries(entries)
|
|
175
178
|
};
|
|
179
|
+
if (merged.landingPage !== "billing") merged.landingPage = "login";
|
|
180
|
+
return merged;
|
|
176
181
|
}
|
|
177
182
|
function AdditionalSettingsTab() {
|
|
178
|
-
const [form, setForm] =
|
|
183
|
+
const [form, setForm] = React.useState(() => ({
|
|
179
184
|
...DEFAULT_FORM$1
|
|
180
185
|
}));
|
|
181
|
-
const [loading, setLoading] =
|
|
182
|
-
const [saving, setSaving] =
|
|
183
|
-
const [downloading, setDownloading] =
|
|
184
|
-
const [toast, setToast] =
|
|
185
|
-
const didInit =
|
|
186
|
-
const dismissToast =
|
|
186
|
+
const [loading, setLoading] = React.useState(false);
|
|
187
|
+
const [saving, setSaving] = React.useState(false);
|
|
188
|
+
const [downloading, setDownloading] = React.useState(false);
|
|
189
|
+
const [toast, setToast] = React.useState(null);
|
|
190
|
+
const didInit = React.useRef(false);
|
|
191
|
+
const dismissToast = React.useCallback(() => setToast(null), []);
|
|
187
192
|
async function onDownloadLog() {
|
|
188
193
|
var _a;
|
|
189
194
|
try {
|
|
@@ -227,7 +232,7 @@ function AdditionalSettingsTab() {
|
|
|
227
232
|
setDownloading(false);
|
|
228
233
|
}
|
|
229
234
|
}
|
|
230
|
-
|
|
235
|
+
React.useEffect(() => {
|
|
231
236
|
if (didInit.current) return;
|
|
232
237
|
didInit.current = true;
|
|
233
238
|
(async () => {
|
|
@@ -327,9 +332,8 @@ function AdditionalSettingsTab() {
|
|
|
327
332
|
})),
|
|
328
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",
|
|
329
334
|
children: [
|
|
330
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "
|
|
331
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "
|
|
332
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "billing", children: "Billing" })
|
|
335
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "login", children: "Login (PayPal account)" }),
|
|
336
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "billing", children: "Guest checkout (card form)" })
|
|
333
337
|
]
|
|
334
338
|
}
|
|
335
339
|
) }),
|
|
@@ -370,6 +374,28 @@ function AdditionalSettingsTab() {
|
|
|
370
374
|
] })
|
|
371
375
|
}
|
|
372
376
|
),
|
|
377
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
378
|
+
FieldRow,
|
|
379
|
+
{
|
|
380
|
+
label: "Send Shipping Address",
|
|
381
|
+
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.",
|
|
382
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
383
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
384
|
+
"input",
|
|
385
|
+
{
|
|
386
|
+
type: "checkbox",
|
|
387
|
+
checked: form.sendShippingAddress,
|
|
388
|
+
onChange: (e) => setForm((p) => ({
|
|
389
|
+
...p,
|
|
390
|
+
sendShippingAddress: e.target.checked
|
|
391
|
+
})),
|
|
392
|
+
className: "h-4 w-4 rounded border-ui-border-base"
|
|
393
|
+
}
|
|
394
|
+
),
|
|
395
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Send the checkout shipping address to PayPal" })
|
|
396
|
+
] })
|
|
397
|
+
}
|
|
398
|
+
),
|
|
373
399
|
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Invoice prefix", htmlFor: "as-invoice-prefix", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
374
400
|
"input",
|
|
375
401
|
{
|
|
@@ -444,6 +470,68 @@ function AdditionalSettingsTab() {
|
|
|
444
470
|
)
|
|
445
471
|
] }) });
|
|
446
472
|
}
|
|
473
|
+
const URL_RE = /(https?:\/\/[^\s]+[^\s.,!?])/g;
|
|
474
|
+
function NoticeText({ message }) {
|
|
475
|
+
const parts = message.split(URL_RE);
|
|
476
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: parts.map(
|
|
477
|
+
(part, i) => /^https?:\/\//.test(part) ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
478
|
+
"a",
|
|
479
|
+
{
|
|
480
|
+
href: part,
|
|
481
|
+
target: "_blank",
|
|
482
|
+
rel: "noopener noreferrer",
|
|
483
|
+
className: "underline",
|
|
484
|
+
children: part
|
|
485
|
+
},
|
|
486
|
+
i
|
|
487
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(React__default.default.Fragment, { children: part }, i)
|
|
488
|
+
) });
|
|
489
|
+
}
|
|
490
|
+
function MerchantStatusNotices({
|
|
491
|
+
environment,
|
|
492
|
+
only,
|
|
493
|
+
reloadKey
|
|
494
|
+
}) {
|
|
495
|
+
const [notices, setNotices] = React.useState([]);
|
|
496
|
+
React.useEffect(() => {
|
|
497
|
+
let cancelled = false;
|
|
498
|
+
setNotices([]);
|
|
499
|
+
(async () => {
|
|
500
|
+
try {
|
|
501
|
+
const json = await adminFetch(
|
|
502
|
+
"/admin/paypal/merchant-status",
|
|
503
|
+
environment ? { query: { environment } } : {}
|
|
504
|
+
);
|
|
505
|
+
if (cancelled) return;
|
|
506
|
+
setNotices(Array.isArray(json == null ? void 0 : json.notices) ? json.notices : []);
|
|
507
|
+
} catch {
|
|
508
|
+
}
|
|
509
|
+
})();
|
|
510
|
+
return () => {
|
|
511
|
+
cancelled = true;
|
|
512
|
+
};
|
|
513
|
+
}, [environment, reloadKey]);
|
|
514
|
+
const visible = only ? notices.filter((notice) => only.includes(notice.code)) : notices;
|
|
515
|
+
if (visible.length === 0) return null;
|
|
516
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", "data-testid": "paypal-merchant-notices", children: visible.map((notice) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
517
|
+
"div",
|
|
518
|
+
{
|
|
519
|
+
role: "alert",
|
|
520
|
+
className: "rounded border p-3 text-sm",
|
|
521
|
+
style: notice.level === "error" ? {
|
|
522
|
+
background: "#fef2f2",
|
|
523
|
+
borderColor: "#fecaca",
|
|
524
|
+
color: "#b91c1c"
|
|
525
|
+
} : {
|
|
526
|
+
background: "#fffbeb",
|
|
527
|
+
borderColor: "#fde68a",
|
|
528
|
+
color: "#92400e"
|
|
529
|
+
},
|
|
530
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(NoticeText, { message: notice.message })
|
|
531
|
+
},
|
|
532
|
+
notice.code
|
|
533
|
+
)) });
|
|
534
|
+
}
|
|
447
535
|
const DEFAULT_FORM = {
|
|
448
536
|
enabled: true,
|
|
449
537
|
title: "Credit or Debit Card",
|
|
@@ -478,15 +566,15 @@ const THREE_DS_OPTIONS = [
|
|
|
478
566
|
];
|
|
479
567
|
function AdvancedCardPaymentsTab() {
|
|
480
568
|
var _a, _b;
|
|
481
|
-
const [form, setForm] =
|
|
569
|
+
const [form, setForm] = React.useState(() => ({
|
|
482
570
|
...DEFAULT_FORM
|
|
483
571
|
}));
|
|
484
|
-
const [loading, setLoading] =
|
|
485
|
-
const [saving, setSaving] =
|
|
486
|
-
const [toast, setToast] =
|
|
487
|
-
const didInit =
|
|
488
|
-
const dismissToast =
|
|
489
|
-
|
|
572
|
+
const [loading, setLoading] = React.useState(false);
|
|
573
|
+
const [saving, setSaving] = React.useState(false);
|
|
574
|
+
const [toast, setToast] = React.useState(null);
|
|
575
|
+
const didInit = React.useRef(false);
|
|
576
|
+
const dismissToast = React.useCallback(() => setToast(null), []);
|
|
577
|
+
React.useEffect(() => {
|
|
490
578
|
if (didInit.current) return;
|
|
491
579
|
didInit.current = true;
|
|
492
580
|
(async () => {
|
|
@@ -529,6 +617,7 @@ function AdvancedCardPaymentsTab() {
|
|
|
529
617
|
/* @__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
618
|
/* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
|
|
531
619
|
/* @__PURE__ */ jsxRuntime.jsx(Toast, { toast, onClose: dismissToast }),
|
|
620
|
+
/* @__PURE__ */ jsxRuntime.jsx(MerchantStatusNotices, { only: ["card_payments_not_enabled"] }),
|
|
532
621
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
533
622
|
SectionCard,
|
|
534
623
|
{
|
|
@@ -699,39 +788,39 @@ function clearCachedUrl(env) {
|
|
|
699
788
|
}
|
|
700
789
|
}
|
|
701
790
|
function PayPalConnectionPage() {
|
|
702
|
-
const [env, setEnv] =
|
|
703
|
-
const [envReady, setEnvReady] =
|
|
704
|
-
const [connState, setConnState] =
|
|
705
|
-
const [error, setError] =
|
|
706
|
-
const [finalUrl, setFinalUrl] =
|
|
707
|
-
const [showManual, setShowManual] =
|
|
708
|
-
const [clientId, setClientId] =
|
|
709
|
-
const [secret, setSecret] =
|
|
710
|
-
const [statusInfo, setStatusInfo] =
|
|
711
|
-
const [onboardingInProgress, setOnboardingInProgress] =
|
|
712
|
-
const initLoaderRef =
|
|
713
|
-
const paypalButtonRef =
|
|
714
|
-
const errorLogRef =
|
|
715
|
-
const runIdRef =
|
|
716
|
-
const currentRunId =
|
|
717
|
-
const completedRef =
|
|
718
|
-
const boundButtonsRef =
|
|
791
|
+
const [env, setEnv] = React.useState("live");
|
|
792
|
+
const [envReady, setEnvReady] = React.useState(false);
|
|
793
|
+
const [connState, setConnState] = React.useState("loading");
|
|
794
|
+
const [error, setError] = React.useState(null);
|
|
795
|
+
const [finalUrl, setFinalUrl] = React.useState("");
|
|
796
|
+
const [showManual, setShowManual] = React.useState(false);
|
|
797
|
+
const [clientId, setClientId] = React.useState("");
|
|
798
|
+
const [secret, setSecret] = React.useState("");
|
|
799
|
+
const [statusInfo, setStatusInfo] = React.useState(null);
|
|
800
|
+
const [onboardingInProgress, setOnboardingInProgress] = React.useState(false);
|
|
801
|
+
const initLoaderRef = React.useRef(null);
|
|
802
|
+
const paypalButtonRef = React.useRef(null);
|
|
803
|
+
const errorLogRef = React.useRef(null);
|
|
804
|
+
const runIdRef = React.useRef(0);
|
|
805
|
+
const currentRunId = React.useRef(0);
|
|
806
|
+
const completedRef = React.useRef(false);
|
|
807
|
+
const boundButtonsRef = React.useRef(
|
|
719
808
|
/* @__PURE__ */ new WeakMap()
|
|
720
809
|
);
|
|
721
|
-
const envRef =
|
|
810
|
+
const envRef = React.useRef(env);
|
|
722
811
|
envRef.current = env;
|
|
723
|
-
const pollTimerRef =
|
|
724
|
-
const pollAttemptsRef =
|
|
725
|
-
const ppBtnMeasureRef =
|
|
726
|
-
const [ppBtnWidth, setPpBtnWidth] =
|
|
727
|
-
const canSaveManual =
|
|
812
|
+
const pollTimerRef = React.useRef(null);
|
|
813
|
+
const pollAttemptsRef = React.useRef(0);
|
|
814
|
+
const ppBtnMeasureRef = React.useRef(null);
|
|
815
|
+
const [ppBtnWidth, setPpBtnWidth] = React.useState(null);
|
|
816
|
+
const canSaveManual = React.useMemo(() => {
|
|
728
817
|
return clientId.trim().length > 0 && secret.trim().length > 0;
|
|
729
818
|
}, [clientId, secret]);
|
|
730
|
-
const showError =
|
|
819
|
+
const showError = React.useCallback((msg) => {
|
|
731
820
|
setConnState("error");
|
|
732
821
|
setError(msg);
|
|
733
822
|
}, []);
|
|
734
|
-
const closeMiniBrowser =
|
|
823
|
+
const closeMiniBrowser = React.useCallback(() => {
|
|
735
824
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
736
825
|
try {
|
|
737
826
|
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;
|
|
@@ -744,14 +833,14 @@ function PayPalConnectionPage() {
|
|
|
744
833
|
} catch {
|
|
745
834
|
}
|
|
746
835
|
}, []);
|
|
747
|
-
const stopStatusPolling =
|
|
836
|
+
const stopStatusPolling = React.useCallback(() => {
|
|
748
837
|
if (pollTimerRef.current) {
|
|
749
838
|
clearTimeout(pollTimerRef.current);
|
|
750
839
|
pollTimerRef.current = null;
|
|
751
840
|
}
|
|
752
841
|
pollAttemptsRef.current = 0;
|
|
753
842
|
}, []);
|
|
754
|
-
const refreshStatusAndMaybeConnect =
|
|
843
|
+
const refreshStatusAndMaybeConnect = React.useCallback(
|
|
755
844
|
async (activeEnv) => {
|
|
756
845
|
try {
|
|
757
846
|
const res = await fetch(`${STATUS_ENDPOINT}?environment=${activeEnv}`, {
|
|
@@ -777,7 +866,7 @@ function PayPalConnectionPage() {
|
|
|
777
866
|
},
|
|
778
867
|
[closeMiniBrowser, stopStatusPolling]
|
|
779
868
|
);
|
|
780
|
-
const startStatusPolling =
|
|
869
|
+
const startStatusPolling = React.useCallback(() => {
|
|
781
870
|
stopStatusPolling();
|
|
782
871
|
const MAX_ATTEMPTS = 100;
|
|
783
872
|
const tick = async () => {
|
|
@@ -792,7 +881,7 @@ function PayPalConnectionPage() {
|
|
|
792
881
|
};
|
|
793
882
|
pollTimerRef.current = setTimeout(tick, 3e3);
|
|
794
883
|
}, [refreshStatusAndMaybeConnect, stopStatusPolling]);
|
|
795
|
-
const completeOnboarding =
|
|
884
|
+
const completeOnboarding = React.useCallback(
|
|
796
885
|
async (authCode, sharedId) => {
|
|
797
886
|
if (!authCode || !sharedId) return;
|
|
798
887
|
if (completedRef.current) return;
|
|
@@ -841,12 +930,12 @@ function PayPalConnectionPage() {
|
|
|
841
930
|
},
|
|
842
931
|
[closeMiniBrowser, stopStatusPolling]
|
|
843
932
|
);
|
|
844
|
-
const isConnectButtonBound =
|
|
933
|
+
const isConnectButtonBound = React.useCallback(() => {
|
|
845
934
|
const anchor = paypalButtonRef.current;
|
|
846
935
|
const mb = getMiniBrowser();
|
|
847
936
|
return !!anchor && !!mb && isMiniBrowserReady() && boundButtonsRef.current.get(anchor) === mb;
|
|
848
937
|
}, []);
|
|
849
|
-
const initPartner =
|
|
938
|
+
const initPartner = React.useCallback(() => {
|
|
850
939
|
const anchor = paypalButtonRef.current;
|
|
851
940
|
const mb = getMiniBrowser();
|
|
852
941
|
if (!anchor || !mb || !isMiniBrowserReady()) return false;
|
|
@@ -861,10 +950,10 @@ function PayPalConnectionPage() {
|
|
|
861
950
|
return false;
|
|
862
951
|
}
|
|
863
952
|
}, []);
|
|
864
|
-
|
|
953
|
+
React.useEffect(() => {
|
|
865
954
|
void loadMiniBrowser();
|
|
866
955
|
}, []);
|
|
867
|
-
const activatePayPal =
|
|
956
|
+
const activatePayPal = React.useCallback(
|
|
868
957
|
(url, runId) => {
|
|
869
958
|
if (paypalButtonRef.current) {
|
|
870
959
|
paypalButtonRef.current.href = url;
|
|
@@ -885,7 +974,7 @@ function PayPalConnectionPage() {
|
|
|
885
974
|
},
|
|
886
975
|
[initPartner, showError]
|
|
887
976
|
);
|
|
888
|
-
const fetchFreshLink =
|
|
977
|
+
const fetchFreshLink = React.useCallback(
|
|
889
978
|
async (targetEnv, runId) => {
|
|
890
979
|
if (initLoaderRef.current) {
|
|
891
980
|
const loaderText = initLoaderRef.current.querySelector("#loader-text");
|
|
@@ -919,7 +1008,7 @@ function PayPalConnectionPage() {
|
|
|
919
1008
|
},
|
|
920
1009
|
[activatePayPal, showError]
|
|
921
1010
|
);
|
|
922
|
-
|
|
1011
|
+
React.useEffect(() => {
|
|
923
1012
|
let alive = true;
|
|
924
1013
|
fetch(ENVIRONMENT_ENDPOINT, { method: "GET", credentials: "include" }).then((r) => r.json()).then((d) => {
|
|
925
1014
|
if (!alive) return;
|
|
@@ -932,7 +1021,7 @@ function PayPalConnectionPage() {
|
|
|
932
1021
|
alive = false;
|
|
933
1022
|
};
|
|
934
1023
|
}, []);
|
|
935
|
-
|
|
1024
|
+
React.useEffect(() => {
|
|
936
1025
|
if (!envReady) return;
|
|
937
1026
|
currentRunId.current = ++runIdRef.current;
|
|
938
1027
|
const runId = currentRunId.current;
|
|
@@ -972,7 +1061,7 @@ function PayPalConnectionPage() {
|
|
|
972
1061
|
cancelled = true;
|
|
973
1062
|
};
|
|
974
1063
|
}, [env, envReady, fetchFreshLink, activatePayPal]);
|
|
975
|
-
|
|
1064
|
+
React.useLayoutEffect(() => {
|
|
976
1065
|
window.onboardingCallback = (authCode, sharedId) => {
|
|
977
1066
|
void completeOnboarding(authCode, sharedId);
|
|
978
1067
|
};
|
|
@@ -980,7 +1069,7 @@ function PayPalConnectionPage() {
|
|
|
980
1069
|
window.onboardingCallback = void 0;
|
|
981
1070
|
};
|
|
982
1071
|
}, [completeOnboarding]);
|
|
983
|
-
|
|
1072
|
+
React.useEffect(() => {
|
|
984
1073
|
const onMessage = (event) => {
|
|
985
1074
|
const data = event == null ? void 0 : event.data;
|
|
986
1075
|
if (!data || data.source !== "paypal-onboarding-return") return;
|
|
@@ -998,8 +1087,8 @@ function PayPalConnectionPage() {
|
|
|
998
1087
|
window.addEventListener("message", onMessage);
|
|
999
1088
|
return () => window.removeEventListener("message", onMessage);
|
|
1000
1089
|
}, [completeOnboarding, refreshStatusAndMaybeConnect]);
|
|
1001
|
-
|
|
1002
|
-
|
|
1090
|
+
React.useEffect(() => stopStatusPolling, [stopStatusPolling]);
|
|
1091
|
+
React.useLayoutEffect(() => {
|
|
1003
1092
|
const el = ppBtnMeasureRef.current;
|
|
1004
1093
|
if (!el) return;
|
|
1005
1094
|
const update = () => {
|
|
@@ -1156,6 +1245,13 @@ function PayPalConnectionPage() {
|
|
|
1156
1245
|
}
|
|
1157
1246
|
)
|
|
1158
1247
|
] }),
|
|
1248
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1249
|
+
MerchantStatusNotices,
|
|
1250
|
+
{
|
|
1251
|
+
environment: env,
|
|
1252
|
+
reloadKey: (statusInfo == null ? void 0 : statusInfo.seller_client_id_masked) || ""
|
|
1253
|
+
}
|
|
1254
|
+
) }),
|
|
1159
1255
|
/* @__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: [
|
|
1160
1256
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium text-ui-fg-base", children: "Connected PayPal account" }),
|
|
1161
1257
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1", children: [
|
|
@@ -1400,9 +1496,6 @@ function PayPalConnectionPage() {
|
|
|
1400
1496
|
function PayPalGooglePayPage() {
|
|
1401
1497
|
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1402
1498
|
}
|
|
1403
|
-
function PayPalPayLaterMessagingPage() {
|
|
1404
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1405
|
-
}
|
|
1406
1499
|
const COLOR_OPTIONS = [
|
|
1407
1500
|
{ value: "gold", label: "Gold (Recommended)" },
|
|
1408
1501
|
{ value: "blue", label: "Blue" },
|
|
@@ -1428,7 +1521,7 @@ const LABEL_OPTIONS = [
|
|
|
1428
1521
|
{ value: "pay", label: "Pay" }
|
|
1429
1522
|
];
|
|
1430
1523
|
function PayPalSettingsTab() {
|
|
1431
|
-
const [form, setForm] =
|
|
1524
|
+
const [form, setForm] = React.useState({
|
|
1432
1525
|
enabled: true,
|
|
1433
1526
|
title: "PayPal",
|
|
1434
1527
|
description: "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account",
|
|
@@ -1438,12 +1531,12 @@ function PayPalSettingsTab() {
|
|
|
1438
1531
|
buttonHeight: 48,
|
|
1439
1532
|
buttonLabel: "paypal"
|
|
1440
1533
|
});
|
|
1441
|
-
const [loading, setLoading] =
|
|
1442
|
-
const [saving, setSaving] =
|
|
1443
|
-
const [toast, setToast] =
|
|
1444
|
-
const didInit =
|
|
1445
|
-
const dismissToast =
|
|
1446
|
-
|
|
1534
|
+
const [loading, setLoading] = React.useState(false);
|
|
1535
|
+
const [saving, setSaving] = React.useState(false);
|
|
1536
|
+
const [toast, setToast] = React.useState(null);
|
|
1537
|
+
const didInit = React.useRef(false);
|
|
1538
|
+
const dismissToast = React.useCallback(() => setToast(null), []);
|
|
1539
|
+
React.useEffect(() => {
|
|
1447
1540
|
if (didInit.current) return;
|
|
1448
1541
|
didInit.current = true;
|
|
1449
1542
|
(async () => {
|
|
@@ -1619,6 +1712,9 @@ function PayPalSettingsTab() {
|
|
|
1619
1712
|
)
|
|
1620
1713
|
] }) });
|
|
1621
1714
|
}
|
|
1715
|
+
function PayPalPayLaterMessagingPage() {
|
|
1716
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1717
|
+
}
|
|
1622
1718
|
const widgetModule = { widgets: [] };
|
|
1623
1719
|
const routeModule = {
|
|
1624
1720
|
routes: [
|
|
@@ -1646,13 +1742,13 @@ const routeModule = {
|
|
|
1646
1742
|
Component: PayPalGooglePayPage,
|
|
1647
1743
|
path: "/settings/paypal/google-pay"
|
|
1648
1744
|
},
|
|
1649
|
-
{
|
|
1650
|
-
Component: PayPalPayLaterMessagingPage,
|
|
1651
|
-
path: "/settings/paypal/pay-later-messaging"
|
|
1652
|
-
},
|
|
1653
1745
|
{
|
|
1654
1746
|
Component: PayPalSettingsTab,
|
|
1655
1747
|
path: "/settings/paypal/paypal-settings"
|
|
1748
|
+
},
|
|
1749
|
+
{
|
|
1750
|
+
Component: PayPalPayLaterMessagingPage,
|
|
1751
|
+
path: "/settings/paypal/pay-later-messaging"
|
|
1656
1752
|
}
|
|
1657
1753
|
]
|
|
1658
1754
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
3
|
import { Navigate, useLocation, Link } from "react-router-dom";
|
|
4
|
-
import { useEffect, useState, useRef, useCallback, useMemo, useLayoutEffect } from "react";
|
|
4
|
+
import React, { useEffect, useState, useRef, useCallback, useMemo, useLayoutEffect } from "react";
|
|
5
5
|
const config$1 = defineRouteConfig({
|
|
6
6
|
label: "PayPal"
|
|
7
7
|
});
|
|
@@ -156,9 +156,10 @@ async function adminFetch(path, opts = {}) {
|
|
|
156
156
|
const DEFAULT_FORM$1 = {
|
|
157
157
|
paymentAction: "capture",
|
|
158
158
|
brandName: "PayPal",
|
|
159
|
-
landingPage: "
|
|
159
|
+
landingPage: "login",
|
|
160
160
|
requireInstantPayment: false,
|
|
161
161
|
sendItemDetails: true,
|
|
162
|
+
sendShippingAddress: true,
|
|
162
163
|
invoicePrefix: "PP-",
|
|
163
164
|
creditCardStatementName: "PayPal",
|
|
164
165
|
debugLogging: false
|
|
@@ -168,10 +169,12 @@ function mergeWithDefaults$1(saved) {
|
|
|
168
169
|
const entries = Object.entries(saved).filter(
|
|
169
170
|
([, value]) => value !== void 0
|
|
170
171
|
);
|
|
171
|
-
|
|
172
|
+
const merged = {
|
|
172
173
|
...DEFAULT_FORM$1,
|
|
173
174
|
...Object.fromEntries(entries)
|
|
174
175
|
};
|
|
176
|
+
if (merged.landingPage !== "billing") merged.landingPage = "login";
|
|
177
|
+
return merged;
|
|
175
178
|
}
|
|
176
179
|
function AdditionalSettingsTab() {
|
|
177
180
|
const [form, setForm] = useState(() => ({
|
|
@@ -326,9 +329,8 @@ function AdditionalSettingsTab() {
|
|
|
326
329
|
})),
|
|
327
330
|
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",
|
|
328
331
|
children: [
|
|
329
|
-
/* @__PURE__ */ jsx("option", { value: "
|
|
330
|
-
/* @__PURE__ */ jsx("option", { value: "
|
|
331
|
-
/* @__PURE__ */ jsx("option", { value: "billing", children: "Billing" })
|
|
332
|
+
/* @__PURE__ */ jsx("option", { value: "login", children: "Login (PayPal account)" }),
|
|
333
|
+
/* @__PURE__ */ jsx("option", { value: "billing", children: "Guest checkout (card form)" })
|
|
332
334
|
]
|
|
333
335
|
}
|
|
334
336
|
) }),
|
|
@@ -369,6 +371,28 @@ function AdditionalSettingsTab() {
|
|
|
369
371
|
] })
|
|
370
372
|
}
|
|
371
373
|
),
|
|
374
|
+
/* @__PURE__ */ jsx(
|
|
375
|
+
FieldRow,
|
|
376
|
+
{
|
|
377
|
+
label: "Send Shipping Address",
|
|
378
|
+
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.",
|
|
379
|
+
children: /* @__PURE__ */ jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
380
|
+
/* @__PURE__ */ jsx(
|
|
381
|
+
"input",
|
|
382
|
+
{
|
|
383
|
+
type: "checkbox",
|
|
384
|
+
checked: form.sendShippingAddress,
|
|
385
|
+
onChange: (e) => setForm((p) => ({
|
|
386
|
+
...p,
|
|
387
|
+
sendShippingAddress: e.target.checked
|
|
388
|
+
})),
|
|
389
|
+
className: "h-4 w-4 rounded border-ui-border-base"
|
|
390
|
+
}
|
|
391
|
+
),
|
|
392
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-base", children: "Send the checkout shipping address to PayPal" })
|
|
393
|
+
] })
|
|
394
|
+
}
|
|
395
|
+
),
|
|
372
396
|
/* @__PURE__ */ jsx(FieldRow, { label: "Invoice prefix", htmlFor: "as-invoice-prefix", children: /* @__PURE__ */ jsx(
|
|
373
397
|
"input",
|
|
374
398
|
{
|
|
@@ -443,6 +467,68 @@ function AdditionalSettingsTab() {
|
|
|
443
467
|
)
|
|
444
468
|
] }) });
|
|
445
469
|
}
|
|
470
|
+
const URL_RE = /(https?:\/\/[^\s]+[^\s.,!?])/g;
|
|
471
|
+
function NoticeText({ message }) {
|
|
472
|
+
const parts = message.split(URL_RE);
|
|
473
|
+
return /* @__PURE__ */ jsx(Fragment, { children: parts.map(
|
|
474
|
+
(part, i) => /^https?:\/\//.test(part) ? /* @__PURE__ */ jsx(
|
|
475
|
+
"a",
|
|
476
|
+
{
|
|
477
|
+
href: part,
|
|
478
|
+
target: "_blank",
|
|
479
|
+
rel: "noopener noreferrer",
|
|
480
|
+
className: "underline",
|
|
481
|
+
children: part
|
|
482
|
+
},
|
|
483
|
+
i
|
|
484
|
+
) : /* @__PURE__ */ jsx(React.Fragment, { children: part }, i)
|
|
485
|
+
) });
|
|
486
|
+
}
|
|
487
|
+
function MerchantStatusNotices({
|
|
488
|
+
environment,
|
|
489
|
+
only,
|
|
490
|
+
reloadKey
|
|
491
|
+
}) {
|
|
492
|
+
const [notices, setNotices] = useState([]);
|
|
493
|
+
useEffect(() => {
|
|
494
|
+
let cancelled = false;
|
|
495
|
+
setNotices([]);
|
|
496
|
+
(async () => {
|
|
497
|
+
try {
|
|
498
|
+
const json = await adminFetch(
|
|
499
|
+
"/admin/paypal/merchant-status",
|
|
500
|
+
environment ? { query: { environment } } : {}
|
|
501
|
+
);
|
|
502
|
+
if (cancelled) return;
|
|
503
|
+
setNotices(Array.isArray(json == null ? void 0 : json.notices) ? json.notices : []);
|
|
504
|
+
} catch {
|
|
505
|
+
}
|
|
506
|
+
})();
|
|
507
|
+
return () => {
|
|
508
|
+
cancelled = true;
|
|
509
|
+
};
|
|
510
|
+
}, [environment, reloadKey]);
|
|
511
|
+
const visible = only ? notices.filter((notice) => only.includes(notice.code)) : notices;
|
|
512
|
+
if (visible.length === 0) return null;
|
|
513
|
+
return /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", "data-testid": "paypal-merchant-notices", children: visible.map((notice) => /* @__PURE__ */ jsx(
|
|
514
|
+
"div",
|
|
515
|
+
{
|
|
516
|
+
role: "alert",
|
|
517
|
+
className: "rounded border p-3 text-sm",
|
|
518
|
+
style: notice.level === "error" ? {
|
|
519
|
+
background: "#fef2f2",
|
|
520
|
+
borderColor: "#fecaca",
|
|
521
|
+
color: "#b91c1c"
|
|
522
|
+
} : {
|
|
523
|
+
background: "#fffbeb",
|
|
524
|
+
borderColor: "#fde68a",
|
|
525
|
+
color: "#92400e"
|
|
526
|
+
},
|
|
527
|
+
children: /* @__PURE__ */ jsx(NoticeText, { message: notice.message })
|
|
528
|
+
},
|
|
529
|
+
notice.code
|
|
530
|
+
)) });
|
|
531
|
+
}
|
|
446
532
|
const DEFAULT_FORM = {
|
|
447
533
|
enabled: true,
|
|
448
534
|
title: "Credit or Debit Card",
|
|
@@ -528,6 +614,7 @@ function AdvancedCardPaymentsTab() {
|
|
|
528
614
|
/* @__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
615
|
/* @__PURE__ */ jsx(PayPalTabs, {}),
|
|
530
616
|
/* @__PURE__ */ jsx(Toast, { toast, onClose: dismissToast }),
|
|
617
|
+
/* @__PURE__ */ jsx(MerchantStatusNotices, { only: ["card_payments_not_enabled"] }),
|
|
531
618
|
/* @__PURE__ */ jsx(
|
|
532
619
|
SectionCard,
|
|
533
620
|
{
|
|
@@ -1155,6 +1242,13 @@ function PayPalConnectionPage() {
|
|
|
1155
1242
|
}
|
|
1156
1243
|
)
|
|
1157
1244
|
] }),
|
|
1245
|
+
/* @__PURE__ */ jsx("div", { className: "mt-3", children: /* @__PURE__ */ jsx(
|
|
1246
|
+
MerchantStatusNotices,
|
|
1247
|
+
{
|
|
1248
|
+
environment: env,
|
|
1249
|
+
reloadKey: (statusInfo == null ? void 0 : statusInfo.seller_client_id_masked) || ""
|
|
1250
|
+
}
|
|
1251
|
+
) }),
|
|
1158
1252
|
/* @__PURE__ */ 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: [
|
|
1159
1253
|
/* @__PURE__ */ jsx("div", { className: "font-medium text-ui-fg-base", children: "Connected PayPal account" }),
|
|
1160
1254
|
/* @__PURE__ */ jsxs("div", { className: "mt-1", children: [
|
|
@@ -1399,9 +1493,6 @@ function PayPalConnectionPage() {
|
|
|
1399
1493
|
function PayPalGooglePayPage() {
|
|
1400
1494
|
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1401
1495
|
}
|
|
1402
|
-
function PayPalPayLaterMessagingPage() {
|
|
1403
|
-
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1404
|
-
}
|
|
1405
1496
|
const COLOR_OPTIONS = [
|
|
1406
1497
|
{ value: "gold", label: "Gold (Recommended)" },
|
|
1407
1498
|
{ value: "blue", label: "Blue" },
|
|
@@ -1618,6 +1709,9 @@ function PayPalSettingsTab() {
|
|
|
1618
1709
|
)
|
|
1619
1710
|
] }) });
|
|
1620
1711
|
}
|
|
1712
|
+
function PayPalPayLaterMessagingPage() {
|
|
1713
|
+
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1714
|
+
}
|
|
1621
1715
|
const widgetModule = { widgets: [] };
|
|
1622
1716
|
const routeModule = {
|
|
1623
1717
|
routes: [
|
|
@@ -1645,13 +1739,13 @@ const routeModule = {
|
|
|
1645
1739
|
Component: PayPalGooglePayPage,
|
|
1646
1740
|
path: "/settings/paypal/google-pay"
|
|
1647
1741
|
},
|
|
1648
|
-
{
|
|
1649
|
-
Component: PayPalPayLaterMessagingPage,
|
|
1650
|
-
path: "/settings/paypal/pay-later-messaging"
|
|
1651
|
-
},
|
|
1652
1742
|
{
|
|
1653
1743
|
Component: PayPalSettingsTab,
|
|
1654
1744
|
path: "/settings/paypal/paypal-settings"
|
|
1745
|
+
},
|
|
1746
|
+
{
|
|
1747
|
+
Component: PayPalPayLaterMessagingPage,
|
|
1748
|
+
path: "/settings/paypal/pay-later-messaging"
|
|
1655
1749
|
}
|
|
1656
1750
|
]
|
|
1657
1751
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/logs/route.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAO7E;;;;;;GAMG;AACH,wBAAsB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/logs/route.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAO7E;;;;;;GAMG;AACH,wBAAsB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BA8BhE"}
|