@coincircuit/checkout 0.1.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/dist/react.js ADDED
@@ -0,0 +1,67 @@
1
+ import {
2
+ CoinCircuitCheckout
3
+ } from "./chunk-VYS76EOY.js";
4
+
5
+ // src/react.ts
6
+ import { useRef, useCallback, useEffect, createElement } from "react";
7
+ function CoinCircuitCheckoutButton(props) {
8
+ const {
9
+ reference,
10
+ theme,
11
+ baseUrl,
12
+ publicKey,
13
+ label = "Pay with CoinCircuit",
14
+ className,
15
+ style,
16
+ disabled,
17
+ onReady,
18
+ onPaymentComplete,
19
+ onPaymentFailed,
20
+ onExpired,
21
+ onClose
22
+ } = props;
23
+ const checkoutRef = useRef(null);
24
+ const onReadyRef = useRef(onReady);
25
+ const onPaymentCompleteRef = useRef(onPaymentComplete);
26
+ const onPaymentFailedRef = useRef(onPaymentFailed);
27
+ const onExpiredRef = useRef(onExpired);
28
+ const onCloseRef = useRef(onClose);
29
+ onReadyRef.current = onReady;
30
+ onPaymentCompleteRef.current = onPaymentComplete;
31
+ onPaymentFailedRef.current = onPaymentFailed;
32
+ onExpiredRef.current = onExpired;
33
+ onCloseRef.current = onClose;
34
+ useEffect(() => {
35
+ checkoutRef.current = new CoinCircuitCheckout({ baseUrl, publicKey });
36
+ return () => {
37
+ checkoutRef.current?.close();
38
+ };
39
+ }, [baseUrl, publicKey]);
40
+ const handleClick = useCallback(() => {
41
+ if (!checkoutRef.current || !reference) return;
42
+ checkoutRef.current.open({
43
+ reference,
44
+ theme,
45
+ onReady: () => onReadyRef.current?.(),
46
+ onPaymentComplete: (data) => onPaymentCompleteRef.current?.(data),
47
+ onPaymentFailed: (data) => onPaymentFailedRef.current?.(data),
48
+ onExpired: () => onExpiredRef.current?.(),
49
+ onClose: () => onCloseRef.current?.()
50
+ });
51
+ }, [reference, theme]);
52
+ return createElement(
53
+ "button",
54
+ {
55
+ type: "button",
56
+ onClick: handleClick,
57
+ disabled: disabled || !reference,
58
+ className,
59
+ style,
60
+ "data-coincircuit-checkout": "true"
61
+ },
62
+ label
63
+ );
64
+ }
65
+ export {
66
+ CoinCircuitCheckoutButton
67
+ };
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Theme options for the checkout.
3
+ */
4
+ type CheckoutTheme = 'light' | 'dark';
5
+ /**
6
+ * Data returned when a payment completes successfully.
7
+ */
8
+ interface PaymentCompleteData {
9
+ reference: string;
10
+ transactionHash?: string;
11
+ status: string;
12
+ amount?: string;
13
+ currency?: string;
14
+ }
15
+ /**
16
+ * Error data returned when a payment fails.
17
+ */
18
+ interface PaymentFailedData {
19
+ reference: string;
20
+ code: string;
21
+ message: string;
22
+ }
23
+ /**
24
+ * Configuration for the CoinCircuitCheckout instance.
25
+ */
26
+ interface CheckoutConfig {
27
+ /**
28
+ * Public API key. Reserved for future use.
29
+ */
30
+ publicKey?: string;
31
+ /**
32
+ * Base URL of the checkout application.
33
+ * Defaults to "https://checkout.coincircuit.io".
34
+ */
35
+ baseUrl?: string;
36
+ }
37
+ /**
38
+ * Options passed to `checkout.open()` to launch the checkout modal.
39
+ */
40
+ interface CheckoutOptions {
41
+ /** The checkout session reference (e.g. "cs_ref_abc123"). */
42
+ reference: string;
43
+ /** Color theme for the checkout UI. Defaults to "light". */
44
+ theme?: CheckoutTheme;
45
+ /** Called when the checkout has loaded and is ready. */
46
+ onReady?: () => void;
47
+ /** Called when the payment completes successfully. */
48
+ onPaymentComplete?: (data: PaymentCompleteData) => void;
49
+ /** Called when the payment fails. */
50
+ onPaymentFailed?: (data: PaymentFailedData) => void;
51
+ /** Called when the checkout session has expired. */
52
+ onExpired?: () => void;
53
+ /** Called when the user closes the checkout modal. */
54
+ onClose?: () => void;
55
+ }
56
+ /**
57
+ * Props for the React CoinCircuitCheckoutButton component.
58
+ */
59
+ interface CheckoutButtonProps extends CheckoutOptions {
60
+ publicKey?: string;
61
+ baseUrl?: string;
62
+ /** Text to display on the button. Defaults to "Pay with CoinCircuit". */
63
+ label?: string;
64
+ /** Additional CSS class name(s) for the button element. */
65
+ className?: string;
66
+ /** Inline styles for the button element. */
67
+ style?: Record<string, string | number>;
68
+ /** Whether the button is disabled. */
69
+ disabled?: boolean;
70
+ }
71
+
72
+ export type { CheckoutConfig as C, PaymentCompleteData as P, CheckoutOptions as a, PaymentFailedData as b, CheckoutTheme as c, CheckoutButtonProps as d };
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Theme options for the checkout.
3
+ */
4
+ type CheckoutTheme = 'light' | 'dark';
5
+ /**
6
+ * Data returned when a payment completes successfully.
7
+ */
8
+ interface PaymentCompleteData {
9
+ reference: string;
10
+ transactionHash?: string;
11
+ status: string;
12
+ amount?: string;
13
+ currency?: string;
14
+ }
15
+ /**
16
+ * Error data returned when a payment fails.
17
+ */
18
+ interface PaymentFailedData {
19
+ reference: string;
20
+ code: string;
21
+ message: string;
22
+ }
23
+ /**
24
+ * Configuration for the CoinCircuitCheckout instance.
25
+ */
26
+ interface CheckoutConfig {
27
+ /**
28
+ * Public API key. Reserved for future use.
29
+ */
30
+ publicKey?: string;
31
+ /**
32
+ * Base URL of the checkout application.
33
+ * Defaults to "https://checkout.coincircuit.io".
34
+ */
35
+ baseUrl?: string;
36
+ }
37
+ /**
38
+ * Options passed to `checkout.open()` to launch the checkout modal.
39
+ */
40
+ interface CheckoutOptions {
41
+ /** The checkout session reference (e.g. "cs_ref_abc123"). */
42
+ reference: string;
43
+ /** Color theme for the checkout UI. Defaults to "light". */
44
+ theme?: CheckoutTheme;
45
+ /** Called when the checkout has loaded and is ready. */
46
+ onReady?: () => void;
47
+ /** Called when the payment completes successfully. */
48
+ onPaymentComplete?: (data: PaymentCompleteData) => void;
49
+ /** Called when the payment fails. */
50
+ onPaymentFailed?: (data: PaymentFailedData) => void;
51
+ /** Called when the checkout session has expired. */
52
+ onExpired?: () => void;
53
+ /** Called when the user closes the checkout modal. */
54
+ onClose?: () => void;
55
+ }
56
+ /**
57
+ * Props for the React CoinCircuitCheckoutButton component.
58
+ */
59
+ interface CheckoutButtonProps extends CheckoutOptions {
60
+ publicKey?: string;
61
+ baseUrl?: string;
62
+ /** Text to display on the button. Defaults to "Pay with CoinCircuit". */
63
+ label?: string;
64
+ /** Additional CSS class name(s) for the button element. */
65
+ className?: string;
66
+ /** Inline styles for the button element. */
67
+ style?: Record<string, string | number>;
68
+ /** Whether the button is disabled. */
69
+ disabled?: boolean;
70
+ }
71
+
72
+ export type { CheckoutConfig as C, PaymentCompleteData as P, CheckoutOptions as a, PaymentFailedData as b, CheckoutTheme as c, CheckoutButtonProps as d };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@coincircuit/checkout",
3
+ "version": "0.1.0",
4
+ "description": "Embed CoinCircuit checkout in your site via iframe, with vanilla JS and React support",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./react": {
15
+ "types": "./dist/react.d.ts",
16
+ "import": "./dist/react.js",
17
+ "require": "./dist/react.cjs"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsup src/index.ts src/react.ts --format esm,cjs --dts --clean",
25
+ "typecheck": "tsc --noEmit"
26
+ },
27
+ "engines": {
28
+ "node": ">=18.0.0"
29
+ },
30
+ "keywords": [
31
+ "coincircuit",
32
+ "checkout",
33
+ "crypto",
34
+ "payments",
35
+ "embed",
36
+ "iframe",
37
+ "stablecoin",
38
+ "sdk"
39
+ ],
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/coincircuit/coincircuit-checkout"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=17.0.0",
47
+ "react-dom": ">=17.0.0"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "react": {
51
+ "optional": true
52
+ },
53
+ "react-dom": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@types/react": "^18.2.0",
59
+ "@types/react-dom": "^18.2.0",
60
+ "react": "^18.2.0",
61
+ "react-dom": "^18.2.0",
62
+ "tsup": "^8.0.0",
63
+ "typescript": "^5.4.0"
64
+ }
65
+ }