@superlogic/spree-pay 0.1.0 → 0.1.1

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
@@ -38,7 +38,10 @@ module.exports = __toCommonJS(index_exports);
38
38
 
39
39
  // src/SpreePay.tsx
40
40
  var import_react7 = require("react");
41
- var import_swr2 = require("swr");
41
+ var import_swr3 = require("swr");
42
+
43
+ // src/SpreePayContent.tsx
44
+ var import_react6 = require("react");
42
45
 
43
46
  // ../../node_modules/clsx/dist/clsx.mjs
44
47
  function r(e) {
@@ -3013,59 +3016,9 @@ function cn(...inputs) {
3013
3016
  return twMerge(clsx(inputs));
3014
3017
  }
3015
3018
 
3016
- // src/components/CheckoutButton.tsx
3017
- var import_jsx_runtime = require("react/jsx-runtime");
3018
- var CheckoutButton = ({ amount }) => {
3019
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex w-full max-w-[540px] flex-col overflow-hidden rounded-[24px] border border-black/25 bg-white text-xs font-medium", children: [
3020
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "px-7 py-5", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "text-secondary", children: [
3021
- "By clicking on the button below I acknowledge that I have read and accepted the",
3022
- " ",
3023
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "underline", href: "/", children: "Property Policies" }),
3024
- ",",
3025
- " ",
3026
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "underline", href: "/", children: "Check-in Instructions" }),
3027
- ",",
3028
- " ",
3029
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "underline", href: "/", children: "Property Fees" }),
3030
- ", and",
3031
- " ",
3032
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "underline", href: "/", children: "Supplier Terms and Conditions" }),
3033
- "."
3034
- ] }) }),
3035
- amount && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "bg-primary pointer w-full py-4 text-xl font-semibold text-white", children: `Pay ${amount}` })
3036
- ] });
3037
- };
3038
-
3039
- // src/components/SpreeLegal.tsx
3040
- var import_jsx_runtime2 = require("react/jsx-runtime");
3041
- var SpreeLegal = () => {
3042
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mt-4 flex items-center gap-4", children: [
3043
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { className: "flex-shrink-0", xmlns: "http://www.w3.org/2000/svg", width: "66", height: "30", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3044
- "path",
3045
- {
3046
- fill: "#000",
3047
- fillOpacity: ".5",
3048
- 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"
3049
- }
3050
- ) }),
3051
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "text-secondary text-xs", children: [
3052
- "Spree enables seamless crypto payments for real-world goods, travel, and experiences. Enjoy secure, fast transactions and earn rewards.",
3053
- " ",
3054
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { className: "underline", href: "/", children: "Learn more" }),
3055
- " ",
3056
- "about Spree."
3057
- ] })
3058
- ] });
3059
- };
3060
-
3061
- // src/components/Tabs.tsx
3062
- var import_react6 = require("react");
3063
- var import_react_stripe_js2 = require("@stripe/react-stripe-js");
3064
- var import_stripe_js = require("@stripe/stripe-js");
3065
-
3066
3019
  // src/context/SpreePayActionsContext.tsx
3067
3020
  var import_react = require("react");
3068
- var import_jsx_runtime3 = require("react/jsx-runtime");
3021
+ var import_jsx_runtime = require("react/jsx-runtime");
3069
3022
  var SpreePayActionsContext = (0, import_react.createContext)(void 0);
3070
3023
  var SpreePayProvider = ({ children, env }) => {
3071
3024
  const processRef = (0, import_react.useRef)(null);
@@ -3092,7 +3045,7 @@ var SpreePayProvider = ({ children, env }) => {
3092
3045
  selectedPaymentMethod,
3093
3046
  setSelectedPaymentMethod
3094
3047
  };
3095
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SpreePayActionsContext.Provider, { value, children });
3048
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SpreePayActionsContext.Provider, { value, children });
3096
3049
  };
3097
3050
  var useSpreePay = () => {
3098
3051
  const ctx = (0, import_react.useContext)(SpreePayActionsContext);
@@ -3115,21 +3068,72 @@ var useSpreePayRegister = () => {
3115
3068
  return { register: ctx.register };
3116
3069
  };
3117
3070
 
3071
+ // src/components/CheckoutButton.tsx
3072
+ var import_jsx_runtime2 = require("react/jsx-runtime");
3073
+ var CheckoutButton = ({ amount, onCheckout }) => {
3074
+ const { selectedPaymentMethod } = useSpreePaymentMethod();
3075
+ const isDisabled = !amount || !selectedPaymentMethod.method;
3076
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex w-full flex-col overflow-hidden rounded-[24px] border border-black/25 bg-white text-xs font-medium", children: [
3077
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "px-7 py-5", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "text-secondary", children: [
3078
+ "By clicking on the button below I acknowledge that I have read and accepted the",
3079
+ " ",
3080
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { className: "underline", href: "/", children: "Property Policies" }),
3081
+ ",",
3082
+ " ",
3083
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { className: "underline", href: "/", children: "Check-in Instructions" }),
3084
+ ",",
3085
+ " ",
3086
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { className: "underline", href: "/", children: "Property Fees" }),
3087
+ ", and",
3088
+ " ",
3089
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { className: "underline", href: "/", children: "Supplier Terms and Conditions" }),
3090
+ "."
3091
+ ] }) }),
3092
+ onCheckout && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3093
+ "button",
3094
+ {
3095
+ disabled: isDisabled,
3096
+ onClick: onCheckout,
3097
+ className: cn("bg-primary pointer w-full py-4 text-xl font-semibold text-white", {
3098
+ "opacity-50": isDisabled
3099
+ }),
3100
+ children: amount ? `Pay ${amount}` : "Checkout"
3101
+ }
3102
+ )
3103
+ ] });
3104
+ };
3105
+
3106
+ // src/components/SpreeLegal.tsx
3107
+ var import_jsx_runtime3 = require("react/jsx-runtime");
3108
+ var SpreeLegal = () => {
3109
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "mt-4 flex items-center gap-4", children: [
3110
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { className: "flex-shrink-0", xmlns: "http://www.w3.org/2000/svg", width: "66", height: "30", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3111
+ "path",
3112
+ {
3113
+ fill: "#000",
3114
+ fillOpacity: ".5",
3115
+ 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"
3116
+ }
3117
+ ) }),
3118
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "text-secondary text-xs", children: [
3119
+ "Spree enables seamless crypto payments for real-world goods, travel, and experiences. Enjoy secure, fast transactions and earn rewards.",
3120
+ " ",
3121
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { className: "underline", href: "/", children: "Learn more" }),
3122
+ " ",
3123
+ "about Spree."
3124
+ ] })
3125
+ ] });
3126
+ };
3127
+
3118
3128
  // src/components/CreditCard/CreditCard.tsx
