@doujins/payments-ui 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -120,14 +120,15 @@ var createClient = (config) => {
120
120
  }
121
121
  };
122
122
  const buildUrl = (path, query) => {
123
- path = path.replace(/^\/+|\/+$/g, "");
124
- const baseUrl = config.baseUrl.replace(/^\/+|\/+$/g, "");
125
- const url = new URL(`${baseUrl}${path.endsWith("v1") ? "/" : "/v1/"}${path}`);
123
+ const sanitizedPath = path.replace(/^\/+/, "");
124
+ const baseUrl = config.baseUrl.trim().replace(/\/+$/, "");
125
+ const versionedBaseUrl = baseUrl.endsWith("/v1") ? baseUrl : `${baseUrl}/v1`;
126
+ const url = new URL(sanitizedPath, `${versionedBaseUrl.replace(/\/+$/, "")}/`);
126
127
  if (query) {
127
- Object.entries(query).forEach(([key, value]) => {
128
- if (value === void 0 || value === null) return;
128
+ for (const [key, value] of Object.entries(query)) {
129
+ if (value === void 0 || value === null) continue;
129
130
  url.searchParams.append(key, String(value));
130
- });
131
+ }
131
132
  }
132
133
  return url.toString();
133
134
  };
@@ -723,12 +724,9 @@ var CardDetailsForm = ({
723
724
  noValidate: true,
724
725
  children: [
725
726
  errorMessage && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md border border-red-500/40 bg-red-500/10 px-4 py-2 text-sm text-red-400", children: errorMessage }),
726
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-5 md:grid-cols-2", children: [
727
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
728
- /* @__PURE__ */ jsxRuntime.jsxs(Label, { htmlFor: "payments-first", className: "flex items-center gap-2 text-white/70", children: [
729
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.User, { className: "h-4 w-4" }),
730
- " First name"
731
- ] }),
727
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4 md:flex-row", children: [
728
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 space-y-2", children: [
729
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: "payments-first", children: "First name" }),
732
730
  /* @__PURE__ */ jsxRuntime.jsx(
733
731
  Input,
734
732
  {
@@ -739,11 +737,8 @@ var CardDetailsForm = ({
739
737
  }
740
738
  )
741
739
  ] }),
742
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
743
- /* @__PURE__ */ jsxRuntime.jsxs(Label, { htmlFor: "payments-last", className: "flex items-center gap-2 text-white/70", children: [
744
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.User, { className: "h-4 w-4" }),
745
- " Last name"
746
- ] }),
740
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 space-y-2", children: [
741
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: "payments-last", children: "Last name" }),
747
742
  /* @__PURE__ */ jsxRuntime.jsx(
748
743
  Input,
749
744
  {
@@ -807,10 +802,7 @@ var CardDetailsForm = ({
807
802
  ] }),
808
803
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-5 md:grid-cols-2", children: [
809
804
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
810
- /* @__PURE__ */ jsxRuntime.jsxs(Label, { htmlFor: "payments-postal", className: "flex items-center gap-2 text-white/70", children: [
811
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MapPin, { className: "h-4 w-4" }),
812
- " Postal code"
813
- ] }),
805
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: "payments-postal", children: "Postal code" }),
814
806
  /* @__PURE__ */ jsxRuntime.jsx(
815
807
  Input,
816
808
  {
@@ -852,17 +844,10 @@ var CardDetailsForm = ({
852
844
  children: submitting || isTokenizing ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
853
845
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "mr-2 h-4 w-4 animate-spin" }),
854
846
  " Processing\u2026"
855
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
856
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CreditCard, { className: "mr-2 h-4 w-4" }),
857
- " ",
858
- submitLabel
859
- ] })
847
+ ] }) : submitLabel
860
848
  }
861
849
  ),
862
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "flex items-center gap-2 text-xs text-white/50", children: [
863
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CreditCard, { className: "h-4 w-4" }),
864
- " Your payment information is encrypted and processed securely."
865
- ] })
850
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-white/60", children: "Your payment information is encrypted and processed securely." })
866
851
  ]
867
852
  }
868
853
  );
