@easypayment/medusa-payment-paypal 0.9.10 → 0.9.13
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 +94 -94
- package/.medusa/server/src/admin/index.mjs +94 -94
- package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal/capture-order/route.js +4 -5
- package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.d.ts.map +1 -1
- package/.medusa/server/src/api/store/paypal-complete/route.js +22 -8
- package/.medusa/server/src/api/store/paypal-complete/route.js.map +1 -1
- package/package.json +19 -13
- package/src/api/store/paypal/capture-order/route.ts +4 -8
- package/src/api/store/paypal-complete/route.ts +22 -9
|
@@ -224,11 +224,89 @@ function AdditionalSettingsTab() {
|
|
|
224
224
|
)
|
|
225
225
|
] }) });
|
|
226
226
|
}
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
const DEFAULT_FORM = {
|
|
228
|
+
enabled: true,
|
|
229
|
+
title: "Credit or Debit Card",
|
|
230
|
+
threeDS: "when_required"
|
|
231
|
+
};
|
|
232
|
+
function mergeWithDefaults(saved) {
|
|
233
|
+
if (!saved) return { ...DEFAULT_FORM };
|
|
234
|
+
const entries = Object.entries(saved).filter(([, value]) => value !== void 0);
|
|
235
|
+
return { ...DEFAULT_FORM, ...Object.fromEntries(entries) };
|
|
229
236
|
}
|
|
230
|
-
|
|
231
|
-
|
|
237
|
+
const THREE_DS_OPTIONS = [
|
|
238
|
+
{ value: "when_required", label: "3D Secure when required", hint: "Triggers 3DS only when the card / issuer requires it." },
|
|
239
|
+
{ value: "sli", label: "3D Secure (SCA) / liability shift (recommended)", hint: "Attempts to optimize for liability shift while remaining compliant." },
|
|
240
|
+
{ value: "always", label: "Always request 3D Secure", hint: "Forces 3DS challenge whenever possible (may reduce conversion)." }
|
|
241
|
+
];
|
|
242
|
+
function AdvancedCardPaymentsTab() {
|
|
243
|
+
var _a, _b;
|
|
244
|
+
const [form, setForm] = react.useState(() => ({ ...DEFAULT_FORM }));
|
|
245
|
+
const [loading, setLoading] = react.useState(false);
|
|
246
|
+
const [saving, setSaving] = react.useState(false);
|
|
247
|
+
const [toast, setToast] = react.useState(null);
|
|
248
|
+
const didInit = react.useRef(false);
|
|
249
|
+
const dismissToast = react.useCallback(() => setToast(null), []);
|
|
250
|
+
react.useEffect(() => {
|
|
251
|
+
if (didInit.current) return;
|
|
252
|
+
didInit.current = true;
|
|
253
|
+
(async () => {
|
|
254
|
+
try {
|
|
255
|
+
setLoading(true);
|
|
256
|
+
const json = await adminFetch("/admin/paypal/settings");
|
|
257
|
+
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
258
|
+
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
259
|
+
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
|
|
260
|
+
} catch {
|
|
261
|
+
} finally {
|
|
262
|
+
setLoading(false);
|
|
263
|
+
}
|
|
264
|
+
})();
|
|
265
|
+
}, []);
|
|
266
|
+
async function onSave() {
|
|
267
|
+
try {
|
|
268
|
+
setSaving(true);
|
|
269
|
+
const json = await adminFetch("/admin/paypal/settings", {
|
|
270
|
+
method: "POST",
|
|
271
|
+
body: { advanced_card_payments: form }
|
|
272
|
+
});
|
|
273
|
+
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
274
|
+
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
275
|
+
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
|
|
276
|
+
setToast({ kind: "success", message: "Settings saved" });
|
|
277
|
+
} catch (e) {
|
|
278
|
+
setToast({ kind: "error", message: (e instanceof Error ? e.message : "") || "Failed to save settings." });
|
|
279
|
+
} finally {
|
|
280
|
+
setSaving(false);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
284
|
+
/* @__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" }) }) }),
|
|
285
|
+
/* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
|
|
286
|
+
/* @__PURE__ */ jsxRuntime.jsx(Toast, { toast, onClose: dismissToast }),
|
|
287
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
288
|
+
SectionCard,
|
|
289
|
+
{
|
|
290
|
+
title: "Advanced Card Payments",
|
|
291
|
+
description: "Control card checkout settings and 3D Secure behavior.",
|
|
292
|
+
right: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
|
|
293
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onSave, disabled: saving || loading, className: "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5", children: saving ? "Saving..." : "Save settings" }),
|
|
294
|
+
loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading…" }) : null
|
|
295
|
+
] }),
|
|
296
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y divide-ui-border-base", children: [
|
|
297
|
+
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Enable/Disable", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
298
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "checkbox", checked: form.enabled, onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })), className: "h-4 w-4 rounded border-ui-border-base" }),
|
|
299
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
|
|
300
|
+
] }) }),
|
|
301
|
+
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Title", htmlFor: "acp-title", children: /* @__PURE__ */ jsxRuntime.jsx("input", { id: "acp-title", value: form.title, onChange: (e) => setForm((p) => ({ ...p, title: e.target.value })), 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", placeholder: "Credit or Debit Card" }) }),
|
|
302
|
+
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Contingency for 3D Secure", hint: "Choose when 3D Secure should be triggered during card payments.", htmlFor: "acp-threeds", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
303
|
+
/* @__PURE__ */ jsxRuntime.jsx("select", { id: "acp-threeds", value: form.threeDS, onChange: (e) => setForm((p) => ({ ...p, threeDS: e.target.value })), 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", children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o.value, children: o.label }, o.value)) }),
|
|
304
|
+
((_a = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _a.hint) ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-ui-fg-subtle", children: (_b = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _b.hint }) : null
|
|
305
|
+
] }) })
|
|
306
|
+
] })
|
|
307
|
+
}
|
|
308
|
+
)
|
|
309
|
+
] }) });
|
|
232
310
|
}
|
|
233
311
|
const config = adminSdk.defineRouteConfig({
|
|
234
312
|
label: "PayPal Connection"
|
|
@@ -814,89 +892,11 @@ function PayPalConnectionPage() {
|
|
|
814
892
|
` })
|
|
815
893
|
] });
|
|
816
894
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
title: "Credit or Debit Card",
|
|
820
|
-
threeDS: "when_required"
|
|
821
|
-
};
|
|
822
|
-
function mergeWithDefaults(saved) {
|
|
823
|
-
if (!saved) return { ...DEFAULT_FORM };
|
|
824
|
-
const entries = Object.entries(saved).filter(([, value]) => value !== void 0);
|
|
825
|
-
return { ...DEFAULT_FORM, ...Object.fromEntries(entries) };
|
|
895
|
+
function PayPalApplePayPage() {
|
|
896
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
826
897
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
{ value: "sli", label: "3D Secure (SCA) / liability shift (recommended)", hint: "Attempts to optimize for liability shift while remaining compliant." },
|
|
830
|
-
{ value: "always", label: "Always request 3D Secure", hint: "Forces 3DS challenge whenever possible (may reduce conversion)." }
|
|
831
|
-
];
|
|
832
|
-
function AdvancedCardPaymentsTab() {
|
|
833
|
-
var _a, _b;
|
|
834
|
-
const [form, setForm] = react.useState(() => ({ ...DEFAULT_FORM }));
|
|
835
|
-
const [loading, setLoading] = react.useState(false);
|
|
836
|
-
const [saving, setSaving] = react.useState(false);
|
|
837
|
-
const [toast, setToast] = react.useState(null);
|
|
838
|
-
const didInit = react.useRef(false);
|
|
839
|
-
const dismissToast = react.useCallback(() => setToast(null), []);
|
|
840
|
-
react.useEffect(() => {
|
|
841
|
-
if (didInit.current) return;
|
|
842
|
-
didInit.current = true;
|
|
843
|
-
(async () => {
|
|
844
|
-
try {
|
|
845
|
-
setLoading(true);
|
|
846
|
-
const json = await adminFetch("/admin/paypal/settings");
|
|
847
|
-
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
848
|
-
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
849
|
-
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
|
|
850
|
-
} catch {
|
|
851
|
-
} finally {
|
|
852
|
-
setLoading(false);
|
|
853
|
-
}
|
|
854
|
-
})();
|
|
855
|
-
}, []);
|
|
856
|
-
async function onSave() {
|
|
857
|
-
try {
|
|
858
|
-
setSaving(true);
|
|
859
|
-
const json = await adminFetch("/admin/paypal/settings", {
|
|
860
|
-
method: "POST",
|
|
861
|
-
body: { advanced_card_payments: form }
|
|
862
|
-
});
|
|
863
|
-
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
864
|
-
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
865
|
-
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
|
|
866
|
-
setToast({ kind: "success", message: "Settings saved" });
|
|
867
|
-
} catch (e) {
|
|
868
|
-
setToast({ kind: "error", message: (e instanceof Error ? e.message : "") || "Failed to save settings." });
|
|
869
|
-
} finally {
|
|
870
|
-
setSaving(false);
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
874
|
-
/* @__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" }) }) }),
|
|
875
|
-
/* @__PURE__ */ jsxRuntime.jsx(PayPalTabs, {}),
|
|
876
|
-
/* @__PURE__ */ jsxRuntime.jsx(Toast, { toast, onClose: dismissToast }),
|
|
877
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
878
|
-
SectionCard,
|
|
879
|
-
{
|
|
880
|
-
title: "Advanced Card Payments",
|
|
881
|
-
description: "Control card checkout settings and 3D Secure behavior.",
|
|
882
|
-
right: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
|
|
883
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onSave, disabled: saving || loading, className: "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5", children: saving ? "Saving..." : "Save settings" }),
|
|
884
|
-
loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading…" }) : null
|
|
885
|
-
] }),
|
|
886
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "divide-y divide-ui-border-base", children: [
|
|
887
|
-
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Enable/Disable", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
888
|
-
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "checkbox", checked: form.enabled, onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })), className: "h-4 w-4 rounded border-ui-border-base" }),
|
|
889
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
|
|
890
|
-
] }) }),
|
|
891
|
-
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Title", htmlFor: "acp-title", children: /* @__PURE__ */ jsxRuntime.jsx("input", { id: "acp-title", value: form.title, onChange: (e) => setForm((p) => ({ ...p, title: e.target.value })), 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", placeholder: "Credit or Debit Card" }) }),
|
|
892
|
-
/* @__PURE__ */ jsxRuntime.jsx(FieldRow, { label: "Contingency for 3D Secure", hint: "Choose when 3D Secure should be triggered during card payments.", htmlFor: "acp-threeds", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
893
|
-
/* @__PURE__ */ jsxRuntime.jsx("select", { id: "acp-threeds", value: form.threeDS, onChange: (e) => setForm((p) => ({ ...p, threeDS: e.target.value })), 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", children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: o.value, children: o.label }, o.value)) }),
|
|
894
|
-
((_a = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _a.hint) ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-ui-fg-subtle", children: (_b = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _b.hint }) : null
|
|
895
|
-
] }) })
|
|
896
|
-
] })
|
|
897
|
-
}
|
|
898
|
-
)
|
|
899
|
-
] }) });
|
|
898
|
+
function PayPalGooglePayPage() {
|
|
899
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
900
900
|
}
|
|
901
901
|
function PayPalPayLaterMessagingPage() {
|
|
902
902
|
return /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
@@ -1120,20 +1120,20 @@ const routeModule = {
|
|
|
1120
1120
|
path: "/settings/paypal/additional-settings"
|
|
1121
1121
|
},
|
|
1122
1122
|
{
|
|
1123
|
-
Component:
|
|
1124
|
-
path: "/settings/paypal/
|
|
1125
|
-
},
|
|
1126
|
-
{
|
|
1127
|
-
Component: PayPalApplePayPage,
|
|
1128
|
-
path: "/settings/paypal/apple-pay"
|
|
1123
|
+
Component: AdvancedCardPaymentsTab,
|
|
1124
|
+
path: "/settings/paypal/advanced-card-payments"
|
|
1129
1125
|
},
|
|
1130
1126
|
{
|
|
1131
1127
|
Component: PayPalConnectionPage,
|
|
1132
1128
|
path: "/settings/paypal/connection"
|
|
1133
1129
|
},
|
|
1134
1130
|
{
|
|
1135
|
-
Component:
|
|
1136
|
-
path: "/settings/paypal/
|
|
1131
|
+
Component: PayPalApplePayPage,
|
|
1132
|
+
path: "/settings/paypal/apple-pay"
|
|
1133
|
+
},
|
|
1134
|
+
{
|
|
1135
|
+
Component: PayPalGooglePayPage,
|
|
1136
|
+
path: "/settings/paypal/google-pay"
|
|
1137
1137
|
},
|
|
1138
1138
|
{
|
|
1139
1139
|
Component: PayPalPayLaterMessagingPage,
|
|
@@ -223,11 +223,89 @@ function AdditionalSettingsTab() {
|
|
|
223
223
|
)
|
|
224
224
|
] }) });
|
|
225
225
|
}
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
const DEFAULT_FORM = {
|
|
227
|
+
enabled: true,
|
|
228
|
+
title: "Credit or Debit Card",
|
|
229
|
+
threeDS: "when_required"
|
|
230
|
+
};
|
|
231
|
+
function mergeWithDefaults(saved) {
|
|
232
|
+
if (!saved) return { ...DEFAULT_FORM };
|
|
233
|
+
const entries = Object.entries(saved).filter(([, value]) => value !== void 0);
|
|
234
|
+
return { ...DEFAULT_FORM, ...Object.fromEntries(entries) };
|
|
228
235
|
}
|
|
229
|
-
|
|
230
|
-
|
|
236
|
+
const THREE_DS_OPTIONS = [
|
|
237
|
+
{ value: "when_required", label: "3D Secure when required", hint: "Triggers 3DS only when the card / issuer requires it." },
|
|
238
|
+
{ value: "sli", label: "3D Secure (SCA) / liability shift (recommended)", hint: "Attempts to optimize for liability shift while remaining compliant." },
|
|
239
|
+
{ value: "always", label: "Always request 3D Secure", hint: "Forces 3DS challenge whenever possible (may reduce conversion)." }
|
|
240
|
+
];
|
|
241
|
+
function AdvancedCardPaymentsTab() {
|
|
242
|
+
var _a, _b;
|
|
243
|
+
const [form, setForm] = useState(() => ({ ...DEFAULT_FORM }));
|
|
244
|
+
const [loading, setLoading] = useState(false);
|
|
245
|
+
const [saving, setSaving] = useState(false);
|
|
246
|
+
const [toast, setToast] = useState(null);
|
|
247
|
+
const didInit = useRef(false);
|
|
248
|
+
const dismissToast = useCallback(() => setToast(null), []);
|
|
249
|
+
useEffect(() => {
|
|
250
|
+
if (didInit.current) return;
|
|
251
|
+
didInit.current = true;
|
|
252
|
+
(async () => {
|
|
253
|
+
try {
|
|
254
|
+
setLoading(true);
|
|
255
|
+
const json = await adminFetch("/admin/paypal/settings");
|
|
256
|
+
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
257
|
+
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
258
|
+
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
|
|
259
|
+
} catch {
|
|
260
|
+
} finally {
|
|
261
|
+
setLoading(false);
|
|
262
|
+
}
|
|
263
|
+
})();
|
|
264
|
+
}, []);
|
|
265
|
+
async function onSave() {
|
|
266
|
+
try {
|
|
267
|
+
setSaving(true);
|
|
268
|
+
const json = await adminFetch("/admin/paypal/settings", {
|
|
269
|
+
method: "POST",
|
|
270
|
+
body: { advanced_card_payments: form }
|
|
271
|
+
});
|
|
272
|
+
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
273
|
+
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
274
|
+
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
|
|
275
|
+
setToast({ kind: "success", message: "Settings saved" });
|
|
276
|
+
} catch (e) {
|
|
277
|
+
setToast({ kind: "error", message: (e instanceof Error ? e.message : "") || "Failed to save settings." });
|
|
278
|
+
} finally {
|
|
279
|
+
setSaving(false);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
283
|
+
/* @__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" }) }) }),
|
|
284
|
+
/* @__PURE__ */ jsx(PayPalTabs, {}),
|
|
285
|
+
/* @__PURE__ */ jsx(Toast, { toast, onClose: dismissToast }),
|
|
286
|
+
/* @__PURE__ */ jsx(
|
|
287
|
+
SectionCard,
|
|
288
|
+
{
|
|
289
|
+
title: "Advanced Card Payments",
|
|
290
|
+
description: "Control card checkout settings and 3D Secure behavior.",
|
|
291
|
+
right: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
292
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: onSave, disabled: saving || loading, className: "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5", children: saving ? "Saving..." : "Save settings" }),
|
|
293
|
+
loading ? /* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading…" }) : null
|
|
294
|
+
] }),
|
|
295
|
+
children: /* @__PURE__ */ jsxs("div", { className: "divide-y divide-ui-border-base", children: [
|
|
296
|
+
/* @__PURE__ */ jsx(FieldRow, { label: "Enable/Disable", children: /* @__PURE__ */ jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
297
|
+
/* @__PURE__ */ jsx("input", { type: "checkbox", checked: form.enabled, onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })), className: "h-4 w-4 rounded border-ui-border-base" }),
|
|
298
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
|
|
299
|
+
] }) }),
|
|
300
|
+
/* @__PURE__ */ jsx(FieldRow, { label: "Title", htmlFor: "acp-title", children: /* @__PURE__ */ jsx("input", { id: "acp-title", value: form.title, onChange: (e) => setForm((p) => ({ ...p, title: e.target.value })), 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", placeholder: "Credit or Debit Card" }) }),
|
|
301
|
+
/* @__PURE__ */ jsx(FieldRow, { label: "Contingency for 3D Secure", hint: "Choose when 3D Secure should be triggered during card payments.", htmlFor: "acp-threeds", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
302
|
+
/* @__PURE__ */ jsx("select", { id: "acp-threeds", value: form.threeDS, onChange: (e) => setForm((p) => ({ ...p, threeDS: e.target.value })), 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", children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, o.value)) }),
|
|
303
|
+
((_a = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _a.hint) ? /* @__PURE__ */ jsx("div", { className: "text-xs text-ui-fg-subtle", children: (_b = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _b.hint }) : null
|
|
304
|
+
] }) })
|
|
305
|
+
] })
|
|
306
|
+
}
|
|
307
|
+
)
|
|
308
|
+
] }) });
|
|
231
309
|
}
|
|
232
310
|
const config = defineRouteConfig({
|
|
233
311
|
label: "PayPal Connection"
|
|
@@ -813,89 +891,11 @@ function PayPalConnectionPage() {
|
|
|
813
891
|
` })
|
|
814
892
|
] });
|
|
815
893
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
title: "Credit or Debit Card",
|
|
819
|
-
threeDS: "when_required"
|
|
820
|
-
};
|
|
821
|
-
function mergeWithDefaults(saved) {
|
|
822
|
-
if (!saved) return { ...DEFAULT_FORM };
|
|
823
|
-
const entries = Object.entries(saved).filter(([, value]) => value !== void 0);
|
|
824
|
-
return { ...DEFAULT_FORM, ...Object.fromEntries(entries) };
|
|
894
|
+
function PayPalApplePayPage() {
|
|
895
|
+
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
825
896
|
}
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
{ value: "sli", label: "3D Secure (SCA) / liability shift (recommended)", hint: "Attempts to optimize for liability shift while remaining compliant." },
|
|
829
|
-
{ value: "always", label: "Always request 3D Secure", hint: "Forces 3DS challenge whenever possible (may reduce conversion)." }
|
|
830
|
-
];
|
|
831
|
-
function AdvancedCardPaymentsTab() {
|
|
832
|
-
var _a, _b;
|
|
833
|
-
const [form, setForm] = useState(() => ({ ...DEFAULT_FORM }));
|
|
834
|
-
const [loading, setLoading] = useState(false);
|
|
835
|
-
const [saving, setSaving] = useState(false);
|
|
836
|
-
const [toast, setToast] = useState(null);
|
|
837
|
-
const didInit = useRef(false);
|
|
838
|
-
const dismissToast = useCallback(() => setToast(null), []);
|
|
839
|
-
useEffect(() => {
|
|
840
|
-
if (didInit.current) return;
|
|
841
|
-
didInit.current = true;
|
|
842
|
-
(async () => {
|
|
843
|
-
try {
|
|
844
|
-
setLoading(true);
|
|
845
|
-
const json = await adminFetch("/admin/paypal/settings");
|
|
846
|
-
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
847
|
-
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
848
|
-
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
|
|
849
|
-
} catch {
|
|
850
|
-
} finally {
|
|
851
|
-
setLoading(false);
|
|
852
|
-
}
|
|
853
|
-
})();
|
|
854
|
-
}, []);
|
|
855
|
-
async function onSave() {
|
|
856
|
-
try {
|
|
857
|
-
setSaving(true);
|
|
858
|
-
const json = await adminFetch("/admin/paypal/settings", {
|
|
859
|
-
method: "POST",
|
|
860
|
-
body: { advanced_card_payments: form }
|
|
861
|
-
});
|
|
862
|
-
const payload = (json == null ? void 0 : json.data) ?? json;
|
|
863
|
-
const saved = payload == null ? void 0 : payload.advanced_card_payments;
|
|
864
|
-
if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved));
|
|
865
|
-
setToast({ kind: "success", message: "Settings saved" });
|
|
866
|
-
} catch (e) {
|
|
867
|
-
setToast({ kind: "error", message: (e instanceof Error ? e.message : "") || "Failed to save settings." });
|
|
868
|
-
} finally {
|
|
869
|
-
setSaving(false);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
return /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
873
|
-
/* @__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" }) }) }),
|
|
874
|
-
/* @__PURE__ */ jsx(PayPalTabs, {}),
|
|
875
|
-
/* @__PURE__ */ jsx(Toast, { toast, onClose: dismissToast }),
|
|
876
|
-
/* @__PURE__ */ jsx(
|
|
877
|
-
SectionCard,
|
|
878
|
-
{
|
|
879
|
-
title: "Advanced Card Payments",
|
|
880
|
-
description: "Control card checkout settings and 3D Secure behavior.",
|
|
881
|
-
right: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
882
|
-
/* @__PURE__ */ jsx("button", { type: "button", onClick: onSave, disabled: saving || loading, className: "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5", children: saving ? "Saving..." : "Save settings" }),
|
|
883
|
-
loading ? /* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-subtle", children: "Loading…" }) : null
|
|
884
|
-
] }),
|
|
885
|
-
children: /* @__PURE__ */ jsxs("div", { className: "divide-y divide-ui-border-base", children: [
|
|
886
|
-
/* @__PURE__ */ jsx(FieldRow, { label: "Enable/Disable", children: /* @__PURE__ */ jsxs("label", { className: "inline-flex items-center gap-2", children: [
|
|
887
|
-
/* @__PURE__ */ jsx("input", { type: "checkbox", checked: form.enabled, onChange: (e) => setForm((p) => ({ ...p, enabled: e.target.checked })), className: "h-4 w-4 rounded border-ui-border-base" }),
|
|
888
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm text-ui-fg-base", children: "Enable Advanced Credit/Debit Card" })
|
|
889
|
-
] }) }),
|
|
890
|
-
/* @__PURE__ */ jsx(FieldRow, { label: "Title", htmlFor: "acp-title", children: /* @__PURE__ */ jsx("input", { id: "acp-title", value: form.title, onChange: (e) => setForm((p) => ({ ...p, title: e.target.value })), 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", placeholder: "Credit or Debit Card" }) }),
|
|
891
|
-
/* @__PURE__ */ jsx(FieldRow, { label: "Contingency for 3D Secure", hint: "Choose when 3D Secure should be triggered during card payments.", htmlFor: "acp-threeds", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
892
|
-
/* @__PURE__ */ jsx("select", { id: "acp-threeds", value: form.threeDS, onChange: (e) => setForm((p) => ({ ...p, threeDS: e.target.value })), 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", children: THREE_DS_OPTIONS.map((o) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, o.value)) }),
|
|
893
|
-
((_a = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _a.hint) ? /* @__PURE__ */ jsx("div", { className: "text-xs text-ui-fg-subtle", children: (_b = THREE_DS_OPTIONS.find((o) => o.value === form.threeDS)) == null ? void 0 : _b.hint }) : null
|
|
894
|
-
] }) })
|
|
895
|
-
] })
|
|
896
|
-
}
|
|
897
|
-
)
|
|
898
|
-
] }) });
|
|
897
|
+
function PayPalGooglePayPage() {
|
|
898
|
+
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
899
899
|
}
|
|
900
900
|
function PayPalPayLaterMessagingPage() {
|
|
901
901
|
return /* @__PURE__ */ jsx(Navigate, { to: "/settings/paypal/connection", replace: true });
|
|
@@ -1119,20 +1119,20 @@ const routeModule = {
|
|
|
1119
1119
|
path: "/settings/paypal/additional-settings"
|
|
1120
1120
|
},
|
|
1121
1121
|
{
|
|
1122
|
-
Component:
|
|
1123
|
-
path: "/settings/paypal/
|
|
1124
|
-
},
|
|
1125
|
-
{
|
|
1126
|
-
Component: PayPalApplePayPage,
|
|
1127
|
-
path: "/settings/paypal/apple-pay"
|
|
1122
|
+
Component: AdvancedCardPaymentsTab,
|
|
1123
|
+
path: "/settings/paypal/advanced-card-payments"
|
|
1128
1124
|
},
|
|
1129
1125
|
{
|
|
1130
1126
|
Component: PayPalConnectionPage,
|
|
1131
1127
|
path: "/settings/paypal/connection"
|
|
1132
1128
|
},
|
|
1133
1129
|
{
|
|
1134
|
-
Component:
|
|
1135
|
-
path: "/settings/paypal/
|
|
1130
|
+
Component: PayPalApplePayPage,
|
|
1131
|
+
path: "/settings/paypal/apple-pay"
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
Component: PayPalGooglePayPage,
|
|
1135
|
+
path: "/settings/paypal/google-pay"
|
|
1136
1136
|
},
|
|
1137
1137
|
{
|
|
1138
1138
|
Component: PayPalPayLaterMessagingPage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/store/paypal/capture-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/capture-order/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AA8K7E,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BA8GjE"}
|
|
@@ -51,7 +51,7 @@ async function findPayPalSessionForCart(cartId, scope) {
|
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
async function
|
|
54
|
+
async function updatePayPalSessionData(sessionId, extraData, scope) {
|
|
55
55
|
try {
|
|
56
56
|
const paymentModule = scope.resolve(utils_1.Modules.PAYMENT);
|
|
57
57
|
const [existing] = await paymentModule.listPaymentSessions({ id: [sessionId] }, { take: 1 });
|
|
@@ -59,13 +59,12 @@ async function updatePayPalSession(sessionId, status, extraData, scope) {
|
|
|
59
59
|
await paymentModule.updatePaymentSession({
|
|
60
60
|
id: sessionId,
|
|
61
61
|
data: mergedData,
|
|
62
|
-
status: status,
|
|
63
62
|
amount: existing?.amount,
|
|
64
63
|
currency_code: existing?.currency_code,
|
|
65
64
|
});
|
|
66
65
|
}
|
|
67
66
|
catch (e) {
|
|
68
|
-
console.error("[PayPal]
|
|
67
|
+
console.error("[PayPal] updatePayPalSessionData failed:", e?.message);
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
async function attachPayPalCaptureToSession(cartId, orderId, capture, scope) {
|
|
@@ -76,7 +75,7 @@ async function attachPayPalCaptureToSession(cartId, orderId, capture, scope) {
|
|
|
76
75
|
return;
|
|
77
76
|
}
|
|
78
77
|
const captureId = capture?.purchase_units?.[0]?.payments?.captures?.[0]?.id || capture?.id;
|
|
79
|
-
await
|
|
78
|
+
await updatePayPalSessionData(session.session_id, {
|
|
80
79
|
paypal: {
|
|
81
80
|
...((session.session_data || {}).paypal || {}),
|
|
82
81
|
order_id: orderId,
|
|
@@ -96,7 +95,7 @@ async function attachPayPalAuthorizationToSession(cartId, orderId, authorization
|
|
|
96
95
|
return;
|
|
97
96
|
}
|
|
98
97
|
const authorizationId = authorization?.purchase_units?.[0]?.payments?.authorizations?.[0]?.id;
|
|
99
|
-
await
|
|
98
|
+
await updatePayPalSessionData(session.session_id, {
|
|
100
99
|
paypal: {
|
|
101
100
|
...((session.session_data || {}).paypal || {}),
|
|
102
101
|
order_id: orderId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/store/paypal/capture-order/route.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/store/paypal/capture-order/route.ts"],"names":[],"mappings":";;AA8KA,oBA8GC;AA1RD,qDAAmD;AACnD,mCAAmC;AAEnC,8EAAmF;AACnF,gFAAkF;AAElF,MAAM,OAAO,GAAG,sBAAsB,CAAA;AAEtC,MAAM,kBAAkB,GAAG,mBAAmB,CAAA;AAO9C,SAAS,qBAAqB,CAAC,GAAkB,EAAE,MAA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,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;YACtC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;IACpC,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAS,CAAA;YACrC,MAAM,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE;gBACpD,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,CAAC,EAAE,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC;aACjC,CAAC,CAAA;YACF,MAAM,MAAM,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAA;QACnD,CAAC;QAAC,MAAM,CAAC;QACT,CAAC;QACD,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,gCAAgC,EAAE,CAAC,CAAA;IAC5E,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../src/api/store/paypal-complete/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-complete/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAM7E,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAyGjE"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.POST = POST;
|
|
4
4
|
const utils_1 = require("@medusajs/framework/utils");
|
|
5
|
+
const core_flows_1 = require("@medusajs/core-flows");
|
|
5
6
|
async function POST(req, res) {
|
|
6
7
|
const { cart_id } = req.body;
|
|
7
8
|
if (!cart_id || typeof cart_id !== "string") {
|
|
@@ -16,6 +17,7 @@ async function POST(req, res) {
|
|
|
16
17
|
entity: "cart",
|
|
17
18
|
fields: [
|
|
18
19
|
"id",
|
|
20
|
+
"completed_at",
|
|
19
21
|
"payment_collection.payment_sessions.id",
|
|
20
22
|
"payment_collection.payment_sessions.data",
|
|
21
23
|
"payment_collection.payment_sessions.status",
|
|
@@ -26,7 +28,11 @@ async function POST(req, res) {
|
|
|
26
28
|
],
|
|
27
29
|
filters: { id: cart_id },
|
|
28
30
|
});
|
|
29
|
-
const
|
|
31
|
+
const cart = carts?.[0];
|
|
32
|
+
if (cart?.completed_at) {
|
|
33
|
+
return res.json({ success: true, cart_id, already_completed: true });
|
|
34
|
+
}
|
|
35
|
+
const sessions = cart?.payment_collection?.payment_sessions || [];
|
|
30
36
|
const session = sessions
|
|
31
37
|
.filter((s) => String(s.provider_id || "").includes("paypal"))
|
|
32
38
|
.sort((a, b) => new Date(b.created_at || 0).getTime() - new Date(a.created_at || 0).getTime())[0];
|
|
@@ -58,18 +64,26 @@ async function POST(req, res) {
|
|
|
58
64
|
});
|
|
59
65
|
}
|
|
60
66
|
const currentStatus = String(session.status || "");
|
|
61
|
-
if (currentStatus
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
if (currentStatus !== "authorized") {
|
|
68
|
+
try {
|
|
69
|
+
await paymentModule.authorizePaymentSession(session.id, {});
|
|
70
|
+
console.info("[paypal-complete] authorizePaymentSession succeeded for session", session.id);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
console.warn("[paypal-complete] authorizePaymentSession non-fatal:", e?.message);
|
|
74
|
+
}
|
|
64
75
|
}
|
|
65
76
|
try {
|
|
66
|
-
await
|
|
67
|
-
|
|
77
|
+
const { result } = await (0, core_flows_1.completeCartWorkflow)(req.scope).run({
|
|
78
|
+
input: { id: cart_id },
|
|
79
|
+
});
|
|
80
|
+
console.info("[paypal-complete] cart completed, order:", result?.id);
|
|
81
|
+
return res.json({ success: true, cart_id, order_id: result?.id });
|
|
68
82
|
}
|
|
69
83
|
catch (e) {
|
|
70
|
-
console.warn("[paypal-complete]
|
|
84
|
+
console.warn("[paypal-complete] completeCartWorkflow failed:", e?.message);
|
|
85
|
+
return res.json({ success: true, session_id: session.id });
|
|
71
86
|
}
|
|
72
|
-
return res.json({ success: true, session_id: session.id });
|
|
73
87
|
}
|
|
74
88
|
catch (e) {
|
|
75
89
|
console.error("[paypal-complete] error:", e?.message || e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../src/api/store/paypal-complete/route.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../src/api/store/paypal-complete/route.ts"],"names":[],"mappings":";;AAMA,oBAyGC;AA7GD,qDAAmD;AACnD,qDAA2D;AAGpD,KAAK,UAAU,IAAI,CAAC,GAAkB,EAAE,GAAmB;IAChE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,IAA2B,CAAA;IAEnD,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC,CAAA;IACjE,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC,CAAA;IACpE,CAAC;IAED,IAAI,CAAC;QACH,MAAM,KAAK,GAA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E,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC,CAAA;QAC1D,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAA;IAC5D,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easypayment/medusa-payment-paypal",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.13",
|
|
4
4
|
"description": "PayPal integration for Medusa v2",
|
|
5
5
|
"author": "EasyPayment Plugins",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,27 +39,33 @@
|
|
|
39
39
|
"prepublishOnly": "npm run build"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@medusajs/admin-sdk": "2.
|
|
43
|
-
"@medusajs/cli": "2.
|
|
44
|
-
"@medusajs/framework": "2.
|
|
45
|
-
"@medusajs/
|
|
46
|
-
"@medusajs/
|
|
42
|
+
"@medusajs/admin-sdk": "^2.15.3",
|
|
43
|
+
"@medusajs/cli": "^2.15.3",
|
|
44
|
+
"@medusajs/framework": "^2.15.3",
|
|
45
|
+
"@medusajs/icons": "^2.15.3",
|
|
46
|
+
"@medusajs/medusa": "^2.15.3",
|
|
47
|
+
"@medusajs/test-utils": "^2.15.3",
|
|
47
48
|
"@medusajs/ui": "^4.0.0",
|
|
48
|
-
"@medusajs/icons": "2.12.5",
|
|
49
49
|
"@swc/core": "^1.5.7",
|
|
50
50
|
"typescript": "^5.6.2"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@medusajs/admin-sdk": "^2.12.0",
|
|
54
54
|
"@medusajs/framework": "^2.12.0",
|
|
55
|
+
"@medusajs/icons": "^2.12.0",
|
|
55
56
|
"@medusajs/medusa": "^2.12.0",
|
|
56
|
-
"@medusajs/ui": "^4.0.0"
|
|
57
|
-
"@medusajs/icons": "^2.12.0"
|
|
57
|
+
"@medusajs/ui": "^4.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
|
-
"@medusajs/admin-sdk": {
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
"@medusajs/admin-sdk": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"@medusajs/ui": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"@medusajs/icons": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
63
69
|
},
|
|
64
70
|
"publishConfig": {
|
|
65
71
|
"access": "public"
|
|
@@ -82,4 +88,4 @@
|
|
|
82
88
|
"medusa-paypal-integration",
|
|
83
89
|
"medusa-paypal"
|
|
84
90
|
]
|
|
85
|
-
}
|
|
91
|
+
}
|
|
@@ -72,9 +72,8 @@ async function findPayPalSessionForCart(
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
async function
|
|
75
|
+
async function updatePayPalSessionData(
|
|
76
76
|
sessionId: string,
|
|
77
|
-
status: string,
|
|
78
77
|
extraData: Record<string, any>,
|
|
79
78
|
scope: any
|
|
80
79
|
): Promise<void> {
|
|
@@ -85,12 +84,11 @@ async function updatePayPalSession(
|
|
|
85
84
|
await (paymentModule as any).updatePaymentSession({
|
|
86
85
|
id: sessionId,
|
|
87
86
|
data: mergedData,
|
|
88
|
-
status: status as any,
|
|
89
87
|
amount: existing?.amount,
|
|
90
88
|
currency_code: existing?.currency_code,
|
|
91
89
|
})
|
|
92
90
|
} catch (e: any) {
|
|
93
|
-
console.error("[PayPal]
|
|
91
|
+
console.error("[PayPal] updatePayPalSessionData failed:", e?.message)
|
|
94
92
|
}
|
|
95
93
|
}
|
|
96
94
|
|
|
@@ -109,9 +107,8 @@ async function attachPayPalCaptureToSession(
|
|
|
109
107
|
|
|
110
108
|
const captureId = capture?.purchase_units?.[0]?.payments?.captures?.[0]?.id || capture?.id
|
|
111
109
|
|
|
112
|
-
await
|
|
110
|
+
await updatePayPalSessionData(
|
|
113
111
|
session.session_id,
|
|
114
|
-
"captured",
|
|
115
112
|
{
|
|
116
113
|
paypal: {
|
|
117
114
|
...((session.session_data || {}).paypal || {}),
|
|
@@ -142,9 +139,8 @@ async function attachPayPalAuthorizationToSession(
|
|
|
142
139
|
|
|
143
140
|
const authorizationId = authorization?.purchase_units?.[0]?.payments?.authorizations?.[0]?.id
|
|
144
141
|
|
|
145
|
-
await
|
|
142
|
+
await updatePayPalSessionData(
|
|
146
143
|
session.session_id,
|
|
147
|
-
"authorized",
|
|
148
144
|
{
|
|
149
145
|
paypal: {
|
|
150
146
|
...((session.session_data || {}).paypal || {}),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
2
|
import type { IPaymentModuleService } from "@medusajs/framework/types"
|
|
3
3
|
import { Modules } from "@medusajs/framework/utils"
|
|
4
|
+
import { completeCartWorkflow } from "@medusajs/core-flows"
|
|
4
5
|
import type PayPalModuleService from "../../../modules/paypal/service"
|
|
5
6
|
|
|
6
7
|
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
@@ -20,6 +21,7 @@ export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
|
20
21
|
entity: "cart",
|
|
21
22
|
fields: [
|
|
22
23
|
"id",
|
|
24
|
+
"completed_at",
|
|
23
25
|
"payment_collection.payment_sessions.id",
|
|
24
26
|
"payment_collection.payment_sessions.data",
|
|
25
27
|
"payment_collection.payment_sessions.status",
|
|
@@ -31,7 +33,12 @@ export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
|
31
33
|
filters: { id: cart_id },
|
|
32
34
|
})
|
|
33
35
|
|
|
34
|
-
const
|
|
36
|
+
const cart = carts?.[0]
|
|
37
|
+
if (cart?.completed_at) {
|
|
38
|
+
return res.json({ success: true, cart_id, already_completed: true })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const sessions = cart?.payment_collection?.payment_sessions || []
|
|
35
42
|
const session = sessions
|
|
36
43
|
.filter((s: any) => String(s.provider_id || "").includes("paypal"))
|
|
37
44
|
.sort(
|
|
@@ -79,19 +86,25 @@ export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
const currentStatus = String(session.status || "")
|
|
82
|
-
if (currentStatus
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
if (currentStatus !== "authorized") {
|
|
90
|
+
try {
|
|
91
|
+
await (paymentModule as any).authorizePaymentSession(session.id, {})
|
|
92
|
+
console.info("[paypal-complete] authorizePaymentSession succeeded for session", session.id)
|
|
93
|
+
} catch (e: any) {
|
|
94
|
+
console.warn("[paypal-complete] authorizePaymentSession non-fatal:", e?.message)
|
|
95
|
+
}
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
try {
|
|
88
|
-
await (
|
|
89
|
-
|
|
99
|
+
const { result } = await completeCartWorkflow(req.scope).run({
|
|
100
|
+
input: { id: cart_id },
|
|
101
|
+
})
|
|
102
|
+
console.info("[paypal-complete] cart completed, order:", result?.id)
|
|
103
|
+
return res.json({ success: true, cart_id, order_id: result?.id })
|
|
90
104
|
} catch (e: any) {
|
|
91
|
-
console.warn("[paypal-complete]
|
|
105
|
+
console.warn("[paypal-complete] completeCartWorkflow failed:", e?.message)
|
|
106
|
+
return res.json({ success: true, session_id: session.id })
|
|
92
107
|
}
|
|
93
|
-
|
|
94
|
-
return res.json({ success: true, session_id: session.id })
|
|
95
108
|
} catch (e: any) {
|
|
96
109
|
console.error("[paypal-complete] error:", e?.message || e)
|
|
97
110
|
return res.status(500).json({ message: "Internal error" })
|