@superlogic/spree-pay 0.1.9 → 0.1.11

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/build/index.cjs CHANGED
@@ -211,8 +211,8 @@ var CheckoutButton = ({ isProcessing, amount, onCheckout }) => {
211
211
  const { selectedPaymentMethod, isInternalProcessing } = useSpreePaymentMethod();
212
212
  const isDisabled = !amount || !selectedPaymentMethod.method || !!isProcessing || isInternalProcessing;
213
213
  const isUSD = selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */;
214
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex w-full flex-col overflow-hidden rounded-[24px] border border-black/25 bg-white text-xs font-medium", children: [
215
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "px-7 py-5", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "text-[#798B95]", children: [
214
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex w-full flex-col overflow-hidden rounded-3xl border border-black/25 bg-white text-xs font-medium", children: [
215
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "px-7 py-5", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "text-black/50", children: [
216
216
  "By clicking on the button below I acknowledge that I have read and accepted the",
217
217
  " ",
218
218
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { className: "underline", href: "/", children: "Property Policies" }),
@@ -251,7 +251,7 @@ var SpreeLegal = () => {
251
251
  d: "M57.79 25.48a4.82 4.82 0 0 1-1.55-.25l.55-1.86c.34.1.65.15.92.15s.51-.1.72-.26c.21-.16.39-.43.53-.81l.2-.55-3.65-10.3h2.52l2.32 7.62h.1l2.34-7.62h2.53l-4.04 11.31c-.19.54-.44 1-.75 1.38-.31.38-.7.68-1.14.88-.45.2-.98.3-1.6.3ZM48.95 21.9a4.2 4.2 0 0 1-1.73-.35c-.5-.23-.9-.57-1.2-1.02a3 3 0 0 1-.44-1.67 2.44 2.44 0 0 1 1.18-2.3c.35-.23.76-.4 1.22-.5.46-.13.93-.21 1.42-.27l1.44-.16c.37-.05.64-.13.8-.24.18-.1.26-.27.26-.5v-.04c0-.5-.15-.88-.44-1.15-.3-.27-.72-.4-1.27-.4-.58 0-1.04.12-1.38.37-.34.26-.57.56-.69.9l-2.22-.31a3.54 3.54 0 0 1 2.35-2.47 6.29 6.29 0 0 1 3.38-.14c.48.1.92.3 1.32.56.4.26.72.6.96 1.06.25.44.37 1 .37 1.67v6.75h-2.29v-1.38h-.08a2.9 2.9 0 0 1-1.59 1.37c-.39.14-.84.22-1.37.22Zm.62-1.75c.48 0 .89-.1 1.24-.28.35-.2.62-.45.8-.77.2-.31.3-.65.3-1.03V16.9c-.08.06-.2.11-.38.17a18.34 18.34 0 0 1-1.8.32c-.36.05-.68.12-.96.23-.28.11-.5.27-.66.46-.16.2-.24.45-.24.75 0 .44.16.77.48 1 .32.22.72.33 1.22.33ZM34.43 21.7V8.23h5.05c1.03 0 1.9.2 2.6.58.7.38 1.23.91 1.6 1.59.36.67.54 1.43.54 2.28 0 .87-.18 1.63-.55 2.3a3.9 3.9 0 0 1-1.6 1.59c-.72.38-1.59.57-2.63.57H36.1v-2h3.01c.6 0 1.1-.11 1.49-.32.38-.21.67-.5.85-.87.2-.37.29-.79.29-1.27 0-.47-.1-.9-.29-1.26a1.92 1.92 0 0 0-.86-.84c-.38-.2-.88-.31-1.49-.31h-2.23v11.41h-2.44ZM14.54.46a14.54 14.54 0 1 1 0 29.08 14.54 14.54 0 0 1 0-29.08ZM5.59 18.12l-.84 3.35h.83l.84-3.35h-.83Zm1.66 0-.83 3.35h1.66l.84-3.35H7.25Zm3.35-9.58c-1.03 0-2.08.84-2.34 1.87l-1.1 4.4c-.26 1.03.37 1.87 1.4 1.87h9.64l-.34 1.44h-8.1l-.85 3.35h9.6c1.04 0 2.1-.85 2.35-1.89l1.05-4.4c.25-1.03-.38-1.85-1.4-1.85h-9.63l.36-1.44h8.13l.84-3.35H10.6Zm10.44 0-.84 3.35h1.67l.83-3.35h-1.66Zm2.5 0-.84 3.35h.83l.84-3.35h-.83Z"
252
252
  }
253
253
  ) }),
