@payconductor-sdk-web/library-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.
Files changed (2) hide show
  1. package/README.md +241 -0
  2. package/package.json +51 -0
package/README.md ADDED
@@ -0,0 +1,241 @@
1
+ # @payconductor-sdk-web/library-react
2
+
3
+ React SDK for integrating with PayConductor Payment Gateway.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @payconductor-sdk-web/library-react
9
+ # or
10
+ yarn add @payconductor-sdk-web/library-react
11
+ # or
12
+ pnpm add @payconductor-sdk-web/library-react
13
+ ```
14
+
15
+ ## Basic Usage
16
+
17
+ ```tsx
18
+ "use client";
19
+
20
+ import {
21
+ PayConductor,
22
+ useElement,
23
+ usePayConductor,
24
+ type PaymentResult,
25
+ } from "@payconductor-sdk-web/library-react";
26
+ import { useState, useEffect } from "react";
27
+
28
+ function CheckoutForm() {
29
+ const { isReady, error } = usePayConductor();
30
+ const { submit, confirmPayment, update } = useElement();
31
+
32
+ const [errorMessage, setErrorMessage] = useState<string | null>(null);
33
+ const [isProcessing, setIsProcessing] = useState(false);
34
+ const [clientName, setClientName] = useState("");
35
+ const [clientEmail, setClientEmail] = useState("");
36
+
37
+ useEffect(() => {
38
+ update({
39
+ billingDetails: {
40
+ name: clientName,
41
+ email: clientEmail,
42
+ },
43
+ });
44
+ }, [clientName, clientEmail, update]);
45
+
46
+ const handleSubmit = async (event: React.FormEvent) => {
47
+ event.preventDefault();
48
+
49
+ if (!isReady) return;
50
+
51
+ setIsProcessing(true);
52
+ setErrorMessage(null);
53
+
54
+ try {
55
+ const { error: submitError } = await submit();
56
+
57
+ if (submitError) {
58
+ setErrorMessage(submitError.message || "Validation failed");
59
+ setIsProcessing(false);
60
+ return;
61
+ }
62
+
63
+ const result: PaymentResult = await confirmPayment({
64
+ intentToken: "pi_xxx_intent_token_xxx",
65
+ returnUrl: window.location.href,
66
+ });
67
+
68
+ if (result.status === "succeeded") {
69
+ alert("Payment successful!");
70
+ }
71
+ } catch (err: any) {
72
+ setErrorMessage(err.message || "Payment failed");
73
+ } finally {
74
+ setIsProcessing(false);
75
+ }
76
+ };
77
+
78
+ return (
79
+ <form onSubmit={handleSubmit}>
80
+ <input
81
+ type="text"
82
+ placeholder="Full name"
83
+ value={clientName}
84
+ onChange={(e) => setClientName(e.target.value)}
85
+ />
86
+ <input
87
+ type="email"
88
+ placeholder="Email"
89
+ value={clientEmail}
90
+ onChange={(e) => setClientEmail(e.target.value)}
91
+ />
92
+ <button type="submit" disabled={!isReady || isProcessing}>
93
+ {isProcessing ? "Processing..." : "Pay now"}
94
+ </button>
95
+ {errorMessage && <div>{errorMessage}</div>}
96
+ {error && <div>Error: {error}</div>}
97
+ </form>
98
+ );
99
+ }
100
+
101
+ export default function App() {
102
+ return (
103
+ <PayConductor
104
+ publicKey="pk_test_123"
105
+ intentToken="pi_test_abc123"
106
+ theme={{ primaryColor: "#0066ff" }}
107
+ locale="en-US"
108
+ height="500px"
109
+ onReady={() => console.log("Ready")}
110
+ onError={(err) => console.error(err)}
111
+ onPaymentComplete={(result) => console.log(result)}
112
+ >
113
+ <CheckoutForm />
114
+ </PayConductor>
115
+ );
116
+ }
117
+ ```
118
+
119
+ ## API Reference
120
+
121
+ ### `<PayConductor />`
122
+
123
+ Main component that initializes the payment iframe.
124
+
125
+ | Prop | Type | Description |
126
+ |------|------|-------------|
127
+ | `publicKey` | `string` | Your PayConductor public key |
128
+ | `intentToken` | `string` | Payment intent token |
129
+ | `theme` | `PayConductorTheme` | Theme configuration |
130
+ | `locale` | `string` | Locale (e.g., 'en-US', 'pt-BR') |
131
+ | `height` | `string` | Iframe height (default: '500px') |
132
+ | `onReady` | `() => void` | Callback when iframe is ready |
133
+ | `onError` | `(error: Error) => void` | Error callback |
134
+ | `onPaymentComplete` | `(result: PaymentResult) => void` | Payment complete callback |
135
+
136
+ ### `usePayConductor()`
137
+
138
+ Hook that returns frame state and configuration.
139
+
140
+ ```tsx
141
+ const { isReady, error, publicKey, intentToken, theme, locale } = usePayConductor();
142
+ ```
143
+
144
+ | Property | Type | Description |
145
+ |----------|------|-------------|
146
+ | `isReady` | `boolean` | Whether iframe is ready |
147
+ | `error` | `string \| null` | Error message if any |
148
+ | `publicKey` | `string` | Public key from config |
149
+ | `intentToken` | `string` | Intent token from config |
150
+ | `theme` | `PayConductorTheme` | Theme from config |
151
+ | `locale` | `string` | Locale from config |
152
+
153
+ ### `useElement()`
154
+
155
+ Hook that provides payment methods.
156
+
157
+ ```tsx
158
+ const {
159
+ submit,
160
+ confirmPayment,
161
+ update,
162
+ validate,
163
+ reset,
164
+ updateConfig,
165
+ updateIntentToken
166
+ } = useElement();
167
+ ```
168
+
169
+ | Method | Description |
170
+ |--------|-------------|
171
+ | `submit()` | Submits the form, returns `{ error?, paymentMethod? }` |
172
+ | `confirmPayment(options)` | Confirms payment with `{ intentToken, returnUrl? }` |
173
+ | `update(options)` | Updates billing details `{ billingDetails?: { name, email, phone, address } }` |
174
+ | `validate(data)` | Validates payment data |
175
+ | `reset()` | Resets the payment form |
176
+ | `updateConfig(config)` | Updates theme, locale, or paymentMethods config |
177
+ | `updateIntentToken(token)` | Updates the intent token |
178
+
179
+ ## Theming
180
+
181
+ ```tsx
182
+ const theme: PayConductorTheme = {
183
+ primaryColor: "#0066ff",
184
+ secondaryColor: "#5a6b7c",
185
+ backgroundColor: "transparent",
186
+ surfaceColor: "#f8fafc",
187
+ textColor: "#0f172a",
188
+ textSecondaryColor: "#64748b",
189
+ errorColor: "#ef4444",
190
+ successColor: "#22c55e",
191
+ warningColor: "#f59e0b",
192
+ borderColor: "#e2e8f0",
193
+ disabledColor: "#cbd5e1",
194
+ fontFamily: '"Poppins", sans-serif',
195
+ fontSize: { xs: "0.75rem", sm: "0.875rem", md: "1rem", lg: "1.125rem", xl: "1.25rem" },
196
+ fontWeight: { normal: 400, medium: 500, bold: 600 },
197
+ lineHeight: "1.5",
198
+ spacing: { xs: "4px", sm: "8px", md: "16px", lg: "24px", xl: "32px" },
199
+ borderRadius: "8px",
200
+ borderWidth: "1px",
201
+ boxShadow: "0 1px 3px 0 rgb(0 0 0 / 0.1)",
202
+ inputBackground: "#ffffff",
203
+ inputBorderColor: "#cbd5e1",
204
+ inputBorderRadius: "8px",
205
+ inputHeight: "44px",
206
+ inputPadding: "12px 16px",
207
+ buttonHeight: "48px",
208
+ buttonPadding: "16px 24px",
209
+ buttonBorderRadius: "8px",
210
+ transitionDuration: "0.2s",
211
+ };
212
+ ```
213
+
214
+ ## Types
215
+
216
+ ```tsx
217
+ type PaymentResult = {
218
+ paymentIntentId: string;
219
+ status: "succeeded" | "pending" | "failed";
220
+ amount: number;
221
+ currency: string;
222
+ };
223
+
224
+ type BillingDetails = {
225
+ name: string;
226
+ email?: string;
227
+ phone?: string;
228
+ address?: {
229
+ line1: string;
230
+ line2?: string;
231
+ city: string;
232
+ state: string;
233
+ postalCode: string;
234
+ country: string;
235
+ };
236
+ };
237
+ ```
238
+
239
+ ## License
240
+
241
+ MIT
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@payconductor-sdk-web/library-react",
3
+ "version": "1.0.0",
4
+ "description": "React SDK for PayConductor",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "http://github.com/payconductor-ai/payconductor-sdk-web"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/payconductor-ai/payconductor-sdk-web/issues"
18
+ },
19
+ "homepage": "https://github.com/payconductor-ai/payconductor-sdk-web#readme",
20
+ "license": "MIT",
21
+ "author": "PayConductor",
22
+ "keywords": [
23
+ "payconductor",
24
+ "payment",
25
+ "gateway",
26
+ "react",
27
+ "sdk",
28
+ "checkout"
29
+ ],
30
+ "exports": {
31
+ ".": {
32
+ "import": "./dist/index.js",
33
+ "require": "./dist/index.js",
34
+ "types": "./dist/index.d.ts"
35
+ }
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "peerDependencies": {
41
+ "react": ">=16.8.0",
42
+ "react-dom": ">=16.8.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/react": "^18.0.0",
46
+ "@types/react-dom": "^18.0.0",
47
+ "react": "^18.0.0",
48
+ "react-dom": "^18.0.0",
49
+ "typescript": "^5.0.0"
50
+ }
51
+ }