@inflow_pay/sdk 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 InflowPay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,336 @@
1
+ # InflowPay SDK v2 - Iframe-based Payment SDK
2
+
3
+ Accept card payments with a pre-built, secure payment form. **Same API as the React SDK** for easy migration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @inflow_pay/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ **Same API as React SDK!** Easy migration from React SDK to iframe-based SDK:
14
+
15
+ ```javascript
16
+ import { InflowPayProvider } from "@inflow_pay/sdk";
17
+
18
+ // Step 1: Create InflowPayProvider (same as React's <InflowPayProvider>)
19
+ const provider = new InflowPayProvider({
20
+ config: { apiKey: "inflow_pub_xxx" },
21
+ });
22
+
23
+ // Step 2: Create CardElement (same as React's <CardElement>)
24
+ const cardElement = provider.createCardElement({
25
+ paymentId: "pay_xxx", // From your backend
26
+ container: "#card-container",
27
+ onComplete: (result) => {
28
+ if (result.status === "CHECKOUT_SUCCESS") {
29
+ window.location.href = "/success";
30
+ }
31
+ },
32
+ });
33
+
34
+ // Step 3: Mount the CardElement
35
+ cardElement.mount();
36
+ ```
37
+
38
+ ## How It Works
39
+
40
+ 1. **Backend**: Create a payment with billing info (your private key)
41
+ 2. **Frontend**: Create `InflowPayProvider` with your API key
42
+ 3. **Frontend**: Create `CardElement` with the `paymentId`
43
+ 4. **User**: Enters card details and submits
44
+ 5. **SDK**: Handles tokenization, 3DS, and payment completion
45
+ 6. **Your app**: Receives success/error via callback
46
+
47
+ ## Payment Status
48
+
49
+ Payments progress through these statuses:
50
+
51
+ | Status | Description | Success? |
52
+ | ------------------ | ----------------- | -------- |
53
+ | `CHECKOUT_SUCCESS` | Payment confirmed | ✅ Yes |
54
+ | `PAYMENT_FAILED` | Failed | ❌ No |
55
+
56
+ **Check for success:**
57
+
58
+ ```javascript
59
+ if (result.status === "CHECKOUT_SUCCESS") {
60
+ // Payment successful
61
+ }
62
+ ```
63
+
64
+ ## API Reference
65
+
66
+ ### InflowPayProvider
67
+
68
+ ```javascript
69
+ const provider = new InflowPayProvider({
70
+ config: {
71
+ apiKey: "inflow_pub_xxx", // Required
72
+ iframeUrl: "https://...", // Optional, auto-detected from API key
73
+ timeout: 30000, // Optional, default: 30000
74
+ debug: false, // Optional, default: false
75
+ },
76
+ });
77
+ ```
78
+
79
+ ### CardElement
80
+
81
+ ```javascript
82
+ const cardElement = provider.createCardElement({
83
+ paymentId: "pay_xxx", // Required
84
+ container: "#card-container", // Required (CSS selector or HTMLElement)
85
+
86
+ // Callbacks (same as React SDK)
87
+ onReady: () => {
88
+ // Card element is mounted and ready
89
+ },
90
+
91
+ onChange: (state) => {
92
+ // Track validation state
93
+ // state.complete - whether form is valid
94
+ },
95
+
96
+ onComplete: (result) => {
97
+ // Payment complete (success or failure)
98
+ if (result.error) {
99
+ console.error(result.error.message);
100
+ }
101
+ },
102
+
103
+ onError: (error) => {
104
+ // SDK-level errors (network, validation)
105
+ console.error(error);
106
+ },
107
+
108
+ onClose: () => {
109
+ // User closed the payment
110
+ },
111
+ });
112
+
113
+ // Mount the CardElement
114
+ cardElement.mount();
115
+ ```
116
+
117
+ ### CardElement Methods
118
+
119
+ #### `mount(): void`
120
+
121
+ Mounts the CardElement to the DOM. This will create and display the iframe.
122
+
123
+ ```javascript
124
+ cardElement.mount();
125
+ ```
126
+
127
+ #### `destroy(): void`
128
+
129
+ Destroys the CardElement and cleans up resources.
130
+
131
+ ```javascript
132
+ cardElement.destroy();
133
+ ```
134
+
135
+ ## HTML Example
136
+
137
+ ```html
138
+ <!DOCTYPE html>
139
+ <html>
140
+ <head>
141
+ <title>My Payment Page</title>
142
+ </head>
143
+ <body>
144
+ <div id="card-container"></div>
145
+
146
+ <script src="https://cdn.inflowpay.com/sdk/v2/inflowpay-sdk.js"></script>
147
+ <script>
148
+ // Same API as React SDK!
149
+ const provider = new InflowPaySDK.InflowPayProvider({
150
+ config: { apiKey: "inflow_pub_xxx" },
151
+ });
152
+
153
+ const cardElement = provider.createCardElement({
154
+ paymentId: "pay_xxx",
155
+ container: "#card-container",
156
+ onComplete: (result) => {
157
+ if (result.status === InflowPaySDK.PaymentStatus.CHECKOUT_SUCCESS) {
158
+ alert("Payment successful!");
159
+ }
160
+ },
161
+ });
162
+
163
+ cardElement.mount();
164
+ </script>
165
+ </body>
166
+ </html>
167
+ ```
168
+
169
+ ## Error Handling
170
+
171
+ Errors are automatically mapped to user-friendly messages:
172
+
173
+ ```javascript
174
+ cardElement.onComplete = (result) => {
175
+ if (result.error) {
176
+ console.log(result.error.message); // User-friendly
177
+ console.log(result.error.retryable); // Can retry?
178
+ }
179
+ };
180
+ ```
181
+
182
+ **Common errors:**
183
+
184
+ - `card_declined` - Card was declined
185
+ - `insufficient_funds` - Not enough funds
186
+ - `invalid_card_number` - Invalid card
187
+ - `THREE_DS_FAILED` - 3DS authentication failed
188
+
189
+ ## 3D Secure
190
+
191
+ 3DS is handled automatically. When required:
192
+
193
+ 1. SDK opens a modal with the authentication page
194
+ 2. User completes authentication
195
+ 3. Modal closes automatically
196
+ 4. Your `onComplete` callback receives the final result
197
+
198
+ **No setup required!** The SDK automatically handles 3DS redirects.
199
+
200
+ ## Backend Integration
201
+
202
+ Create payments on your backend with your **private key**:
203
+
204
+ ```javascript
205
+ // Your backend (Node.js example)
206
+ const response = await fetch("https://api.inflowpay.xyz/api/server/payment", {
207
+ method: "POST",
208
+ headers: {
209
+ Accept: "application/json",
210
+ "Content-Type": "application/json",
211
+ "X-Inflow-Api-Key": "inflow_priv_xxx", // Private key
212
+ },
213
+ body: JSON.stringify({
214
+ products: [{ name: "Product", price: 4999, quantity: 1 }],
215
+ currency: "EUR",
216
+ customerEmail: "customer@example.com",
217
+ billingCountry: "FR",
218
+ postalCode: "75001",
219
+ firstName: "John",
220
+ lastName: "Doe",
221
+ purchasingAsBusiness: false,
222
+ successUrl: "https://yourdomain.com/success",
223
+ cancelUrl: "https://yourdomain.com/cancel",
224
+ }),
225
+ });
226
+
227
+ const { payment } = await response.json();
228
+ // Send payment.id to your frontend
229
+ ```
230
+
231
+ See [API documentation](https://docs.inflowpay.com/v0/reference/createpayment) for full backend API reference.
232
+
233
+ ## Migration from React SDK
234
+
235
+ The SDK v2 uses the **same API** as the React SDK, making migration easy. You have two options:
236
+
237
+ ### Option 1: Keep Using React (Recommended for React Apps)
238
+
239
+ If you're using React, you can use the React components which work **exactly like the original SDK**:
240
+
241
+ ```tsx
242
+ // Just change the import path!
243
+ import { InflowPayProvider, CardElement } from "@inflow_pay/sdk/react";
244
+
245
+ function App() {
246
+ return (
247
+ <InflowPayProvider config={{ apiKey: "inflow_pub_xxx" }}>
248
+ <CardElement
249
+ paymentId={paymentId}
250
+ onComplete={(result) => {
251
+ if (result.status === "CHECKOUT_SUCCESS") {
252
+ window.location.href = "/success";
253
+ }
254
+ }}
255
+ />
256
+ </InflowPayProvider>
257
+ );
258
+ }
259
+ ```
260
+
261
+ **No changes needed!** Same API, same behavior, just a different import path.
262
+
263
+ ### Option 2: Vanilla JavaScript (For Non-React Apps)
264
+
265
+ If you're not using React, you can use the vanilla JavaScript API:
266
+
267
+ ```javascript
268
+ import { InflowPayProvider } from "@inflow_pay/sdk";
269
+
270
+ const provider = new InflowPayProvider({
271
+ config: { apiKey: "inflow_pub_xxx" },
272
+ });
273
+
274
+ const cardElement = provider.createCardElement({
275
+ paymentId: paymentId,
276
+ container: "#card-container",
277
+ onComplete: (result) => {
278
+ if (result.status === "CHECKOUT_SUCCESS") {
279
+ window.location.href = "/success";
280
+ }
281
+ },
282
+ });
283
+
284
+ cardElement.mount();
285
+ ```
286
+
287
+ **Key differences from React version:**
288
+
289
+ - No React required - works with vanilla JavaScript
290
+ - Explicit `container` prop (CSS selector or HTMLElement) instead of JSX
291
+ - Call `mount()` explicitly instead of automatic React mounting
292
+ - Same callbacks, same status codes, same error handling
293
+
294
+ ## TypeScript
295
+
296
+ Full type definitions included:
297
+
298
+ ```typescript
299
+ import { InflowPayProvider, PaymentStatus } from "@inflow_pay/sdk";
300
+ import type { PaymentResult, PaymentError } from "@inflow_pay/sdk";
301
+
302
+ const provider = new InflowPayProvider({
303
+ config: { apiKey: "inflow_pub_xxx" },
304
+ });
305
+
306
+ const cardElement = provider.createCardElement({
307
+ paymentId: "pay_xxx",
308
+ container: "#card-container",
309
+ onComplete: (result: PaymentResult) => {
310
+ if (result.status === PaymentStatus.CHECKOUT_SUCCESS) {
311
+ // Success
312
+ }
313
+ },
314
+ onError: (error: PaymentError) => {
315
+ console.error(error);
316
+ },
317
+ });
318
+ ```
319
+
320
+ ## Security
321
+
322
+ - ✅ Card data is tokenized before reaching your server (PCI compliant)
323
+ - ✅ Public keys can be safely exposed in browser
324
+ - ✅ Private keys should never be in frontend code
325
+ - ✅ All requests over HTTPS
326
+ - ✅ Iframe isolation for security
327
+
328
+ ## Support
329
+
330
+ - **Documentation:** https://docs.inflowpay.com/v0/reference/createpayment
331
+ - **Email:** support@inflowpay.com
332
+ - **GitHub:** https://github.com/inflowpay/sdk
333
+
334
+ ## License
335
+
336
+ MIT - See [LICENSE](./LICENSE)
@@ -0,0 +1,104 @@
1
+ import { ReactNode } from 'react';
2
+ import { PaymentSDK } from '../payment-sdk';
3
+ export interface SDKConfig {
4
+ apiKey: string;
5
+ iframeUrl?: string;
6
+ timeout?: number;
7
+ /** Enable debug logging (default: false, only allowed in local/dev environments) */
8
+ debug?: boolean;
9
+ }
10
+ export interface PaymentResult {
11
+ status: string;
12
+ data?: any;
13
+ alreadyProcessed?: boolean;
14
+ error?: {
15
+ code: string;
16
+ message: string;
17
+ retryable: boolean;
18
+ };
19
+ }
20
+ export interface PaymentError {
21
+ code: string;
22
+ message: string;
23
+ retryable: boolean;
24
+ }
25
+ export interface CardElementState {
26
+ complete: boolean;
27
+ }
28
+ export interface CardElementProps {
29
+ paymentId: string;
30
+ onReady?: () => void;
31
+ onChange?: (state: CardElementState) => void;
32
+ onComplete?: (result: PaymentResult) => void;
33
+ onError?: (error: PaymentError) => void;
34
+ buttonText?: string;
35
+ buttonStyle?: any;
36
+ style?: any;
37
+ placeholders?: {
38
+ cardNumber?: string;
39
+ expiry?: string;
40
+ cvc?: string;
41
+ };
42
+ }
43
+ /**
44
+ * InflowPayProvider - React component
45
+ *
46
+ * Same API as the original React SDK
47
+ *
48
+ * @example
49
+ * ```tsx
50
+ * <InflowPayProvider config={{ apiKey: 'inflow_pub_xxx' }}>
51
+ * <CardElement
52
+ * paymentId="pay_xxx"
53
+ * onComplete={(result) => {
54
+ * if (result.status === 'CHECKOUT_SUCCESS') {
55
+ * window.location.href = '/success';
56
+ * }
57
+ * }}
58
+ * />
59
+ * </InflowPayProvider>
60
+ * ```
61
+ */
62
+ export declare function InflowPayProvider({ config, children, }: {
63
+ config: SDKConfig;
64
+ children: ReactNode;
65
+ }): import("react/jsx-runtime").JSX.Element;
66
+ /**
67
+ * useInflowPay - Hook to access InflowPay SDK instance
68
+ *
69
+ * @example
70
+ * ```tsx
71
+ * function CustomComponent() {
72
+ * const inflow = useInflowPay();
73
+ *
74
+ * const checkStatus = async () => {
75
+ * const status = await inflow.getPaymentStatus('pay_xxx');
76
+ * console.log(status);
77
+ * };
78
+ *
79
+ * return <button onClick={checkStatus}>Check Status</button>;
80
+ * }
81
+ * ```
82
+ */
83
+ export declare function useInflowPay(): PaymentSDK;
84
+ /**
85
+ * CardElement - React component
86
+ *
87
+ * Same API as the original React SDK
88
+ *
89
+ * @example
90
+ * ```tsx
91
+ * <CardElement
92
+ * paymentId="pay_xxx"
93
+ * onComplete={(result) => {
94
+ * if (result.status === 'CHECKOUT_SUCCESS') {
95
+ * window.location.href = '/success';
96
+ * }
97
+ * }}
98
+ * />
99
+ * ```
100
+ */
101
+ export declare function CardElement({ paymentId, onReady, onChange, onComplete, onError, buttonText, buttonStyle, style, placeholders, config: propConfig, }: CardElementProps & {
102
+ config?: SDKConfig;
103
+ }): import("react/jsx-runtime").JSX.Element;
104
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/react/index.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAAiB,SAAS,EAA2C,MAAM,OAAO,CAAC;AAIjG,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAA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