@easypayment/medusa-payment-paypal 1.3.9 → 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 +102 -31
- package/.medusa/server/src/admin/index.mjs +102 -31
- 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 +12 -6
- 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 +11 -12
- package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/service.js +52 -75
- package/.medusa/server/src/modules/paypal/service.js.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.d.ts +0 -12
- package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/types/config.js +0 -23
- package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/merchant-status.d.ts +1 -3
- package/.medusa/server/src/modules/paypal/utils/merchant-status.d.ts.map +1 -1
- package/.medusa/server/src/modules/paypal/utils/merchant-status.js.map +1 -1
- 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 +46 -0
- package/README.md +2 -3
- package/package.json +1 -1
- package/src/admin/routes/settings/paypal/additional-settings/page.tsx +22 -6
- package/src/admin/routes/settings/paypal/connection/page.tsx +66 -6
- package/src/api/store/paypal/create-order/route.ts +15 -8
- package/src/api/utils/request-logger.ts +7 -3
- package/src/modules/paypal/service.ts +70 -100
- package/src/modules/paypal/types/config.ts +0 -32
- package/src/modules/paypal/utils/merchant-status.ts +5 -3
- package/src/modules/paypal/utils/request-logger.ts +30 -2
|
@@ -158,15 +158,18 @@ async function adminFetch(path, opts = {}) {
|
|
|
158
158
|
}
|
|
159
159
|
const DEFAULT_FORM$1 = {
|
|
160
160
|
paymentAction: "capture",
|
|
161
|
-
brandName: "
|
|
161
|
+
brandName: "",
|
|
162
162
|
landingPage: "login",
|
|
163
163
|
requireInstantPayment: false,
|
|
164
164
|
sendItemDetails: true,
|
|
165
165
|
sendShippingAddress: true,
|
|
166
166
|
invoicePrefix: "PP-",
|
|
167
|
-
creditCardStatementName: "
|
|
167
|
+
creditCardStatementName: "",
|
|
168
168
|
debugLogging: false
|
|
169
169
|
};
|
|
170
|
+
function isPlaceholderName(value) {
|
|
171
|
+
return typeof value === "string" && value.trim().toLowerCase() === "paypal";
|
|
172
|
+
}
|
|
170
173
|
function mergeWithDefaults$1(saved) {
|
|
171
174
|
if (!saved) return { ...DEFAULT_FORM$1 };
|
|
172
175
|
const entries = Object.entries(saved).filter(
|
|
@@ -177,6 +180,10 @@ function mergeWithDefaults$1(saved) {
|
|
|
177
180
|
...Object.fromEntries(entries)
|
|
178
181
|
};
|
|
179
182
|
if (merged.landingPage !== "billing") merged.landingPage = "login";
|
|
183
|
+
if (isPlaceholderName(merged.brandName)) merged.brandName = "";
|
|
184
|
+
if (isPlaceholderName(merged.creditCardStatementName)) {
|
|
185
|
+
merged.creditCardStatementName = "";
|
|
186
|
+
}
|
|
180
187
|
return merged;
|
|
181
188
|
}
|
|
182
189
|
function AdditionalSettingsTab() {
|
|
@@ -311,16 +318,24 @@ function AdditionalSettingsTab() {
|
|
|
311
318
|
]
|
|
312
319
|
}
|
|
313
320
|
) }),
|
|
314
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
315
|
-
|
|
321
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
322
|
+
FieldRow,
|
|
316
323
|
{
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
+
)
|
|
322
337
|
}
|
|
323
|
-
)
|
|
338
|
+
),
|
|
324
339
|
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Landing Page", htmlFor: "as-landing-page", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
325
340
|
"select",
|
|
326
341
|
{
|
|
@@ -411,6 +426,7 @@ function AdditionalSettingsTab() {
|
|
|
411
426
|
{
|
|
412
427
|
label: "Credit Card Statement Name",
|
|
413
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.",
|
|
414
430
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
415
431
|
"input",
|
|
416
432
|
{
|
|
@@ -421,7 +437,8 @@ function AdditionalSettingsTab() {
|
|
|
421
437
|
creditCardStatementName: e.target.value
|
|
422
438
|
})),
|
|
423
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",
|
|
424
|
-
placeholder: "
|
|
440
|
+
placeholder: "Your business name",
|
|
441
|
+
maxLength: 22
|
|
425
442
|
}
|
|
426
443
|
)
|
|
427
444
|
}
|
|
@@ -448,7 +465,7 @@ function AdditionalSettingsTab() {
|
|
|
448
465
|
FieldRow,
|
|
449
466
|
{
|
|
450
467
|
label: "Request/response logging",
|
|
451
|
-
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.",
|
|
452
469
|
children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
453
470
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
454
471
|
"input",
|
|
@@ -470,6 +487,9 @@ function AdditionalSettingsTab() {
|
|
|
470
487
|
)
|
|
471
488
|
] }) });
|
|
472
489
|
}
|
|
490
|
+
function PayPalApplePayPage() {
|
|
491
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
492
|
+
}
|
|
473
493
|
const URL_RE = /(https?:\/\/[^\s]+[^\s.,!?])/g;
|
|
474
494
|
function NoticeText({ message }) {
|
|
475
495
|
const parts = message.split(URL_RE);
|
|
@@ -688,12 +708,24 @@ function AdvancedCardPaymentsTab() {
|
|
|
688
708
|
)
|
|
689
709
|
] }) });
|
|
690
710
|
}
|
|
691
|
-
function
|
|
711
|
+
function PayPalGooglePayPage() {
|
|
692
712
|
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
693
713
|
}
|
|
694
714
|
const config = adminSdk.defineRouteConfig({
|
|
695
715
|
label: "PayPal Connection"
|
|
696
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
|
+
}
|
|
697
729
|
const PARTNER_JS_URL = "https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js";
|
|
698
730
|
const PARTNER_SCRIPT_ID = "paypal-partner-js";
|
|
699
731
|
const PARTNER_HELPER_SCRIPT_IDS = [
|
|
@@ -903,7 +935,13 @@ function PayPalConnectionPage() {
|
|
|
903
935
|
});
|
|
904
936
|
if (!res.ok) {
|
|
905
937
|
const txt = await res.text().catch(() => "");
|
|
906
|
-
throw new Error(
|
|
938
|
+
throw new Error(
|
|
939
|
+
describeFailure(
|
|
940
|
+
res.status,
|
|
941
|
+
txt,
|
|
942
|
+
`Onboarding exchange failed (${res.status})`
|
|
943
|
+
)
|
|
944
|
+
);
|
|
907
945
|
}
|
|
908
946
|
closeMiniBrowser();
|
|
909
947
|
clearCachedUrl(activeEnv);
|
|
@@ -1141,7 +1179,13 @@ function PayPalConnectionPage() {
|
|
|
1141
1179
|
});
|
|
1142
1180
|
if (!res.ok) {
|
|
1143
1181
|
const txt = await res.text().catch(() => "");
|
|
1144
|
-
throw new Error(
|
|
1182
|
+
throw new Error(
|
|
1183
|
+
describeFailure(
|
|
1184
|
+
res.status,
|
|
1185
|
+
txt,
|
|
1186
|
+
`Save credentials failed (${res.status})`
|
|
1187
|
+
)
|
|
1188
|
+
);
|
|
1145
1189
|
}
|
|
1146
1190
|
const statusRes = await fetch(`${STATUS_ENDPOINT}?environment=${env}`, {
|
|
1147
1191
|
method: "GET",
|
|
@@ -1179,7 +1223,9 @@ function PayPalConnectionPage() {
|
|
|
1179
1223
|
});
|
|
1180
1224
|
if (!res.ok) {
|
|
1181
1225
|
const t = await res.text().catch(() => "");
|
|
1182
|
-
throw new Error(
|
|
1226
|
+
throw new Error(
|
|
1227
|
+
describeFailure(res.status, t, `Disconnect failed (${res.status})`)
|
|
1228
|
+
);
|
|
1183
1229
|
}
|
|
1184
1230
|
clearCachedUrl(env);
|
|
1185
1231
|
completedRef.current = false;
|
|
@@ -1187,7 +1233,8 @@ function PayPalConnectionPage() {
|
|
|
1187
1233
|
await fetchFreshLink(env, currentRunId.current);
|
|
1188
1234
|
} catch (e) {
|
|
1189
1235
|
console.error(e);
|
|
1190
|
-
|
|
1236
|
+
const stillConnected = await refreshStatusAndMaybeConnect(env);
|
|
1237
|
+
if (!stillConnected) setConnState("error");
|
|
1191
1238
|
setError((e == null ? void 0 : e.message) || "Failed to disconnect.");
|
|
1192
1239
|
} finally {
|
|
1193
1240
|
setOnboardingInProgress(false);
|
|
@@ -1232,8 +1279,27 @@ function PayPalConnectionPage() {
|
|
|
1232
1279
|
) }),
|
|
1233
1280
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium pt-2", children: env === "sandbox" ? "Connect to PayPal (Sandbox)" : "Connect to PayPal" }),
|
|
1234
1281
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-xl", children: connState === "connected" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1235
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm text-green-600 bg-green-50 p-3 rounded border border-green-200", children: [
|
|
1236
|
-
|
|
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" }),
|
|
1237
1303
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1238
1304
|
"a",
|
|
1239
1305
|
{
|
|
@@ -1260,6 +1326,14 @@ function PayPalConnectionPage() {
|
|
|
1260
1326
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono text-ui-fg-base", children: (statusInfo == null ? void 0 : statusInfo.seller_email) || "Unavailable" })
|
|
1261
1327
|
] })
|
|
1262
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,
|
|
1263
1337
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 flex items-center gap-2", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1264
1338
|
"button",
|
|
1265
1339
|
{
|
|
@@ -1493,7 +1567,7 @@ function PayPalConnectionPage() {
|
|
|
1493
1567
|
` })
|
|
1494
1568
|
] });
|
|
1495
1569
|
}
|
|
1496
|
-
function
|
|
1570
|
+
function PayPalPayLaterMessagingPage() {
|
|
1497
1571
|
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1498
1572
|
}
|
|
1499
1573
|
const COLOR_OPTIONS = [
|
|
@@ -1712,9 +1786,6 @@ function PayPalSettingsTab() {
|
|
|
1712
1786
|
)
|
|
1713
1787
|
] }) });
|
|
1714
1788
|
}
|
|
1715
|
-
function PayPalPayLaterMessagingPage() {
|
|
1716
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1717
|
-
}
|
|
1718
1789
|
const widgetModule = { widgets: [] };
|
|
1719
1790
|
const routeModule = {
|
|
1720
1791
|
routes: [
|
|
@@ -1726,29 +1797,29 @@ const routeModule = {
|
|
|
1726
1797
|
Component: AdditionalSettingsTab,
|
|
1727
1798
|
path: "/settings/paypal/additional-settings"
|
|
1728
1799
|
},
|
|
1729
|
-
{
|
|
1730
|
-
Component: AdvancedCardPaymentsTab,
|
|
1731
|
-
path: "/settings/paypal/advanced-card-payments"
|
|
1732
|
-
},
|
|
1733
1800
|
{
|
|
1734
1801
|
Component: PayPalApplePayPage,
|
|
1735
1802
|
path: "/settings/paypal/apple-pay"
|
|
1736
1803
|
},
|
|
1737
1804
|
{
|
|
1738
|
-
Component:
|
|
1739
|
-
path: "/settings/paypal/
|
|
1805
|
+
Component: AdvancedCardPaymentsTab,
|
|
1806
|
+
path: "/settings/paypal/advanced-card-payments"
|
|
1740
1807
|
},
|
|
1741
1808
|
{
|
|
1742
1809
|
Component: PayPalGooglePayPage,
|
|
1743
1810
|
path: "/settings/paypal/google-pay"
|
|
1744
1811
|
},
|
|
1745
1812
|
{
|
|
1746
|
-
Component:
|
|
1747
|
-
path: "/settings/paypal/
|
|
1813
|
+
Component: PayPalConnectionPage,
|
|
1814
|
+
path: "/settings/paypal/connection"
|
|
1748
1815
|
},
|
|
1749
1816
|
{
|
|
1750
1817
|
Component: PayPalPayLaterMessagingPage,
|
|
1751
1818
|
path: "/settings/paypal/pay-later-messaging"
|
|
1819
|
+
},
|
|
1820
|
+
{
|
|
1821
|
+
Component: PayPalSettingsTab,
|
|
1822
|
+
path: "/settings/paypal/paypal-settings"
|
|
1752
1823
|
}
|
|
1753
1824
|
]
|
|
1754
1825
|
};
|
|
@@ -155,15 +155,18 @@ async function adminFetch(path, opts = {}) {
|
|
|
155
155
|
}
|
|
156
156
|
const DEFAULT_FORM$1 = {
|
|
157
157
|
paymentAction: "capture",
|
|
158
|
-
brandName: "
|
|
158
|
+
brandName: "",
|
|
159
159
|
landingPage: "login",
|
|
160
160
|
requireInstantPayment: false,
|
|
161
161
|
sendItemDetails: true,
|
|
162
162
|
sendShippingAddress: true,
|
|
163
163
|
invoicePrefix: "PP-",
|
|
164
|
-
creditCardStatementName: "
|
|
164
|
+
creditCardStatementName: "",
|
|
165
165
|
debugLogging: false
|
|
166
166
|
};
|
|
167
|
+
function isPlaceholderName(value) {
|
|
168
|
+
return typeof value === "string" && value.trim().toLowerCase() === "paypal";
|
|
169
|
+
}
|
|
167
170
|
function mergeWithDefaults$1(saved) {
|
|
168
171
|
if (!saved) return { ...DEFAULT_FORM$1 };
|
|
169
172
|
const entries = Object.entries(saved).filter(
|
|
@@ -174,6 +177,10 @@ function mergeWithDefaults$1(saved) {
|
|
|
174
177
|
...Object.fromEntries(entries)
|
|
175
178
|
};
|
|
176
179
|
if (merged.landingPage !== "billing") merged.landingPage = "login";
|
|
180
|
+
if (isPlaceholderName(merged.brandName)) merged.brandName = "";
|
|
181
|
+
if (isPlaceholderName(merged.creditCardStatementName)) {
|
|
182
|
+
merged.creditCardStatementName = "";
|
|
183
|
+
}
|
|
177
184
|
return merged;
|
|
178
185
|
}
|
|
179
186
|
function AdditionalSettingsTab() {
|
|
@@ -308,16 +315,24 @@ function AdditionalSettingsTab() {
|
|
|
308
315
|
]
|
|
309
316
|
}
|
|
310
317
|
) }),
|
|
311
|
-
/* @__PURE__ */ jsx(
|
|
312
|
-
|
|
318
|
+
/* @__PURE__ */ jsx(
|
|
319
|
+
FieldRow,
|
|
313
320
|
{
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
321
|
+
label: "Brand Name",
|
|
322
|
+
htmlFor: "as-brand-name",
|
|
323
|
+
hint: "The business name customers see in the PayPal checkout. Leave empty to use your store's name.",
|
|
324
|
+
children: /* @__PURE__ */ jsx(
|
|
325
|
+
"input",
|
|
326
|
+
{
|
|
327
|
+
id: "as-brand-name",
|
|
328
|
+
value: form.brandName,
|
|
329
|
+
onChange: (e) => setForm((p) => ({ ...p, brandName: e.target.value })),
|
|
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",
|
|
331
|
+
placeholder: "Your store name"
|
|
332
|
+
}
|
|
333
|
+
)
|
|
319
334
|
}
|
|
320
|
-
)
|
|
335
|
+
),
|
|
321
336
|
/* @__PURE__ */ jsx(FieldRow, { label: "Landing Page", htmlFor: "as-landing-page", children: /* @__PURE__ */ jsxs(
|
|
322
337
|
"select",
|
|
323
338
|
{
|
|
@@ -408,6 +423,7 @@ function AdditionalSettingsTab() {
|
|
|
408
423
|
{
|
|
409
424
|
label: "Credit Card Statement Name",
|
|
410
425
|
htmlFor: "as-cc-statement",
|
|
426
|
+
hint: "Shown on the customer's card statement (up to 22 characters). Leave empty to use the name on your PayPal account.",
|
|
411
427
|
children: /* @__PURE__ */ jsx(
|
|
412
428
|
"input",
|
|
413
429
|
{
|
|
@@ -418,7 +434,8 @@ function AdditionalSettingsTab() {
|
|
|
418
434
|
creditCardStatementName: e.target.value
|
|
419
435
|
})),
|
|
420
436
|
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",
|
|
421
|
-
placeholder: "
|
|
437
|
+
placeholder: "Your business name",
|
|
438
|
+
maxLength: 22
|
|
422
439
|
}
|
|
423
440
|
)
|
|
424
441
|
}
|
|
@@ -445,7 +462,7 @@ function AdditionalSettingsTab() {
|
|
|
445
462
|
FieldRow,
|
|
446
463
|
{
|
|
447
464
|
label: "Request/response logging",
|
|
448
|
-
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.",
|
|
465
|
+
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.",
|
|
449
466
|
children: /* @__PURE__ */ jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
450
467
|
/* @__PURE__ */ jsx(
|
|
451
468
|
"input",
|
|
@@ -467,6 +484,9 @@ function AdditionalSettingsTab() {
|
|
|
467
484
|
)
|
|
468
485
|
] }) });
|
|
469
486
|
}
|
|
487
|
+
function PayPalApplePayPage() {
|
|
488
|
+
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
489
|
+
}
|
|
470
490
|
const URL_RE = /(https?:\/\/[^\s]+[^\s.,!?])/g;
|
|
471
491
|
function NoticeText({ message }) {
|
|
472
492
|
const parts = message.split(URL_RE);
|
|
@@ -685,12 +705,24 @@ function AdvancedCardPaymentsTab() {
|
|
|
685
705
|
)
|
|
686
706
|
] }) });
|
|
687
707
|
}
|
|
688
|
-
function
|
|
708
|
+
function PayPalGooglePayPage() {
|
|
689
709
|
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
690
710
|
}
|
|
691
711
|
const config = defineRouteConfig({
|
|
692
712
|
label: "PayPal Connection"
|
|
693
713
|
});
|
|
714
|
+
const SESSION_EXPIRED_MESSAGE = "Your admin session has expired. Reload this page and log in again.";
|
|
715
|
+
function describeFailure(status, body, fallback) {
|
|
716
|
+
var _a;
|
|
717
|
+
if (status === 401) return SESSION_EXPIRED_MESSAGE;
|
|
718
|
+
try {
|
|
719
|
+
const message = (_a = JSON.parse(body)) == null ? void 0 : _a.message;
|
|
720
|
+
if (typeof message === "string" && message.trim()) return message.trim();
|
|
721
|
+
} catch {
|
|
722
|
+
}
|
|
723
|
+
const text = body.trim();
|
|
724
|
+
return text && !text.startsWith("<") ? text.slice(0, 300) : fallback;
|
|
725
|
+
}
|
|
694
726
|
const PARTNER_JS_URL = "https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js";
|
|
695
727
|
const PARTNER_SCRIPT_ID = "paypal-partner-js";
|
|
696
728
|
const PARTNER_HELPER_SCRIPT_IDS = [
|
|
@@ -900,7 +932,13 @@ function PayPalConnectionPage() {
|
|
|
900
932
|
});
|
|
901
933
|
if (!res.ok) {
|
|
902
934
|
const txt = await res.text().catch(() => "");
|
|
903
|
-
throw new Error(
|
|
935
|
+
throw new Error(
|
|
936
|
+
describeFailure(
|
|
937
|
+
res.status,
|
|
938
|
+
txt,
|
|
939
|
+
`Onboarding exchange failed (${res.status})`
|
|
940
|
+
)
|
|
941
|
+
);
|
|
904
942
|
}
|
|
905
943
|
closeMiniBrowser();
|
|
906
944
|
clearCachedUrl(activeEnv);
|
|
@@ -1138,7 +1176,13 @@ function PayPalConnectionPage() {
|
|
|
1138
1176
|
});
|
|
1139
1177
|
if (!res.ok) {
|
|
1140
1178
|
const txt = await res.text().catch(() => "");
|
|
1141
|
-
throw new Error(
|
|
1179
|
+
throw new Error(
|
|
1180
|
+
describeFailure(
|
|
1181
|
+
res.status,
|
|
1182
|
+
txt,
|
|
1183
|
+
`Save credentials failed (${res.status})`
|
|
1184
|
+
)
|
|
1185
|
+
);
|
|
1142
1186
|
}
|
|
1143
1187
|
const statusRes = await fetch(`${STATUS_ENDPOINT}?environment=${env}`, {
|
|
1144
1188
|
method: "GET",
|
|
@@ -1176,7 +1220,9 @@ function PayPalConnectionPage() {
|
|
|
1176
1220
|
});
|
|
1177
1221
|
if (!res.ok) {
|
|
1178
1222
|
const t = await res.text().catch(() => "");
|
|
1179
|
-
throw new Error(
|
|
1223
|
+
throw new Error(
|
|
1224
|
+
describeFailure(res.status, t, `Disconnect failed (${res.status})`)
|
|
1225
|
+
);
|
|
1180
1226
|
}
|
|
1181
1227
|
clearCachedUrl(env);
|
|
1182
1228
|
completedRef.current = false;
|
|
@@ -1184,7 +1230,8 @@ function PayPalConnectionPage() {
|
|
|
1184
1230
|
await fetchFreshLink(env, currentRunId.current);
|
|
1185
1231
|
} catch (e) {
|
|
1186
1232
|
console.error(e);
|
|
1187
|
-
|
|
1233
|
+
const stillConnected = await refreshStatusAndMaybeConnect(env);
|
|
1234
|
+
if (!stillConnected) setConnState("error");
|
|
1188
1235
|
setError((e == null ? void 0 : e.message) || "Failed to disconnect.");
|
|
1189
1236
|
} finally {
|
|
1190
1237
|
setOnboardingInProgress(false);
|
|
@@ -1229,8 +1276,27 @@ function PayPalConnectionPage() {
|
|
|
1229
1276
|
) }),
|
|
1230
1277
|
/* @__PURE__ */ jsx("div", { className: "text-sm font-medium pt-2", children: env === "sandbox" ? "Connect to PayPal (Sandbox)" : "Connect to PayPal" }),
|
|
1231
1278
|
/* @__PURE__ */ jsx("div", { className: "max-w-xl", children: connState === "connected" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
1232
|
-
/* @__PURE__ */ jsxs("div", { className: "text-sm text-green-600 bg-green-50 p-3 rounded border border-green-200", children: [
|
|
1233
|
-
|
|
1279
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded border border-green-200", children: [
|
|
1280
|
+
/* @__PURE__ */ jsxs(
|
|
1281
|
+
"svg",
|
|
1282
|
+
{
|
|
1283
|
+
width: "16",
|
|
1284
|
+
height: "16",
|
|
1285
|
+
viewBox: "0 0 24 24",
|
|
1286
|
+
fill: "none",
|
|
1287
|
+
stroke: "currentColor",
|
|
1288
|
+
strokeWidth: "2.5",
|
|
1289
|
+
strokeLinecap: "round",
|
|
1290
|
+
strokeLinejoin: "round",
|
|
1291
|
+
"aria-hidden": "true",
|
|
1292
|
+
style: { flexShrink: 0 },
|
|
1293
|
+
children: [
|
|
1294
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1295
|
+
/* @__PURE__ */ jsx("path", { d: "m8 12 3 3 5-6" })
|
|
1296
|
+
]
|
|
1297
|
+
}
|
|
1298
|
+
),
|
|
1299
|
+
/* @__PURE__ */ jsx("span", { children: "Successfully connected to PayPal" }),
|
|
1234
1300
|
/* @__PURE__ */ jsx(
|
|
1235
1301
|
"a",
|
|
1236
1302
|
{
|
|
@@ -1257,6 +1323,14 @@ function PayPalConnectionPage() {
|
|
|
1257
1323
|
/* @__PURE__ */ jsx("span", { className: "font-mono text-ui-fg-base", children: (statusInfo == null ? void 0 : statusInfo.seller_email) || "Unavailable" })
|
|
1258
1324
|
] })
|
|
1259
1325
|
] }),
|
|
1326
|
+
error ? /* @__PURE__ */ jsx(
|
|
1327
|
+
"div",
|
|
1328
|
+
{
|
|
1329
|
+
role: "alert",
|
|
1330
|
+
className: "mt-3 text-left text-xs bg-red-50 text-red-600 p-3 border border-red-200 rounded",
|
|
1331
|
+
children: error
|
|
1332
|
+
}
|
|
1333
|
+
) : null,
|
|
1260
1334
|
/* @__PURE__ */ jsx("div", { className: "mt-3 flex items-center gap-2", children: /* @__PURE__ */ jsx(
|
|
1261
1335
|
"button",
|
|
1262
1336
|
{
|
|
@@ -1490,7 +1564,7 @@ function PayPalConnectionPage() {
|
|
|
1490
1564
|
` })
|
|
1491
1565
|
] });
|
|
1492
1566
|
}
|
|
1493
|
-
function
|
|
1567
|
+
function PayPalPayLaterMessagingPage() {
|
|
1494
1568
|
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1495
1569
|
}
|
|
1496
1570
|
const COLOR_OPTIONS = [
|
|
@@ -1709,9 +1783,6 @@ function PayPalSettingsTab() {
|
|
|
1709
1783
|
)
|
|
1710
1784
|
] }) });
|
|
1711
1785
|
}
|
|
1712
|
-
function PayPalPayLaterMessagingPage() {
|
|
1713
|
-
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
1714
|
-
}
|
|
1715
1786
|
const widgetModule = { widgets: [] };
|
|
1716
1787
|
const routeModule = {
|
|
1717
1788
|
routes: [
|
|
@@ -1723,29 +1794,29 @@ const routeModule = {
|
|
|
1723
1794
|
Component: AdditionalSettingsTab,
|
|
1724
1795
|
path: "/settings/paypal/additional-settings"
|
|
1725
1796
|
},
|
|
1726
|
-
{
|
|
1727
|
-
Component: AdvancedCardPaymentsTab,
|
|
1728
|
-
path: "/settings/paypal/advanced-card-payments"
|
|
1729
|
-
},
|
|
1730
1797
|
{
|
|
1731
1798
|
Component: PayPalApplePayPage,
|
|
1732
1799
|
path: "/settings/paypal/apple-pay"
|
|
1733
1800
|
},
|
|
1734
1801
|
{
|
|
1735
|
-
Component:
|
|
1736
|
-
path: "/settings/paypal/
|
|
1802
|
+
Component: AdvancedCardPaymentsTab,
|
|
1803
|
+
path: "/settings/paypal/advanced-card-payments"
|
|
1737
1804
|
},
|
|
1738
1805
|
{
|
|
1739
1806
|
Component: PayPalGooglePayPage,
|
|
1740
1807
|
path: "/settings/paypal/google-pay"
|
|
1741
1808
|
},
|
|
1742
1809
|
{
|
|
1743
|
-
Component:
|
|
1744
|
-
path: "/settings/paypal/
|
|
1810
|
+
Component: PayPalConnectionPage,
|
|
1811
|
+
path: "/settings/paypal/connection"
|
|
1745
1812
|
},
|
|
1746
1813
|
{
|
|
1747
1814
|
Component: PayPalPayLaterMessagingPage,
|
|
1748
1815
|
path: "/settings/paypal/pay-later-messaging"
|
|
1816
|
+
},
|
|
1817
|
+
{
|
|
1818
|
+
Component: PayPalSettingsTab,
|
|
1819
|
+
path: "/settings/paypal/paypal-settings"
|
|
1749
1820
|
}
|
|
1750
1821
|
]
|
|
1751
1822
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/store/paypal/create-order/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/store/paypal/create-order/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAgG7E;;;;;;;;;;GAUG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAqmBjE"}
|
|
@@ -11,6 +11,16 @@ const paypal_fetch_1 = require("../../../../modules/paypal/utils/paypal-fetch");
|
|
|
11
11
|
const payment_session_1 = require("../../../../modules/paypal/utils/payment-session");
|
|
12
12
|
const storefront_url_1 = require("../../../../modules/paypal/utils/storefront-url");
|
|
13
13
|
const order_context_1 = require("../../../../modules/paypal/utils/order-context");
|
|
14
|
+
/**
|
|
15
|
+
* A merchant-entered name setting, or "" when it is unset. The admin form
|
|
16
|
+
* pre-filled "PayPal" for the brand and card-statement names until 1.3.10, so
|
|
17
|
+
* stores that saved it sent "PayPal" as their own business name; that value
|
|
18
|
+
* is treated as unset (the brand name then falls back to the store's name).
|
|
19
|
+
*/
|
|
20
|
+
function merchantName(setting) {
|
|
21
|
+
const name = typeof setting === "string" ? setting.trim() : "";
|
|
22
|
+
return name.toLowerCase() === "paypal" ? "" : name;
|
|
23
|
+
}
|
|
14
24
|
function resolveIdempotencyKey(req, suffix, fallback) {
|
|
15
25
|
const header = req.headers["idempotency-key"] ||
|
|
16
26
|
req.headers["Idempotency-Key"] ||
|
|
@@ -238,17 +248,13 @@ async function POST(req, res) {
|
|
|
238
248
|
? additionalSettings.paymentAction
|
|
239
249
|
: "capture";
|
|
240
250
|
const paymentAction = paymentActionRaw === "authorize" ? "AUTHORIZE" : "CAPTURE";
|
|
241
|
-
const brandName =
|
|
242
|
-
? additionalSettings.brandName
|
|
243
|
-
: undefined;
|
|
251
|
+
const brandName = merchantName(additionalSettings.brandName) || undefined;
|
|
244
252
|
const landingPage = (0, order_context_1.resolveLandingPage)(additionalSettings.landingPage);
|
|
245
253
|
const requireInstantPayment = typeof additionalSettings.requireInstantPayment === "boolean"
|
|
246
254
|
? additionalSettings.requireInstantPayment
|
|
247
255
|
: undefined;
|
|
248
256
|
const sendItemDetails = additionalSettings.sendItemDetails !== false;
|
|
249
|
-
const statementName =
|
|
250
|
-
? additionalSettings.creditCardStatementName.trim()
|
|
251
|
-
: "";
|
|
257
|
+
const statementName = merchantName(additionalSettings.creditCardStatementName);
|
|
252
258
|
const invoicePrefix = typeof additionalSettings.invoicePrefix === "string"
|
|
253
259
|
? additionalSettings.invoicePrefix
|
|
254
260
|
: "";
|