@one-payments/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,237 @@
1
+ # @one-payments/react
2
+
3
+ React wrapper component for One Payments SDK. Use this package to integrate One Payments into your React applications with a native React component API.
4
+
5
+ ## Features
6
+
7
+ - Native React component wrapping One Payments web component
8
+ - Full TypeScript support with type definitions
9
+ - React event handlers instead of DOM events
10
+ - Seamless integration with React hooks and lifecycle
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @one-payments/react @one-payments/adapters-web
16
+ # or
17
+ yarn add @one-payments/react @one-payments/adapters-web
18
+ # or
19
+ pnpm add @one-payments/react @one-payments/adapters-web
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Basic Example
25
+
26
+ ```tsx
27
+ import React from 'react';
28
+ import { OnePayment } from '@one-payments/react';
29
+ import { createWebAdapters } from '@one-payments/adapters-web';
30
+ import type { PaymentSucceededPayload, PaymentFailedPayload } from '@one-payments/react';
31
+
32
+ function CheckoutPage() {
33
+ const adapters = createWebAdapters();
34
+
35
+ const handleSuccess = (event: CustomEvent<PaymentSucceededPayload>) => {
36
+ console.log('Payment successful!', event.detail);
37
+ // Navigate to success page or show confirmation
38
+ };
39
+
40
+ const handleError = (event: CustomEvent<PaymentFailedPayload>) => {
41
+ console.error('Payment failed:', event.detail);
42
+ // Show error message to user
43
+ };
44
+
45
+ return (
46
+ <div className="checkout">
47
+ <h1>Complete Your Payment</h1>
48
+ <OnePayment
49
+ config={{
50
+ apiKey: 'your-api-key',
51
+ secretKey: 'your-secret-key',
52
+ environment: 'prod'
53
+ }}
54
+ adapters={adapters}
55
+ amount={5000}
56
+ currency="SGD"
57
+ orderId={`order-${Date.now()}`}
58
+ onPaymentSuccess={handleSuccess}
59
+ onPaymentError={handleError}
60
+ />
61
+ </div>
62
+ );
63
+ }
64
+
65
+ export default CheckoutPage;
66
+ ```
67
+
68
+ ### With State Management
69
+
70
+ ```tsx
71
+ import React, { useState } from 'react';
72
+ import { OnePayment } from '@one-payments/react';
73
+ import { createWebAdapters } from '@one-payments/adapters-web';
74
+ import type {
75
+ PaymentSucceededPayload,
76
+ PaymentFailedPayload,
77
+ StateChangedPayload
78
+ } from '@one-payments/react';
79
+
80
+ function CheckoutWithState() {
81
+ const [paymentStatus, setPaymentStatus] = useState<'idle' | 'processing' | 'success' | 'error'>('idle');
82
+ const [errorMessage, setErrorMessage] = useState<string>('');
83
+
84
+ const adapters = createWebAdapters();
85
+
86
+ const handleSuccess = (event: CustomEvent<PaymentSucceededPayload>) => {
87
+ setPaymentStatus('success');
88
+ console.log('Payment Intent ID:', event.detail.paymentIntentId);
89
+ };
90
+
91
+ const handleError = (event: CustomEvent<PaymentFailedPayload>) => {
92
+ setPaymentStatus('error');
93
+ setErrorMessage(event.detail.message);
94
+ };
95
+
96
+ const handleStateChange = (event: CustomEvent<StateChangedPayload>) => {
97
+ console.log('Payment state:', event.detail.status);
98
+ if (event.detail.status === 'processing') {
99
+ setPaymentStatus('processing');
100
+ }
101
+ };
102
+
103
+ if (paymentStatus === 'success') {
104
+ return <div>Payment successful! Thank you for your order.</div>;
105
+ }
106
+
107
+ return (
108
+ <div>
109
+ {paymentStatus === 'error' && (
110
+ <div className="error">{errorMessage}</div>
111
+ )}
112
+ {paymentStatus === 'processing' && (
113
+ <div className="processing">Processing your payment...</div>
114
+ )}
115
+ <OnePayment
116
+ config={{
117
+ apiKey: process.env.REACT_APP_ONE_PAYMENTS_API_KEY!,
118
+ secretKey: process.env.REACT_APP_ONE_PAYMENTS_SECRET_KEY!,
119
+ environment: 'prod'
120
+ }}
121
+ adapters={adapters}
122
+ amount={5000}
123
+ currency="SGD"
124
+ orderId={`order-${Date.now()}`}
125
+ metadata={{
126
+ userId: '12345',
127
+ productId: 'product-abc'
128
+ }}
129
+ onPaymentSuccess={handleSuccess}
130
+ onPaymentError={handleError}
131
+ onStateChange={handleStateChange}
132
+ />
133
+ </div>
134
+ );
135
+ }
136
+ ```
137
+
138
+ ### With React Router
139
+
140
+ ```tsx
141
+ import React from 'react';
142
+ import { useNavigate } from 'react-router-dom';
143
+ import { OnePayment } from '@one-payments/react';
144
+ import { createWebAdapters } from '@one-payments/adapters-web';
145
+
146
+ function CheckoutPage() {
147
+ const navigate = useNavigate();
148
+ const adapters = createWebAdapters();
149
+
150
+ return (
151
+ <OnePayment
152
+ config={{
153
+ apiKey: process.env.REACT_APP_ONE_PAYMENTS_API_KEY!,
154
+ secretKey: process.env.REACT_APP_ONE_PAYMENTS_SECRET_KEY!,
155
+ environment: 'prod'
156
+ }}
157
+ adapters={adapters}
158
+ amount={5000}
159
+ currency="SGD"
160
+ orderId={`order-${Date.now()}`}
161
+ onPaymentSuccess={(event) => {
162
+ navigate('/success', {
163
+ state: { paymentId: event.detail.paymentIntentId }
164
+ });
165
+ }}
166
+ onPaymentError={(event) => {
167
+ navigate('/error', {
168
+ state: { error: event.detail.message }
169
+ });
170
+ }}
171
+ />
172
+ );
173
+ }
174
+ ```
175
+
176
+ ## API Reference
177
+
178
+ ### OnePayment Props
179
+
180
+ | Prop | Type | Required | Description |
181
+ |------|------|----------|-------------|
182
+ | `config` | `SDKConfig` | Yes | SDK configuration with API keys and environment |
183
+ | `adapters` | `Adapters` | Yes | Platform adapters (use `createWebAdapters()` for web) |
184
+ | `amount` | `number` | Yes | Payment amount in smallest currency unit (e.g., cents) |
185
+ | `currency` | `string` | Yes | ISO currency code (e.g., "USD", "EUR", "SGD") |
186
+ | `orderId` | `string` | Yes | Unique order identifier |
187
+ | `metadata` | `Record<string, string \| number \| boolean>` | No | Additional metadata to attach to the payment |
188
+ | `onPaymentSuccess` | `(event: CustomEvent<PaymentSucceededPayload>) => void` | No | Callback when payment succeeds |
189
+ | `onPaymentError` | `(event: CustomEvent<PaymentFailedPayload>) => void` | No | Callback when payment fails |
190
+ | `onStateChange` | `(event: CustomEvent<StateChangedPayload>) => void` | No | Callback when payment state changes |
191
+
192
+ ### Types
193
+
194
+ ```typescript
195
+ interface SDKConfig {
196
+ apiKey: string;
197
+ secretKey: string;
198
+ environment: 'dev' | 'staging' | 'prod';
199
+ }
200
+
201
+ interface PaymentSucceededPayload {
202
+ paymentIntentId: string;
203
+ amount: number;
204
+ currency: string;
205
+ status: 'succeeded';
206
+ metadata?: Record<string, unknown>;
207
+ }
208
+
209
+ interface PaymentFailedPayload {
210
+ code: string;
211
+ message: string;
212
+ details?: Record<string, unknown>;
213
+ }
214
+
215
+ interface StateChangedPayload {
216
+ status: 'idle' | 'initializing' | 'ready' | 'processing' | 'requires_action' | 'succeeded' | 'failed';
217
+ [key: string]: unknown;
218
+ }
219
+ ```
220
+
221
+ ## Requirements
222
+
223
+ - React >= 16.8.0 (hooks support)
224
+ - TypeScript >= 5.0.0 (for TypeScript projects)
225
+
226
+ ## Related Packages
227
+
228
+ - [@one-payments/core](../core) - Core SDK types and interfaces
229
+ - [@one-payments/web-components](../web-components) - Underlying web component
230
+ - [@one-payments/adapters-web](../adapters-web) - Web platform adapters
231
+ - [@one-payments/vue](../vue) - Vue wrapper
232
+ - [@one-payments/angular](../angular) - Angular wrapper
233
+ - [@one-payments/react-native](../react-native) - React Native implementation
234
+
235
+ ## License
236
+
237
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var react = require('@lit/react');
5
+ var webComponents = require('@one-payments/web-components');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var React__default = /*#__PURE__*/_interopDefault(React);
10
+
11
+ // src/OnePayment.tsx
12
+ var OnePayment = react.createComponent({
13
+ tagName: "one-payment",
14
+ elementClass: webComponents.OnePaymentElement,
15
+ react: React__default.default,
16
+ events: {
17
+ onPaymentSuccess: "payment-success",
18
+ onPaymentError: "payment-error",
19
+ onStateChange: "state-change"
20
+ }
21
+ });
22
+
23
+ exports.OnePayment = OnePayment;
24
+ //# sourceMappingURL=index.cjs.map
25
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/OnePayment.tsx"],"names":["createComponent","OnePaymentElement","React"],"mappings":";;;;;;;;;;;AAoBO,IAAM,aAAaA,qBAAA,CAAgB;AAAA,EACxC,OAAA,EAAS,aAAA;AAAA,EACT,YAAA,EAAcC,+BAAA;AAAA,EACd,KAAA,EAAOC,sBAAA;AAAA,EACP,MAAA,EAAQ;AAAA,IACN,gBAAA,EAAkB,iBAAA;AAAA,IAClB,cAAA,EAAgB,eAAA;AAAA,IAChB,aAAA,EAAe;AAAA;AAEnB,CAAC","file":"index.cjs","sourcesContent":["/**\n * React wrapper for <one-payment> web component\n * @module @one-payments/react\n */\n\nimport React from 'react';\nimport { createComponent } from '@lit/react';\nimport { OnePaymentElement } from '@one-payments/web-components';\nimport type {\n SDKConfig,\n PaymentSucceededPayload,\n PaymentFailedPayload,\n StateChangedPayload,\n Adapters,\n} from '@one-payments/core';\n\n/**\n * React component wrapping <one-payment> custom element\n * Uses unified tag name: one-payment\n */\nexport const OnePayment = createComponent({\n tagName: 'one-payment',\n elementClass: OnePaymentElement,\n react: React,\n events: {\n onPaymentSuccess: 'payment-success',\n onPaymentError: 'payment-error',\n onStateChange: 'state-change',\n },\n});\n\n/**\n * Typed props interface for OnePayment React component\n */\nexport interface OnePaymentProps {\n config: SDKConfig;\n adapters: Adapters;\n amount: number;\n currency: string;\n orderId: string;\n metadata?: Record<string, string | number | boolean>;\n onPaymentSuccess?: (event: CustomEvent<PaymentSucceededPayload>) => void;\n onPaymentError?: (event: CustomEvent<PaymentFailedPayload>) => void;\n onStateChange?: (event: CustomEvent<StateChangedPayload>) => void;\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import * as _lit_react from '@lit/react';
2
+ import { OnePaymentElement } from '@one-payments/web-components';
3
+ import { SDKConfig, Adapters, PaymentSucceededPayload, PaymentFailedPayload, StateChangedPayload } from '@one-payments/core';
4
+ export { Adapters, PaymentFailedPayload, PaymentIntent, PaymentSucceededPayload, SDKConfig, State, StateChangedPayload } from '@one-payments/core';
5
+
6
+ /**
7
+ * React component wrapping <one-payment> custom element
8
+ * Uses unified tag name: one-payment
9
+ */
10
+ declare const OnePayment: _lit_react.ReactWebComponent<OnePaymentElement, {
11
+ onPaymentSuccess: string;
12
+ onPaymentError: string;
13
+ onStateChange: string;
14
+ }>;
15
+ /**
16
+ * Typed props interface for OnePayment React component
17
+ */
18
+ interface OnePaymentProps {
19
+ config: SDKConfig;
20
+ adapters: Adapters;
21
+ amount: number;
22
+ currency: string;
23
+ orderId: string;
24
+ metadata?: Record<string, string | number | boolean>;
25
+ onPaymentSuccess?: (event: CustomEvent<PaymentSucceededPayload>) => void;
26
+ onPaymentError?: (event: CustomEvent<PaymentFailedPayload>) => void;
27
+ onStateChange?: (event: CustomEvent<StateChangedPayload>) => void;
28
+ }
29
+
30
+ export { OnePayment, type OnePaymentProps };
@@ -0,0 +1,30 @@
1
+ import * as _lit_react from '@lit/react';
2
+ import { OnePaymentElement } from '@one-payments/web-components';
3
+ import { SDKConfig, Adapters, PaymentSucceededPayload, PaymentFailedPayload, StateChangedPayload } from '@one-payments/core';
4
+ export { Adapters, PaymentFailedPayload, PaymentIntent, PaymentSucceededPayload, SDKConfig, State, StateChangedPayload } from '@one-payments/core';
5
+
6
+ /**
7
+ * React component wrapping <one-payment> custom element
8
+ * Uses unified tag name: one-payment
9
+ */
10
+ declare const OnePayment: _lit_react.ReactWebComponent<OnePaymentElement, {
11
+ onPaymentSuccess: string;
12
+ onPaymentError: string;
13
+ onStateChange: string;
14
+ }>;
15
+ /**
16
+ * Typed props interface for OnePayment React component
17
+ */
18
+ interface OnePaymentProps {
19
+ config: SDKConfig;
20
+ adapters: Adapters;
21
+ amount: number;
22
+ currency: string;
23
+ orderId: string;
24
+ metadata?: Record<string, string | number | boolean>;
25
+ onPaymentSuccess?: (event: CustomEvent<PaymentSucceededPayload>) => void;
26
+ onPaymentError?: (event: CustomEvent<PaymentFailedPayload>) => void;
27
+ onStateChange?: (event: CustomEvent<StateChangedPayload>) => void;
28
+ }
29
+
30
+ export { OnePayment, type OnePaymentProps };
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { createComponent } from '@lit/react';
3
+ import { OnePaymentElement } from '@one-payments/web-components';
4
+
5
+ // src/OnePayment.tsx
6
+ var OnePayment = createComponent({
7
+ tagName: "one-payment",
8
+ elementClass: OnePaymentElement,
9
+ react: React,
10
+ events: {
11
+ onPaymentSuccess: "payment-success",
12
+ onPaymentError: "payment-error",
13
+ onStateChange: "state-change"
14
+ }
15
+ });
16
+
17
+ export { OnePayment };
18
+ //# sourceMappingURL=index.js.map
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/OnePayment.tsx"],"names":[],"mappings":";;;;;AAoBO,IAAM,aAAa,eAAA,CAAgB;AAAA,EACxC,OAAA,EAAS,aAAA;AAAA,EACT,YAAA,EAAc,iBAAA;AAAA,EACd,KAAA,EAAO,KAAA;AAAA,EACP,MAAA,EAAQ;AAAA,IACN,gBAAA,EAAkB,iBAAA;AAAA,IAClB,cAAA,EAAgB,eAAA;AAAA,IAChB,aAAA,EAAe;AAAA;AAEnB,CAAC","file":"index.js","sourcesContent":["/**\n * React wrapper for <one-payment> web component\n * @module @one-payments/react\n */\n\nimport React from 'react';\nimport { createComponent } from '@lit/react';\nimport { OnePaymentElement } from '@one-payments/web-components';\nimport type {\n SDKConfig,\n PaymentSucceededPayload,\n PaymentFailedPayload,\n StateChangedPayload,\n Adapters,\n} from '@one-payments/core';\n\n/**\n * React component wrapping <one-payment> custom element\n * Uses unified tag name: one-payment\n */\nexport const OnePayment = createComponent({\n tagName: 'one-payment',\n elementClass: OnePaymentElement,\n react: React,\n events: {\n onPaymentSuccess: 'payment-success',\n onPaymentError: 'payment-error',\n onStateChange: 'state-change',\n },\n});\n\n/**\n * Typed props interface for OnePayment React component\n */\nexport interface OnePaymentProps {\n config: SDKConfig;\n adapters: Adapters;\n amount: number;\n currency: string;\n orderId: string;\n metadata?: Record<string, string | number | boolean>;\n onPaymentSuccess?: (event: CustomEvent<PaymentSucceededPayload>) => void;\n onPaymentError?: (event: CustomEvent<PaymentFailedPayload>) => void;\n onStateChange?: (event: CustomEvent<StateChangedPayload>) => void;\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@one-payments/react",
3
+ "version": "1.0.0",
4
+ "description": "React wrapper for One Payments SDK",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "dev": "tsup --watch",
22
+ "build": "tsup",
23
+ "typecheck": "tsc --noEmit",
24
+ "lint": "eslint src --ext .ts,.tsx",
25
+ "test": "vitest"
26
+ },
27
+ "peerDependencies": {
28
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
29
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
30
+ },
31
+ "dependencies": {
32
+ "@one-payments/core": "workspace:*",
33
+ "@one-payments/web-components": "workspace:*",
34
+ "@lit/react": "^1.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/react": "^18.2.0",
38
+ "@types/react-dom": "^18.2.0",
39
+ "react": "^18.2.0",
40
+ "react-dom": "^18.2.0",
41
+ "tsup": "^8.0.0",
42
+ "typescript": "^5.3.0",
43
+ "vitest": "^1.0.0"
44
+ },
45
+ "keywords": [
46
+ "react",
47
+ "payments",
48
+ "sdk",
49
+ "typescript"
50
+ ],
51
+ "publishConfig": {
52
+ "access": "public"
53
+ }
54
+ }