@easypayment/medusa-paypal-ui 1.0.45 → 1.0.46
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/dist/index.cjs +227 -167
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -136
- package/dist/index.d.ts +10 -136
- package/dist/index.mjs +183 -143
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/adapters/MedusaNextPayPalAdapter.tsx +3 -3
- package/src/client/http.ts +10 -6
- package/src/client/paypal.ts +20 -0
- package/src/client/types.ts +1 -1
- package/src/components/PayPalAdvancedCard.tsx +3 -22
- package/src/components/PayPalCurrencyNotice.tsx +19 -19
- package/src/components/PayPalProvider.tsx +0 -1
- package/src/components/PayPalSmartButtons.tsx +2 -21
- package/src/hooks/usePayPalConfig.ts +2 -0
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
19
|
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
MedusaNextPayPalAdapter: () => MedusaNextPayPalAdapter,
|
|
24
|
+
PAYPAL_CARD_PROVIDER_ID: () => PAYPAL_CARD_PROVIDER_ID,
|
|
25
|
+
PAYPAL_WALLET_PROVIDER_ID: () => PAYPAL_WALLET_PROVIDER_ID,
|
|
26
|
+
PayPalAdvancedCard: () => PayPalAdvancedCard,
|
|
27
|
+
PayPalCurrencyNotice: () => PayPalCurrencyNotice,
|
|
28
|
+
PayPalPaymentSection: () => PayPalPaymentSection,
|
|
29
|
+
PayPalProvider: () => PayPalProvider,
|
|
30
|
+
PayPalSmartButtons: () => PayPalSmartButtons,
|
|
31
|
+
createPayPalStoreApi: () => createPayPalStoreApi,
|
|
32
|
+
isPayPalProviderId: () => isPayPalProviderId,
|
|
33
|
+
markPaymentComplete: () => markPaymentComplete,
|
|
34
|
+
usePayPalConfig: () => usePayPalConfig,
|
|
35
|
+
usePayPalPaymentMethods: () => usePayPalPaymentMethods
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
6
38
|
|
|
7
39
|
// src/client/http.ts
|
|
8
40
|
function toHeaderRecord(headers) {
|
|
@@ -41,25 +73,44 @@ function createHttpClient(opts) {
|
|
|
41
73
|
"[PayPal] Forbidden (403) \u2014 this request is not allowed. Check your CORS and API key settings."
|
|
42
74
|
);
|
|
43
75
|
}
|
|
44
|
-
throw new Error(
|
|
76
|
+
throw new Error(
|
|
77
|
+
text.slice(0, 500).replace(/<[^>]*>/g, "") || `Request failed (${res.status})`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (!text) {
|
|
81
|
+
throw new Error(`[PayPal] Empty response body from ${path} (${res.status})`);
|
|
45
82
|
}
|
|
46
|
-
if (!text) return {};
|
|
47
83
|
const contentType = res.headers.get("content-type") || "";
|
|
48
84
|
if (!contentType.includes("application/json")) {
|
|
49
|
-
|
|
50
|
-
|
|
85
|
+
throw new Error(
|
|
86
|
+
`[PayPal] Unexpected non-JSON response (${contentType}) from ${path}`
|
|
87
|
+
);
|
|
51
88
|
}
|
|
52
89
|
try {
|
|
53
90
|
return JSON.parse(text);
|
|
54
91
|
} catch {
|
|
55
|
-
|
|
56
|
-
return {};
|
|
92
|
+
throw new Error(`[PayPal] Failed to parse JSON response from ${path}`);
|
|
57
93
|
}
|
|
58
94
|
}
|
|
59
95
|
return { request };
|
|
60
96
|
}
|
|
61
97
|
|
|
62
98
|
// src/client/paypal.ts
|
|
99
|
+
async function markPaymentComplete(baseUrl, cartId, publishableApiKey) {
|
|
100
|
+
try {
|
|
101
|
+
await fetch(`${baseUrl.replace(/\/$/, "")}/store/paypal-complete`, {
|
|
102
|
+
method: "POST",
|
|
103
|
+
headers: {
|
|
104
|
+
"Content-Type": "application/json",
|
|
105
|
+
...publishableApiKey ? { "x-publishable-api-key": publishableApiKey } : {}
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify({ cart_id: cartId }),
|
|
108
|
+
credentials: "include"
|
|
109
|
+
});
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.warn("[PayPal] paypal-complete call failed:", e);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
63
114
|
function createPayPalStoreApi(opts) {
|
|
64
115
|
const http = createHttpClient(opts);
|
|
65
116
|
return {
|
|
@@ -86,6 +137,9 @@ function createPayPalStoreApi(opts) {
|
|
|
86
137
|
}
|
|
87
138
|
};
|
|
88
139
|
}
|
|
140
|
+
|
|
141
|
+
// src/hooks/usePayPalConfig.ts
|
|
142
|
+
var import_react = require("react");
|
|
89
143
|
var _cache = /* @__PURE__ */ new Map();
|
|
90
144
|
var CACHE_TTL = 5 * 60 * 1e3;
|
|
91
145
|
function cacheKey(baseUrl, cartId) {
|
|
@@ -97,18 +151,18 @@ function usePayPalConfig({
|
|
|
97
151
|
cartId,
|
|
98
152
|
enabled = true
|
|
99
153
|
}) {
|
|
100
|
-
const api =
|
|
154
|
+
const api = (0, import_react.useMemo)(
|
|
101
155
|
() => createPayPalStoreApi({ baseUrl, publishableApiKey }),
|
|
102
156
|
[baseUrl, publishableApiKey]
|
|
103
157
|
);
|
|
104
158
|
const key = cacheKey(baseUrl, cartId);
|
|
105
159
|
const hit = _cache.get(key);
|
|
106
160
|
const seedConfig = hit && Date.now() - hit.at < CACHE_TTL ? hit.config : null;
|
|
107
|
-
const [config, setConfig] =
|
|
108
|
-
const [loading, setLoading] =
|
|
109
|
-
const [error, setError] =
|
|
110
|
-
const fetchIdRef =
|
|
111
|
-
|
|
161
|
+
const [config, setConfig] = (0, import_react.useState)(seedConfig);
|
|
162
|
+
const [loading, setLoading] = (0, import_react.useState)(seedConfig === null && enabled);
|
|
163
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
164
|
+
const fetchIdRef = (0, import_react.useRef)(0);
|
|
165
|
+
(0, import_react.useEffect)(() => {
|
|
112
166
|
if (!enabled) {
|
|
113
167
|
setLoading(false);
|
|
114
168
|
setError(null);
|
|
@@ -148,13 +202,17 @@ function usePayPalConfig({
|
|
|
148
202
|
}, [api, baseUrl, cartId, enabled]);
|
|
149
203
|
return { config, loading, error };
|
|
150
204
|
}
|
|
205
|
+
|
|
206
|
+
// src/components/PayPalProvider.tsx
|
|
207
|
+
var import_react2 = require("react");
|
|
208
|
+
var import_react_paypal_js = require("@paypal/react-paypal-js");
|
|
209
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
151
210
|
var BN_CODE = "MBJTechnolabs_SI_SPB";
|
|
152
211
|
function PayPalProvider(props) {
|
|
153
212
|
const { config, intent = "capture", disableFunding, children } = props;
|
|
154
|
-
const options =
|
|
213
|
+
const options = (0, import_react2.useMemo)(() => {
|
|
155
214
|
return {
|
|
156
215
|
clientId: config.client_id,
|
|
157
|
-
"client-id": config.client_id,
|
|
158
216
|
currency: config.currency,
|
|
159
217
|
intent,
|
|
160
218
|
components: config.client_token ? "buttons,card-fields" : "buttons",
|
|
@@ -163,8 +221,8 @@ function PayPalProvider(props) {
|
|
|
163
221
|
"data-partner-attribution-id": BN_CODE
|
|
164
222
|
};
|
|
165
223
|
}, [config, intent, disableFunding]);
|
|
166
|
-
return /* @__PURE__ */
|
|
167
|
-
|
|
224
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
225
|
+
import_react_paypal_js.PayPalScriptProvider,
|
|
168
226
|
{
|
|
169
227
|
options,
|
|
170
228
|
children
|
|
@@ -172,13 +230,21 @@ function PayPalProvider(props) {
|
|
|
172
230
|
`${options.clientId}-${options["data-client-token"] ?? "no-token"}`
|
|
173
231
|
);
|
|
174
232
|
}
|
|
233
|
+
|
|
234
|
+
// src/components/PayPalCurrencyNotice.tsx
|
|
235
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
175
236
|
function PayPalCurrencyNotice({ config }) {
|
|
176
237
|
if (config.currency_supported) return null;
|
|
177
|
-
return /* @__PURE__ */
|
|
178
|
-
/* @__PURE__ */
|
|
179
|
-
/* @__PURE__ */
|
|
238
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { padding: 12, border: "1px solid #ddd", borderRadius: 10 }, children: [
|
|
239
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { fontWeight: 600, marginBottom: 6 }, children: "PayPal currency issue" }),
|
|
240
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { style: { margin: 0, paddingLeft: 18 }, children: (config.currency_errors || []).map((e) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { children: e }, e)) })
|
|
180
241
|
] });
|
|
181
242
|
}
|
|
243
|
+
|
|
244
|
+
// src/components/PayPalSmartButtons.tsx
|
|
245
|
+
var import_react3 = require("react");
|
|
246
|
+
var import_react_paypal_js2 = require("@paypal/react-paypal-js");
|
|
247
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
182
248
|
var SPIN_STYLE = `@keyframes _pp_spin { to { transform: rotate(360deg) } }`;
|
|
183
249
|
var BUTTON_WIDTH_MAP = {
|
|
184
250
|
small: "300px",
|
|
@@ -186,34 +252,19 @@ var BUTTON_WIDTH_MAP = {
|
|
|
186
252
|
large: "500px",
|
|
187
253
|
responsive: "100%"
|
|
188
254
|
};
|
|
189
|
-
async function markPaymentComplete(baseUrl, cartId, publishableApiKey) {
|
|
190
|
-
try {
|
|
191
|
-
await fetch(`${baseUrl.replace(/\/$/, "")}/store/paypal-complete`, {
|
|
192
|
-
method: "POST",
|
|
193
|
-
headers: {
|
|
194
|
-
"Content-Type": "application/json",
|
|
195
|
-
...publishableApiKey ? { "x-publishable-api-key": publishableApiKey } : {}
|
|
196
|
-
},
|
|
197
|
-
body: JSON.stringify({ cart_id: cartId }),
|
|
198
|
-
credentials: "include"
|
|
199
|
-
});
|
|
200
|
-
} catch (e) {
|
|
201
|
-
console.warn("[PayPal] paypal-complete call failed:", e);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
255
|
function PayPalSmartButtons(props) {
|
|
205
256
|
const { baseUrl, publishableApiKey, cartId, config, onPaid, onError } = props;
|
|
206
|
-
const api =
|
|
257
|
+
const api = (0, import_react3.useMemo)(
|
|
207
258
|
() => createPayPalStoreApi({ baseUrl, publishableApiKey }),
|
|
208
259
|
[baseUrl, publishableApiKey]
|
|
209
260
|
);
|
|
210
|
-
const [error, setError] =
|
|
211
|
-
const [processing, setProcessing] =
|
|
261
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
262
|
+
const [processing, setProcessing] = (0, import_react3.useState)(false);
|
|
212
263
|
if (!config.currency_supported) return null;
|
|
213
264
|
const containerWidth = BUTTON_WIDTH_MAP[config.button_width ?? "responsive"] ?? "100%";
|
|
214
|
-
return /* @__PURE__ */
|
|
215
|
-
/* @__PURE__ */
|
|
216
|
-
processing && /* @__PURE__ */
|
|
265
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { width: containerWidth, position: "relative" }, children: [
|
|
266
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: SPIN_STYLE }),
|
|
267
|
+
processing && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
217
268
|
"div",
|
|
218
269
|
{
|
|
219
270
|
style: {
|
|
@@ -230,7 +281,7 @@ function PayPalSmartButtons(props) {
|
|
|
230
281
|
minHeight: 60
|
|
231
282
|
},
|
|
232
283
|
children: [
|
|
233
|
-
/* @__PURE__ */
|
|
284
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
234
285
|
"div",
|
|
235
286
|
{
|
|
236
287
|
style: {
|
|
@@ -243,14 +294,14 @@ function PayPalSmartButtons(props) {
|
|
|
243
294
|
}
|
|
244
295
|
}
|
|
245
296
|
),
|
|
246
|
-
/* @__PURE__ */
|
|
247
|
-
/* @__PURE__ */
|
|
248
|
-
/* @__PURE__ */
|
|
297
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { textAlign: "center" }, children: [
|
|
298
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: 13, color: "#374151", fontWeight: 500 }, children: "Processing your payment\u2026" }),
|
|
299
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 4 }, children: "Please do not close or refresh this page" })
|
|
249
300
|
] })
|
|
250
301
|
]
|
|
251
302
|
}
|
|
252
303
|
),
|
|
253
|
-
config.environment === "sandbox" && /* @__PURE__ */
|
|
304
|
+
config.environment === "sandbox" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
254
305
|
"div",
|
|
255
306
|
{
|
|
256
307
|
style: {
|
|
@@ -267,7 +318,7 @@ function PayPalSmartButtons(props) {
|
|
|
267
318
|
marginBottom: 10
|
|
268
319
|
},
|
|
269
320
|
children: [
|
|
270
|
-
/* @__PURE__ */
|
|
321
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
271
322
|
"svg",
|
|
272
323
|
{
|
|
273
324
|
width: "16",
|
|
@@ -279,17 +330,17 @@ function PayPalSmartButtons(props) {
|
|
|
279
330
|
strokeLinecap: "round",
|
|
280
331
|
style: { flexShrink: 0, marginTop: 1 },
|
|
281
332
|
children: [
|
|
282
|
-
/* @__PURE__ */
|
|
283
|
-
/* @__PURE__ */
|
|
333
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
334
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 8v4M12 16h.01" })
|
|
284
335
|
]
|
|
285
336
|
}
|
|
286
337
|
),
|
|
287
|
-
/* @__PURE__ */
|
|
338
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "Sandbox mode \u2014 you will not be charged. Use your PayPal sandbox account to complete the payment." })
|
|
288
339
|
]
|
|
289
340
|
}
|
|
290
341
|
),
|
|
291
|
-
/* @__PURE__ */
|
|
292
|
-
|
|
342
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
343
|
+
import_react_paypal_js2.PayPalButtons,
|
|
293
344
|
{
|
|
294
345
|
style: {
|
|
295
346
|
layout: "vertical",
|
|
@@ -315,6 +366,7 @@ function PayPalSmartButtons(props) {
|
|
|
315
366
|
const msg = e instanceof Error ? e.message : "Payment capture failed";
|
|
316
367
|
setError(msg);
|
|
317
368
|
onError?.(msg);
|
|
369
|
+
} finally {
|
|
318
370
|
setProcessing(false);
|
|
319
371
|
}
|
|
320
372
|
},
|
|
@@ -329,7 +381,7 @@ function PayPalSmartButtons(props) {
|
|
|
329
381
|
}
|
|
330
382
|
}
|
|
331
383
|
),
|
|
332
|
-
error ? /* @__PURE__ */
|
|
384
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
333
385
|
"div",
|
|
334
386
|
{
|
|
335
387
|
style: {
|
|
@@ -346,13 +398,18 @@ function PayPalSmartButtons(props) {
|
|
|
346
398
|
lineHeight: 1.5
|
|
347
399
|
},
|
|
348
400
|
children: [
|
|
349
|
-
/* @__PURE__ */
|
|
350
|
-
/* @__PURE__ */
|
|
401
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { flexShrink: 0, fontSize: 15 }, children: "\u26A0\uFE0F" }),
|
|
402
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: error })
|
|
351
403
|
]
|
|
352
404
|
}
|
|
353
405
|
) : null
|
|
354
406
|
] });
|
|
355
407
|
}
|
|
408
|
+
|
|
409
|
+
// src/components/PayPalAdvancedCard.tsx
|
|
410
|
+
var import_react4 = require("react");
|
|
411
|
+
var import_react_paypal_js3 = require("@paypal/react-paypal-js");
|
|
412
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
356
413
|
var SPIN_STYLE2 = `@keyframes _pp_spin { to { transform: rotate(360deg) } }`;
|
|
357
414
|
var cardStyle = {
|
|
358
415
|
input: {
|
|
@@ -396,29 +453,14 @@ var labelStyle = {
|
|
|
396
453
|
marginBottom: 6,
|
|
397
454
|
letterSpacing: "0.01em"
|
|
398
455
|
};
|
|
399
|
-
async function markPaymentComplete2(baseUrl, cartId, publishableApiKey) {
|
|
400
|
-
try {
|
|
401
|
-
await fetch(`${baseUrl.replace(/\/$/, "")}/store/paypal-complete`, {
|
|
402
|
-
method: "POST",
|
|
403
|
-
headers: {
|
|
404
|
-
"Content-Type": "application/json",
|
|
405
|
-
...publishableApiKey ? { "x-publishable-api-key": publishableApiKey } : {}
|
|
406
|
-
},
|
|
407
|
-
body: JSON.stringify({ cart_id: cartId }),
|
|
408
|
-
credentials: "include"
|
|
409
|
-
});
|
|
410
|
-
} catch (e) {
|
|
411
|
-
console.warn("[PayPal Card] paypal-complete call failed:", e);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
456
|
function SubmitButton({
|
|
415
457
|
disabled,
|
|
416
458
|
label,
|
|
417
459
|
onSubmit
|
|
418
460
|
}) {
|
|
419
|
-
const { cardFieldsForm } =
|
|
461
|
+
const { cardFieldsForm } = (0, import_react_paypal_js3.usePayPalCardFields)();
|
|
420
462
|
const isDisabled = disabled || !cardFieldsForm;
|
|
421
|
-
return /* @__PURE__ */
|
|
463
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
422
464
|
"button",
|
|
423
465
|
{
|
|
424
466
|
type: "button",
|
|
@@ -445,12 +487,14 @@ function SubmitButton({
|
|
|
445
487
|
},
|
|
446
488
|
onMouseEnter: (e) => {
|
|
447
489
|
if (!isDisabled) {
|
|
490
|
+
;
|
|
448
491
|
e.target.style.background = "linear-gradient(180deg, #1d4ed8 0%, #1e40af 100%)";
|
|
449
492
|
e.target.style.boxShadow = "0 4px 6px rgba(37,99,235,0.35), 0 2px 4px rgba(0,0,0,0.06)";
|
|
450
493
|
}
|
|
451
494
|
},
|
|
452
495
|
onMouseLeave: (e) => {
|
|
453
496
|
if (!isDisabled) {
|
|
497
|
+
;
|
|
454
498
|
e.target.style.background = "linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%)";
|
|
455
499
|
e.target.style.boxShadow = "0 1px 3px rgba(37,99,235,0.3), 0 1px 2px rgba(0,0,0,0.06)";
|
|
456
500
|
}
|
|
@@ -461,15 +505,15 @@ function SubmitButton({
|
|
|
461
505
|
}
|
|
462
506
|
function PayPalAdvancedCard(props) {
|
|
463
507
|
const { baseUrl, publishableApiKey, cartId, config, onPaid, onError } = props;
|
|
464
|
-
const api =
|
|
508
|
+
const api = (0, import_react4.useMemo)(
|
|
465
509
|
() => createPayPalStoreApi({ baseUrl, publishableApiKey }),
|
|
466
510
|
[baseUrl, publishableApiKey]
|
|
467
511
|
);
|
|
468
|
-
const [error, setError] =
|
|
469
|
-
const [submitting, setSubmitting] =
|
|
512
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
513
|
+
const [submitting, setSubmitting] = (0, import_react4.useState)(false);
|
|
470
514
|
if (!config.currency_supported) return null;
|
|
471
515
|
if (!config.client_token) {
|
|
472
|
-
return /* @__PURE__ */
|
|
516
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
473
517
|
"div",
|
|
474
518
|
{
|
|
475
519
|
style: {
|
|
@@ -485,9 +529,9 @@ function PayPalAdvancedCard(props) {
|
|
|
485
529
|
);
|
|
486
530
|
}
|
|
487
531
|
const isSandbox = config.environment === "sandbox";
|
|
488
|
-
return /* @__PURE__ */
|
|
489
|
-
/* @__PURE__ */
|
|
490
|
-
submitting && /* @__PURE__ */
|
|
532
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { position: "relative" }, children: [
|
|
533
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: SPIN_STYLE2 }),
|
|
534
|
+
submitting && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
491
535
|
"div",
|
|
492
536
|
{
|
|
493
537
|
style: {
|
|
@@ -504,7 +548,7 @@ function PayPalAdvancedCard(props) {
|
|
|
504
548
|
minHeight: 180
|
|
505
549
|
},
|
|
506
550
|
children: [
|
|
507
|
-
/* @__PURE__ */
|
|
551
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
508
552
|
"div",
|
|
509
553
|
{
|
|
510
554
|
style: {
|
|
@@ -517,20 +561,20 @@ function PayPalAdvancedCard(props) {
|
|
|
517
561
|
}
|
|
518
562
|
}
|
|
519
563
|
),
|
|
520
|
-
/* @__PURE__ */
|
|
521
|
-
/* @__PURE__ */
|
|
522
|
-
/* @__PURE__ */
|
|
564
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { textAlign: "center" }, children: [
|
|
565
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontSize: 15, fontWeight: 600, color: "#111827" }, children: "Processing your payment\u2026" }),
|
|
566
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontSize: 13, color: "#6b7280", marginTop: 4 }, children: "Please do not close or refresh this page" })
|
|
523
567
|
] })
|
|
524
568
|
]
|
|
525
569
|
}
|
|
526
570
|
),
|
|
527
|
-
/* @__PURE__ */
|
|
528
|
-
|
|
571
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
572
|
+
import_react_paypal_js3.PayPalCardFieldsProvider,
|
|
529
573
|
{
|
|
530
574
|
style: cardStyle,
|
|
531
575
|
createOrder: async () => {
|
|
532
576
|
setError(null);
|
|
533
|
-
const r = await api.createOrder(cartId);
|
|
577
|
+
const r = await api.createOrder(cartId, true);
|
|
534
578
|
return r.id;
|
|
535
579
|
},
|
|
536
580
|
onApprove: async (data) => {
|
|
@@ -538,12 +582,13 @@ function PayPalAdvancedCard(props) {
|
|
|
538
582
|
setError(null);
|
|
539
583
|
const orderId = String(data?.orderID || "");
|
|
540
584
|
const result = await api.captureOrder(cartId, orderId);
|
|
541
|
-
await
|
|
585
|
+
await markPaymentComplete(baseUrl, cartId, publishableApiKey);
|
|
542
586
|
onPaid?.(result);
|
|
543
587
|
} catch (e) {
|
|
544
588
|
const msg = e instanceof Error ? e.message : "Card payment failed";
|
|
545
589
|
setError(msg);
|
|
546
590
|
onError?.(msg);
|
|
591
|
+
} finally {
|
|
547
592
|
setSubmitting(false);
|
|
548
593
|
}
|
|
549
594
|
},
|
|
@@ -556,7 +601,7 @@ function PayPalAdvancedCard(props) {
|
|
|
556
601
|
onError?.(msg);
|
|
557
602
|
setSubmitting(false);
|
|
558
603
|
},
|
|
559
|
-
children: /* @__PURE__ */
|
|
604
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
560
605
|
"div",
|
|
561
606
|
{
|
|
562
607
|
style: {
|
|
@@ -566,7 +611,7 @@ function PayPalAdvancedCard(props) {
|
|
|
566
611
|
width: "100%"
|
|
567
612
|
},
|
|
568
613
|
children: [
|
|
569
|
-
isSandbox && /* @__PURE__ */
|
|
614
|
+
isSandbox && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
570
615
|
"div",
|
|
571
616
|
{
|
|
572
617
|
style: {
|
|
@@ -582,22 +627,22 @@ function PayPalAdvancedCard(props) {
|
|
|
582
627
|
lineHeight: 1.55
|
|
583
628
|
},
|
|
584
629
|
children: [
|
|
585
|
-
/* @__PURE__ */
|
|
586
|
-
/* @__PURE__ */
|
|
630
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: 15, flexShrink: 0, marginTop: 1 }, children: "\u{1F9EA}" }),
|
|
631
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
587
632
|
"Sandbox mode \u2014 use test card",
|
|
588
633
|
" ",
|
|
589
|
-
/* @__PURE__ */
|
|
634
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("strong", { style: { fontFamily: "monospace", letterSpacing: "0.05em" }, children: "4111 1111 1111 1111" }),
|
|
590
635
|
" ",
|
|
591
636
|
"with any future date and any CVV."
|
|
592
637
|
] })
|
|
593
638
|
]
|
|
594
639
|
}
|
|
595
640
|
),
|
|
596
|
-
/* @__PURE__ */
|
|
597
|
-
/* @__PURE__ */
|
|
598
|
-
/* @__PURE__ */
|
|
641
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
642
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { style: labelStyle, children: "Card number" }),
|
|
643
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_paypal_js3.PayPalNumberField, {})
|
|
599
644
|
] }),
|
|
600
|
-
/* @__PURE__ */
|
|
645
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
601
646
|
"div",
|
|
602
647
|
{
|
|
603
648
|
style: {
|
|
@@ -606,18 +651,18 @@ function PayPalAdvancedCard(props) {
|
|
|
606
651
|
gap: 16
|
|
607
652
|
},
|
|
608
653
|
children: [
|
|
609
|
-
/* @__PURE__ */
|
|
610
|
-
/* @__PURE__ */
|
|
611
|
-
/* @__PURE__ */
|
|
654
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
655
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { style: labelStyle, children: "Expiration date" }),
|
|
656
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_paypal_js3.PayPalExpiryField, {})
|
|
612
657
|
] }),
|
|
613
|
-
/* @__PURE__ */
|
|
614
|
-
/* @__PURE__ */
|
|
615
|
-
/* @__PURE__ */
|
|
658
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
659
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { style: labelStyle, children: "Security code" }),
|
|
660
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_paypal_js3.PayPalCVVField, {})
|
|
616
661
|
] })
|
|
617
662
|
]
|
|
618
663
|
}
|
|
619
664
|
),
|
|
620
|
-
/* @__PURE__ */
|
|
665
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
621
666
|
"div",
|
|
622
667
|
{
|
|
623
668
|
style: {
|
|
@@ -628,7 +673,7 @@ function PayPalAdvancedCard(props) {
|
|
|
628
673
|
color: "#6b7280"
|
|
629
674
|
},
|
|
630
675
|
children: [
|
|
631
|
-
/* @__PURE__ */
|
|
676
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
632
677
|
"svg",
|
|
633
678
|
{
|
|
634
679
|
width: "14",
|
|
@@ -639,14 +684,14 @@ function PayPalAdvancedCard(props) {
|
|
|
639
684
|
strokeWidth: "2.5",
|
|
640
685
|
strokeLinecap: "round",
|
|
641
686
|
strokeLinejoin: "round",
|
|
642
|
-
children: /* @__PURE__ */
|
|
687
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" })
|
|
643
688
|
}
|
|
644
689
|
),
|
|
645
|
-
/* @__PURE__ */
|
|
690
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: "Your payment is secured with 256-bit SSL encryption" })
|
|
646
691
|
]
|
|
647
692
|
}
|
|
648
693
|
),
|
|
649
|
-
/* @__PURE__ */
|
|
694
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
650
695
|
SubmitButton,
|
|
651
696
|
{
|
|
652
697
|
disabled: submitting,
|
|
@@ -657,7 +702,7 @@ function PayPalAdvancedCard(props) {
|
|
|
657
702
|
}
|
|
658
703
|
}
|
|
659
704
|
),
|
|
660
|
-
error && /* @__PURE__ */
|
|
705
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
661
706
|
"div",
|
|
662
707
|
{
|
|
663
708
|
style: {
|
|
@@ -673,8 +718,8 @@ function PayPalAdvancedCard(props) {
|
|
|
673
718
|
lineHeight: 1.5
|
|
674
719
|
},
|
|
675
720
|
children: [
|
|
676
|
-
/* @__PURE__ */
|
|
677
|
-
/* @__PURE__ */
|
|
721
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { flexShrink: 0, marginTop: 1 }, children: "\u26A0\uFE0F" }),
|
|
722
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: error })
|
|
678
723
|
]
|
|
679
724
|
}
|
|
680
725
|
)
|
|
@@ -685,11 +730,15 @@ function PayPalAdvancedCard(props) {
|
|
|
685
730
|
)
|
|
686
731
|
] });
|
|
687
732
|
}
|
|
733
|
+
|
|
734
|
+
// src/adapters/MedusaNextPayPalAdapter.tsx
|
|
735
|
+
var import_react5 = require("react");
|
|
736
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
688
737
|
var DEFAULT_PAYPAL_PROVIDER_ID = "pp_paypal_paypal";
|
|
689
738
|
var DEFAULT_PAYPAL_CARD_PROVIDER_ID = "pp_paypal_card_paypal_card";
|
|
690
739
|
var SPIN_STYLE3 = `@keyframes _pp_spin { to { transform: rotate(360deg) } }`;
|
|
691
740
|
function PayPalLoadingCard() {
|
|
692
|
-
return /* @__PURE__ */
|
|
741
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
693
742
|
"div",
|
|
694
743
|
{
|
|
695
744
|
style: {
|
|
@@ -702,8 +751,8 @@ function PayPalLoadingCard() {
|
|
|
702
751
|
borderRadius: 10
|
|
703
752
|
},
|
|
704
753
|
children: [
|
|
705
|
-
/* @__PURE__ */
|
|
706
|
-
/* @__PURE__ */
|
|
754
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("style", { children: SPIN_STYLE3 }),
|
|
755
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
707
756
|
"div",
|
|
708
757
|
{
|
|
709
758
|
style: {
|
|
@@ -717,16 +766,16 @@ function PayPalLoadingCard() {
|
|
|
717
766
|
}
|
|
718
767
|
}
|
|
719
768
|
),
|
|
720
|
-
/* @__PURE__ */
|
|
721
|
-
/* @__PURE__ */
|
|
722
|
-
/* @__PURE__ */
|
|
769
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
770
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: 13, fontWeight: 500, color: "#111827" }, children: "Connecting to PayPal\u2026" }),
|
|
771
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 2 }, children: "Setting up secure payment" })
|
|
723
772
|
] })
|
|
724
773
|
]
|
|
725
774
|
}
|
|
726
775
|
);
|
|
727
776
|
}
|
|
728
777
|
function PayPalErrorCard({ message }) {
|
|
729
|
-
return /* @__PURE__ */
|
|
778
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
730
779
|
"div",
|
|
731
780
|
{
|
|
732
781
|
style: {
|
|
@@ -761,7 +810,7 @@ function MedusaNextPayPalAdapter(props) {
|
|
|
761
810
|
cartId,
|
|
762
811
|
enabled: shouldRender
|
|
763
812
|
});
|
|
764
|
-
const handlePaid =
|
|
813
|
+
const handlePaid = (0, import_react5.useCallback)(
|
|
765
814
|
(captureResult) => {
|
|
766
815
|
onPaid?.(captureResult);
|
|
767
816
|
onSuccess?.(cartId);
|
|
@@ -769,21 +818,22 @@ function MedusaNextPayPalAdapter(props) {
|
|
|
769
818
|
[cartId, onPaid, onSuccess]
|
|
770
819
|
);
|
|
771
820
|
if (!shouldRender) return null;
|
|
772
|
-
if (loading) return /* @__PURE__ */
|
|
773
|
-
if (error) return /* @__PURE__ */
|
|
821
|
+
if (loading) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PayPalLoadingCard, {});
|
|
822
|
+
if (error) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PayPalErrorCard, { message: error });
|
|
774
823
|
if (!config) return null;
|
|
775
|
-
|
|
776
|
-
if (
|
|
824
|
+
const isCardProvider = selectedProviderId === paypalCardProviderId;
|
|
825
|
+
if (config.paypal_enabled === false && !isCardProvider) return null;
|
|
826
|
+
if (isCardProvider && config.card_enabled === false) return null;
|
|
777
827
|
const disableFunding = Array.isArray(config.disable_buttons) ? config.disable_buttons.join(",") : void 0;
|
|
778
|
-
return /* @__PURE__ */
|
|
779
|
-
/* @__PURE__ */
|
|
780
|
-
/* @__PURE__ */
|
|
828
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "grid", gap: 12 }, children: [
|
|
829
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PayPalCurrencyNotice, { config }),
|
|
830
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
781
831
|
PayPalProvider,
|
|
782
832
|
{
|
|
783
833
|
config,
|
|
784
834
|
intent: config.intent === "authorize" ? "authorize" : "capture",
|
|
785
835
|
disableFunding,
|
|
786
|
-
children:
|
|
836
|
+
children: isCardProvider ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
787
837
|
PayPalAdvancedCard,
|
|
788
838
|
{
|
|
789
839
|
baseUrl,
|
|
@@ -793,7 +843,7 @@ function MedusaNextPayPalAdapter(props) {
|
|
|
793
843
|
onPaid: handlePaid,
|
|
794
844
|
onError
|
|
795
845
|
}
|
|
796
|
-
) : /* @__PURE__ */
|
|
846
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
797
847
|
PayPalSmartButtons,
|
|
798
848
|
{
|
|
799
849
|
baseUrl,
|
|
@@ -808,6 +858,10 @@ function MedusaNextPayPalAdapter(props) {
|
|
|
808
858
|
)
|
|
809
859
|
] }, selectedProviderId);
|
|
810
860
|
}
|
|
861
|
+
|
|
862
|
+
// src/components/PayPalPaymentSection.tsx
|
|
863
|
+
var import_react6 = require("react");
|
|
864
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
811
865
|
var PAYPAL_WALLET_PROVIDER_ID = "pp_paypal_paypal";
|
|
812
866
|
var PAYPAL_CARD_PROVIDER_ID = "pp_paypal_card_paypal_card";
|
|
813
867
|
var PAYPAL_PROVIDER_IDS = [
|
|
@@ -820,7 +874,7 @@ function isPayPalProviderId(id) {
|
|
|
820
874
|
}
|
|
821
875
|
var SPIN_STYLE4 = `@keyframes _pp_section_spin { to { transform: rotate(360deg) } }`;
|
|
822
876
|
function SessionInitCard() {
|
|
823
|
-
return /* @__PURE__ */
|
|
877
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
824
878
|
"div",
|
|
825
879
|
{
|
|
826
880
|
style: {
|
|
@@ -834,8 +888,8 @@ function SessionInitCard() {
|
|
|
834
888
|
borderRadius: 10
|
|
835
889
|
},
|
|
836
890
|
children: [
|
|
837
|
-
/* @__PURE__ */
|
|
838
|
-
/* @__PURE__ */
|
|
891
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("style", { children: SPIN_STYLE4 }),
|
|
892
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
839
893
|
"div",
|
|
840
894
|
{
|
|
841
895
|
style: {
|
|
@@ -849,13 +903,13 @@ function SessionInitCard() {
|
|
|
849
903
|
}
|
|
850
904
|
}
|
|
851
905
|
),
|
|
852
|
-
/* @__PURE__ */
|
|
906
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: { fontSize: 13, fontWeight: 500, color: "#111827" }, children: "Setting up payment\u2026" })
|
|
853
907
|
]
|
|
854
908
|
}
|
|
855
909
|
);
|
|
856
910
|
}
|
|
857
911
|
function ConfigLoadingCard() {
|
|
858
|
-
return /* @__PURE__ */
|
|
912
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
859
913
|
"div",
|
|
860
914
|
{
|
|
861
915
|
style: {
|
|
@@ -868,8 +922,8 @@ function ConfigLoadingCard() {
|
|
|
868
922
|
borderRadius: 10
|
|
869
923
|
},
|
|
870
924
|
children: [
|
|
871
|
-
/* @__PURE__ */
|
|
872
|
-
/* @__PURE__ */
|
|
925
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("style", { children: SPIN_STYLE4 }),
|
|
926
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
873
927
|
"div",
|
|
874
928
|
{
|
|
875
929
|
style: {
|
|
@@ -883,16 +937,16 @@ function ConfigLoadingCard() {
|
|
|
883
937
|
}
|
|
884
938
|
}
|
|
885
939
|
),
|
|
886
|
-
/* @__PURE__ */
|
|
887
|
-
/* @__PURE__ */
|
|
888
|
-
/* @__PURE__ */
|
|
940
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
|
|
941
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: { fontSize: 13, fontWeight: 500, color: "#111827" }, children: "Connecting to PayPal\u2026" }),
|
|
942
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 2 }, children: "Setting up secure payment" })
|
|
889
943
|
] })
|
|
890
944
|
]
|
|
891
945
|
}
|
|
892
946
|
);
|
|
893
947
|
}
|
|
894
948
|
function ErrorCard({ message }) {
|
|
895
|
-
return /* @__PURE__ */
|
|
949
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
896
950
|
"div",
|
|
897
951
|
{
|
|
898
952
|
style: {
|
|
@@ -924,7 +978,7 @@ function PayPalPaymentSection({
|
|
|
924
978
|
cartId,
|
|
925
979
|
enabled: shouldRender
|
|
926
980
|
});
|
|
927
|
-
const handlePaid =
|
|
981
|
+
const handlePaid = (0, import_react6.useCallback)(
|
|
928
982
|
(captureResult) => {
|
|
929
983
|
onPaid?.(captureResult);
|
|
930
984
|
onSuccess?.(cartId);
|
|
@@ -932,9 +986,9 @@ function PayPalPaymentSection({
|
|
|
932
986
|
[cartId, onPaid, onSuccess]
|
|
933
987
|
);
|
|
934
988
|
if (!shouldRender) return null;
|
|
935
|
-
if (sessionLoading) return /* @__PURE__ */
|
|
936
|
-
if (loading) return /* @__PURE__ */
|
|
937
|
-
if (error) return /* @__PURE__ */
|
|
989
|
+
if (sessionLoading) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SessionInitCard, {});
|
|
990
|
+
if (loading) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ConfigLoadingCard, {});
|
|
991
|
+
if (error) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorCard, { message: error });
|
|
938
992
|
if (!config) return null;
|
|
939
993
|
if (config.paypal_enabled === false && selectedProviderId === PAYPAL_WALLET_PROVIDER_ID) {
|
|
940
994
|
return null;
|
|
@@ -942,15 +996,15 @@ function PayPalPaymentSection({
|
|
|
942
996
|
const isCardProvider = selectedProviderId === PAYPAL_CARD_PROVIDER_ID;
|
|
943
997
|
if (isCardProvider && config.card_enabled === false) return null;
|
|
944
998
|
const disableFunding = Array.isArray(config.disable_buttons) ? config.disable_buttons.join(",") : void 0;
|
|
945
|
-
return /* @__PURE__ */
|
|
946
|
-
/* @__PURE__ */
|
|
947
|
-
/* @__PURE__ */
|
|
999
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "grid", gap: 12 }, children: [
|
|
1000
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PayPalCurrencyNotice, { config }),
|
|
1001
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
948
1002
|
PayPalProvider,
|
|
949
1003
|
{
|
|
950
1004
|
config,
|
|
951
1005
|
intent: config.intent === "authorize" ? "authorize" : "capture",
|
|
952
1006
|
disableFunding,
|
|
953
|
-
children: isCardProvider ? /* @__PURE__ */
|
|
1007
|
+
children: isCardProvider ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
954
1008
|
PayPalAdvancedCard,
|
|
955
1009
|
{
|
|
956
1010
|
baseUrl,
|
|
@@ -960,7 +1014,7 @@ function PayPalPaymentSection({
|
|
|
960
1014
|
onPaid: handlePaid,
|
|
961
1015
|
onError
|
|
962
1016
|
}
|
|
963
|
-
) : /* @__PURE__ */
|
|
1017
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
964
1018
|
PayPalSmartButtons,
|
|
965
1019
|
{
|
|
966
1020
|
baseUrl,
|
|
@@ -975,6 +1029,9 @@ function PayPalPaymentSection({
|
|
|
975
1029
|
)
|
|
976
1030
|
] }, selectedProviderId);
|
|
977
1031
|
}
|
|
1032
|
+
|
|
1033
|
+
// src/hooks/usePayPalPaymentMethods.ts
|
|
1034
|
+
var import_react7 = require("react");
|
|
978
1035
|
var _cache2 = /* @__PURE__ */ new Map();
|
|
979
1036
|
var CACHE_TTL2 = 5 * 60 * 1e3;
|
|
980
1037
|
function cacheKey2(baseUrl, cartId) {
|
|
@@ -993,16 +1050,16 @@ function usePayPalPaymentMethods({
|
|
|
993
1050
|
cartId,
|
|
994
1051
|
enabled = true
|
|
995
1052
|
}) {
|
|
996
|
-
const api =
|
|
1053
|
+
const api = (0, import_react7.useMemo)(
|
|
997
1054
|
() => createPayPalStoreApi({ baseUrl, publishableApiKey }),
|
|
998
1055
|
[baseUrl, publishableApiKey]
|
|
999
1056
|
);
|
|
1000
1057
|
const key = cacheKey2(baseUrl, cartId);
|
|
1001
1058
|
const hit = _cache2.get(key);
|
|
1002
1059
|
const seed = hit && Date.now() - hit.at < CACHE_TTL2 ? hit.result : null;
|
|
1003
|
-
const [result, setResult] =
|
|
1004
|
-
const fetchIdRef =
|
|
1005
|
-
|
|
1060
|
+
const [result, setResult] = (0, import_react7.useState)(seed ?? { ...DEFAULT_RESULT, loading: enabled });
|
|
1061
|
+
const fetchIdRef = (0, import_react7.useRef)(0);
|
|
1062
|
+
(0, import_react7.useEffect)(() => {
|
|
1006
1063
|
if (!enabled) {
|
|
1007
1064
|
setResult((prev) => ({ ...prev, loading: false }));
|
|
1008
1065
|
return;
|
|
@@ -1053,17 +1110,20 @@ function usePayPalPaymentMethods({
|
|
|
1053
1110
|
}, [api, baseUrl, cartId, enabled]);
|
|
1054
1111
|
return result;
|
|
1055
1112
|
}
|
|
1056
|
-
|
|
1057
|
-
exports
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1114
|
+
0 && (module.exports = {
|
|
1115
|
+
MedusaNextPayPalAdapter,
|
|
1116
|
+
PAYPAL_CARD_PROVIDER_ID,
|
|
1117
|
+
PAYPAL_WALLET_PROVIDER_ID,
|
|
1118
|
+
PayPalAdvancedCard,
|
|
1119
|
+
PayPalCurrencyNotice,
|
|
1120
|
+
PayPalPaymentSection,
|
|
1121
|
+
PayPalProvider,
|
|
1122
|
+
PayPalSmartButtons,
|
|
1123
|
+
createPayPalStoreApi,
|
|
1124
|
+
isPayPalProviderId,
|
|
1125
|
+
markPaymentComplete,
|
|
1126
|
+
usePayPalConfig,
|
|
1127
|
+
usePayPalPaymentMethods
|
|
1128
|
+
});
|
|
1069
1129
|
//# sourceMappingURL=index.cjs.map
|