@easypayment/medusa-paypal-ui 1.0.45 → 1.0.48

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.mjs CHANGED
@@ -1,7 +1,3 @@
1
- import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
2
- import { PayPalScriptProvider, PayPalButtons, PayPalCardFieldsProvider, PayPalNumberField, PayPalExpiryField, PayPalCVVField, usePayPalCardFields } from '@paypal/react-paypal-js';
3
- import { jsx, jsxs } from 'react/jsx-runtime';
4
-
5
1
  // src/client/http.ts
6
2
  function toHeaderRecord(headers) {
7
3
  if (!headers) {
@@ -39,25 +35,47 @@ function createHttpClient(opts) {
39
35
  "[PayPal] Forbidden (403) \u2014 this request is not allowed. Check your CORS and API key settings."
40
36
  );
41
37
  }
42
- throw new Error(text || `Request failed (${res.status})`);
38
+ throw new Error(
39
+ text.slice(0, 500).replace(/<[^>]*>/g, "") || `Request failed (${res.status})`
40
+ );
41
+ }
42
+ if (!text) {
43
+ throw new Error(`[PayPal] Empty response body from ${path} (${res.status})`);
43
44
  }
44
- if (!text) return {};
45
45
  const contentType = res.headers.get("content-type") || "";
46
46
  if (!contentType.includes("application/json")) {
47
- console.warn("[PayPal] Unexpected non-JSON response:", contentType, text.slice(0, 200));
48
- return {};
47
+ throw new Error(
48
+ `[PayPal] Unexpected non-JSON response (${contentType}) from ${path}`
49
+ );
49
50
  }
50
51
  try {
51
52
  return JSON.parse(text);
52
53
  } catch {
53
- console.warn("[PayPal] Failed to parse JSON response:", text.slice(0, 200));
54
- return {};
54
+ throw new Error(`[PayPal] Failed to parse JSON response from ${path}`);
55
55
  }
56
56
  }
57
57
  return { request };
58
58
  }
59
59
 
60
60
  // src/client/paypal.ts
61
+ async function markPaymentComplete(baseUrl, cartId, publishableApiKey) {
62
+ try {
63
+ const resp = await fetch(`${baseUrl.replace(/\/$/, "")}/store/paypal-complete`, {
64
+ method: "POST",
65
+ headers: {
66
+ "Content-Type": "application/json",
67
+ ...publishableApiKey ? { "x-publishable-api-key": publishableApiKey } : {}
68
+ },
69
+ body: JSON.stringify({ cart_id: cartId }),
70
+ credentials: "include"
71
+ });
72
+ const data = await resp.json().catch(() => ({}));
73
+ return data || {};
74
+ } catch (e) {
75
+ console.warn("[PayPal] paypal-complete call failed:", e);
76
+ return {};
77
+ }
78
+ }
61
79
  function createPayPalStoreApi(opts) {
62
80
  const http = createHttpClient(opts);
63
81
  return {
@@ -84,6 +102,9 @@ function createPayPalStoreApi(opts) {
84
102
  }
85
103
  };
86
104
  }
105
+
106
+ // src/hooks/usePayPalConfig.ts
107
+ import { useEffect, useMemo, useRef, useState } from "react";
87
108
  var _cache = /* @__PURE__ */ new Map();
88
109
  var CACHE_TTL = 5 * 60 * 1e3;
89
110
  function cacheKey(baseUrl, cartId) {
@@ -146,13 +167,17 @@ function usePayPalConfig({
146
167
  }, [api, baseUrl, cartId, enabled]);
147
168
  return { config, loading, error };
148
169
  }
170
+
171
+ // src/components/PayPalProvider.tsx
172
+ import { useMemo as useMemo2 } from "react";
173
+ import { PayPalScriptProvider } from "@paypal/react-paypal-js";
174
+ import { jsx } from "react/jsx-runtime";
149
175
  var BN_CODE = "MBJTechnolabs_SI_SPB";
