@sintecinformatik/checkout 1.0.0 → 1.2.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/README.md CHANGED
@@ -5,10 +5,33 @@ React components for integrating Sintec License Server checkout into your produc
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @sintec/checkout
8
+ npm install @sintecinformatik/checkout
9
9
  ```
10
10
 
11
- > **Note**: Package not yet published to npm. For now, copy the source from this directory or use a local path reference.
11
+ ## Finding Your Product Slug
12
+
13
+ To find available products and their slugs, call the products endpoint:
14
+
15
+ ```bash
16
+ curl https://license.sintec.ch/api/v1/checkout/products
17
+ ```
18
+
19
+ Response:
20
+ ```json
21
+ [
22
+ {
23
+ "slug": "littlewoodshed",
24
+ "name": "LittleWoodshed",
25
+ "perpetualPriceCents": 19900,
26
+ "monthlyPriceCents": 900,
27
+ "yearlyPriceCents": 7800,
28
+ "currency": "chf",
29
+ "checkoutEnabled": true
30
+ }
31
+ ]
32
+ ```
33
+
34
+ Use the `slug` value as your `productSlug` prop.
12
35
 
13
36
  ## Usage
14
37
 
@@ -17,7 +40,7 @@ npm install @sintec/checkout
17
40
  The simplest way to add a buy button:
18
41
 
19
42
  ```tsx
20
- import { CheckoutButton } from "@sintec/checkout";
43
+ import { CheckoutButton } from "@sintecinformatik/checkout";
21
44
 