3119
3129
  var import_react5 = require("react");
3130
+ var import_react_stripe_js2 = require("@stripe/react-stripe-js");
3131
+ var import_stripe_js = require("@stripe/stripe-js");
3120
3132
 
3121
3133
  // src/hooks/useCards.ts
3122
3134
  var import_swr = __toESM(require("swr"), 1);
3123
3135
  var useCards = () => {
3124
- const { env } = useSpreePayEnv();
3125
- const { data, isLoading, mutate } = (0, import_swr.default)(
3126
- `/payments/cards?userExternalId=${env.userId}`,
3127
- {
3128
- revalidateOnFocus: false,
3129
- revalidateIfStale: false,
3130
- revalidateOnReconnect: false
3131
- }
3132
- );
3136
+ const { data, isLoading, mutate } = (0, import_swr.default)(`/v1/payments/cards`);
3133
3137
  return {
3134
3138
  cards: data?.data.filter((c) => c.active) || [],
3135
3139
  cardsIsLoading: isLoading,
@@ -3137,6 +3141,13 @@ var useCards = () => {
3137
3141
  };
3138
3142
  };
3139
3143
 
3144
+ // src/hooks/useConfig.ts
3145
+ var import_swr2 = __toESM(require("swr"), 1);
3146
+ var useConfig = () => {
3147
+ const { data, isLoading } = (0, import_swr2.default)("/v1/tenants/configs/spree-pay");
3148
+ return { config: data, configIsLoading: isLoading };
3149
+ };
3150
+
3140
3151
  // src/components/CreditCard/CardsList.tsx
3141
3152
  var import_jsx_runtime4 = require("react/jsx-runtime");
3142
3153
  var CardListItem = ({ card, isSelected, onSelect }) => {
@@ -3196,14 +3207,15 @@ var CardListItem = ({ card, isSelected, onSelect }) => {
3196
3207
  };
3197
3208
  var CardsList = ({ selectedCard, setCard }) => {
3198
3209
  const { cards, cardsIsLoading } = useCards();
3199
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
3200
- cardsIsLoading && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
3210
+ if (cardsIsLoading) {
3211
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex w-full flex-col gap-1", children: [
3201
3212
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" }),
3202
3213
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" }),
3203
3214
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" })
3204
- ] }),
3205
- cards.map((card) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CardListItem, { isSelected: selectedCard?.id === card.id, onSelect: setCard, card }, card.id))
3206
- ] });
3215
+ ] });
3216
+ }
3217
+ if (cards.length === 0) return null;
3218
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "flex w-full flex-col gap-1", children: cards.map((card) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CardListItem, { isSelected: selectedCard?.id === card.id, onSelect: setCard, card }, card.id)) });
3207
3219
  };
3208
3220
 
3209
3221
  // src/components/CreditCard/CreditCardForm.tsx
@@ -4300,10 +4312,15 @@ var CreditCardForm = ({ saveCard }) => {
4300
4312
 
4301
4313
  // src/components/CreditCard/CreditCard.tsx
4302
4314
  var import_jsx_runtime14 = require("react/jsx-runtime");
4315
+ var SripeWrapper = (props) => {
4316
+ const stripePromise = (0, import_react5.useMemo)(() => (0, import_stripe_js.loadStripe)(props.publicKey), [props.publicKey]);
4317
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_stripe_js2.Elements, { stripe: stripePromise, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CreditCardForm, { saveCard: props.saveNewCard }) });
4318
+ };
4303
4319
  var CreditCard = () => {
4304
4320
  const [showForm, setShowForm] = (0, import_react5.useState)(false);
4305
4321
  const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
4306
4322
  const { mutateCards } = useCards();
4323
+ const { config } = useConfig();
4307
4324
  const setCard = (card) => {
4308
4325
  setSelectedPaymentMethod({ type: "CREDIT_CARD" /* CREDIT_CARD */, method: card });
4309
4326
  };
@@ -4322,9 +4339,9 @@ var CreditCard = () => {
4322
4339
  setCard
4323
4340
  }
4324
4341
  ),
4325
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { onClick: () => setShowForm(true), className: "text-sm font-medium text-black", children: "Add new card" })
4342
+ config?.stripePublicKey && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { onClick: () => setShowForm(true), className: "text-sm font-medium text-black", children: "Add new card" })
4326
4343
  ] }),
4327
- showForm && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CreditCardForm, { saveCard: saveNewCard })
4344
+ config?.stripePublicKey && showForm && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SripeWrapper, { saveNewCard, publicKey: config.stripePublicKey })
4328
4345
  ] });
4329
4346
  };
4330
4347
 