254
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "text-xs text-[#798B95]", children: [
254
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "text-xs text-black/50", children: [
255
255
  "Spree enables seamless crypto payments for real-world goods, travel, and experiences. Enjoy secure, fast transactions and earn rewards.",
256
256
  " ",
257
257
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { className: "underline", href: "/", children: "Learn more" }),
@@ -316,7 +316,8 @@ function Dialog({ ...props }) {
316
316
  }
317
317
  function DialogPortal({ ...props }) {
318
318
  const container = usePortalContainer();
319
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DialogPrimitive.Portal, { container: container ?? void 0, "data-slot": "dialog-portal", ...props });
319
+ const safeContainer = container && document.body.contains(container) ? container : void 0;
320
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DialogPrimitive.Portal, { container: safeContainer, "data-slot": "dialog-portal", ...props });
320
321
  }
321
322
  function DialogOverlay({ className, ...props }) {
322
323
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -527,14 +528,14 @@ var SlapiPaymentService = {
527
528
  // return coin.balance > outAmountNumber;
528
529
  // },
529
530
  createPayment: (params) => {
530
- const { type, hash } = params;
531
+ const { type, hash, metadata, capture = false } = params;
531
532
  let reqParams;
532
533
  if (type === "CRYPTO" /* CRYPTO */) {
533
534
  reqParams = { type, hash, crypto: params.crypto };
534
535
  } else {
535
536
  reqParams = { type, hash, card: params.card };
536
537
  }
537
- return slapiApi.post("/v1/payments", { ...reqParams, capture: false }).then((data) => ({ data }));
538
+ return slapiApi.post("/v1/payments", { ...reqParams, capture, metadata }).then((data) => ({ data }));
538
539
  },
539
540
  baseVerify: ({ id, txHash }) => {
540
541
  return slapiApi.post(`/v1/base-transactions/transactions/${id}/verify`, { txHash });
@@ -561,7 +562,13 @@ var SlapiPaymentService = {
561
562
  };
562
563
 
563
564
  // src/services/cardPayment.ts
564
- var cardPayment = async ({ card, hash, redirect3dsURI }) => {
565
+ var cardPayment = async ({
566
+ card,
567
+ hash,
568
+ redirect3dsURI,
569
+ metadata,
570
+ capture
571
+ }) => {
565
572
  let cardId = card.id;
566
573
  if ("token" in card) {
567
574
  const { data: cardResData } = await SlapiPaymentService.addCard({ hash, source: card.token });
@@ -570,6 +577,8 @@ var cardPayment = async ({ card, hash, redirect3dsURI }) => {
570
577
  const { data: paymentResData } = await SlapiPaymentService.createPayment({
571
578
  hash,
572
579
  type: "CREDIT_CARD" /* CREDIT_CARD */,
580
+ metadata,
581
+ capture,
573
582
  card: { cardId, returnUrl: `${window.location.origin}${redirect3dsURI}` }
574
583
  });
575
584
  if (paymentResData.redirectUrl) {
@@ -578,15 +587,17 @@ var cardPayment = async ({ card, hash, redirect3dsURI }) => {
578
587
  const { data: validateData } = await SlapiPaymentService.validate3DS({ paymentId: paymentResData.id });
579
588
  return {
580
589
  status: validateData.status,
581
- txHash: null,
582
- paymentId: paymentResData.id
590
+ paymentId: paymentResData.id,
591
+ txId: paymentResData.txId,
592
+ txHash: null
583
593
  };
584
594
  }
585
595
  }
586
596
  return {
587
597
  status: paymentResData.status,
588
- txHash: null,
589
- paymentId: paymentResData.id
598
+ paymentId: paymentResData.id,
599
+ txId: paymentResData.txId,
600
+ txHash: null
590
601
  };
591
602
  };
592
603
 
@@ -707,7 +718,7 @@ var CardListItem = ({ card, isSelected, onSelect }) => {
707
718
  children: [
708
719
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "text-sm font-medium text-black", children: card.schema }) }),
709
720
  /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex items-center gap-2", children: [
710
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("p", { className: "text-sm font-medium text-[#798B95]", children: [
721
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("p", { className: "text-sm font-medium text-black/50", children: [
711
722
  "Ending in ",
712
723
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "text-black", children: card.lastFourNumbers })
713
724
  ] }),
@@ -999,8 +1010,8 @@ var CreditCardTab = () => {
999
1010
  try {
1000
1011
  if (selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && selectedPaymentMethod.method) {
1001
1012
  const res = await cardPayment({
1013
+ ...data,
1002
1014
  card: selectedPaymentMethod.method,
1003
- hash: data.hash,
1004
1015
  redirect3dsURI: env.redirect3dsURI
1005
1016
  });
1006
1017
  if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
@@ -1160,7 +1171,7 @@ var useCryptoPayment = () => {
1160
1171
  const { data: walletClient } = (0, import_wagmi.useWalletClient)();
1161
1172
  const config2 = (0, import_wagmi.useConfig)();
1162
1173
  const { selectedPaymentMethod } = useSpreePaymentMethod();
1163
- const cryptoPayment = async ({ hash }) => {
1174
+ const cryptoPayment = async (params) => {
1164
1175
  if (!walletClient) {
1165
1176
  throw new Error("Wallet not connected");
1166
1177
  }
@@ -1194,8 +1205,8 @@ var useCryptoPayment = () => {
1194
1205
  }
1195
1206
  }
1196
1207
  const paymentRes = await SlapiPaymentService.createPayment({
1208
+ ...params,
1197
1209
  type: "CRYPTO" /* CRYPTO */,
1198
- hash,
1199
1210
  crypto: {
1200
1211
  token: TOKEN,
1201
1212
  publicKey: walletClient.account.address,
@@ -1213,7 +1224,8 @@ var useCryptoPayment = () => {
1213
1224
  const res = await SlapiPaymentService.baseVerify({ id: paymentRes.data.txId, txHash });
1214
1225
  return {
1215
1226
  txHash,
1216
- paymentId: paymentRes.data.txId,
1227
+ paymentId: paymentRes.data.id,
1228
+ txId: paymentRes.data.txId,
1217
1229
  status: res.verified ? "AUTHORIZED" /* AUTHORIZED */ : "FAILED" /* FAILED */
1218
1230
  };
1219
1231
  };
@@ -1231,7 +1243,7 @@ var ConnectButton = () => {
1231
1243
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1232
1244
  "button",
1233
1245
  {
1234
- className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium",
1246
+ className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-black",
1235
1247
  onClick: openConnectModal,
1236
1248
  children: "Connect a Wallet"
1237
1249
  }
@@ -1250,7 +1262,7 @@ var ConnectButton = () => {
1250
1262
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
1251
1263
  "button",
1252
1264
  {
1253
- className: "flex h-[34px] items-center gap-2 rounded-md border-1 border-black px-1.5 text-sm font-medium",
1265
+ className: "flex h-[34px] items-center gap-2 rounded-md border-1 border-black px-1.5 text-sm font-medium text-black",
1254
1266
  onClick: openAccountModal,
1255
1267
  children: [
1256
1268
  chain.hasIcon && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "h-6 w-6 overflow-hidden rounded-full", style: { background: chain.iconBackground }, children: chain.iconUrl && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("img", { alt: chain.name ?? "Chain icon", src: chain.iconUrl }) }),
@@ -1495,7 +1507,7 @@ var CryptoSelectModal = import_nice_modal_react3.default.create(() => {
1495
1507
  nativeBalance && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
1496
1508
  "button",
1497
1509
  {
1498
- className: "flex h-11 w-full items-center justify-between gap-4 rounded-sm px-1.5 hover:bg-gray-100",
1510
+ className: "flex h-11 w-full items-center justify-between gap-4 rounded-sm px-1.5 text-black hover:bg-gray-100",
1499
1511
  onClick: () => handleSelect(nativeBalance),
1500
1512
  children: [
1501
1513
  /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-2", children: [
@@ -1524,7 +1536,7 @@ var CryptoSelectModal = import_nice_modal_react3.default.create(() => {
1524
1536
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
1525
1537
  "button",
1526
1538
  {
1527
- className: "flex h-11 w-full items-center justify-between gap-4 rounded-sm px-1.5 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",
1539
+ className: "flex h-11 w-full items-center justify-between gap-4 rounded-sm px-1.5 text-black hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",
1528
1540
  onClick: () => handleSelect(coin),
1529
1541
  children: [
1530
1542
  /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-2", children: [
@@ -1570,10 +1582,10 @@ var SelectedCoin = (props) => {
1570
1582
  /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex items-center gap-1", children: [
1571
1583
  Icon,
1572
1584
  !Icon && logoURI && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("img", { className: "mr-1 h-8 w-8 shrink-0", src: logoURI, alt: `${coin} logo` }),
1573
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "font-semibold", children: coin }),
1585
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { className: "font-semibold text-black", children: coin }),
1574
1586
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("path", { d: "M6 12.4341L10 8.43408L6 4.43408", stroke: "black", strokeLinecap: "round" }) })
1575
1587
  ] }),
1576
- /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("p", { className: "text-xs font-medium text-[#798B95]", children: [
1588
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("p", { className: "text-xs font-medium text-black/50", children: [
1577
1589
  "Wallet balance ",
1578
1590
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "text-black", children: balance })
1579
1591
  ] })
@@ -1592,7 +1604,7 @@ var Crypto = () => {
1592
1604
  const handlePay = (0, import_react8.useCallback)(
1593
1605
  async (data) => {
1594
1606
  try {
1595
- const res = await cryptoPayment({ hash: data.hash });
1607
+ const res = await cryptoPayment(data);
1596
1608
  if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
1597
1609
  return Promise.resolve(res);
1598
1610
  }
@@ -1718,7 +1730,7 @@ var TabButtons = (props) => {
1718
1730
  var import_jsx_runtime26 = require("react/jsx-runtime");
1719
1731
  var Tabs = () => {
1720
1732
  const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
1721
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "mb-4 rounded-2xl border border-black/25 bg-white", children: [
1733
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "mb-4 rounded-3xl border border-black/25 bg-white", children: [
1722
1734
  /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "flex w-full flex-col gap-4 border-b-1 border-black/7 px-7 py-6", children: [
1723
1735
  /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("h2", { className: "text-primary text-2xl font-semibold", children: "Choose a Payment Method" }),
1724
1736
  /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(TabButtons, { value: selectedPaymentMethod.type, onChange: setSelectedPaymentMethod })
@@ -1849,7 +1861,7 @@ var envConfig = {
1849
1861
  var SpreePay = ({ className, ...rest }) => {
1850
1862
  const rootRef = (0, import_react10.useRef)(null);
1851
1863
  const [portalEl, setPortalEl] = (0, import_react10.useState)(null);
1852
- (0, import_react10.useEffect)(() => {
1864
+ (0, import_react10.useLayoutEffect)(() => {
1853
1865
  if (!rootRef.current) return;
1854
1866
  const el = rootRef.current.querySelector(":scope > .sl-spreepay__portal");
1855
1867
  setPortalEl(el ?? null);
@@ -1858,11 +1870,11 @@ var SpreePay = ({ className, ...rest }) => {
1858
1870
  const environment = env?.environment || "dev";
1859
1871
  const tenantId = env?.tenantId || "bookit";
1860
1872
  const { isChecking, accessToken, error } = useKeycloakSSO({
1861
- realm: env.tenantId,
1873
+ realm: tenantId,
1862
1874
  url: envConfig[environment][tenantId].keyklockUrl,
1863
1875
  clientId: envConfig[environment][tenantId].keyklockClientId,
1864
- ssoPageURI: env.ssoPageURI,
1865
- enabled: !env.accessToken
1876
+ ssoPageURI: env?.ssoPageURI,
1877
+ enabled: !env?.accessToken
1866
1878
  });
1867
1879
  const slapiFetcher = (0, import_react10.useMemo)(() => {
1868
1880
  if (accessToken || env.accessToken) {
@@ -1873,18 +1885,17 @@ var SpreePay = ({ className, ...rest }) => {
1873
1885
  });
1874
1886
  }
1875
1887
  }, [env.accessToken, environment, tenantId, accessToken]);
1876
- if (isChecking) {
1877
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { ref: rootRef, className: cn("sl-spreepay", className), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("p", { className: "w-full text-center text-sm", children: "Loading..." }) });
1878
- }
1879
- if (error) {
1880
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { ref: rootRef, className: cn("sl-spreepay", className), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("p", { className: "w-full text-center text-sm", children: [
1881
- "Error: ",
1882
- error.message
1883
- ] }) });
1884
- }
1885
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { ref: rootRef, className: cn("sl-spreepay", className), children: [
1886
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "sl-spreepay__portal" }),
1887
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1888
+ const getContent = () => {
1889
+ if (isChecking) {
1890
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("p", { className: "w-full text-center text-sm", children: "Loading..." });
1891
+ }
1892
+ if (error) {
1893
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("p", { className: "w-full text-center text-sm", children: [
1894
+ "Error: ",
1895
+ error.message
1896
+ ] });
1897
+ }
1898
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1888
1899
  import_swr4.SWRConfig,
1889
1900
  {
1890
1901
  value: {
@@ -1895,7 +1906,11 @@ var SpreePay = ({ className, ...rest }) => {
1895
1906
  },
1896
1907
  children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(PortalContainerProvider, { container: portalEl, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_nice_modal_react6.default.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(SpreePayContent, { ...rest }) }) })
1897
1908
  }
1898
- )
1909
+ );
1910
+ };
1911
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { ref: rootRef, className: cn("sl-spreepay", className), children: [
1912
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "sl-spreepay__portal" }),
1913
+ getContent()
1899
1914
  ] });
1900
1915
  };
1901
1916