22
45
  function BuyPage() {
23
46
  return (
@@ -38,7 +61,7 @@ function BuyPage() {
38
61
  For custom UI implementations:
39
62
 
40
63
  ```tsx
41
- import { useCheckout } from "@sintec/checkout";
64
+ import { useCheckout } from "@sintecinformatik/checkout";
42
65
 
43
66
  function CustomCheckout() {
44
67
  const { startCheckout, isLoading, error } = useCheckout();
package/dist/index.d.mts CHANGED
@@ -12,6 +12,8 @@ interface StartCheckoutParams {
12
12
  licenseType: LicenseType;
13
13
  /** Customer email (optional, pre-fills Stripe checkout) */
14
14
  customerEmail?: string;
15
+ /** Customer name (optional, stored with license) */
16
+ customerName?: string;
15
17
  }
16
18
  interface CheckoutButtonProps extends StartCheckoutParams {
17
19
  /** Base URL of the license server */
@@ -31,8 +33,20 @@ interface CheckoutSessionResponse {
31
33
  interface CheckoutErrorResponse {
32
34
  error: string;
33
35
  }
36
+ interface ProductPricing {
37
+ id: string;
38
+ name: string;
39
+ slug: string;
40
+ description: string | null;
41
+ perpetualPriceCents: number | null;
42
+ monthlyPriceCents: number | null;
43
+ yearlyPriceCents: number | null;
44
+ currency: string;
45
+ checkoutEnabled: boolean;
46
+ trialDaysLimit: number;
47
+ }
34
48
 
35
- declare function CheckoutButton({ productSlug, licenseType, customerEmail, serverUrl, className, children, onCheckoutStart, onError, }: CheckoutButtonProps): react_jsx_runtime.JSX.Element;
49
+ declare function CheckoutButton({ productSlug, licenseType, customerEmail, customerName, serverUrl, className, children, onCheckoutStart, onError, }: CheckoutButtonProps): react_jsx_runtime.JSX.Element;
36
50
 
37
51
  interface UseCheckoutReturn {
38
52
  /** Start the checkout process */
@@ -44,4 +58,11 @@ interface UseCheckoutReturn {
44
58
  }
45
59
  declare function useCheckout(options?: CheckoutOptions): UseCheckoutReturn;
46
60
 
47
- export { CheckoutButton, type CheckoutButtonProps, type CheckoutErrorResponse, type CheckoutOptions, type CheckoutSessionResponse, type LicenseType, type StartCheckoutParams, type UseCheckoutReturn, useCheckout };
61
+ interface UseProductReturn {
62
+ product: ProductPricing | null;
63
+ isLoading: boolean;
64
+ error: string | null;
65
+ }
66
+ declare function useProduct(slug: string, options?: CheckoutOptions): UseProductReturn;
67
+
68
+ export { CheckoutButton, type CheckoutButtonProps, type CheckoutErrorResponse, type CheckoutOptions, type CheckoutSessionResponse, type LicenseType, type ProductPricing, type StartCheckoutParams, type UseCheckoutReturn, type UseProductReturn, useCheckout, useProduct };
package/dist/index.d.ts CHANGED
@@ -12,6 +12,8 @@ interface StartCheckoutParams {
12
12
  licenseType: LicenseType;
13
13
  /** Customer email (optional, pre-fills Stripe checkout) */
14
14
  customerEmail?: string;
15
+ /** Customer name (optional, stored with license) */
16
+ customerName?: string;
15
17
  }
16
18
  interface CheckoutButtonProps extends StartCheckoutParams {
17
19
  /** Base URL of the license server */
@@ -31,8 +33,20 @@ interface CheckoutSessionResponse {
31
33
  interface CheckoutErrorResponse {
32
34
  error: string;
33
35
  }
36
+ interface ProductPricing {
37
+ id: string;
38
+ name: string;
39
+ slug: string;
40
+ description: string | null;
41
+ perpetualPriceCents: number | null;
42
+ monthlyPriceCents: number | null;
43
+ yearlyPriceCents: number | null;
44
+ currency: string;
45
+ checkoutEnabled: boolean;
46
+ trialDaysLimit: number;
47
+ }
34
48
 
35
- declare function CheckoutButton({ productSlug, licenseType, customerEmail, serverUrl, className, children, onCheckoutStart, onError, }: CheckoutButtonProps): react_jsx_runtime.JSX.Element;
49
+ declare function CheckoutButton({ productSlug, licenseType, customerEmail, customerName, serverUrl, className, children, onCheckoutStart, onError, }: CheckoutButtonProps): react_jsx_runtime.JSX.Element;
36
50
 
37
51
  interface UseCheckoutReturn {
38
52
  /** Start the checkout process */
@@ -44,4 +58,11 @@ interface UseCheckoutReturn {
44
58
  }
45
59
  declare function useCheckout(options?: CheckoutOptions): UseCheckoutReturn;
46
60
 
47
- export { CheckoutButton, type CheckoutButtonProps, type CheckoutErrorResponse, type CheckoutOptions, type CheckoutSessionResponse, type LicenseType, type StartCheckoutParams, type UseCheckoutReturn, useCheckout };
61
+ interface UseProductReturn {
62
+ product: ProductPricing | null;
63
+ isLoading: boolean;
64
+ error: string | null;
65
+ }
66
+ declare function useProduct(slug: string, options?: CheckoutOptions): UseProductReturn;
67
+
68
+ export { CheckoutButton, type CheckoutButtonProps, type CheckoutErrorResponse, type CheckoutOptions, type CheckoutSessionResponse, type LicenseType, type ProductPricing, type StartCheckoutParams, type UseCheckoutReturn, type UseProductReturn, useCheckout, useProduct };
package/dist/index.js CHANGED
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  CheckoutButton: () => CheckoutButton,
24
- useCheckout: () => useCheckout
24
+ useCheckout: () => useCheckout,
25
+ useProduct: () => useProduct
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
27
28
 
@@ -45,7 +46,8 @@ function useCheckout(options = {}) {
45
46
  body: JSON.stringify({
46
47
  productSlug: params.productSlug,
47
48
  licenseType: params.licenseType,
48
- customerEmail: params.customerEmail
49
+ customerEmail: params.customerEmail,
50
+ customerName: params.customerName
49
51
  })
50
52
  });
51
53
  const data = await response.json();
@@ -82,6 +84,7 @@ function CheckoutButton({
82
84
  productSlug,
83
85
  licenseType,
84
86
  customerEmail,
87
+ customerName,
85
88
  serverUrl,
86
89
  className,
87
90
  children = "Buy Now",
@@ -95,7 +98,8 @@ function CheckoutButton({
95
98
  await startCheckout({
96
99
  productSlug,
97
100
  licenseType,
98
- customerEmail
101
+ customerEmail,
102
+ customerName
99
103
  });
100
104
  } catch (err) {
101
105
  const message = err instanceof Error ? err.message : "Checkout failed";
@@ -113,8 +117,40 @@ function CheckoutButton({
113
117
  }
114
118
  );
115
119
  }
120
+
121
+ // src/useProduct.ts
122
+ var import_react2 = require("react");
123
+ var DEFAULT_SERVER_URL2 = "https://license.sintec.ch";
124
+ function useProduct(slug, options = {}) {
125
+ const { serverUrl = DEFAULT_SERVER_URL2 } = options;
126
+ const [product, setProduct] = (0, import_react2.useState)(null);
127
+ const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
128
+ const [error, setError] = (0, import_react2.useState)(null);
129
+ (0, import_react2.useEffect)(() => {
130
+ async function fetchProduct() {
131
+ setIsLoading(true);
132
+ setError(null);
133
+ try {
134
+ const response = await fetch(`${serverUrl}/api/v1/checkout/products/${slug}`);
135
+ if (!response.ok) {
136
+ const data2 = await response.json();
137
+ throw new Error(data2.error || "Failed to fetch product");
138
+ }
139
+ const data = await response.json();
140
+ setProduct(data);
141
+ } catch (err) {
142
+ setError(err instanceof Error ? err.message : "Failed to fetch product");
143
+ } finally {
144
+ setIsLoading(false);
145
+ }
146
+ }
147
+ fetchProduct();
148
+ }, [slug, serverUrl]);
149
+ return { product, isLoading, error };
150
+ }
116
151
  // Annotate the CommonJS export names for ESM import in node:
117
152
  0 && (module.exports = {
118
153
  CheckoutButton,
119
- useCheckout
154
+ useCheckout,
155
+ useProduct
120
156
  });
package/dist/index.mjs CHANGED
@@ -18,7 +18,8 @@ function useCheckout(options = {}) {
18
18
  body: JSON.stringify({
19
19
  productSlug: params.productSlug,
20
20
  licenseType: params.licenseType,
21
- customerEmail: params.customerEmail
21
+ customerEmail: params.customerEmail,
22
+ customerName: params.customerName
22
23
  })
23
24
  });
24
25
  const data = await response.json();
@@ -55,6 +56,7 @@ function CheckoutButton({
55
56
  productSlug,
56
57
  licenseType,
57
58
  customerEmail,
59
+ customerName,
58
60
  serverUrl,
59
61
  className,
60
62
  children = "Buy Now",
@@ -68,7 +70,8 @@ function CheckoutButton({
68
70
  await startCheckout({
69
71
  productSlug,
70
72
  licenseType,
71
- customerEmail
73
+ customerEmail,
74
+ customerName
72
75
  });
73
76
  } catch (err) {
74
77
  const message = err instanceof Error ? err.message : "Checkout failed";
@@ -86,7 +89,39 @@ function CheckoutButton({
86
89
  }
87
90
  );
88
91
  }
92
+
93
+ // src/useProduct.ts
94
+ import { useState as useState2, useEffect } from "react";
95
+ var DEFAULT_SERVER_URL2 = "https://license.sintec.ch";
96
+ function useProduct(slug, options = {}) {
97
+ const { serverUrl = DEFAULT_SERVER_URL2 } = options;
98
+ const [product, setProduct] = useState2(null);
99
+ const [isLoading, setIsLoading] = useState2(true);
100
+ const [error, setError] = useState2(null);
101
+ useEffect(() => {
102
+ async function fetchProduct() {
103
+ setIsLoading(true);
104
+ setError(null);
105
+ try {
106
+ const response = await fetch(`${serverUrl}/api/v1/checkout/products/${slug}`);
107
+ if (!response.ok) {
108
+ const data2 = await response.json();
109
+ throw new Error(data2.error || "Failed to fetch product");
110
+ }
111
+ const data = await response.json();
112
+ setProduct(data);
113
+ } catch (err) {
114
+ setError(err instanceof Error ? err.message : "Failed to fetch product");
115
+ } finally {
116
+ setIsLoading(false);
117
+ }
118
+ }
119
+ fetchProduct();
120
+ }, [slug, serverUrl]);
121
+ return { product, isLoading, error };
122
+ }
89
123
  export {
90
124
  CheckoutButton,
91
- useCheckout
125
+ useCheckout,
126
+ useProduct
92
127
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sintecinformatik/checkout",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Checkout components for Sintec License Server",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",