@@ -4386,23 +4403,21 @@ var TabButtons = (props) => {
4386
4403
  // src/components/Tabs.tsx
4387
4404
  var import_jsx_runtime16 = require("react/jsx-runtime");
4388
4405
  var Tabs = () => {
4389
- const { env } = useSpreePayEnv();
4390
4406
  const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
4391
- const stripePromise = (0, import_react6.useMemo)(() => (0, import_stripe_js.loadStripe)(env.stripePublicKey), [env.stripePublicKey]);
4392
4407
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "mb-4 rounded-2xl border border-black/25 bg-white", children: [
4393
4408
  /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex w-full flex-col gap-4 border-b-1 border-black/7 px-7 py-6", children: [
4394
4409
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("h2", { className: "text-primary text-2xl font-semibold", children: "Choose a Payment Method" }),
4395
4410
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(TabButtons, { value: selectedPaymentMethod.type, onChange: setSelectedPaymentMethod })
4396
4411
  ] }),
4397
4412
  /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "px-7 py-6", children: [
4398
- selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_stripe_js2.Elements, { stripe: stripePromise, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(CreditCard, {}) }),
4413
+ selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(CreditCard, {}),
4399
4414
  selectedPaymentMethod.type === "CRYPTO" /* CRYPTO */ && null
4400
4415
  ] })
4401
4416
  ] });
4402
4417
  };
4403
4418
 
4404
4419
  // src/fetcher/client.ts
4405
- var cfg = { baseUrl: void 0, authKey: void 0 };
4420
+ var cfg = { baseUrl: void 0, accessToken: void 0, tenantId: void 0 };
4406
4421
  var buildUrl = (key) => {
4407
4422
  if (!cfg.baseUrl) throw new Error("Missing SLAPI baseUrl. Call registerApi(...) first.");
4408
4423
  if (typeof key === "string") return cfg.baseUrl + key;
@@ -4419,8 +4434,10 @@ var request = async (method, url, body) => {
4419
4434
  const headers = {
4420
4435
  Accept: "application/json"
4421
4436
  };
4422
- if (!cfg.authKey) throw new Error("Missing SLAPI authKey. Call registerApi(...) first.");
4423
- headers.Authorization = `Bearer ${cfg.authKey}`;
4437
+ if (!cfg.accessToken) throw new Error("Missing SLAPI accessToken. Call registerApi(...) first.");
4438
+ if (!cfg.tenantId) throw new Error("Missing SLAPI tenantId. Call registerApi(...) first.");
4439
+ headers.Authorization = `Bearer ${cfg.accessToken}`;
4440
+ headers["X-Tenant-ID"] = cfg.tenantId;
4424
4441
  let payload;
4425
4442
  if (method !== "GET" && method !== "DELETE" && body !== void 0) {
4426
4443
  if (typeof FormData !== "undefined" && body instanceof FormData) {
@@ -4448,9 +4465,6 @@ var request = async (method, url, body) => {
4448
4465
  }
4449
4466
  return await res.json();
4450
4467
  };
4451
- var slapiFetcher = async () => {
4452
- throw new Error("slapiFetcher is not configured. Call registerApi(...) first.");
4453
- };
4454
4468
  var slapiApi = {
4455
4469
  get: async () => {
4456
4470
  throw new Error("slapiApi is not configured. Call registerApi(...) first.");
@@ -4470,7 +4484,8 @@ var slapiApi = {
4470
4484
  };
4471
4485
  var registerApi = (config) => {
4472
4486
  cfg.baseUrl = config.baseUrl;
4473
- cfg.authKey = config.authKey;
4487
+ cfg.accessToken = config.accessToken;
4488
+ cfg.tenantId = config.tenantId;
4474
4489
  slapiApi = {
4475
4490
  get: async (key) => {
4476
4491
  const url = buildUrl(key);
@@ -4493,7 +4508,7 @@ var registerApi = (config) => {
4493
4508
  return request("DELETE", url);
4494
4509
  }
4495
4510
  };
4496
- slapiFetcher = async (key) => slapiApi.get(key);
4511
+ return (key) => slapiApi.get(key);
4497
4512
  };
4498
4513
 
4499
4514
  // src/services/slapi.ts
@@ -4536,7 +4551,7 @@ var SlapiPaymentService = {
4536
4551
  // },
4537
4552
  createPayment: (params) => {
4538
4553
  const { type, hash } = params;
4539
- return slapiApi.post("/payments", { ...{ type, hash, card: params.card }, capture: false }).then((data) => ({ data }));
4554
+ return slapiApi.post("/v1/payments", { ...{ type, hash, card: params.card }, capture: false }).then((data) => ({ data }));
4540
4555
  },
4541
4556
  // signEncodedTransaction: async (signTransaction: SignTransaction, encodedTX: string): Promise<string> => {
4542
4557
  // const swapTransactionBuf = Buffer.from(encodedTX, 'base64');
@@ -4551,11 +4566,11 @@ var SlapiPaymentService = {
4551
4566
  // },
4552
4567
  addCard: (params) => {
4553
4568
  const { source, hash } = params;
4554
- return slapiApi.post("/payments/cards", { hash, source }).then((data) => ({ data }));
4569
+ return slapiApi.post("/v1/payments/cards", { hash, source }).then((data) => ({ data }));
4555
4570
  },
4556
4571
  validate3DS: (params) => {
4557
4572
  const { paymentId } = params;
4558
- return slapiApi.post("/payments/validate", { paymentId, type: "CREDIT_CARD" }).then((data) => ({ data }));
4573
+ return slapiApi.post("/v1/payments/validate", { paymentId, type: "CREDIT_CARD" }).then((data) => ({ data }));
4559
4574
  }
4560
4575
  };
4561
4576
 
@@ -4574,17 +4589,13 @@ var cardPayment = async ({ card, hash }) => {
4574
4589
  return { status: paymentResData.status };
4575
4590
  };
4576
4591
 
4577
- // src/SpreePay.tsx
4592
+ // src/SpreePayContent.tsx
4578
4593
  var import_jsx_runtime17 = require("react/jsx-runtime");
4579
- var SpreePay = (props) => {
4580
- const { className } = props;
4581
- const { env } = useSpreePayEnv();
4594
+ var SpreePayContent = (props) => {
4595
+ const { className, amount, onProcess } = props;
4582
4596
  const { selectedPaymentMethod } = useSpreePaymentMethod();
4583
- (0, import_react7.useEffect)(() => {
4584
- registerApi({ baseUrl: env.slapiUrl, authKey: env.slapiAuthKey });
4585
- }, [env.slapiUrl, env.slapiAuthKey]);
4586
4597
  const { register } = useSpreePayRegister();
4587
- const handlePay = (0, import_react7.useCallback)(
4598
+ const handlePay = (0, import_react6.useCallback)(
4588
4599
  (data) => {
4589
4600
  if (selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && selectedPaymentMethod.method) {
4590
4601
  return cardPayment({ card: selectedPaymentMethod.method, hash: data.hash });
@@ -4593,14 +4604,45 @@ var SpreePay = (props) => {
4593
4604
  },
4594
4605
  [selectedPaymentMethod]
4595
4606
  );
4596
- (0, import_react7.useEffect)(() => {
4607
+ (0, import_react6.useEffect)(() => {
4597
4608
  register(handlePay);
4598
4609
  }, [register, handlePay]);
4599
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_swr2.SWRConfig, { value: { fetcher: slapiFetcher }, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: cn("sl-spreepay", className), children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "w-full max-w-[540px]", children: [
4610
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: cn("sl-spreepay", className), children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "w-full max-w-[540px]", children: [
4600
4611
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Tabs, {}),
4601
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(CheckoutButton, { amount: props.amount }),
4612
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(CheckoutButton, { onCheckout: onProcess, amount }),
4602
4613
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SpreeLegal, {})
4603
- ] }) }) });
4614
+ ] }) });
4615
+ };
4616
+
4617
+ // src/SpreePay.tsx
4618
+ var import_jsx_runtime18 = require("react/jsx-runtime");
4619
+ var envConfig = {
4620
+ dev: { slapiUrl: "https://slapi.dev.superlogic.com", tenantId: "bookit" },
4621
+ stg: { slapiUrl: "https://slapi.dev.superlogic.com", tenantId: "bookit" },
4622
+ prod: { slapiUrl: "https://slapi.dev.superlogic.com", tenantId: "bookit" }
4623
+ };
4624
+ var SpreePay = (props) => {
4625
+ const { env } = useSpreePayEnv();
4626
+ const slapiFetcher = (0, import_react7.useMemo)(
4627
+ () => registerApi({
4628
+ accessToken: env.accessToken,
4629
+ baseUrl: envConfig[env.environment].slapiUrl,
4630
+ tenantId: envConfig[env.environment].tenantId
4631
+ }),
4632
+ [env]
4633
+ );
4634
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
4635
+ import_swr3.SWRConfig,
4636
+ {
4637
+ value: {
4638
+ fetcher: slapiFetcher,
4639
+ revalidateOnFocus: false,
4640
+ revalidateIfStale: false,
4641
+ revalidateOnReconnect: false
4642
+ },
4643
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SpreePayContent, { ...props })
4644
+ }
4645
+ );
4604
4646
  };
