@apiosk/checkout-react 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/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # `@apiosk/checkout-react`
2
+
3
+ React and Next.js wrapper for the Apiosk four-layer checkout button.
4
+
5
+ This package does not reimplement the UI logic. It mounts the shared
6
+ `@apiosk/checkout-web` custom element and passes the normalized config through
7
+ to that runtime.
8
+
9
+ ## Install
10
+
11
+ After publish:
12
+
13
+ ```bash
14
+ npm install @apiosk/checkout-react @apiosk/checkout-web @apiosk/checkout-core
15
+ ```
16
+
17
+ Before publish:
18
+
19
+ ```bash
20
+ npm install ./subs/checkout-react ./subs/checkout-web ./subs/checkout-core
21
+ ```
22
+
23
+ ## Quick start
24
+
25
+ ```tsx
26
+ import { PayWithApioskButton } from "@apiosk/checkout-react";
27
+
28
+ export function MerchantCheckout() {
29
+ return (
30
+ <PayWithApioskButton
31
+ merchantName="Northstar Marketplace"
32
+ productName="Automation bundle"
33
+ amountLabel="24.95 EUR"
34
+ orderReference="ord_2048"
35
+ subtitle="One trigger for humans, agents, and programmable rails."
36
+ rails={[
37
+ {
38
+ id: "credits",
39
+ status: "live",
40
+ launchUrl: "https://gateway.apiosk.com/geocode/forward",
41
+ },
42
+ {
43
+ id: "x402",
44
+ status: "live",
45
+ launchUrl: "https://gateway.apiosk.com/geocode/forward",
46
+ },
47
+ {
48
+ id: "agent",
49
+ status: "pilot",
50
+ },
51
+ ]}
52
+ callbacks={{
53
+ successUrl: "https://merchant.example/success",
54
+ cancelUrl: "https://merchant.example/cancel",
55
+ webhookUrl: "https://merchant.example/webhooks/apiosk",
56
+ }}
57
+ />
58
+ );
59
+ }
60
+ ```
61
+
62
+ ## Ref API
63
+
64
+ ```tsx
65
+ import { useRef } from "react";
66
+ import { PayWithApioskButton } from "@apiosk/checkout-react";
67
+
68
+ const checkoutRef = useRef(null);
69
+
70
+ <PayWithApioskButton ref={checkoutRef} config={config} />;
71
+
72
+ checkoutRef.current?.openCheckout();
73
+ ```
74
+
75
+ The component exposes:
76
+
77
+ - `openCheckout()`
78
+ - `closeCheckout()`
79
+ - `element`
80
+
81
+ ## Why this wrapper exists
82
+
83
+ The React package should stay thin. The DOM runtime belongs in
84
+ `@apiosk/checkout-web`, and the shared schema belongs in
85
+ `@apiosk/checkout-core`.
86
+
87
+ That keeps React, Vue, and plain HTML integrations aligned around one contract.
package/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import type { CSSProperties, ForwardRefExoticComponent, RefAttributes } from "react";
2
+ import type { CheckoutConfigInput } from "@apiosk/checkout-core";
3
+
4
+ export interface ApioskCheckoutButtonHandle {
5
+ element: HTMLElement | null;
6
+ openCheckout(): void;
7
+ closeCheckout(): void;
8
+ }
9
+
10
+ export interface ApioskCheckoutButtonProps extends CheckoutConfigInput {
11
+ config?: CheckoutConfigInput;
12
+ className?: string;
13
+ style?: CSSProperties;
14
+ testId?: string;
15
+ onReady?: (element: HTMLElement) => void;
16
+ }
17
+
18
+ export declare const ApioskCheckoutButton: ForwardRefExoticComponent<
19
+ ApioskCheckoutButtonProps & RefAttributes<ApioskCheckoutButtonHandle>
20
+ >;
21
+
22
+ export declare const PayWithApioskButton: typeof ApioskCheckoutButton;
23
+ export declare function registerApioskCheckoutButton(): unknown;
24
+ export default ApioskCheckoutButton;
package/index.mjs ADDED
@@ -0,0 +1,66 @@
1
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
2
+ import { normalizeCheckoutConfig } from "@apiosk/checkout-core";
3
+ import {
4
+ CHECKOUT_ELEMENT_TAG,
5
+ registerApioskCheckoutButton,
6
+ serializeCheckoutConfig,
7
+ } from "@apiosk/checkout-web";
8
+
9
+ export const ApioskCheckoutButton = forwardRef(function ApioskCheckoutButton(
10
+ props,
11
+ forwardedRef,
12
+ ) {
13
+ const elementRef = useRef(null);
14
+ const {
15
+ config,
16
+ className,
17
+ style,
18
+ testId,
19
+ onReady,
20
+ ...flatConfig
21
+ } = props || {};
22
+ const normalizedConfig = normalizeCheckoutConfig(config || flatConfig);
23
+ const serializedConfig = serializeCheckoutConfig(normalizedConfig);
24
+
25
+ useEffect(() => {
26
+ registerApioskCheckoutButton();
27
+ }, []);
28
+
29
+ useEffect(() => {
30
+ if (!elementRef.current) {
31
+ return;
32
+ }
33
+
34
+ elementRef.current.config = normalizedConfig;
35
+
36
+ if (typeof onReady === "function") {
37
+ onReady(elementRef.current);
38
+ }
39
+ }, [normalizedConfig, onReady]);
40
+
41
+ useImperativeHandle(
42
+ forwardedRef,
43
+ () => ({
44
+ get element() {
45
+ return elementRef.current;
46
+ },
47
+ openCheckout: () => elementRef.current?.openCheckout?.(),
48
+ closeCheckout: () => elementRef.current?.closeCheckout?.(),
49
+ }),
50
+ [],
51
+ );
52
+
53
+ return React.createElement(CHECKOUT_ELEMENT_TAG, {
54
+ ref: (value) => {
55
+ elementRef.current = value;
56
+ },
57
+ config: serializedConfig,
58
+ className,
59
+ style,
60
+ "data-testid": testId,
61
+ });
62
+ });
63
+
64
+ export const PayWithApioskButton = ApioskCheckoutButton;
65
+ export { registerApioskCheckoutButton };
66
+ export default ApioskCheckoutButton;
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@apiosk/checkout-react",
3
+ "version": "0.1.0",
4
+ "description": "React wrapper for the Apiosk four-layer checkout button",
5
+ "type": "module",
6
+ "main": "./index.mjs",
7
+ "types": "./index.d.ts",
8
+ "files": [
9
+ "index.mjs",
10
+ "index.d.ts",
11
+ "README.md"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./index.d.ts",
16
+ "default": "./index.mjs"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "check": "node --check index.mjs"
21
+ },
22
+ "keywords": [
23
+ "apiosk",
24
+ "checkout",
25
+ "react",
26
+ "nextjs",
27
+ "payments"
28
+ ],
29
+ "author": "Apiosk",
30
+ "license": "MIT",
31
+ "homepage": "https://docs.apiosk.com",
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "dependencies": {
36
+ "@apiosk/checkout-core": "^0.1.0",
37
+ "@apiosk/checkout-web": "^0.1.0"
38
+ },
39
+ "peerDependencies": {
40
+ "react": ">=18",
41
+ "react-dom": ">=18"
42
+ }
43
+ }