@moneymq/react 0.2.0 → 0.3.0
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/LICENSE +21 -0
- package/dist/index.d.mts +243 -12
- package/dist/index.d.ts +243 -12
- package/dist/index.js +268 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -103
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -9
package/dist/index.js
CHANGED
|
@@ -30,9 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
CheckoutButton: () => CheckoutButton,
|
|
34
|
+
CheckoutModal: () => CheckoutModal,
|
|
35
|
+
MoneyMQContext: () => MoneyMQContext,
|
|
33
36
|
MoneyMQProvider: () => MoneyMQProvider,
|
|
34
|
-
|
|
35
|
-
PaymentModal: () => PaymentModal,
|
|
37
|
+
SandboxContext: () => SandboxContext,
|
|
36
38
|
useMoneyMQ: () => useMoneyMQ,
|
|
37
39
|
usePayment: () => usePayment,
|
|
38
40
|
useSandbox: () => useSandbox
|
|
@@ -435,13 +437,19 @@ function MoneyMQProvider({
|
|
|
435
437
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MoneyMQContext.Provider, { value: client, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SandboxContext.Provider, { value: sandboxContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_adapter_react2.ConnectionProvider, { endpoint: rpcEndpoint, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_adapter_react2.WalletProvider, { wallets, autoConnect: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CustomWalletModalProvider, { branding, children }) }) }) }) });
|
|
436
438
|
}
|
|
437
439
|
|
|
438
|
-
// src/
|
|
439
|
-
var import_react6 = require("react");
|
|
440
|
+
// src/checkout-button.tsx
|
|
441
|
+
var import_react6 = __toESM(require("react"));
|
|
440
442
|
|
|
441
|
-
// src/
|
|
442
|
-
var import_react4 = require("react");
|
|
443
|
+
// src/checkout-modal.tsx
|
|
444
|
+
var import_react4 = __toESM(require("react"));
|
|
443
445
|
var import_wallet_adapter_react3 = require("@solana/wallet-adapter-react");
|
|
444
446
|
var import_react5 = require("@headlessui/react");
|
|
447
|
+
var import_lottie_react = __toESM(require("lottie-react"));
|
|
448
|
+
|
|
449
|
+
// src/assets/logo-animation.json
|
|
450
|
+
var logo_animation_default = { assets: [{ id: "4", layers: [{ ind: 3, ty: 4, ks: {}, ip: 0, op: 58, st: 0, shapes: [{ ty: "rc", p: { a: 0, k: [40, 40] }, r: { a: 0, k: 0 }, s: { a: 0, k: [80, 80] } }, { ty: "fl", c: { a: 0, k: [0, 0, 0, 0] }, o: { a: 0, k: 0 } }] }, { ind: 0, ty: 4, ks: { s: { a: 0, k: [133.33, 133.33] } }, ip: 0, op: 58, st: 0, shapes: [{ ty: "gr", it: [{ ty: "gr", it: [{ ty: "sh", ks: { a: 0, k: { c: true, i: [[0, 0], [0, 20.55], [20.55, 0], [0, -20.55], [-20.55, 0]], o: [[20.55, 0], [0, -20.55], [-20.55, 0], [0, 20.55], [0, 0]], v: [[39.65, 76.85], [76.85, 39.65], [39.65, 2.43], [2.44, 39.65], [39.65, 76.85]] } } }, { ty: "st", c: { a: 0, k: [0, 0, 0, 1] }, lc: 1, lj: 1, ml: 10, o: { a: 0, k: 100 }, w: { a: 0, k: 4.87 } }, { ty: "fl", c: { a: 0, k: [1, 1, 1, 1] }, o: { a: 0, k: 100 } }, { ty: "tr", o: { a: 0, k: 100 }, s: { a: 0, k: [75, 75] } }] }, { ty: "tr", o: { a: 0, k: 100 } }] }] }] }, { id: "7", layers: [{ ind: 6, ty: 0, ks: {}, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "4" }] }, { id: "12", layers: [{ ind: 11, ty: 4, ks: {}, ip: 0, op: 58, st: 0, shapes: [{ ty: "rc", p: { a: 0, k: [40, 40] }, r: { a: 0, k: 0 }, s: { a: 0, k: [80, 80] } }, { ty: "fl", c: { a: 0, k: [0, 0, 0, 0] }, o: { a: 0, k: 0 } }] }, { ind: 0, ty: 4, ks: { s: { a: 0, k: [133.33, 133.33] } }, ip: 0, op: 58, st: 0, shapes: [{ ty: "gr", it: [{ ty: "gr", it: [{ ty: "sh", ks: { a: 0, k: { c: true, i: [[0, 0], [0, 20.55], [20.55, 0], [0, -20.55], [-20.55, 0]], o: [[20.55, 0], [0, -20.55], [-20.55, 0], [0, 20.55], [0, 0]], v: [[39.65, 76.85], [76.85, 39.65], [39.65, 2.43], [2.44, 39.65], [39.65, 76.85]] } } }, { ty: "st", c: { a: 0, k: [0, 0, 0, 1] }, lc: 1, lj: 1, ml: 10, o: { a: 0, k: 100 }, w: { a: 0, k: 4.87 } }, { ty: "fl", c: { a: 0, k: [1, 1, 1, 1] }, o: { a: 0, k: 100 } }, { ty: "tr", o: { a: 0, k: 100 }, s: { a: 0, k: [75, 75] } }] }, { ty: "tr", o: { a: 0, k: 100 } }] }] }] }, { id: "17", layers: [{ ind: 16, ty: 4, ks: {}, ip: 0, op: 58, st: 0, shapes: [{ ty: "rc", p: { a: 0, k: [40, 40] }, r: { a: 0, k: 0 }, s: { a: 0, k: [80, 80] } }, { ty: "fl", c: { a: 0, k: [0, 0, 0, 0] }, o: { a: 0, k: 0 } }] }, { ind: 0, ty: 4, ks: { s: { a: 0, k: [133.33, 133.33] } }, ip: 0, op: 58, st: 0, shapes: [{ ty: "gr", it: [{ ty: "gr", it: [{ ty: "sh", ks: { a: 0, k: { c: true, i: [[0, 0], [0, 20.55], [20.55, 0], [0, -20.55], [-20.55, 0]], o: [[20.55, 0], [0, -20.55], [-20.55, 0], [0, 20.55], [0, 0]], v: [[39.65, 76.85], [76.85, 39.65], [39.65, 2.43], [2.44, 39.65], [39.65, 76.85]] } } }, { ty: "st", c: { a: 0, k: [0, 0, 0, 1] }, lc: 1, lj: 1, ml: 10, o: { a: 0, k: 100 }, w: { a: 0, k: 4.87 } }, { ty: "fl", c: { a: 0, k: [1, 1, 1, 1] }, o: { a: 0, k: 100 } }, { ty: "tr", o: { a: 0, k: 100 }, s: { a: 0, k: [75, 75] } }] }, { ty: "tr", o: { a: 0, k: 100 } }] }] }] }, { id: "22", layers: [{ ind: 21, ty: 4, ks: {}, ip: 0, op: 58, st: 0, shapes: [{ ty: "rc", p: { a: 0, k: [40, 40] }, r: { a: 0, k: 0 }, s: { a: 0, k: [80, 80] } }, { ty: "fl", c: { a: 0, k: [0, 0, 0, 0] }, o: { a: 0, k: 0 } }] }, { ind: 0, ty: 4, ks: { s: { a: 0, k: [133.33, 133.33] } }, ip: 0, op: 58, st: 0, shapes: [{ ty: "gr", it: [{ ty: "gr", it: [{ ty: "sh", ks: { a: 0, k: { c: true, i: [[0, 0], [0, 20.55], [20.55, 0], [0, -20.55], [-20.55, 0]], o: [[20.55, 0], [0, -20.55], [-20.55, 0], [0, 20.55], [0, 0]], v: [[39.65, 76.85], [76.85, 39.65], [39.65, 2.43], [2.44, 39.65], [39.65, 76.85]] } } }, { ty: "st", c: { a: 0, k: [0, 0, 0, 1] }, lc: 1, lj: 1, ml: 10, o: { a: 0, k: 100 }, w: { a: 0, k: 4.87 } }, { ty: "fl", c: { a: 0, k: [1, 1, 1, 1] }, o: { a: 0, k: 100 } }, { ty: "tr", o: { a: 0, k: 100 }, s: { a: 0, k: [75, 75] } }] }, { ty: "tr", o: { a: 0, k: 100 } }] }] }] }], fr: 60, h: 200, ip: 0, layers: [{ ind: 9, ty: 0, parent: 2, ks: { a: { a: 0, k: [40, 40] }, o: { a: 1, k: [{ t: 0, s: [100], h: 1 }, { t: 7.2, s: [100], h: 1 }, { t: 7.2, s: [0], h: 1 }, { t: 57, s: [0], h: 1 }] }, p: { a: 1, k: [{ t: 0, s: [119, 40], i: { x: [0, 1], y: [1, 1] }, o: { x: [0.384, 0], y: [0, 0] } }, { t: 48, s: [219, 40], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [219, 40], h: 1 }] }, s: { a: 1, k: [{ t: 0, s: [100, 100], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 5.4, s: [100, 100], i: { x: [0, 0], y: [1, 1] }, o: { x: [0.5, 0.5], y: [0, 0] } }, { t: 7.2, s: [103, 103], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [103, 103], h: 1 }] } }, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "7" }, { ind: 14, ty: 0, parent: 10, ks: {}, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "12" }, { ind: 10, ty: 3, parent: 2, ks: { p: { a: 1, k: [{ t: 0, s: [39, 0], i: { x: [0, 1], y: [1, 1] }, o: { x: [0.384, 0], y: [0, 0] } }, { t: 48, s: [79, 0], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [79, 0], h: 1 }] } }, ip: 0, op: 58, st: 0 }, { ind: 19, ty: 0, parent: 15, ks: {}, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "17" }, { ind: 15, ty: 3, parent: 2, ks: { p: { a: 1, k: [{ t: 0, s: [0, 0], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 7.2, s: [0, 0], i: { x: [0, 1], y: [1, 1] }, o: { x: [0.384, 0], y: [0, 0] } }, { t: 55.2, s: [39, 0], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [39, 0], h: 1 }] } }, ip: 0, op: 58, st: 0 }, { ind: 24, ty: 0, parent: 20, ks: {}, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "22" }, { ind: 20, ty: 3, parent: 2, ks: { a: { a: 0, k: [40, 40] }, p: { a: 0, k: [40, 40] }, s: { a: 1, k: [{ t: 0, s: [70, 70], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 13.8, s: [70, 70], i: { x: [0, 0], y: [1, 1] }, o: { x: [0.5, 0.5], y: [0, 0] } }, { t: 37.2, s: [100, 100], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [100, 100], h: 1 }] } }, ip: 0, op: 58, st: 0 }, { ind: 2, ty: 3, parent: 1, ks: { p: { a: 0, k: [21, 61] } }, ip: 0, op: 58, st: 0 }, { ind: 1, ty: 3, parent: 0, ks: {}, ip: 0, op: 58, st: 0 }, { ind: 0, ty: 3, ks: {}, ip: 0, op: 58, st: 0 }], meta: { g: "https://jitter.video" }, op: 57, v: "5.7.4", w: 200 };
|
|
451
|
+
|
|
452
|
+
// src/checkout-modal.tsx
|
|
445
453
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
446
454
|
function encodeFormData(data) {
|
|
447
455
|
const params = new URLSearchParams();
|
|
@@ -522,8 +530,9 @@ async function makeRequestWith402Handling(url, method, body, secretKeyHex, rpcUr
|
|
|
522
530
|
}
|
|
523
531
|
return data;
|
|
524
532
|
}
|
|
525
|
-
async function createSandboxPayment(apiUrl, rpcUrl, amount, currency, recipient, senderAddress, secretKeyHex,
|
|
533
|
+
async function createSandboxPayment(apiUrl, rpcUrl, amount, currency, recipient, senderAddress, secretKeyHex, lineItems) {
|
|
526
534
|
console.log("[MoneyMQ] Creating sandbox payment...", { amount, currency, recipient, senderAddress });
|
|
535
|
+
const description = lineItems && lineItems.length > 0 ? `Purchase - ${lineItems.map((item) => item.product.name).join(", ")}` : "Payment";
|
|
527
536
|
const paymentIntent = await makeRequestWith402Handling(
|
|
528
537
|
`${apiUrl}/catalog/v1/payment_intents`,
|
|
529
538
|
"POST",
|
|
@@ -532,7 +541,7 @@ async function createSandboxPayment(apiUrl, rpcUrl, amount, currency, recipient,
|
|
|
532
541
|
// Convert to cents (Stripe-style)
|
|
533
542
|
currency: currency.toLowerCase(),
|
|
534
543
|
customer: senderAddress,
|
|
535
|
-
description
|
|
544
|
+
description,
|
|
536
545
|
metadata: {
|
|
537
546
|
sender_address: senderAddress,
|
|
538
547
|
recipient_address: recipient
|
|
@@ -557,27 +566,31 @@ var truncateAddress = (address) => {
|
|
|
557
566
|
if (address.length <= 12) return address;
|
|
558
567
|
return `${address.slice(0, 4)}...${address.slice(-4)}`;
|
|
559
568
|
};
|
|
560
|
-
function
|
|
569
|
+
function CheckoutModal({
|
|
561
570
|
visible,
|
|
562
571
|
onClose,
|
|
563
572
|
amount,
|
|
564
573
|
currency,
|
|
565
574
|
recipient,
|
|
566
|
-
|
|
575
|
+
lineItems,
|
|
567
576
|
onSuccess,
|
|
568
577
|
onError,
|
|
569
|
-
accentColor = "#ec4899"
|
|
578
|
+
accentColor = "#ec4899",
|
|
579
|
+
debug = false
|
|
570
580
|
}) {
|
|
571
581
|
const [isSending, setIsSending] = (0, import_react4.useState)(false);
|
|
572
582
|
const [copiedSender, setCopiedSender] = (0, import_react4.useState)(false);
|
|
573
583
|
const [copiedRecipient, setCopiedRecipient] = (0, import_react4.useState)(false);
|
|
574
584
|
const [showDetails, setShowDetails] = (0, import_react4.useState)(false);
|
|
585
|
+
const [showDebug, setShowDebug] = (0, import_react4.useState)(false);
|
|
586
|
+
const [accountBalance, setAccountBalance] = (0, import_react4.useState)(null);
|
|
575
587
|
const [selectedWallet, setSelectedWallet] = (0, import_react4.useState)(null);
|
|
576
588
|
const [selectedPaymentMethod, setSelectedPaymentMethod] = (0, import_react4.useState)(null);
|
|
577
589
|
const { publicKey, connected, disconnect, wallets, select, wallet: connectedWallet } = (0, import_wallet_adapter_react3.useWallet)();
|
|
578
590
|
const branding = useBranding();
|
|
579
591
|
const { isSandboxMode, sandboxAccounts } = useSandbox();
|
|
580
592
|
const client = useMoneyMQ();
|
|
593
|
+
const lottieRef = (0, import_react4.useRef)(null);
|
|
581
594
|
const copyToClipboard = (text, type) => {
|
|
582
595
|
navigator.clipboard.writeText(text);
|
|
583
596
|
if (type === "sender") {
|
|
@@ -629,6 +642,58 @@ function PaymentModal({
|
|
|
629
642
|
return null;
|
|
630
643
|
};
|
|
631
644
|
const currentSelection = getCurrentSelectionDisplay();
|
|
645
|
+
import_react4.default.useEffect(() => {
|
|
646
|
+
if (!debug || !currentSelection) {
|
|
647
|
+
setAccountBalance(null);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
async function fetchBalance() {
|
|
651
|
+
try {
|
|
652
|
+
if (currentSelection?.type === "sandbox_account" && selectedPaymentMethod?.sandboxAccount) {
|
|
653
|
+
setAccountBalance(selectedPaymentMethod.sandboxAccount.usdcBalance ?? null);
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
if (currentSelection?.type === "browser_extension" && publicKey) {
|
|
657
|
+
const apiUrl = normalizeRpcUrl2(client.config.endpoint);
|
|
658
|
+
try {
|
|
659
|
+
const configResponse = await fetch(`${apiUrl}/config`);
|
|
660
|
+
const config = await configResponse.json();
|
|
661
|
+
const rpcUrl = normalizeRpcUrl2(config.x402?.validator?.rpcUrl || "http://localhost:8899");
|
|
662
|
+
const response = await fetch(rpcUrl, {
|
|
663
|
+
method: "POST",
|
|
664
|
+
headers: { "Content-Type": "application/json" },
|
|
665
|
+
body: JSON.stringify({
|
|
666
|
+
jsonrpc: "2.0",
|
|
667
|
+
id: 1,
|
|
668
|
+
method: "getTokenAccountsByOwner",
|
|
669
|
+
params: [
|
|
670
|
+
publicKey.toBase58(),
|
|
671
|
+
{ programId: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
|
|
672
|
+
{ encoding: "jsonParsed" }
|
|
673
|
+
]
|
|
674
|
+
})
|
|
675
|
+
});
|
|
676
|
+
const data = await response.json();
|
|
677
|
+
const usdcAccount = data.result?.value?.find(
|
|
678
|
+
(acc) => acc.account.data.parsed.info.mint === "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
|
679
|
+
// USDC mint
|
|
680
|
+
);
|
|
681
|
+
if (usdcAccount) {
|
|
682
|
+
setAccountBalance(usdcAccount.account.data.parsed.info.tokenAmount.uiAmount);
|
|
683
|
+
} else {
|
|
684
|
+
setAccountBalance(0);
|
|
685
|
+
}
|
|
686
|
+
} catch {
|
|
687
|
+
console.log("[MoneyMQ] Could not fetch balance");
|
|
688
|
+
setAccountBalance(null);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
} catch {
|
|
692
|
+
setAccountBalance(null);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
fetchBalance();
|
|
696
|
+
}, [debug, currentSelection, selectedPaymentMethod, publicKey, client.config.endpoint]);
|
|
632
697
|
const handlePay = (0, import_react4.useCallback)(async () => {
|
|
633
698
|
if (!recipient) return;
|
|
634
699
|
let senderAddress;
|
|
@@ -661,7 +726,7 @@ function PaymentModal({
|
|
|
661
726
|
recipient,
|
|
662
727
|
senderAddress,
|
|
663
728
|
secretKeyHex,
|
|
664
|
-
|
|
729
|
+
lineItems
|
|
665
730
|
);
|
|
666
731
|
setIsSending(false);
|
|
667
732
|
onSuccess?.(paymentId);
|
|
@@ -709,14 +774,35 @@ function PaymentModal({
|
|
|
709
774
|
setIsSending(false);
|
|
710
775
|
onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
711
776
|
}
|
|
712
|
-
}, [publicKey, recipient, amount, currency, onSuccess, onError, onClose, selectedPaymentMethod, client.config.endpoint,
|
|
777
|
+
}, [publicKey, recipient, amount, currency, onSuccess, onError, onClose, selectedPaymentMethod, client.config.endpoint, lineItems]);
|
|
713
778
|
const canPay = (connected && publicKey || selectedPaymentMethod?.type === "sandbox_account") && recipient && !isSending;
|
|
779
|
+
(0, import_react4.useEffect)(() => {
|
|
780
|
+
if (!canPay || !visible) return;
|
|
781
|
+
lottieRef.current?.goToAndPlay(0, true);
|
|
782
|
+
const interval = setInterval(() => {
|
|
783
|
+
lottieRef.current?.goToAndPlay(0, true);
|
|
784
|
+
}, 3e3);
|
|
785
|
+
return () => clearInterval(interval);
|
|
786
|
+
}, [canPay, visible]);
|
|
714
787
|
if (!visible) return null;
|
|
715
788
|
const WalletIcon = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: [
|
|
716
789
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M21 12V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2h14a2 2 0 002-2v-5z" }),
|
|
717
790
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M16 12h.01", strokeWidth: "2", strokeLinecap: "round" })
|
|
718
791
|
] });
|
|
719
792
|
const SandboxIcon = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M9.75 3.104v5.714a2.25 2.25 0 0 1-.659 1.591L5 14.5M9.75 3.104c-.251.023-.501.05-.75.082m.75-.082a24.301 24.301 0 0 1 4.5 0m0 0v5.714c0 .597.237 1.17.659 1.591L19.8 15.3M14.25 3.104c.251.023.501.05.75.082M19.8 15.3l-1.57.393A9.065 9.065 0 0 1 12 15a9.065 9.065 0 0 1-6.23.693L5 15.5m14.8-.2a2.25 2.25 0 0 1 .775 2.646l-.972 2.916a2.25 2.25 0 0 1-2.134 1.538H6.532a2.25 2.25 0 0 1-2.135-1.538l-.971-2.916A2.25 2.25 0 0 1 4.2 15.3", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
793
|
+
const WrenchIcon = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M11.42 15.17L17.25 21A2.652 2.652 0 0 0 21 17.25l-5.877-5.877M11.42 15.17l2.496-3.03c.317-.384.74-.626 1.208-.766M11.42 15.17l-4.655 5.653a2.548 2.548 0 1 1-3.586-3.586l6.837-5.63m5.108-.233c.55-.164 1.163-.188 1.743-.14a4.5 4.5 0 0 0 4.486-6.336l-3.276 3.277a3.004 3.004 0 0 1-2.25-2.25l3.276-3.276a4.5 4.5 0 0 0-6.336 4.486c.091 1.076-.071 2.264-.904 2.95l-.102.085m-1.745 1.437L5.909 7.5H4.5L2.25 3.75l1.5-1.5L7.5 4.5v1.409l4.26 4.26m-1.745 1.437 1.745-1.437m6.615 8.206L15.75 15.75M4.867 19.125h.008v.008h-.008v-.008Z", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
794
|
+
const MoneyMQLogo = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("svg", { width: "80", height: "17", viewBox: "0 0 471 99", fill: "none", children: [
|
|
795
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("g", { clipPath: "url(#clip0_524_7)", children: [
|
|
796
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M12.8892 77.1417H0V0.637573H14.3415L40.0291 60.1104L65.8075 0.637573H80.149V77.1417H67.169V25.5014L44.9306 77.2327H35.0368L12.8892 25.5014V77.2327V77.1417Z", fill: "white" }),
|
|
797
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M113.28 77.9614C108.015 77.9614 103.295 76.7774 99.2104 74.5005C95.1257 72.2235 91.8581 68.9448 89.5888 64.7553C87.2289 60.5658 86.1396 55.6476 86.1396 49.9098C86.1396 44.172 87.3196 39.1628 89.7704 34.9733C92.2211 30.7838 95.4888 27.5051 99.6642 25.2281C103.84 22.9512 108.56 21.7673 113.733 21.7673C118.907 21.7673 123.627 22.9512 127.803 25.2281C131.978 27.5051 135.336 30.7838 137.787 34.9733C140.238 39.1628 141.509 44.081 141.509 49.8188C141.509 55.5566 140.238 60.5658 137.787 64.7553C135.246 68.9448 131.887 72.2235 127.621 74.5005C123.355 76.7774 118.635 77.9614 113.37 77.9614H113.28ZM113.189 66.9411C115.73 66.9411 118.181 66.3036 120.45 65.1196C122.72 63.8445 124.626 62.023 126.078 59.4729C127.53 56.9227 128.257 53.735 128.257 49.8188C128.257 45.9025 127.53 42.897 126.169 40.3468C124.807 37.7967 122.992 35.9752 120.723 34.7001C118.453 33.425 116.003 32.8786 113.461 32.8786C110.92 32.8786 108.56 33.5161 106.381 34.7001C104.203 35.9752 102.478 37.7967 101.207 40.3468C99.9365 42.897 99.3011 46.0846 99.3011 50.0009C99.3011 53.9172 99.9365 56.9227 101.117 59.4729C102.387 62.023 104.021 63.8445 106.2 65.1196C108.378 66.3947 110.647 66.9411 113.189 66.9411Z", fill: "white" }),
|
|
798
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M146.41 22.4959H157.484L158.392 27.8694C160.207 25.9568 162.386 24.4995 164.927 23.4066C167.469 22.3137 170.192 21.7673 173.096 21.7673C177.272 21.7673 180.993 22.678 184.079 24.4085C187.166 26.23 189.526 28.7801 191.25 32.241C192.884 35.7019 193.792 39.9825 193.792 45.1739V77.0506H181.356V46.9043C181.356 42.2594 180.449 38.7075 178.633 36.4305C176.818 34.1536 174.095 32.9696 170.373 32.9696C166.652 32.9696 163.747 34.1536 161.75 36.5216C159.753 38.8896 158.846 42.4416 158.846 47.0865V77.1417H146.501V22.4959H146.41Z", fill: "white" }),
|
|
799
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M225.107 77.9614C219.661 77.9614 214.85 76.7774 210.765 74.3183C206.681 71.8592 203.504 68.5805 201.144 64.2999C198.875 60.0193 197.695 55.0101 197.695 49.4545C197.695 44.172 198.784 39.4361 201.053 35.2466C203.322 31.057 206.409 27.7783 210.402 25.4103C214.396 23.0423 218.935 21.7673 223.927 21.7673C228.919 21.7673 233.73 22.8602 237.633 25.1371C241.536 27.414 244.622 30.5106 246.892 34.609C249.161 38.6164 250.25 43.3523 250.25 48.6348C250.25 49.5455 250.25 50.4563 250.068 51.4581C249.978 52.46 249.796 53.4618 249.705 54.5547H211.038C211.31 57.1959 212.127 59.3818 213.398 61.2033C214.669 63.0248 216.302 64.4821 218.209 65.4839C220.205 66.4857 222.475 67.0322 225.107 67.0322C228.102 67.0322 230.825 66.3947 233.185 65.1196C235.636 63.8445 237.27 62.2051 238.268 60.2925L249.07 63.9356C246.892 68.3073 243.715 71.7682 239.448 74.2272C235.182 76.6863 230.372 77.9614 225.016 77.9614H225.107ZM236.816 44.5363C236.816 42.2594 236.272 40.2557 235.092 38.4342C233.912 36.6127 232.368 35.1555 230.553 34.1536C228.647 33.0607 226.559 32.6053 224.199 32.6053C222.112 32.6053 220.115 33.1518 218.39 34.1536C216.575 35.1555 215.122 36.6127 213.852 38.3431C212.581 40.1647 211.764 42.2594 211.31 44.6274H236.816V44.5363Z", fill: "white" }),
|
|
800
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M291.368 22.4958H304.439L272.398 99H260.235L270.038 75.5022L248.707 22.4958H262.413L276.754 61.2033L291.368 22.4958Z", fill: "white" }),
|
|
801
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M320.687 77.1417H307.797V0.637573H322.139L347.827 60.1104L373.605 0.637573H387.946V77.1417H374.966V25.5014L352.728 77.2327H342.834L320.596 25.5014V77.2327L320.687 77.1417Z", fill: "white" }),
|
|
802
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M432.332 77.9614C426.977 77.9614 421.894 77.0506 417.174 75.138C412.454 73.2254 408.369 70.5842 404.829 67.1233C401.289 63.6624 398.566 59.5639 396.569 54.7369C394.573 50.0009 393.574 44.7185 393.574 38.9807C393.574 33.2429 394.573 28.0515 396.569 23.3155C398.566 18.5796 401.289 14.3901 404.829 10.9292C408.369 7.46826 412.454 4.73597 417.174 2.82337C421.894 0.910764 426.886 0 432.332 0C437.779 0 442.771 0.910764 447.4 2.82337C452.029 4.73597 456.205 7.37719 459.745 10.9292C463.285 14.3901 466.008 18.5796 468.005 23.3155C470.002 28.0515 471 33.3339 471 38.9807C471 44.6274 470.002 50.0009 468.095 54.7369C466.098 59.4729 463.375 63.6624 459.835 67.1233C456.295 70.5842 452.12 73.2254 447.491 75.138C442.862 77.0506 437.779 77.9614 432.423 77.9614H432.332ZM432.242 66.9411C437.143 66.9411 441.591 65.7571 445.403 63.4802C449.215 61.2033 452.302 57.9246 454.571 53.735C456.84 49.5455 457.929 44.6274 457.929 38.8896C457.929 33.1518 456.84 28.1426 454.571 24.0442C452.302 19.9457 449.306 16.667 445.403 14.3901C441.591 12.1132 437.143 10.9292 432.242 10.9292C427.34 10.9292 422.892 12.1132 419.08 14.3901C415.268 16.667 412.182 19.9457 410.003 24.0442C407.825 28.1426 406.736 33.1518 406.736 38.8896C406.736 44.6274 407.825 49.5455 410.094 53.735C412.273 57.9246 415.359 61.2033 419.171 63.4802C422.983 65.7571 427.34 66.9411 432.332 66.9411H432.242ZM426.251 55.0101H438.868V87.9798H426.251V55.0101Z", fill: "white" })
|
|
803
|
+
] }),
|
|
804
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("clipPath", { id: "clip0_524_7", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("rect", { width: "471", height: "99", fill: "white" }) }) })
|
|
805
|
+
] });
|
|
720
806
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
721
807
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: `
|
|
722
808
|
@keyframes spin {
|
|
@@ -774,40 +860,58 @@ function PaymentModal({
|
|
|
774
860
|
borderBottom: "1px solid #3a3a3c"
|
|
775
861
|
},
|
|
776
862
|
children: [
|
|
777
|
-
|
|
778
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
863
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
864
|
+
branding?.logo ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
779
865
|
"img",
|
|
780
866
|
{
|
|
781
867
|
src: branding.logo,
|
|
782
868
|
alt: "Logo",
|
|
783
869
|
style: { height: "24px", width: "auto", filter: "invert(1)" }
|
|
784
870
|
}
|
|
785
|
-
),
|
|
786
|
-
isSandboxMode && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: "0.75rem", fontWeight: 600, color: "#ff9f0a" }, children: "
|
|
787
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
788
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", children: [
|
|
789
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("circle", { cx: "12", cy: "12", r: "10", fill: accentColor }),
|
|
790
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M8 12l2.5 2.5L16 9", stroke: "white", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })
|
|
791
|
-
] }),
|
|
792
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: "1.125rem", fontWeight: 600, color: "#fff" }, children: "Pay" }),
|
|
793
|
-
isSandboxMode && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: "0.75rem", fontWeight: 600, color: "#ff9f0a" }, children: "| SANDBOX" })
|
|
871
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoneyMQLogo, {}),
|
|
872
|
+
isSandboxMode && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: "0.75rem", fontWeight: 600, color: "#ff9f0a", position: "relative", top: "-1px" }, children: "{ sandbox }" })
|
|
794
873
|
] }),
|
|
795
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
874
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
875
|
+
debug && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
876
|
+
"button",
|
|
877
|
+
{
|
|
878
|
+
onClick: () => setShowDebug(!showDebug),
|
|
879
|
+
style: {
|
|
880
|
+
width: "28px",
|
|
881
|
+
height: "28px",
|
|
882
|
+
borderRadius: "9999px",
|
|
883
|
+
border: "none",
|
|
884
|
+
backgroundColor: showDebug ? "rgba(255, 159, 10, 0.2)" : "#3a3a3c",
|
|
885
|
+
color: showDebug ? "#ff9f0a" : "#8e8e93",
|
|
886
|
+
cursor: "pointer",
|
|
887
|
+
display: "flex",
|
|
888
|
+
alignItems: "center",
|
|
889
|
+
justifyContent: "center",
|
|
890
|
+
padding: 0,
|
|
891
|
+
transition: "all 150ms"
|
|
892
|
+
},
|
|
893
|
+
title: "Debug info",
|
|
894
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(WrenchIcon, {})
|
|
895
|
+
}
|
|
896
|
+
),
|
|
897
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
898
|
+
"button",
|
|
899
|
+
{
|
|
900
|
+
onClick: onClose,
|
|
901
|
+
style: {
|
|
902
|
+
padding: "0.375rem 0.75rem",
|
|
903
|
+
fontSize: "0.8125rem",
|
|
904
|
+
fontWeight: 500,
|
|
905
|
+
color: "#8e8e93",
|
|
906
|
+
backgroundColor: "#3a3a3c",
|
|
907
|
+
borderRadius: "9999px",
|
|
908
|
+
border: "none",
|
|
909
|
+
cursor: "pointer"
|
|
910
|
+
},
|
|
911
|
+
children: "cancel"
|
|
912
|
+
}
|
|
913
|
+
)
|
|
914
|
+
] })
|
|
811
915
|
]
|
|
812
916
|
}
|
|
813
917
|
),
|
|
@@ -891,10 +995,11 @@ function PaymentModal({
|
|
|
891
995
|
fontSize: "0.75rem",
|
|
892
996
|
fontWeight: 500,
|
|
893
997
|
color: "#ff453a",
|
|
894
|
-
|
|
998
|
+
backgroundColor: "rgba(255, 69, 58, 0.15)",
|
|
999
|
+
borderRadius: "9999px",
|
|
895
1000
|
border: "none",
|
|
896
1001
|
cursor: "pointer",
|
|
897
|
-
padding: "0.25rem 0.
|
|
1002
|
+
padding: "0.25rem 0.625rem"
|
|
898
1003
|
},
|
|
899
1004
|
children: "unlink"
|
|
900
1005
|
}
|
|
@@ -1198,7 +1303,38 @@ function PaymentModal({
|
|
|
1198
1303
|
},
|
|
1199
1304
|
children: [
|
|
1200
1305
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { marginBottom: "1rem" }, children: [
|
|
1201
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: {
|
|
1306
|
+
lineItems && lineItems.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { marginBottom: "0.75rem" }, children: lineItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1307
|
+
"div",
|
|
1308
|
+
{
|
|
1309
|
+
style: {
|
|
1310
|
+
display: "flex",
|
|
1311
|
+
justifyContent: "space-between",
|
|
1312
|
+
alignItems: "center",
|
|
1313
|
+
padding: "0.5rem 0",
|
|
1314
|
+
borderBottom: index < lineItems.length - 1 ? "1px solid #3a3a3c" : "none"
|
|
1315
|
+
},
|
|
1316
|
+
children: [
|
|
1317
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { flex: 1 }, children: [
|
|
1318
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontSize: "0.875rem", color: "#fff", fontWeight: 500 }, children: item.product.name }),
|
|
1319
|
+
item.quantity > 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { fontSize: "0.75rem", color: "#8e8e93" }, children: [
|
|
1320
|
+
"Qty: ",
|
|
1321
|
+
item.quantity,
|
|
1322
|
+
" \xD7 ",
|
|
1323
|
+
(item.price.unit_amount / 100).toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 }),
|
|
1324
|
+
" ",
|
|
1325
|
+
item.price.currency.toUpperCase()
|
|
1326
|
+
] })
|
|
1327
|
+
] }),
|
|
1328
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { fontSize: "0.875rem", color: "#fff", fontWeight: 500 }, children: [
|
|
1329
|
+
item.subtotal.toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 }),
|
|
1330
|
+
" ",
|
|
1331
|
+
item.price.currency.toUpperCase()
|
|
1332
|
+
] })
|
|
1333
|
+
]
|
|
1334
|
+
},
|
|
1335
|
+
item.product.id + "-" + index
|
|
1336
|
+
)) }),
|
|
1337
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontSize: "0.875rem", color: "#8e8e93", marginBottom: "0.25rem" }, children: "Total" }),
|
|
1202
1338
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
1203
1339
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", alignItems: "baseline", gap: "0.375rem" }, children: [
|
|
1204
1340
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: "2rem", fontWeight: 600, color: "#fff" }, children: amount.toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }),
|
|
@@ -1277,6 +1413,33 @@ function PaymentModal({
|
|
|
1277
1413
|
] })
|
|
1278
1414
|
] })
|
|
1279
1415
|
}
|
|
1416
|
+
),
|
|
1417
|
+
showDebug && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1418
|
+
"div",
|
|
1419
|
+
{
|
|
1420
|
+
style: {
|
|
1421
|
+
marginTop: "0.75rem",
|
|
1422
|
+
padding: "0.75rem",
|
|
1423
|
+
backgroundColor: "#1c1c1e",
|
|
1424
|
+
borderRadius: "0.5rem",
|
|
1425
|
+
fontSize: "0.75rem",
|
|
1426
|
+
fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace'
|
|
1427
|
+
},
|
|
1428
|
+
children: [
|
|
1429
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: {
|
|
1430
|
+
display: "flex",
|
|
1431
|
+
alignItems: "center",
|
|
1432
|
+
gap: "0.5rem",
|
|
1433
|
+
marginBottom: "0.5rem",
|
|
1434
|
+
paddingBottom: "0.5rem",
|
|
1435
|
+
borderBottom: "1px solid #2c2c2e"
|
|
1436
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { color: "#8e8e93" }, children: "DEBUG" }) }),
|
|
1437
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
1438
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { color: "#8e8e93" }, children: "balance" }),
|
|
1439
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { color: "#30d158" }, children: accountBalance !== null ? `${accountBalance.toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ${currency}` : currentSelection ? "..." : "null" })
|
|
1440
|
+
] })
|
|
1441
|
+
]
|
|
1442
|
+
}
|
|
1280
1443
|
)
|
|
1281
1444
|
] }),
|
|
1282
1445
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
@@ -1286,18 +1449,18 @@ function PaymentModal({
|
|
|
1286
1449
|
disabled: !canPay,
|
|
1287
1450
|
style: {
|
|
1288
1451
|
width: "100%",
|
|
1289
|
-
padding: "1rem",
|
|
1452
|
+
padding: "0.5rem 1rem",
|
|
1290
1453
|
borderRadius: "0.75rem",
|
|
1291
1454
|
border: "none",
|
|
1292
1455
|
fontSize: "1.0625rem",
|
|
1293
1456
|
fontWeight: 600,
|
|
1294
1457
|
cursor: canPay ? "pointer" : "not-allowed",
|
|
1295
|
-
backgroundColor: canPay ?
|
|
1458
|
+
backgroundColor: canPay ? "#000" : "#48484a",
|
|
1296
1459
|
color: canPay ? "#fff" : "#8e8e93",
|
|
1297
1460
|
display: "flex",
|
|
1298
1461
|
alignItems: "center",
|
|
1299
1462
|
justifyContent: "center",
|
|
1300
|
-
gap: "0.
|
|
1463
|
+
gap: "0.25rem",
|
|
1301
1464
|
transition: "opacity 150ms"
|
|
1302
1465
|
},
|
|
1303
1466
|
children: isSending ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
@@ -1316,7 +1479,25 @@ function PaymentModal({
|
|
|
1316
1479
|
),
|
|
1317
1480
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: "Processing..." })
|
|
1318
1481
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1319
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1482
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1483
|
+
import_lottie_react.default,
|
|
1484
|
+
{
|
|
1485
|
+
lottieRef,
|
|
1486
|
+
animationData: logo_animation_default,
|
|
1487
|
+
loop: false,
|
|
1488
|
+
autoplay: false,
|
|
1489
|
+
style: {
|
|
1490
|
+
width: 48,
|
|
1491
|
+
height: 48,
|
|
1492
|
+
marginTop: "-8px",
|
|
1493
|
+
marginBottom: "-8px",
|
|
1494
|
+
marginLeft: "-8px",
|
|
1495
|
+
marginRight: "4px",
|
|
1496
|
+
opacity: canPay ? 1 : 0.55,
|
|
1497
|
+
transition: "opacity 150ms"
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
),
|
|
1320
1501
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
|
|
1321
1502
|
"Pay ",
|
|
1322
1503
|
amount.toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 }),
|
|
@@ -1337,7 +1518,7 @@ function PaymentModal({
|
|
|
1337
1518
|
] });
|
|
1338
1519
|
}
|
|
1339
1520
|
|
|
1340
|
-
// src/
|
|
1521
|
+
// src/checkout-button.tsx
|
|
1341
1522
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1342
1523
|
var baseStyle = {
|
|
1343
1524
|
position: "relative",
|
|
@@ -1365,32 +1546,48 @@ var outlineStyle = {
|
|
|
1365
1546
|
color: "#ec4899",
|
|
1366
1547
|
border: "1px solid #ec4899"
|
|
1367
1548
|
};
|
|
1368
|
-
var
|
|
1369
|
-
function
|
|
1370
|
-
|
|
1371
|
-
price: priceObject,
|
|
1372
|
-
product: productObject,
|
|
1549
|
+
var CheckoutButton = (0, import_react6.forwardRef)(
|
|
1550
|
+
function CheckoutButton2({
|
|
1551
|
+
basket,
|
|
1373
1552
|
onSuccess,
|
|
1374
1553
|
onError,
|
|
1375
1554
|
variant = "solid",
|
|
1376
1555
|
children,
|
|
1377
|
-
disabled
|
|
1556
|
+
disabled,
|
|
1557
|
+
debug = false
|
|
1378
1558
|
}, ref) {
|
|
1379
1559
|
const client = useMoneyMQ();
|
|
1380
1560
|
const [isModalOpen, setIsModalOpen] = (0, import_react6.useState)(false);
|
|
1381
1561
|
const [isHovered, setIsHovered] = (0, import_react6.useState)(false);
|
|
1382
|
-
const
|
|
1383
|
-
const [isLoading, setIsLoading] = (0, import_react6.useState)(!hasPriceObject);
|
|
1562
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(true);
|
|
1384
1563
|
const [error, setError] = (0, import_react6.useState)(null);
|
|
1385
|
-
const [amount, setAmount] = (0, import_react6.useState)(hasPriceObject ? priceObject.unit_amount / 100 : 0);
|
|
1386
|
-
const [currency, setCurrency] = (0, import_react6.useState)(hasPriceObject ? priceObject.currency.toUpperCase() : "USDC");
|
|
1387
1564
|
const [recipient, setRecipient] = (0, import_react6.useState)("");
|
|
1388
|
-
const
|
|
1565
|
+
const { totalAmount, currency, lineItems } = import_react6.default.useMemo(() => {
|
|
1566
|
+
if (!basket || basket.length === 0) {
|
|
1567
|
+
return { totalAmount: 0, currency: "USDC", lineItems: [] };
|
|
1568
|
+
}
|
|
1569
|
+
const baseCurrency = basket[0].price.currency.toUpperCase();
|
|
1570
|
+
const items = basket.map((item) => ({
|
|
1571
|
+
product: item.product,
|
|
1572
|
+
price: item.price,
|
|
1573
|
+
quantity: item.quantity ?? 1,
|
|
1574
|
+
subtotal: item.price.unit_amount / 100 * (item.quantity ?? 1)
|
|
1575
|
+
}));
|
|
1576
|
+
const total = items.reduce((sum, item) => sum + item.subtotal, 0);
|
|
1577
|
+
return {
|
|
1578
|
+
totalAmount: total,
|
|
1579
|
+
currency: baseCurrency,
|
|
1580
|
+
lineItems: items
|
|
1581
|
+
};
|
|
1582
|
+
}, [basket]);
|
|
1389
1583
|
(0, import_react6.useEffect)(() => {
|
|
1390
1584
|
async function fetchPaymentDetails() {
|
|
1391
1585
|
setIsLoading(true);
|
|
1392
1586
|
setError(null);
|
|
1393
1587
|
try {
|
|
1588
|
+
if (!basket || basket.length === 0) {
|
|
1589
|
+
throw new Error("Basket is empty");
|
|
1590
|
+
}
|
|
1394
1591
|
const apiUrl = client.config.endpoint;
|
|
1395
1592
|
const configResponse = await fetch(`${apiUrl}/config`);
|
|
1396
1593
|
if (!configResponse.ok) {
|
|
@@ -1400,44 +1597,8 @@ var PayButton = (0, import_react6.forwardRef)(
|
|
|
1400
1597
|
if (config.x402?.payoutAccount?.address) {
|
|
1401
1598
|
setRecipient(config.x402.payoutAccount.address);
|
|
1402
1599
|
}
|
|
1403
|
-
if (hasPriceObject) {
|
|
1404
|
-
setAmount(priceObject.unit_amount / 100);
|
|
1405
|
-
setCurrency(priceObject.currency.toUpperCase());
|
|
1406
|
-
if (productObject) {
|
|
1407
|
-
setProductName(productObject.name);
|
|
1408
|
-
} else if (priceObject.product) {
|
|
1409
|
-
try {
|
|
1410
|
-
const productResponse = await fetch(`${apiUrl}/catalog/v1/products/${priceObject.product}`);
|
|
1411
|
-
if (productResponse.ok) {
|
|
1412
|
-
const product = await productResponse.json();
|
|
1413
|
-
setProductName(product.name);
|
|
1414
|
-
}
|
|
1415
|
-
} catch {
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
} else if (priceId) {
|
|
1419
|
-
const priceResponse = await fetch(`${apiUrl}/catalog/v1/prices/${priceId}`);
|
|
1420
|
-
if (!priceResponse.ok) {
|
|
1421
|
-
throw new Error(`Failed to fetch price: ${priceResponse.status}`);
|
|
1422
|
-
}
|
|
1423
|
-
const price = await priceResponse.json();
|
|
1424
|
-
setAmount(price.unit_amount / 100);
|
|
1425
|
-
setCurrency(price.currency.toUpperCase());
|
|
1426
|
-
if (price.product) {
|
|
1427
|
-
try {
|
|
1428
|
-
const productResponse = await fetch(`${apiUrl}/catalog/v1/products/${price.product}`);
|
|
1429
|
-
if (productResponse.ok) {
|
|
1430
|
-
const product = await productResponse.json();
|
|
1431
|
-
setProductName(product.name);
|
|
1432
|
-
}
|
|
1433
|
-
} catch {
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
} else {
|
|
1437
|
-
throw new Error("Either priceId or price object is required");
|
|
1438
|
-
}
|
|
1439
1600
|
} catch (err) {
|
|
1440
|
-
console.error("[
|
|
1601
|
+
console.error("[CheckoutButton] Error fetching payment details:", err);
|
|
1441
1602
|
const errorMessage = err instanceof Error ? err.message : "Failed to load payment details";
|
|
1442
1603
|
setError(errorMessage);
|
|
1443
1604
|
onError?.(new Error(errorMessage));
|
|
@@ -1446,7 +1607,7 @@ var PayButton = (0, import_react6.forwardRef)(
|
|
|
1446
1607
|
}
|
|
1447
1608
|
}
|
|
1448
1609
|
fetchPaymentDetails();
|
|
1449
|
-
}, [
|
|
1610
|
+
}, [basket, client.config.endpoint, onError]);
|
|
1450
1611
|
const handleClick = () => {
|
|
1451
1612
|
if (!isLoading && !error) {
|
|
1452
1613
|
setIsModalOpen(true);
|
|
@@ -1455,7 +1616,7 @@ var PayButton = (0, import_react6.forwardRef)(
|
|
|
1455
1616
|
const handlePaymentSuccess = (signature) => {
|
|
1456
1617
|
const payment = {
|
|
1457
1618
|
id: `pay_${Date.now()}`,
|
|
1458
|
-
amount,
|
|
1619
|
+
amount: totalAmount,
|
|
1459
1620
|
currency,
|
|
1460
1621
|
status: "completed",
|
|
1461
1622
|
signature
|
|
@@ -1487,16 +1648,17 @@ var PayButton = (0, import_react6.forwardRef)(
|
|
|
1487
1648
|
}
|
|
1488
1649
|
),
|
|
1489
1650
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1490
|
-
|
|
1651
|
+
CheckoutModal,
|
|
1491
1652
|
{
|
|
1492
1653
|
visible: isModalOpen,
|
|
1493
1654
|
onClose: () => setIsModalOpen(false),
|
|
1494
|
-
amount,
|
|
1655
|
+
amount: totalAmount,
|
|
1495
1656
|
currency,
|
|
1496
1657
|
recipient,
|
|
1497
|
-
|
|
1658
|
+
lineItems,
|
|
1498
1659
|
onSuccess: handlePaymentSuccess,
|
|
1499
|
-
onError: handlePaymentError
|
|
1660
|
+
onError: handlePaymentError,
|
|
1661
|
+
debug
|
|
1500
1662
|
}
|
|
1501
1663
|
)
|
|
1502
1664
|
] });
|
|
@@ -1557,9 +1719,11 @@ function usePayment() {
|
|
|
1557
1719
|
}
|
|
1558
1720
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1559
1721
|
0 && (module.exports = {
|
|
1722
|
+
CheckoutButton,
|
|
1723
|
+
CheckoutModal,
|
|
1724
|
+
MoneyMQContext,
|
|
1560
1725
|
MoneyMQProvider,
|
|
1561
|
-
|
|
1562
|
-
PaymentModal,
|
|
1726
|
+
SandboxContext,
|
|
1563
1727
|
useMoneyMQ,
|
|
1564
1728
|
usePayment,
|
|
1565
1729
|
useSandbox
|