4605
4647
  // Annotate the CommonJS export names for ESM import in node:
4606
4648
  0 && (module.exports = {
package/build/index.d.cts CHANGED
@@ -1,16 +1,15 @@
1
1
  import { FC, ReactNode } from 'react';
2
2
 
3
3
  type SpreePayProps = {
4
+ onProcess?: () => Promise<void>;
4
5
  amount?: string;
5
6
  className?: string;
6
7
  };
8
+
7
9
  declare const SpreePay: FC<SpreePayProps>;
8
10
 
9
11
  type ENV = {
10
- userId: string;
11
- stripePublicKey: string;
12
- slapiUrl: string;
13
- slapiAuthKey: string;
12
+ environment: 'dev' | 'stg' | 'prod';
14
13
  accessToken: string;
15
14
  };
16
15
 
@@ -81,4 +80,4 @@ declare const useSpreePay: () => {
81
80
  selectedPaymentMethod: SelectedPaymentMethod;
82
81
  };
83
82
 
84
- export { SpreePay, type SpreePayProps, SpreePayProvider, useSpreePay };
83
+ export { SpreePay, SpreePayProvider, useSpreePay };
package/build/index.d.ts CHANGED
@@ -1,16 +1,15 @@
1
1
  import { FC, ReactNode } from 'react';
2
2
 
3
3
  type SpreePayProps = {
4
+ onProcess?: () => Promise<void>;
4
5
  amount?: string;
5
6
  className?: string;
6
7
  };
8
+
7
9
  declare const SpreePay: FC<SpreePayProps>;
8
10
 
9
11
  type ENV = {
10
- userId: string;
11
- stripePublicKey: string;
12
- slapiUrl: string;
13
- slapiAuthKey: string;
12
+ environment: 'dev' | 'stg' | 'prod';
14
13
  accessToken: string;
15
14
  };
16
15
 
@@ -81,4 +80,4 @@ declare const useSpreePay: () => {
81
80
  selectedPaymentMethod: SelectedPaymentMethod;
82
81
  };
83
82
 
84
- export { SpreePay, type SpreePayProps, SpreePayProvider, useSpreePay };
83
+ export { SpreePay, SpreePayProvider, useSpreePay };
package/build/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  // src/SpreePay.tsx
2
- import { useCallback as useCallback5, useEffect as useEffect5 } from "react";
2
+ import { useMemo as useMemo5 } from "react";
3
3
  import { SWRConfig } from "swr";
4
4
 
5
+ // src/SpreePayContent.tsx
6
+ import { useCallback as useCallback5, useEffect as useEffect5 } from "react";
7
+
5
8
  // ../../node_modules/clsx/dist/clsx.mjs
6
9
  function r(e) {
7
10
  var t, f, n = "";
@@ -2975,59 +2978,9 @@ function cn(...inputs) {
2975
2978
  return twMerge(clsx(inputs));
2976
2979
  }
2977
2980
 
2978
- // src/components/CheckoutButton.tsx
2979
- import { jsx, jsxs } from "react/jsx-runtime";
2980
- var CheckoutButton = ({ amount }) => {
2981
- return /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[540px] flex-col overflow-hidden rounded-[24px] border border-black/25 bg-white text-xs font-medium", children: [
2982
- /* @__PURE__ */ jsx("div", { className: "px-7 py-5", children: /* @__PURE__ */ jsxs("p", { className: "text-secondary", children: [
2983
- "By clicking on the button below I acknowledge that I have read and accepted the",
2984
- " ",
2985
- /* @__PURE__ */ jsx("a", { className: "underline", href: "/", children: "Property Policies" }),
2986
- ",",
2987
- " ",
2988
- /* @__PURE__ */ jsx("a", { className: "underline", href: "/", children: "Check-in Instructions" }),
2989
- ",",
2990
- " ",
2991
- /* @__PURE__ */ jsx("a", { className: "underline", href: "/", children: "Property Fees" }),
2992
- ", and",
2993
- " ",
2994
- /* @__PURE__ */ jsx("a", { className: "underline", href: "/", children: "Supplier Terms and Conditions" }),
2995
- "."
2996
- ] }) }),
2997
- amount && /* @__PURE__ */ jsx("button", { className: "bg-primary pointer w-full py-4 text-xl font-semibold text-white", children: `Pay ${amount}` })
2998
- ] });
2999
- };
3000
-
3001
- // src/components/SpreeLegal.tsx
3002
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
3003
- var SpreeLegal = () => {
3004
- return /* @__PURE__ */ jsxs2("div", { className: "mt-4 flex items-center gap-4", children: [
3005
- /* @__PURE__ */ jsx2("svg", { className: "flex-shrink-0", xmlns: "http://www.w3.org/2000/svg", width: "66", height: "30", fill: "none", children: /* @__PURE__ */ jsx2(
3006
- "path",
3007
- {
3008
- fill: "#000",
3009
- fillOpacity: ".5",
3010
- 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"
3011
- }
3012
- ) }),
3013
- /* @__PURE__ */ jsxs2("p", { className: "text-secondary text-xs", children: [
3014
- "Spree enables seamless crypto payments for real-world goods, travel, and experiences. Enjoy secure, fast transactions and earn rewards.",
3015
- " ",
3016
- /* @__PURE__ */ jsx2("a", { className: "underline", href: "/", children: "Learn more" }),
3017
- " ",
3018
- "about Spree."
3019
- ] })
3020
- ] });
3021
- };
3022
-
3023
- // src/components/Tabs.tsx
3024
- import { useMemo as useMemo4 } from "react";
3025
- import { Elements } from "@stripe/react-stripe-js";
3026
- import { loadStripe } from "@stripe/stripe-js";
3027
-
3028
2981
  // src/context/SpreePayActionsContext.tsx