@@ -976,9 +961,7 @@ var formatCardLabel = (method) => {
976
961
  var StoredPaymentMethods = ({
977
962
  selectedMethodId,
978
963
  onMethodSelect,
979
- showAddButton = true,
980
- heading = "Payment Methods",
981
- description = "Manage your saved cards"
964
+ showAddButton = true
982
965
  }) => {
983
966
  const { listQuery, createMutation, deleteMutation } = usePaymentMethods();
984
967
  const [isModalOpen, setIsModalOpen] = React17.useState(false);
@@ -997,31 +980,18 @@ var StoredPaymentMethods = ({
997
980
  );
998
981
  };
999
982
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
1000
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between", children: [
1001
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1002
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "flex items-center gap-2 text-sm font-medium text-muted-foreground", children: [
1003
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.WalletCards, { className: "h-4 w-4" }),
1004
- " ",
1005
- heading
1006
- ] }),
1007
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: description })
1008
- ] }),
1009
- showAddButton && /* @__PURE__ */ jsxRuntime.jsxs(Button, { size: "sm", variant: "outline", onClick: () => setIsModalOpen(true), children: [
1010
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CreditCard, { className: "mr-2 h-4 w-4" }),
1011
- " Add card"
1012
- ] })
1013
- ] }),
1014
- listQuery.isLoading ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center rounded-lg border border-dashed border-border/60 bg-muted/10 py-8 text-sm text-muted-foreground", children: [
983
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-start justify-between gap-4", children: showAddButton && /* @__PURE__ */ jsxRuntime.jsx(Button, { size: "sm", variant: "ghost", onClick: () => setIsModalOpen(true), children: "Add card" }) }),
984
+ listQuery.isLoading ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center py-4 text-sm text-muted-foreground", children: [
1015
985
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "mr-2 h-4 w-4 animate-spin" }),
1016
- " Loading cards\u2026"
1017
- ] }) : payments.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-dashed border-border/60 bg-muted/10 px-4 py-6 text-sm text-muted-foreground", children: "No saved payment methods yet." }) : /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "max-h-[320px] pr-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: payments.map((method) => {
986
+ " Loading cards..."
987
+ ] }) : payments.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 text-center text-sm text-muted-foreground", children: "No saved payment methods yet." }) : /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "max-h-[320px] pr-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: payments.map((method) => {
1018
988
  const isSelected = selectedMethodId === method.id;
1019
989
  return /* @__PURE__ */ jsxRuntime.jsxs(
1020
990
  "div",
1021
991
  {
1022
992
  className: cn(
1023
- "flex flex-col gap-3 rounded-lg border px-4 py-3 transition-colors md:flex-row md:items-center md:justify-between",
1024
- isSelected ? "border-primary/60 bg-primary/5" : "border-border/60 bg-background"
993
+ "flex flex-col gap-3 rounded-md px-4 py-3 transition-colors md:flex-row md:items-center md:justify-between",
994
+ isSelected ? "ring-1 ring-primary/70 bg-primary/5" : "ring-1 ring-border/40 bg-transparent"
1025
995
  ),
1026
996
  children: [
1027
997
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
@@ -1048,7 +1018,8 @@ var StoredPaymentMethods = ({
1048
1018
  Button,
1049
1019
  {
1050
1020
  size: "sm",
1051
- variant: isSelected ? "default" : "outline",
1021
+ variant: "ghost",
1022
+ className: "px-3",
1052
1023
  onClick: () => onMethodSelect(method),
1053
1024
  children: isSelected ? "Selected" : "Use card"
1054
1025
  }
@@ -1056,12 +1027,12 @@ var StoredPaymentMethods = ({
1056
1027
  /* @__PURE__ */ jsxRuntime.jsx(
1057
1028
  Button,
1058
1029
  {
1059
- size: "icon",
1060
- variant: "outline",
1061
- className: "text-destructive",
1030
+ size: "sm",
1031
+ variant: "ghost",
1032
+ className: "px-3 text-destructive",
1062
1033
  onClick: () => handleDelete(method),
1063
1034
  disabled: deletingId === method.id && deleteMutation.isPending,
1064
- children: deletingId === method.id && deleteMutation.isPending ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "h-4 w-4" })
1035
+ children: deletingId === method.id && deleteMutation.isPending ? "Removing\u2026" : "Remove"
1065
1036
  }
1066
1037
  )
1067
1038
  ] })
@@ -1800,7 +1771,7 @@ var SolanaPaymentView = ({
1800
1771
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
1801
1772
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium text-foreground", children: "Select token" }),
1802
1773
  /* @__PURE__ */ jsxRuntime.jsxs(Select, { value: selectedToken?.symbol ?? "", onValueChange: handleTokenChange, children: [
1803
- /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: "Select token" }) }),
1774
+ /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "border border-border/60 bg-transparent", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: "Select token" }) }),
1804
1775
  /* @__PURE__ */ jsxRuntime.jsx(SelectContent, { className: "max-h-64", children: tokens.map((token) => /* @__PURE__ */ jsxRuntime.jsxs(SelectItem, { value: token.symbol, children: [
1805
1776
  token.name,
1806
1777
  " (",
@@ -1827,7 +1798,7 @@ var SolanaPaymentView = ({
1827
1798
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-2xl font-semibold text-foreground", children: "Pay with Solana" }),
1828
1799
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Choose a supported token and send the payment via Solana Pay QR code." })
1829
1800
  ] }),
1830
- onClose && /* @__PURE__ */ jsxRuntime.jsxs(
1801
+ onClose && /* @__PURE__ */ jsxRuntime.jsx(
1831
1802
  Button,
1832
1803
  {
1833
1804
  type: "button",
@@ -1835,11 +1806,8 @@ var SolanaPaymentView = ({
1835
1806
  variant: "ghost",
1836
1807
  onClick: handleClose,
1837
1808
  disabled: paymentState === "processing" || paymentState === "confirming",
1838
- className: "h-8 px-2 text-sm",
1839
- children: [
1840
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowLeft, { className: "mr-2 h-4 w-4" }),
1841
- " Back"
1842
- ]
1809
+ className: "h-8 px-3 text-sm",
1810
+ children: "Back"
1843
1811
  }
1844
1812
  )
1845
1813
  ] }),
@@ -1958,11 +1926,9 @@ var PaymentExperience = ({
1958
1926
  /* @__PURE__ */ jsxRuntime.jsx(
1959
1927
  StoredPaymentMethods,
1960
1928
  {
1961
- heading: "Saved cards",
1929
+ showAddButton: false,
1962
1930
  selectedMethodId,
1963
- onMethodSelect: handleMethodSelect,
1964
- description: "Select one of your stored payment methods.",
1965
- showAddButton: false
1931
+ onMethodSelect: handleMethodSelect
1966
1932
  }
1967
1933
  ),
1968
1934
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1971,7 +1937,7 @@ var PaymentExperience = ({
1971
1937
  className: "w-full",
1972
1938
  disabled: !selectedMethodId || savedStatus === "processing",
1973
1939
  onClick: handleSavedPayment,
1974
- children: savedStatus === "processing" ? "Processing\u2026" : "Pay with selected card"
1940
+ children: savedStatus === "processing" ? "Processing..." : "Pay with selected card"
1975
1941
  }
1976
1942
  ),
1977
1943
  savedError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: savedError })
@@ -2004,8 +1970,8 @@ var PaymentExperience = ({
2004
1970
  /* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: "saved", disabled: !showStored, children: "Use saved card" }),
2005
1971
  /* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: "new", disabled: !showNewCard, children: "Add new card" })
2006
1972
  ] }),
2007
- /* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "saved", className: "space-y-4", children: renderSavedTab() }),
2008
- /* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "new", className: "space-y-4", children: renderNewTab() })
1973
+ /* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "saved", children: renderSavedTab() }),
1974
+ /* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "new", children: renderNewTab() })
2009
1975
  ]
2010
1976
  }
2011
1977
  ),
@@ -2193,11 +2159,11 @@ var SubscriptionCheckoutModal = ({
2193
2159
  };
2194
2160
  const handleNewCardPayment = async ({ token, billing }) => {
2195
2161
  const response = await subscribeWithCard({
2196
- priceId: ensurePrice(),
2162
+ billing,
2197
2163
  provider,
2164
+ idempotencyKey,
2198
2165
  paymentToken: token,
2199
- billing,
2200
- idempotencyKey
2166
+ priceId: ensurePrice()
2201
2167
  });
2202
2168
  assertCheckoutSuccess(response.status, response.message);
2203
2169
  notifySuccess();
@@ -2236,14 +2202,14 @@ var SubscriptionCheckoutModal = ({
2236
2202
  {
2237
2203
  usdAmount,
2238
2204
  priceId: priceId ?? "",
2239
- onSolanaSuccess: solanaSuccess,
2205
+ initialMode,
2240
2206
  onSolanaError: solanaError,
2207
+ onSolanaSuccess: solanaSuccess,
2241
2208
  enableNewCard: Boolean(priceId),
2242
2209
  enableStoredMethods: Boolean(priceId),
2243
2210
  enableSolanaPay: enableSolanaPay && Boolean(priceId),
2244
2211
  onNewCardPayment: priceId ? handleNewCardPayment : void 0,
2245
- onSavedMethodPayment: priceId ? handleSavedMethodPayment : void 0,
2246
- initialMode
2212
+ onSavedMethodPayment: priceId ? handleSavedMethodPayment : void 0
2247
2213
  }
2248
2214
  )
2249
2215
  ] })
@@ -3157,7 +3123,7 @@ var PaymentMethodsSection = ({
3157
3123
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "mr-2 h-5 w-5 animate-spin" }),
3158
3124
  " ",
3159
3125
  t.loadingCards
3160
- ] }) : payments.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-dashed border-white/20 bg-white/5 p-6 text-sm text-white/60", children: t.noPaymentMethods }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: payments.map((method) => /* @__PURE__ */ jsxRuntime.jsxs(
3126
+ ] }) : payments.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6 text-sm text-center", children: t.noPaymentMethods }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: payments.map((method) => /* @__PURE__ */ jsxRuntime.jsxs(
3161
3127
  "div",
3162
3128
  {
3163
3129
  className: "rounded-lg border border-white/10 bg-white/5 p-4 shadow-sm",