@apolopay-sdk/react 1.0.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,66 @@
1
+ # @apolopay-sdk/react
2
+
3
+ React wrapper for the Apolo Pay SDK. Provides a convenient component to integrate the Apolo Pay payment button into React applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @apolopay-sdk/react
9
+ # or
10
+ pnpm add @apolopay-sdk/react
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { ApoloPayButton, ApoloPayClient, type ClientResponse, type ClientError } from '@apolopay-sdk/react';
17
+
18
+ // 1. Initialize the client
19
+ const client = new ApoloPayClient({
20
+ publicKey: 'pk_test_...',
21
+ });
22
+
23
+ function App() {
24
+ const handleSuccess = (response: ClientResponse) => {
25
+ console.log('Payment successful!', response);
26
+ };
27
+
28
+ const handleError = (error: ClientError) => {
29
+ console.error('Payment error:', error);
30
+ };
31
+
32
+ return (
33
+ <div className="App">
34
+ <h1>My Store</h1>
35
+
36
+ {/* 2. Use the component */}
37
+ <ApoloPayButton
38
+ client={client}
39
+ processId="your-process-id"
40
+ productTitle="Order #12345"
41
+ lang="es"
42
+ onSuccess={handleSuccess}
43
+ onError={handleError}
44
+ barrierDismissible={true}
45
+ />
46
+ </div>
47
+ );
48
+ }
49
+ ```
50
+
51
+ ## Props
52
+
53
+ The `ApoloPayButton` component accepts the following props:
54
+
55
+ - `client`: (ApoloPayClient) **Required**. Instance of ApoloPayClient.
56
+ - `processId`: (string) **Required**. The UUID of the payment process.
57
+ - `productTitle`: (string) Title to display in the modal.
58
+ - `lang`: ('es' | 'en') Language.
59
+ - `label`: (string) Custom label for the button.
60
+ - `barrierDismissible`: (boolean) If true, clicking backdrop closes modal.
61
+ - `onSuccess`: (function) Callback when payment completes.
62
+ - `onError`: (function) Callback when an error occurs.
63
+
64
+ ## License
65
+
66
+ MIT
@@ -0,0 +1,20 @@
1
+ import { ApoloPayClient, Locale, ClientResponse, ClientError } from '@apolopay-sdk/ui';
2
+ export * from '@apolopay-sdk/ui';
3
+ import React from 'react';
4
+
5
+ type ApoloPayButtonProps = {
6
+ client?: ApoloPayClient;
7
+ processId?: string;
8
+ productTitle?: string;
9
+ lang?: Locale;
10
+ barrierDismissible?: boolean;
11
+ children?: React.ReactNode;
12
+ disabled?: boolean;
13
+ loading?: boolean;
14
+ label?: string;
15
+ onSuccess?: (response: ClientResponse) => void;
16
+ onError?: (error: ClientError) => void;
17
+ };
18
+ declare const ApoloPayButton: React.FC<ApoloPayButtonProps>;
19
+
20
+ export { ApoloPayButton };
@@ -0,0 +1,20 @@
1
+ import { ApoloPayClient, Locale, ClientResponse, ClientError } from '@apolopay-sdk/ui';
2
+ export * from '@apolopay-sdk/ui';
3
+ import React from 'react';
4
+
5
+ type ApoloPayButtonProps = {
6
+ client?: ApoloPayClient;
7
+ processId?: string;
8
+ productTitle?: string;
9
+ lang?: Locale;
10
+ barrierDismissible?: boolean;
11
+ children?: React.ReactNode;
12
+ disabled?: boolean;
13
+ loading?: boolean;
14
+ label?: string;
15
+ onSuccess?: (response: ClientResponse) => void;
16
+ onError?: (error: ClientError) => void;
17
+ };
18
+ declare const ApoloPayButton: React.FC<ApoloPayButtonProps>;
19
+
20
+ export { ApoloPayButton };
package/dist/index.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.tsx
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ ApoloPayButton: () => ApoloPayButton
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+ var import_ui = require("@apolopay-sdk/ui");
38
+ var import_react = __toESM(require("react"));
39
+ __reExport(src_exports, require("@apolopay-sdk/ui"), module.exports);
40
+ var ApoloPayButton = ({
41
+ client,
42
+ processId,
43
+ productTitle,
44
+ lang,
45
+ barrierDismissible,
46
+ children,
47
+ disabled,
48
+ loading,
49
+ label,
50
+ onSuccess,
51
+ onError
52
+ }) => {
53
+ const ref = (0, import_react.useRef)(null);
54
+ (0, import_react.useEffect)(() => {
55
+ const node = ref.current;
56
+ if (!node)
57
+ return;
58
+ const handleSuccess = (event) => {
59
+ onSuccess?.(event.detail);
60
+ };
61
+ const handleError = (event) => {
62
+ onError?.(event.detail);
63
+ };
64
+ node.addEventListener("success", handleSuccess);
65
+ node.addEventListener("error", handleError);
66
+ return () => {
67
+ node.removeEventListener("success", handleSuccess);
68
+ node.removeEventListener("error", handleError);
69
+ };
70
+ }, [onSuccess, onError]);
71
+ return import_react.default.createElement(
72
+ "apolopay-button",
73
+ {
74
+ ref,
75
+ client,
76
+ "process-id": processId,
77
+ "product-title": productTitle,
78
+ lang,
79
+ disabled,
80
+ loading,
81
+ label,
82
+ "barrier-dismissible": barrierDismissible
83
+ },
84
+ children
85
+ );
86
+ };
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ ApoloPayButton,
90
+ ...require("@apolopay-sdk/ui")
91
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,54 @@
1
+ // src/index.tsx
2
+ import "@apolopay-sdk/ui";
3
+ import React, { useRef, useEffect } from "react";
4
+ export * from "@apolopay-sdk/ui";
5
+ var ApoloPayButton = ({
6
+ client,
7
+ processId,
8
+ productTitle,
9
+ lang,
10
+ barrierDismissible,
11
+ children,
12
+ disabled,
13
+ loading,
14
+ label,
15
+ onSuccess,
16
+ onError
17
+ }) => {
18
+ const ref = useRef(null);
19
+ useEffect(() => {
20
+ const node = ref.current;
21
+ if (!node)
22
+ return;
23
+ const handleSuccess = (event) => {
24
+ onSuccess?.(event.detail);
25
+ };
26
+ const handleError = (event) => {
27
+ onError?.(event.detail);
28
+ };
29
+ node.addEventListener("success", handleSuccess);
30
+ node.addEventListener("error", handleError);
31
+ return () => {
32
+ node.removeEventListener("success", handleSuccess);
33
+ node.removeEventListener("error", handleError);
34
+ };
35
+ }, [onSuccess, onError]);
36
+ return React.createElement(
37
+ "apolopay-button",
38
+ {
39
+ ref,
40
+ client,
41
+ "process-id": processId,
42
+ "product-title": productTitle,
43
+ lang,
44
+ disabled,
45
+ loading,
46
+ label,
47
+ "barrier-dismissible": barrierDismissible
48
+ },
49
+ children
50
+ );
51
+ };
52
+ export {
53
+ ApoloPayButton
54
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@apolopay-sdk/react",
3
+ "version": "1.0.0",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "dependencies": {
8
+ "@apolopay-sdk/ui": "1.0.0"
9
+ },
10
+ "devDependencies": {
11
+ "@types/react": "18.3.3",
12
+ "react": "18.3.1",
13
+ "tsup": "8.0.0",
14
+ "typescript": "5.4.5"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "peerDependencies": {
23
+ "react": ">=16.8.0"
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.mjs",
29
+ "require": "./dist/index.js"
30
+ }
31
+ },
32
+ "scripts": {
33
+ "build": "tsup src/index.tsx --format esm,cjs --dts --clean --external react @apolopay-sdk/ui",
34
+ "dev": "tsup src/index.tsx --format esm,cjs --dts --watch --external react @apolopay-sdk/ui"
35
+ }
36
+ }