3029
2982
  import { createContext, useCallback, useContext, useRef, useState } from "react";
3030
- import { jsx as jsx3 } from "react/jsx-runtime";
2983
+ import { jsx } from "react/jsx-runtime";
3031
2984
  var SpreePayActionsContext = createContext(void 0);
3032
2985
  var SpreePayProvider = ({ children, env }) => {
3033
2986
  const processRef = useRef(null);
@@ -3054,7 +3007,7 @@ var SpreePayProvider = ({ children, env }) => {
3054
3007
  selectedPaymentMethod,
3055
3008
  setSelectedPaymentMethod
3056
3009
  };
3057
- return /* @__PURE__ */ jsx3(SpreePayActionsContext.Provider, { value, children });
3010
+ return /* @__PURE__ */ jsx(SpreePayActionsContext.Provider, { value, children });
3058
3011
  };
3059
3012
  var useSpreePay = () => {
3060
3013
  const ctx = useContext(SpreePayActionsContext);
@@ -3077,21 +3030,72 @@ var useSpreePayRegister = () => {
3077
3030
  return { register: ctx.register };
3078
3031
  };
3079
3032
 
3033
+ // src/components/CheckoutButton.tsx
3034
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
3035
+ var CheckoutButton = ({ amount, onCheckout }) => {
3036
+ const { selectedPaymentMethod } = useSpreePaymentMethod();
3037
+ const isDisabled = !amount || !selectedPaymentMethod.method;
3038
+ return /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col overflow-hidden rounded-[24px] border border-black/25 bg-white text-xs font-medium", children: [
3039
+ /* @__PURE__ */ jsx2("div", { className: "px-7 py-5", children: /* @__PURE__ */ jsxs("p", { className: "text-secondary", children: [
3040
+ "By clicking on the button below I acknowledge that I have read and accepted the",
3041
+ " ",
3042
+ /* @__PURE__ */ jsx2("a", { className: "underline", href: "/", children: "Property Policies" }),
3043
+ ",",
3044
+ " ",
3045
+ /* @__PURE__ */ jsx2("a", { className: "underline", href: "/", children: "Check-in Instructions" }),
3046
+ ",",
3047
+ " ",
3048
+ /* @__PURE__ */ jsx2("a", { className: "underline", href: "/", children: "Property Fees" }),
3049
+ ", and",
3050
+ " ",
3051
+ /* @__PURE__ */ jsx2("a", { className: "underline", href: "/", children: "Supplier Terms and Conditions" }),
3052
+ "."
3053
+ ] }) }),
3054
+ onCheckout && /* @__PURE__ */ jsx2(
3055
+ "button",
3056
+ {
3057
+ disabled: isDisabled,
3058
+ onClick: onCheckout,
3059
+ className: cn("bg-primary pointer w-full py-4 text-xl font-semibold text-white", {
3060
+ "opacity-50": isDisabled
3061
+ }),
3062
+ children: amount ? `Pay ${amount}` : "Checkout"
3063
+ }
3064
+ )
3065
+ ] });
3066
+ };
3067
+
3068
+ // src/components/SpreeLegal.tsx
3069
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
3070
+ var SpreeLegal = () => {
3071
+ return /* @__PURE__ */ jsxs2("div", { className: "mt-4 flex items-center gap-4", children: [
3072
+ /* @__PURE__ */ jsx3("svg", { className: "flex-shrink-0", xmlns: "http://www.w3.org/2000/svg", width: "66", height: "30", fill: "none", children: /* @__PURE__ */ jsx3(
3073
+ "path",
3074
+ {
3075
+ fill: "#000",
3076
+ fillOpacity: ".5",
3077
+ 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"
3078
+ }
3079
+ ) }),
3080
+ /* @__PURE__ */ jsxs2("p", { className: "text-secondary text-xs", children: [
3081
+ "Spree enables seamless crypto payments for real-world goods, travel, and experiences. Enjoy secure, fast transactions and earn rewards.",
3082
+ " ",
3083
+ /* @__PURE__ */ jsx3("a", { className: "underline", href: "/", children: "Learn more" }),
3084
+ " ",
3085
+ "about Spree."
3086
+ ] })
3087
+ ] });
3088
+ };
3089
+
3080
3090
  // src/components/CreditCard/CreditCard.tsx