150
176
  function PayPalProvider(props) {
151
177
  const { config, intent = "capture", disableFunding, children } = props;
152
- const options = useMemo(() => {
178
+ const options = useMemo2(() => {
153
179
  return {
154
180
  clientId: config.client_id,
155
- "client-id": config.client_id,
156
181
  currency: config.currency,
157
182
  intent,
158
183
  components: config.client_token ? "buttons,card-fields" : "buttons",
@@ -170,13 +195,21 @@ function PayPalProvider(props) {
170
195
  `${options.clientId}-${options["data-client-token"] ?? "no-token"}`
171
196
  );
172
197
  }
198
+
199
+ // src/components/PayPalCurrencyNotice.tsx
200
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
173
201
  function PayPalCurrencyNotice({ config }) {
174
202
  if (config.currency_supported) return null;
175
203
  return /* @__PURE__ */ jsxs("div", { style: { padding: 12, border: "1px solid #ddd", borderRadius: 10 }, children: [
176
- /* @__PURE__ */ jsx("div", { style: { fontWeight: 600, marginBottom: 6 }, children: "PayPal currency issue" }),
177
- /* @__PURE__ */ jsx("ul", { style: { margin: 0, paddingLeft: 18 }, children: (config.currency_errors || []).map((e, i) => /* @__PURE__ */ jsx("li", { children: e }, i)) })
204
+ /* @__PURE__ */ jsx2("div", { style: { fontWeight: 600, marginBottom: 6 }, children: "PayPal currency issue" }),
205
+ /* @__PURE__ */ jsx2("ul", { style: { margin: 0, paddingLeft: 18 }, children: (config.currency_errors || []).map((e) => /* @__PURE__ */ jsx2("li", { children: e }, e)) })
178
206
  ] });
179
207
  }
208
+
209
+ // src/components/PayPalSmartButtons.tsx
210
+ import { useMemo as useMemo3, useState as useState2 } from "react";
211
+ import { PayPalButtons } from "@paypal/react-paypal-js";
212
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
180
213
  var SPIN_STYLE = `@keyframes _pp_spin { to { transform: rotate(360deg) } }`;
181
214
  var BUTTON_WIDTH_MAP = {
182
215
  small: "300px",
@@ -184,34 +217,19 @@ var BUTTON_WIDTH_MAP = {
184
217
  large: "500px",
185
218
  responsive: "100%"
186
219
  };
187
- async function markPaymentComplete(baseUrl, cartId, publishableApiKey) {
188
- try {
189
- await fetch(`${baseUrl.replace(/\/$/, "")}/store/paypal-complete`, {
190
- method: "POST",
191
- headers: {
192
- "Content-Type": "application/json",
193
- ...publishableApiKey ? { "x-publishable-api-key": publishableApiKey } : {}
194
- },
195
- body: JSON.stringify({ cart_id: cartId }),
196
- credentials: "include"
197
- });
198
- } catch (e) {
199
- console.warn("[PayPal] paypal-complete call failed:", e);
200
- }
201
- }
202
220
  function PayPalSmartButtons(props) {
203
221
  const { baseUrl, publishableApiKey, cartId, config, onPaid, onError } = props;
204
- const api = useMemo(
222
+ const api = useMemo3(
205
223
  () => createPayPalStoreApi({ baseUrl, publishableApiKey }),
206
224
  [baseUrl, publishableApiKey]
207
225
  );
208
- const [error, setError] = useState(null);
209
- const [processing, setProcessing] = useState(false);
226
+ const [error, setError] = useState2(null);
227
+ const [processing, setProcessing] = useState2(false);
210
228
  if (!config.currency_supported) return null;
211
229
  const containerWidth = BUTTON_WIDTH_MAP[config.button_width ?? "responsive"] ?? "100%";
212
- return /* @__PURE__ */ jsxs("div", { style: { width: containerWidth, position: "relative" }, children: [
213
- /* @__PURE__ */ jsx("style", { children: SPIN_STYLE }),
214
- processing && /* @__PURE__ */ jsxs(
230
+ return /* @__PURE__ */ jsxs2("div", { style: { width: containerWidth, position: "relative" }, children: [
231
+ /* @__PURE__ */ jsx3("style", { children: SPIN_STYLE }),
232
+ processing && /* @__PURE__ */ jsxs2(
215
233
  "div",
216
234
  {
217
235
  style: {
@@ -228,7 +246,7 @@ function PayPalSmartButtons(props) {
228
246
  minHeight: 60
229
247
  },
230
248
  children: [
231
- /* @__PURE__ */ jsx(
249
+ /* @__PURE__ */ jsx3(
232
250
  "div",
233
251
  {
234
252
  style: {
@@ -241,14 +259,14 @@ function PayPalSmartButtons(props) {
241
259
  }
242
260
  }
243
261
  ),
244
- /* @__PURE__ */ jsxs("div", { style: { textAlign: "center" }, children: [
245
- /* @__PURE__ */ jsx("div", { style: { fontSize: 13, color: "#374151", fontWeight: 500 }, children: "Processing your payment\u2026" }),
246
- /* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 4 }, children: "Please do not close or refresh this page" })
262
+ /* @__PURE__ */ jsxs2("div", { style: { textAlign: "center" }, children: [
263
+ /* @__PURE__ */ jsx3("div", { style: { fontSize: 13, color: "#374151", fontWeight: 500 }, children: "Processing your payment\u2026" }),
264
+ /* @__PURE__ */ jsx3("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 4 }, children: "Please do not close or refresh this page" })
247
265
  ] })
248
266
  ]
249
267
  }
250
268
  ),
251
- config.environment === "sandbox" && /* @__PURE__ */ jsxs(
269
+ config.environment === "sandbox" && /* @__PURE__ */ jsxs2(
252
270
  "div",
253
271
  {
254
272
  style: {
@@ -265,7 +283,7 @@ function PayPalSmartButtons(props) {
265
283
  marginBottom: 10
266
284
  },
267
285
  children: [
268
- /* @__PURE__ */ jsxs(
286
+ /* @__PURE__ */ jsxs2(
269
287
  "svg",
270
288
  {
271
289
  width: "16",
@@ -277,16 +295,16 @@ function PayPalSmartButtons(props) {
277
295
  strokeLinecap: "round",
278
296
  style: { flexShrink: 0, marginTop: 1 },
279
297
  children: [
280
- /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
281
- /* @__PURE__ */ jsx("path", { d: "M12 8v4M12 16h.01" })
298
+ /* @__PURE__ */ jsx3("circle", { cx: "12", cy: "12", r: "10" }),
299
+ /* @__PURE__ */ jsx3("path", { d: "M12 8v4M12 16h.01" })
282
300
  ]
283
301
  }
284
302
  ),
285
- /* @__PURE__ */ jsx("span", { children: "Sandbox mode \u2014 you will not be charged. Use your PayPal sandbox account to complete the payment." })
303
+ /* @__PURE__ */ jsx3("span", { children: "Sandbox mode \u2014 you will not be charged. Use your PayPal sandbox account to complete the payment." })
286
304
  ]
287
305
  }
288
306
  ),
289
- /* @__PURE__ */ jsx(
307
+ /* @__PURE__ */ jsx3(
290
308
  PayPalButtons,
291
309
  {
292
310
  style: {
@@ -307,12 +325,13 @@ function PayPalSmartButtons(props) {
307
325
  setError(null);
308
326
  const orderId = String(data?.orderID || "");
309
327
  const result = await api.captureOrder(cartId, orderId);
310
- await markPaymentComplete(baseUrl, cartId, publishableApiKey);
311
- onPaid?.(result);
328
+ const completeResult = await markPaymentComplete(baseUrl, cartId, publishableApiKey);
329
+ onPaid?.({ ...result, ...completeResult });
312
330
  } catch (e) {
313
331
  const msg = e instanceof Error ? e.message : "Payment capture failed";
314
332
  setError(msg);
315
333
  onError?.(msg);
334
+ } finally {
316
335
  setProcessing(false);
317
336
  }
318
337
  },
@@ -327,7 +346,7 @@ function PayPalSmartButtons(props) {
327
346
  }
328
347
  }
329
348
  ),
330
- error ? /* @__PURE__ */ jsxs(
349
+ error ? /* @__PURE__ */ jsxs2(
331
350
  "div",
332
351
  {
333
352
  style: {
@@ -344,13 +363,24 @@ function PayPalSmartButtons(props) {
344
363
  lineHeight: 1.5
345
364
  },
346
365
  children: [
347
- /* @__PURE__ */ jsx("span", { style: { flexShrink: 0, fontSize: 15 }, children: "\u26A0\uFE0F" }),
348
- /* @__PURE__ */ jsx("span", { children: error })
366
+ /* @__PURE__ */ jsx3("span", { style: { flexShrink: 0, fontSize: 15 }, children: "\u26A0\uFE0F" }),
367
+ /* @__PURE__ */ jsx3("span", { children: error })
349
368
  ]
350
369
  }
351
370
  ) : null
352
371
  ] });
353
372
  }
373
+
374
+ // src/components/PayPalAdvancedCard.tsx
375
+ import { useMemo as useMemo4, useState as useState3 } from "react";
376
+ import {
377
+ PayPalCardFieldsProvider,
378
+ PayPalNumberField,
379
+ PayPalExpiryField,
380
+ PayPalCVVField,
381
+ usePayPalCardFields
382
+ } from "@paypal/react-paypal-js";
383
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
354
384
  var SPIN_STYLE2 = `@keyframes _pp_spin { to { transform: rotate(360deg) } }`;
355
385
  var cardStyle = {
356
386
  input: {
@@ -394,21 +424,6 @@ var labelStyle = {
394
424
  marginBottom: 6,
395
425
  letterSpacing: "0.01em"
396
426
  };
397
- async function markPaymentComplete2(baseUrl, cartId, publishableApiKey) {
398
- try {
399
- await fetch(`${baseUrl.replace(/\/$/, "")}/store/paypal-complete`, {
400
- method: "POST",
401
- headers: {
402
- "Content-Type": "application/json",
403
- ...publishableApiKey ? { "x-publishable-api-key": publishableApiKey } : {}
404
- },
405
- body: JSON.stringify({ cart_id: cartId }),
406
- credentials: "include"
407
- });
408
- } catch (e) {
409
- console.warn("[PayPal Card] paypal-complete call failed:", e);
410
- }
411
- }
412
427
  function SubmitButton({
413
428
  disabled,
414
429
  label,
@@ -416,7 +431,7 @@ function SubmitButton({
416
431
  }) {
417
432
  const { cardFieldsForm } = usePayPalCardFields();
418
433
  const isDisabled = disabled || !cardFieldsForm;
419
- return /* @__PURE__ */ jsx(
434
+ return /* @__PURE__ */ jsx4(
420
435
  "button",
421
436
  {
422
437
  type: "button",
@@ -443,12 +458,14 @@ function SubmitButton({
443
458
  },
444
459
  onMouseEnter: (e) => {
445
460
  if (!isDisabled) {
461
+ ;
446
462
  e.target.style.background = "linear-gradient(180deg, #1d4ed8 0%, #1e40af 100%)";
447
463
  e.target.style.boxShadow = "0 4px 6px rgba(37,99,235,0.35), 0 2px 4px rgba(0,0,0,0.06)";
448
464
  }
449
465
  },
450
466
  onMouseLeave: (e) => {
451
467
  if (!isDisabled) {
468
+ ;
452
469
  e.target.style.background = "linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%)";
453
470
  e.target.style.boxShadow = "0 1px 3px rgba(37,99,235,0.3), 0 1px 2px rgba(0,0,0,0.06)";
454
471
  }
@@ -459,15 +476,15 @@ function SubmitButton({
459
476
  }
460
477
  function PayPalAdvancedCard(props) {
461
478
  const { baseUrl, publishableApiKey, cartId, config, onPaid, onError } = props;
462
- const api = useMemo(
479
+ const api = useMemo4(
463
480
  () => createPayPalStoreApi({ baseUrl, publishableApiKey }),
464
481
  [baseUrl, publishableApiKey]
465
482
  );
466
- const [error, setError] = useState(null);
467
- const [submitting, setSubmitting] = useState(false);
483
+ const [error, setError] = useState3(null);
484
+ const [submitting, setSubmitting] = useState3(false);
468
485
  if (!config.currency_supported) return null;
469
486
  if (!config.client_token) {
470
- return /* @__PURE__ */ jsx(
487
+ return /* @__PURE__ */ jsx4(
471
488
  "div",
472
489
  {
473
490
  style: {
@@ -483,9 +500,9 @@ function PayPalAdvancedCard(props) {
483
500
  );
484
501
  }
485
502
  const isSandbox = config.environment === "sandbox";
486
- return /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
487
- /* @__PURE__ */ jsx("style", { children: SPIN_STYLE2 }),
488
- submitting && /* @__PURE__ */ jsxs(
503
+ return /* @__PURE__ */ jsxs3("div", { style: { position: "relative" }, children: [
504
+ /* @__PURE__ */ jsx4("style", { children: SPIN_STYLE2 }),
505
+ submitting && /* @__PURE__ */ jsxs3(
489
506
  "div",
490
507
  {
491
508
  style: {
@@ -502,7 +519,7 @@ function PayPalAdvancedCard(props) {
502
519
  minHeight: 180
503
520
  },
504
521
  children: [
505
- /* @__PURE__ */ jsx(
522
+ /* @__PURE__ */ jsx4(
506
523
  "div",
507
524
  {
508
525
  style: {
@@ -515,20 +532,20 @@ function PayPalAdvancedCard(props) {
515
532
  }
516
533
  }
517
534
  ),
518
- /* @__PURE__ */ jsxs("div", { style: { textAlign: "center" }, children: [
519
- /* @__PURE__ */ jsx("div", { style: { fontSize: 15, fontWeight: 600, color: "#111827" }, children: "Processing your payment\u2026" }),
520
- /* @__PURE__ */ jsx("div", { style: { fontSize: 13, color: "#6b7280", marginTop: 4 }, children: "Please do not close or refresh this page" })
535
+ /* @__PURE__ */ jsxs3("div", { style: { textAlign: "center" }, children: [
536
+ /* @__PURE__ */ jsx4("div", { style: { fontSize: 15, fontWeight: 600, color: "#111827" }, children: "Processing your payment\u2026" }),
537
+ /* @__PURE__ */ jsx4("div", { style: { fontSize: 13, color: "#6b7280", marginTop: 4 }, children: "Please do not close or refresh this page" })
521
538
  ] })
522
539
  ]
523
540
  }
524
541
  ),
525
- /* @__PURE__ */ jsx(
542
+ /* @__PURE__ */ jsx4(
526
543
  PayPalCardFieldsProvider,
527
544
  {
528
545
  style: cardStyle,
529
546
  createOrder: async () => {
530
547
  setError(null);
531
- const r = await api.createOrder(cartId);
548
+ const r = await api.createOrder(cartId, true);
532
549
  return r.id;
533
550
  },
534
551
  onApprove: async (data) => {
@@ -536,12 +553,13 @@ function PayPalAdvancedCard(props) {
536
553
  setError(null);
537
554
  const orderId = String(data?.orderID || "");
538
555
  const result = await api.captureOrder(cartId, orderId);
539
- await markPaymentComplete2(baseUrl, cartId, publishableApiKey);
540
- onPaid?.(result);
556
+ const completeResult = await markPaymentComplete(baseUrl, cartId, publishableApiKey);
557
+ onPaid?.({ ...result, ...completeResult });
541
558
  } catch (e) {
542
559
  const msg = e instanceof Error ? e.message : "Card payment failed";
543
560
  setError(msg);
544
561
  onError?.(msg);
562
+ } finally {
545
563
  setSubmitting(false);
546
564
  }
547
565
  },
@@ -554,7 +572,7 @@ function PayPalAdvancedCard(props) {
554
572
  onError?.(msg);
555
573
  setSubmitting(false);
556
574
  },
557
- children: /* @__PURE__ */ jsxs(
575
+ children: /* @__PURE__ */ jsxs3(
558
576
  "div",
559
577
  {
560
578
  style: {
@@ -564,7 +582,7 @@ function PayPalAdvancedCard(props) {
564
582
  width: "100%"
565
583
  },
566
584
  children: [
567
- isSandbox && /* @__PURE__ */ jsxs(
585
+ isSandbox && /* @__PURE__ */ jsxs3(
568
586
  "div",
569
587
  {
570
588
  style: {
@@ -580,22 +598,22 @@ function PayPalAdvancedCard(props) {
580
598
  lineHeight: 1.55
581
599
  },
582
600
  children: [
583
- /* @__PURE__ */ jsx("span", { style: { fontSize: 15, flexShrink: 0, marginTop: 1 }, children: "\u{1F9EA}" }),
584
- /* @__PURE__ */ jsxs("span", { children: [
601
+ /* @__PURE__ */ jsx4("span", { style: { fontSize: 15, flexShrink: 0, marginTop: 1 }, children: "\u{1F9EA}" }),
602
+ /* @__PURE__ */ jsxs3("span", { children: [
585
603
  "Sandbox mode \u2014 use test card",
586
604
  " ",
587
- /* @__PURE__ */ jsx("strong", { style: { fontFamily: "monospace", letterSpacing: "0.05em" }, children: "4111 1111 1111 1111" }),
605
+ /* @__PURE__ */ jsx4("strong", { style: { fontFamily: "monospace", letterSpacing: "0.05em" }, children: "4111 1111 1111 1111" }),
588
606
  " ",
589
607
  "with any future date and any CVV."
590
608
  ] })
591
609
  ]
592
610
  }
593
611
  ),
594
- /* @__PURE__ */ jsxs("div", { children: [
595
- /* @__PURE__ */ jsx("label", { style: labelStyle, children: "Card number" }),
596
- /* @__PURE__ */ jsx(PayPalNumberField, {})
612
+ /* @__PURE__ */ jsxs3("div", { children: [
613
+ /* @__PURE__ */ jsx4("label", { style: labelStyle, children: "Card number" }),
614
+ /* @__PURE__ */ jsx4(PayPalNumberField, {})
597
615
  ] }),
598
- /* @__PURE__ */ jsxs(
616
+ /* @__PURE__ */ jsxs3(
599
617
  "div",
600
618
  {
601
619
  style: {
@@ -604,18 +622,18 @@ function PayPalAdvancedCard(props) {
604
622
  gap: 16
605
623
  },
606
624
  children: [
607
- /* @__PURE__ */ jsxs("div", { children: [
608
- /* @__PURE__ */ jsx("label", { style: labelStyle, children: "Expiration date" }),
609
- /* @__PURE__ */ jsx(PayPalExpiryField, {})
625
+ /* @__PURE__ */ jsxs3("div", { children: [
626
+ /* @__PURE__ */ jsx4("label", { style: labelStyle, children: "Expiration date" }),
627
+ /* @__PURE__ */ jsx4(PayPalExpiryField, {})
610
628
  ] }),
611
- /* @__PURE__ */ jsxs("div", { children: [
612
- /* @__PURE__ */ jsx("label", { style: labelStyle, children: "Security code" }),
613
- /* @__PURE__ */ jsx(PayPalCVVField, {})
629
+ /* @__PURE__ */ jsxs3("div", { children: [
630
+ /* @__PURE__ */ jsx4("label", { style: labelStyle, children: "Security code" }),
631
+ /* @__PURE__ */ jsx4(PayPalCVVField, {})
614
632
  ] })
615
633
  ]
616
634
  }
617
635
  ),
618
- /* @__PURE__ */ jsxs(
636
+ /* @__PURE__ */ jsxs3(
619
637
  "div",
620
638
  {
621
639
  style: {
@@ -626,7 +644,7 @@ function PayPalAdvancedCard(props) {
626
644
  color: "#6b7280"
627
645
  },
628
646
  children: [
629
- /* @__PURE__ */ jsx(
647
+ /* @__PURE__ */ jsx4(
630
648
  "svg",
631
649
  {
632
650
  width: "14",
@@ -637,14 +655,14 @@ function PayPalAdvancedCard(props) {
637
655
  strokeWidth: "2.5",
638
656
  strokeLinecap: "round",
639
657
  strokeLinejoin: "round",
640
- children: /* @__PURE__ */ jsx("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" })
658
+ children: /* @__PURE__ */ jsx4("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" })
641
659
  }
642
660
  ),
643
- /* @__PURE__ */ jsx("span", { children: "Your payment is secured with 256-bit SSL encryption" })
661
+ /* @__PURE__ */ jsx4("span", { children: "Your payment is secured with 256-bit SSL encryption" })
644
662
  ]
645
663
  }
646
664
  ),
647
- /* @__PURE__ */ jsx(
665
+ /* @__PURE__ */ jsx4(
648
666
  SubmitButton,
649
667
  {
650
668
  disabled: submitting,
@@ -655,7 +673,7 @@ function PayPalAdvancedCard(props) {
655
673
  }
656
674
  }
657
675
  ),
658
- error && /* @__PURE__ */ jsxs(
676
+ error && /* @__PURE__ */ jsxs3(
659
677
  "div",
660
678
  {
661
679
  style: {
@@ -671,8 +689,8 @@ function PayPalAdvancedCard(props) {
671
689
  lineHeight: 1.5
672
690
  },
673
691
  children: [
674
- /* @__PURE__ */ jsx("span", { style: { flexShrink: 0, marginTop: 1 }, children: "\u26A0\uFE0F" }),
675
- /* @__PURE__ */ jsx("span", { children: error })
692
+ /* @__PURE__ */ jsx4("span", { style: { flexShrink: 0, marginTop: 1 }, children: "\u26A0\uFE0F" }),
693
+ /* @__PURE__ */ jsx4("span", { children: error })
676
694
  ]
677
695
  }
678
696
  )
@@ -683,11 +701,15 @@ function PayPalAdvancedCard(props) {
683
701
  )
684
702
  ] });
685
703
  }
704
+
705
+ // src/adapters/MedusaNextPayPalAdapter.tsx
706
+ import { useCallback } from "react";
707
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
686
708
  var DEFAULT_PAYPAL_PROVIDER_ID = "pp_paypal_paypal";
687
709
  var DEFAULT_PAYPAL_CARD_PROVIDER_ID = "pp_paypal_card_paypal_card";
688
710
  var SPIN_STYLE3 = `@keyframes _pp_spin { to { transform: rotate(360deg) } }`;
689
711
  function PayPalLoadingCard() {
690
- return /* @__PURE__ */ jsxs(
712
+ return /* @__PURE__ */ jsxs4(
691
713
  "div",
692
714
  {
693
715
  style: {
@@ -700,8 +722,8 @@ function PayPalLoadingCard() {
700
722
  borderRadius: 10
701
723
  },
702
724
  children: [
703
- /* @__PURE__ */ jsx("style", { children: SPIN_STYLE3 }),
704
- /* @__PURE__ */ jsx(
725
+ /* @__PURE__ */ jsx5("style", { children: SPIN_STYLE3 }),
726
+ /* @__PURE__ */ jsx5(
705
727
  "div",
706
728
  {
707
729
  style: {
@@ -715,16 +737,16 @@ function PayPalLoadingCard() {
715
737
  }
716
738
  }
717
739
  ),
718
- /* @__PURE__ */ jsxs("div", { children: [
719
- /* @__PURE__ */ jsx("div", { style: { fontSize: 13, fontWeight: 500, color: "#111827" }, children: "Connecting to PayPal\u2026" }),
720
- /* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 2 }, children: "Setting up secure payment" })
740
+ /* @__PURE__ */ jsxs4("div", { children: [
741
+ /* @__PURE__ */ jsx5("div", { style: { fontSize: 13, fontWeight: 500, color: "#111827" }, children: "Connecting to PayPal\u2026" }),
742
+ /* @__PURE__ */ jsx5("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 2 }, children: "Setting up secure payment" })
721
743
  ] })
722
744
  ]
723
745
  }
724
746
  );
725
747
  }
726
748
  function PayPalErrorCard({ message }) {
727
- return /* @__PURE__ */ jsx(
749
+ return /* @__PURE__ */ jsx5(
728
750
  "div",
729
751
  {
730
752
  style: {
@@ -767,21 +789,22 @@ function MedusaNextPayPalAdapter(props) {
767
789
  [cartId, onPaid, onSuccess]
768
790
  );
769
791
  if (!shouldRender) return null;
770
- if (loading) return /* @__PURE__ */ jsx(PayPalLoadingCard, {});
771
- if (error) return /* @__PURE__ */ jsx(PayPalErrorCard, { message: error });
792
+ if (loading) return /* @__PURE__ */ jsx5(PayPalLoadingCard, {});
793
+ if (error) return /* @__PURE__ */ jsx5(PayPalErrorCard, { message: error });
772
794
  if (!config) return null;
773
- if (config.paypal_enabled === false) return null;
774
- if (selectedProviderId === paypalCardProviderId && config.card_enabled === false) return null;
795
+ const isCardProvider = selectedProviderId === paypalCardProviderId;
796
+ if (config.paypal_enabled === false && !isCardProvider) return null;
797
+ if (isCardProvider && config.card_enabled === false) return null;
775
798
  const disableFunding = Array.isArray(config.disable_buttons) ? config.disable_buttons.join(",") : void 0;
776
- return /* @__PURE__ */ jsxs("div", { style: { display: "grid", gap: 12 }, children: [
777
- /* @__PURE__ */ jsx(PayPalCurrencyNotice, { config }),
778
- /* @__PURE__ */ jsx(
799
+ return /* @__PURE__ */ jsxs4("div", { style: { display: "grid", gap: 12 }, children: [
800
+ /* @__PURE__ */ jsx5(PayPalCurrencyNotice, { config }),
801
+ /* @__PURE__ */ jsx5(
779
802
  PayPalProvider,
780
803
  {
781
804
  config,
782
805
  intent: config.intent === "authorize" ? "authorize" : "capture",
783
806
  disableFunding,
784
- children: selectedProviderId === paypalCardProviderId ? /* @__PURE__ */ jsx(
807
+ children: isCardProvider ? /* @__PURE__ */ jsx5(
785
808
  PayPalAdvancedCard,
786
809
  {
787
810
  baseUrl,
@@ -791,7 +814,7 @@ function MedusaNextPayPalAdapter(props) {
791
814
  onPaid: handlePaid,
792
815
  onError
793
816
  }
794
- ) : /* @__PURE__ */ jsx(
817
+ ) : /* @__PURE__ */ jsx5(
795
818
  PayPalSmartButtons,
796
819
  {
797
820
  baseUrl,
@@ -806,6 +829,10 @@ function MedusaNextPayPalAdapter(props) {
806
829
  )
807
830
  ] }, selectedProviderId);
808
831
  }
832
+
833
+ // src/components/PayPalPaymentSection.tsx
834
+ import { useCallback as useCallback2 } from "react";
835
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
809
836
  var PAYPAL_WALLET_PROVIDER_ID = "pp_paypal_paypal";
810
837
  var PAYPAL_CARD_PROVIDER_ID = "pp_paypal_card_paypal_card";
811
838
  var PAYPAL_PROVIDER_IDS = [
@@ -818,7 +845,7 @@ function isPayPalProviderId(id) {
818
845
  }
819
846
  var SPIN_STYLE4 = `@keyframes _pp_section_spin { to { transform: rotate(360deg) } }`;
820
847
  function SessionInitCard() {
821
- return /* @__PURE__ */ jsxs(
848
+ return /* @__PURE__ */ jsxs5(
822
849
  "div",
823
850
  {
824
851
  style: {
@@ -832,8 +859,8 @@ function SessionInitCard() {
832
859
  borderRadius: 10
833
860
  },
834
861
  children: [
835
- /* @__PURE__ */ jsx("style", { children: SPIN_STYLE4 }),
836
- /* @__PURE__ */ jsx(
862
+ /* @__PURE__ */ jsx6("style", { children: SPIN_STYLE4 }),
863
+ /* @__PURE__ */ jsx6(
837
864
  "div",
838
865
  {
839
866
  style: {
@@ -847,13 +874,13 @@ function SessionInitCard() {
847
874
  }
848
875
  }
849
876
  ),
850
- /* @__PURE__ */ jsx("div", { style: { fontSize: 13, fontWeight: 500, color: "#111827" }, children: "Setting up payment\u2026" })
877
+ /* @__PURE__ */ jsx6("div", { style: { fontSize: 13, fontWeight: 500, color: "#111827" }, children: "Setting up payment\u2026" })
851
878
  ]
852
879
  }
853
880
  );
854
881
  }
855
882
  function ConfigLoadingCard() {
856
- return /* @__PURE__ */ jsxs(
883
+ return /* @__PURE__ */ jsxs5(
857
884
  "div",
858
885
  {
859
886
  style: {
@@ -866,8 +893,8 @@ function ConfigLoadingCard() {
866
893
  borderRadius: 10
867
894
  },
868
895
  children: [
869
- /* @__PURE__ */ jsx("style", { children: SPIN_STYLE4 }),
870
- /* @__PURE__ */ jsx(
896
+ /* @__PURE__ */ jsx6("style", { children: SPIN_STYLE4 }),
897
+ /* @__PURE__ */ jsx6(
871
898
  "div",
872
899
  {
873
900
  style: {
@@ -881,16 +908,16 @@ function ConfigLoadingCard() {
881
908
  }
882
909
  }
883
910
  ),
884
- /* @__PURE__ */ jsxs("div", { children: [
885
- /* @__PURE__ */ jsx("div", { style: { fontSize: 13, fontWeight: 500, color: "#111827" }, children: "Connecting to PayPal\u2026" }),
886
- /* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 2 }, children: "Setting up secure payment" })
911
+ /* @__PURE__ */ jsxs5("div", { children: [
912
+ /* @__PURE__ */ jsx6("div", { style: { fontSize: 13, fontWeight: 500, color: "#111827" }, children: "Connecting to PayPal\u2026" }),
913
+ /* @__PURE__ */ jsx6("div", { style: { fontSize: 12, color: "#6b7280", marginTop: 2 }, children: "Setting up secure payment" })
887
914
  ] })
888
915
  ]
889
916
  }
890
917
  );
891
918
  }
892
919
  function ErrorCard({ message }) {
893
- return /* @__PURE__ */ jsx(
920
+ return /* @__PURE__ */ jsx6(
894
921
  "div",
895
922
  {
896
923
  style: {
@@ -922,7 +949,7 @@ function PayPalPaymentSection({
922
949
  cartId,
923
950
  enabled: shouldRender
924
951
  });
925
- const handlePaid = useCallback(
952
+ const handlePaid = useCallback2(
926
953
  (captureResult) => {
927
954
  onPaid?.(captureResult);
928
955
  onSuccess?.(cartId);
@@ -930,9 +957,9 @@ function PayPalPaymentSection({
930
957
  [cartId, onPaid, onSuccess]
931
958
  );
932
959
  if (!shouldRender) return null;
933
- if (sessionLoading) return /* @__PURE__ */ jsx(SessionInitCard, {});
934
- if (loading) return /* @__PURE__ */ jsx(ConfigLoadingCard, {});
935
- if (error) return /* @__PURE__ */ jsx(ErrorCard, { message: error });
960
+ if (sessionLoading) return /* @__PURE__ */ jsx6(SessionInitCard, {});
961
+ if (loading) return /* @__PURE__ */ jsx6(ConfigLoadingCard, {});
962
+ if (error) return /* @__PURE__ */ jsx6(ErrorCard, { message: error });
936
963
  if (!config) return null;
937
964
  if (config.paypal_enabled === false && selectedProviderId === PAYPAL_WALLET_PROVIDER_ID) {
938
965
  return null;
@@ -940,15 +967,15 @@ function PayPalPaymentSection({
940
967
  const isCardProvider = selectedProviderId === PAYPAL_CARD_PROVIDER_ID;
941
968
  if (isCardProvider && config.card_enabled === false) return null;
942
969
  const disableFunding = Array.isArray(config.disable_buttons) ? config.disable_buttons.join(",") : void 0;
943
- return /* @__PURE__ */ jsxs("div", { style: { display: "grid", gap: 12 }, children: [
944
- /* @__PURE__ */ jsx(PayPalCurrencyNotice, { config }),
945
- /* @__PURE__ */ jsx(
970
+ return /* @__PURE__ */ jsxs5("div", { style: { display: "grid", gap: 12 }, children: [
971
+ /* @__PURE__ */ jsx6(PayPalCurrencyNotice, { config }),
972
+ /* @__PURE__ */ jsx6(
946
973
  PayPalProvider,
947
974
  {
948
975
  config,
949
976
  intent: config.intent === "authorize" ? "authorize" : "capture",
950
977
  disableFunding,
951
- children: isCardProvider ? /* @__PURE__ */ jsx(
978
+ children: isCardProvider ? /* @__PURE__ */ jsx6(
952
979
  PayPalAdvancedCard,
953
980
  {
954
981
  baseUrl,
@@ -958,7 +985,7 @@ function PayPalPaymentSection({
958
985
  onPaid: handlePaid,
959
986
  onError
960
987
  }
961
- ) : /* @__PURE__ */ jsx(
988
+ ) : /* @__PURE__ */ jsx6(
962
989
  PayPalSmartButtons,
963
990
  {
964
991
  baseUrl,
@@ -973,6 +1000,9 @@ function PayPalPaymentSection({
973
1000
  )
974
1001
  ] }, selectedProviderId);
975
1002
  }
1003
+
1004
+ // src/hooks/usePayPalPaymentMethods.ts
1005
+ import { useEffect as useEffect2, useMemo as useMemo5, useRef as useRef2, useState as useState4 } from "react";
976
1006
  var _cache2 = /* @__PURE__ */ new Map();
977
1007
  var CACHE_TTL2 = 5 * 60 * 1e3;
978
1008
  function cacheKey2(baseUrl, cartId) {
@@ -991,16 +1021,16 @@ function usePayPalPaymentMethods({
991
1021
  cartId,
992
1022
  enabled = true
993
1023
  }) {
994
- const api = useMemo(
1024
+ const api = useMemo5(
995
1025
  () => createPayPalStoreApi({ baseUrl, publishableApiKey }),
996
1026
  [baseUrl, publishableApiKey]
997
1027
  );
998
1028
  const key = cacheKey2(baseUrl, cartId);
999
1029
  const hit = _cache2.get(key);
1000
1030
  const seed = hit && Date.now() - hit.at < CACHE_TTL2 ? hit.result : null;
1001
- const [result, setResult] = useState(seed ?? { ...DEFAULT_RESULT, loading: enabled });
1002
- const fetchIdRef = useRef(0);
1003
- useEffect(() => {
1031
+ const [result, setResult] = useState4(seed ?? { ...DEFAULT_RESULT, loading: enabled });
1032
+ const fetchIdRef = useRef2(0);
1033
+ useEffect2(() => {
1004
1034
  if (!enabled) {
1005
1035
  setResult((prev) => ({ ...prev, loading: false }));
1006
1036
  return;
@@ -1051,6 +1081,19 @@ function usePayPalPaymentMethods({
1051
1081
  }, [api, baseUrl, cartId, enabled]);
1052
1082
  return result;
1053
1083
  }
1054
-
1055
- export { MedusaNextPayPalAdapter, PAYPAL_CARD_PROVIDER_ID, PAYPAL_WALLET_PROVIDER_ID, PayPalAdvancedCard, PayPalCurrencyNotice, PayPalPaymentSection, PayPalProvider, PayPalSmartButtons, createPayPalStoreApi, isPayPalProviderId, usePayPalConfig, usePayPalPaymentMethods };
1084
+ export {
1085
+ MedusaNextPayPalAdapter,
1086
+ PAYPAL_CARD_PROVIDER_ID,
1087
+ PAYPAL_WALLET_PROVIDER_ID,
1088
+ PayPalAdvancedCard,
1089
+ PayPalCurrencyNotice,
1090
+ PayPalPaymentSection,
1091
+ PayPalProvider,
1092
+ PayPalSmartButtons,
1093
+ createPayPalStoreApi,
1094
+ isPayPalProviderId,
1095
+ markPaymentComplete,
1096
+ usePayPalConfig,
1097
+ usePayPalPaymentMethods
1098
+ };
1056
1099
  //# sourceMappingURL=index.mjs.map