3081
- import { useState as useState7 } from "react";
3091
+ import { useMemo as useMemo4, useState as useState7 } from "react";
3092
+ import { Elements } from "@stripe/react-stripe-js";
3093
+ import { loadStripe } from "@stripe/stripe-js";
3082
3094
 
3083
3095
  // src/hooks/useCards.ts
3084
3096
  import useSWR from "swr";
3085
3097
  var useCards = () => {
3086
- const { env } = useSpreePayEnv();
3087
- const { data, isLoading, mutate } = useSWR(
3088
- `/payments/cards?userExternalId=${env.userId}`,
3089
- {
3090
- revalidateOnFocus: false,
3091
- revalidateIfStale: false,
3092
- revalidateOnReconnect: false
3093
- }
3094
- );
3098
+ const { data, isLoading, mutate } = useSWR(`/v1/payments/cards`);
3095
3099
  return {
3096
3100
  cards: data?.data.filter((c) => c.active) || [],
3097
3101
  cardsIsLoading: isLoading,
@@ -3099,8 +3103,15 @@ var useCards = () => {
3099
3103
  };
3100
3104
  };
3101
3105
 
3106
+ // src/hooks/useConfig.ts
3107
+ import useSWR2 from "swr";
3108
+ var useConfig = () => {
3109
+ const { data, isLoading } = useSWR2("/v1/tenants/configs/spree-pay");
3110
+ return { config: data, configIsLoading: isLoading };
3111
+ };
3112
+
3102
3113
  // src/components/CreditCard/CardsList.tsx
3103
- import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
3114
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
3104
3115
  var CardListItem = ({ card, isSelected, onSelect }) => {
3105
3116
  const handleSelect = () => {
3106
3117
  onSelect(card);
@@ -3158,14 +3169,15 @@ var CardListItem = ({ card, isSelected, onSelect }) => {
3158
3169
  };
3159
3170
  var CardsList = ({ selectedCard, setCard }) => {
3160
3171
  const { cards, cardsIsLoading } = useCards();
3161
- return /* @__PURE__ */ jsxs3("div", { className: "flex w-full flex-col gap-1", children: [
3162
- cardsIsLoading && /* @__PURE__ */ jsxs3(Fragment, { children: [
3172
+ if (cardsIsLoading) {
3173
+ return /* @__PURE__ */ jsxs3("div", { className: "flex w-full flex-col gap-1", children: [
3163
3174
  /* @__PURE__ */ jsx4("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" }),
3164
3175
  /* @__PURE__ */ jsx4("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" }),
3165
3176
  /* @__PURE__ */ jsx4("div", { className: "bg-primary/8 h-11 animate-pulse rounded-md" })
3166
- ] }),
3167
- cards.map((card) => /* @__PURE__ */ jsx4(CardListItem, { isSelected: selectedCard?.id === card.id, onSelect: setCard, card }, card.id))
3168
- ] });
3177
+ ] });
3178
+ }
3179
+ if (cards.length === 0) return null;
3180
+ return /* @__PURE__ */ jsx4("div", { className: "flex w-full flex-col gap-1", children: cards.map((card) => /* @__PURE__ */ jsx4(CardListItem, { isSelected: selectedCard?.id === card.id, onSelect: setCard, card }, card.id)) });
3169
3181
  };
3170
3182
 
3171
3183
  // src/components/CreditCard/CreditCardForm.tsx
@@ -3213,7 +3225,7 @@ function useComposedRefs(...refs) {
3213
3225
  }
3214
3226
 
3215
3227
  // ../../node_modules/@radix-ui/react-slot/dist/index.mjs
3216
- import { Fragment as Fragment22, jsx as jsx5 } from "react/jsx-runtime";
3228
+ import { Fragment as Fragment2, jsx as jsx5 } from "react/jsx-runtime";
3217
3229
  // @__NO_SIDE_EFFECTS__
3218
3230
  function createSlot(ownerName) {
3219
3231
  const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
@@ -4262,10 +4274,15 @@ var CreditCardForm = ({ saveCard }) => {
4262
4274
 
4263
4275
  // src/components/CreditCard/CreditCard.tsx
4264
4276
  import { Fragment as Fragment5, jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
4277
+ var SripeWrapper = (props) => {
4278
+ const stripePromise = useMemo4(() => loadStripe(props.publicKey), [props.publicKey]);
4279
+ return /* @__PURE__ */ jsx14(Elements, { stripe: stripePromise, children: /* @__PURE__ */ jsx14(CreditCardForm, { saveCard: props.saveNewCard }) });
4280
+ };
4265
4281
  var CreditCard = () => {
4266
4282
  const [showForm, setShowForm] = useState7(false);
4267
4283
  const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
4268
4284
  const { mutateCards } = useCards();
4285
+ const { config } = useConfig();
4269
4286
  const setCard = (card) => {
4270
4287
  setSelectedPaymentMethod({ type: "CREDIT_CARD" /* CREDIT_CARD */, method: card });
4271
4288
  };
@@ -4284,9 +4301,9 @@ var CreditCard = () => {
4284
4301
  setCard
4285
4302
  }
4286
4303
  ),
4287
- /* @__PURE__ */ jsx14("button", { onClick: () => setShowForm(true), className: "text-sm font-medium text-black", children: "Add new card" })
4304
+ config?.stripePublicKey && /* @__PURE__ */ jsx14("button", { onClick: () => setShowForm(true), className: "text-sm font-medium text-black", children: "Add new card" })
4288
4305
  ] }),
4289
- showForm && /* @__PURE__ */ jsx14(CreditCardForm, { saveCard: saveNewCard })
4306
+ config?.stripePublicKey && showForm && /* @__PURE__ */ jsx14(SripeWrapper, { saveNewCard, publicKey: config.stripePublicKey })
4290
4307
  ] });
4291
4308
  };
4292
4309
 
@@ -4348,23 +4365,21 @@ var TabButtons = (props) => {
4348
4365
  // src/components/Tabs.tsx
4349
4366
  import { jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
4350
4367
  var Tabs = () => {
4351
- const { env } = useSpreePayEnv();
4352
4368
  const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
4353
- const stripePromise = useMemo4(() => loadStripe(env.stripePublicKey), [env.stripePublicKey]);
4354
4369
  return /* @__PURE__ */ jsxs8("div", { className: "mb-4 rounded-2xl border border-black/25 bg-white", children: [
4355
4370
  /* @__PURE__ */ jsxs8("div", { className: "flex w-full flex-col gap-4 border-b-1 border-black/7 px-7 py-6", children: [
4356
4371
  /* @__PURE__ */ jsx16("h2", { className: "text-primary text-2xl font-semibold", children: "Choose a Payment Method" }),
4357
4372
  /* @__PURE__ */ jsx16(TabButtons, { value: selectedPaymentMethod.type, onChange: setSelectedPaymentMethod })
4358
4373
  ] }),
4359
4374
  /* @__PURE__ */ jsxs8("div", { className: "px-7 py-6", children: [
4360
- selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && /* @__PURE__ */ jsx16(Elements, { stripe: stripePromise, children: /* @__PURE__ */ jsx16(CreditCard, {}) }),
4375
+ selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && /* @__PURE__ */ jsx16(CreditCard, {}),
4361
4376
  selectedPaymentMethod.type === "CRYPTO" /* CRYPTO */ && null
4362
4377
  ] })
4363
4378
  ] });
4364
4379
  };
4365
4380
 
4366
4381
  // src/fetcher/client.ts
4367
- var cfg = { baseUrl: void 0, authKey: void 0 };
4382
+ var cfg = { baseUrl: void 0, accessToken: void 0, tenantId: void 0 };
4368
4383
  var buildUrl = (key) => {
4369
4384
  if (!cfg.baseUrl) throw new Error("Missing SLAPI baseUrl. Call registerApi(...) first.");
4370
4385
  if (typeof key === "string") return cfg.baseUrl + key;
@@ -4381,8 +4396,10 @@ var request = async (method, url, body) => {
4381
4396
  const headers = {
4382
4397
  Accept: "application/json"
4383
4398
  };
4384
- if (!cfg.authKey) throw new Error("Missing SLAPI authKey. Call registerApi(...) first.");
4385
- headers.Authorization = `Bearer ${cfg.authKey}`;
4399
+ if (!cfg.accessToken) throw new Error("Missing SLAPI accessToken. Call registerApi(...) first.");
4400
+ if (!cfg.tenantId) throw new Error("Missing SLAPI tenantId. Call registerApi(...) first.");
4401
+ headers.Authorization = `Bearer ${cfg.accessToken}`;
4402
+ headers["X-Tenant-ID"] = cfg.tenantId;
4386
4403
  let payload;
4387
4404
  if (method !== "GET" && method !== "DELETE" && body !== void 0) {
4388
4405
  if (typeof FormData !== "undefined" && body instanceof FormData) {
@@ -4410,9 +4427,6 @@ var request = async (method, url, body) => {
4410
4427
  }
4411
4428
  return await res.json();
4412
4429
  };
4413
- var slapiFetcher = async () => {
4414
- throw new Error("slapiFetcher is not configured. Call registerApi(...) first.");
4415
- };
4416
4430
  var slapiApi = {
4417
4431
  get: async () => {
4418
4432
  throw new Error("slapiApi is not configured. Call registerApi(...) first.");
@@ -4432,7 +4446,8 @@ var slapiApi = {
4432
4446
  };
4433
4447
  var registerApi = (config) => {
4434
4448
  cfg.baseUrl = config.baseUrl;
4435
- cfg.authKey = config.authKey;
4449
+ cfg.accessToken = config.accessToken;
4450
+ cfg.tenantId = config.tenantId;
4436
4451
  slapiApi = {
4437
4452
  get: async (key) => {
4438
4453
  const url = buildUrl(key);
@@ -4455,7 +4470,7 @@ var registerApi = (config) => {
4455
4470
  return request("DELETE", url);
4456
4471
  }
4457
4472
  };
4458
- slapiFetcher = async (key) => slapiApi.get(key);
4473
+ return (key) => slapiApi.get(key);
4459
4474
  };
4460
4475
 
4461
4476
  // src/services/slapi.ts
@@ -4498,7 +4513,7 @@ var SlapiPaymentService = {
4498
4513
  // },
4499
4514
  createPayment: (params) => {
4500
4515
  const { type, hash } = params;
4501
- return slapiApi.post("/payments", { ...{ type, hash, card: params.card }, capture: false }).then((data) => ({ data }));
4516
+ return slapiApi.post("/v1/payments", { ...{ type, hash, card: params.card }, capture: false }).then((data) => ({ data }));
4502
4517
  },
4503
4518
  // signEncodedTransaction: async (signTransaction: SignTransaction, encodedTX: string): Promise<string> => {
4504
4519
  // const swapTransactionBuf = Buffer.from(encodedTX, 'base64');
@@ -4513,11 +4528,11 @@ var SlapiPaymentService = {
4513
4528
  // },
4514
4529
  addCard: (params) => {
4515
4530
  const { source, hash } = params;
4516
- return slapiApi.post("/payments/cards", { hash, source }).then((data) => ({ data }));
4531
+ return slapiApi.post("/v1/payments/cards", { hash, source }).then((data) => ({ data }));
4517
4532
  },
4518
4533
  validate3DS: (params) => {
4519
4534
  const { paymentId } = params;
4520
- return slapiApi.post("/payments/validate", { paymentId, type: "CREDIT_CARD" }).then((data) => ({ data }));
4535
+ return slapiApi.post("/v1/payments/validate", { paymentId, type: "CREDIT_CARD" }).then((data) => ({ data }));
4521
4536
  }
4522
4537
  };
4523
4538
 
@@ -4536,15 +4551,11 @@ var cardPayment = async ({ card, hash }) => {
4536
4551
  return { status: paymentResData.status };
4537
4552
  };
4538
4553
 
4539
- // src/SpreePay.tsx
4554
+ // src/SpreePayContent.tsx
4540
4555
  import { jsx as jsx17, jsxs as jsxs9 } from "react/jsx-runtime";
4541
- var SpreePay = (props) => {
4542
- const { className } = props;
4543
- const { env } = useSpreePayEnv();
4556
+ var SpreePayContent = (props) => {
4557
+ const { className, amount, onProcess } = props;
4544
4558
  const { selectedPaymentMethod } = useSpreePaymentMethod();
4545
- useEffect5(() => {
4546
- registerApi({ baseUrl: env.slapiUrl, authKey: env.slapiAuthKey });
4547
- }, [env.slapiUrl, env.slapiAuthKey]);
4548
4559
  const { register } = useSpreePayRegister();
4549
4560
  const handlePay = useCallback5(
4550
4561
  (data) => {
@@ -4558,11 +4569,42 @@ var SpreePay = (props) => {
4558
4569
  useEffect5(() => {
4559
4570
  register(handlePay);
4560
4571
  }, [register, handlePay]);
4561
- return /* @__PURE__ */ jsx17(SWRConfig, { value: { fetcher: slapiFetcher }, children: /* @__PURE__ */ jsx17("div", { className: cn("sl-spreepay", className), children: /* @__PURE__ */ jsxs9("div", { className: "w-full max-w-[540px]", children: [
4572
+ return /* @__PURE__ */ jsx17("div", { className: cn("sl-spreepay", className), children: /* @__PURE__ */ jsxs9("div", { className: "w-full max-w-[540px]", children: [
4562
4573
  /* @__PURE__ */ jsx17(Tabs, {}),
4563
- /* @__PURE__ */ jsx17(CheckoutButton, { amount: props.amount }),
4574
+ /* @__PURE__ */ jsx17(CheckoutButton, { onCheckout: onProcess, amount }),
4564
4575
  /* @__PURE__ */ jsx17(SpreeLegal, {})
4565
- ] }) }) });
4576
+ ] }) });
4577
+ };
4578
+
4579
+ // src/SpreePay.tsx
4580
+ import { jsx as jsx18 } from "react/jsx-runtime";
4581
+ var envConfig = {
4582
+ dev: { slapiUrl: "https://slapi.dev.superlogic.com", tenantId: "bookit" },
4583
+ stg: { slapiUrl: "https://slapi.dev.superlogic.com", tenantId: "bookit" },
4584
+ prod: { slapiUrl: "https://slapi.dev.superlogic.com", tenantId: "bookit" }
4585
+ };
4586
+ var SpreePay = (props) => {
4587
+ const { env } = useSpreePayEnv();
4588
+ const slapiFetcher = useMemo5(
4589
+ () => registerApi({
4590
+ accessToken: env.accessToken,
4591
+ baseUrl: envConfig[env.environment].slapiUrl,
4592
+ tenantId: envConfig[env.environment].tenantId
4593
+ }),
4594
+ [env]
4595
+ );
4596
+ return /* @__PURE__ */ jsx18(
4597
+ SWRConfig,
4598
+ {
4599
+ value: {
4600
+ fetcher: slapiFetcher,
4601
+ revalidateOnFocus: false,
4602
+ revalidateIfStale: false,
4603
+ revalidateOnReconnect: false
4604
+ },
4605
+ children: /* @__PURE__ */ jsx18(SpreePayContent, { ...props })
4606
+ }
4607
+ );
4566
4608
  };
4567
4609
  export {
4568
4610
  SpreePay,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superlogic/spree-pay",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Spree-pay React component and utilities",
5
5
  "private": false,
6
6
  "type": "module",
@@ -19,11 +19,6 @@
19
19
  "check-ts": "tsc --noEmit",
20
20
  "publish": "npm run build"
21
21
  },
22
- "exports": {
23
- ".": {
24
- "import": "./src/index.ts"
25
- }
26
- },
27
22
  "publishConfig": {
28
23
  "access": "public"
29
24
  },