@inflow_pay/sdk 0.0.1 → 0.2.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 CHANGED
@@ -8,27 +8,45 @@ Accept card payments with a pre-built, secure payment form. **Same API as the Re
8
8
  npm install @inflow_pay/sdk
9
9
  ```
10
10
 
11
+ Or use via CDN (UMD build):
12
+
13
+ ```html
14
+ <!-- Main SDK -->
15
+ <script src="https://cdn.inflowpay.com/sdk/v2/sdk.umd.js"></script>
16
+ <script>
17
+ // SDK is available as window.InflowPaySDK
18
+ const provider = new InflowPaySDK.InflowPayProvider({
19
+ config: { apiKey: 'inflow_pub_xxx' }
20
+ });
21
+ </script>
22
+
23
+ <!-- React SDK (if using React) -->
24
+ <script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
25
+ <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
26
+ <script src="https://cdn.inflowpay.com/sdk/v2/react.umd.js"></script>
27
+ ```
28
+
11
29
  ## Quick Start
12
30
 
13
31
  **Same API as React SDK!** Easy migration from React SDK to iframe-based SDK:
14
32
 
15
33
  ```javascript
16
- import { InflowPayProvider } from "@inflow_pay/sdk";
34
+ import { InflowPayProvider } from '@inflow_pay/sdk';
17
35
 
18
36
  // Step 1: Create InflowPayProvider (same as React's <InflowPayProvider>)
19
37
  const provider = new InflowPayProvider({
20
- config: { apiKey: "inflow_pub_xxx" },
38
+ config: { apiKey: 'inflow_pub_xxx' }
21
39
  });
22
40
 
23
41
  // Step 2: Create CardElement (same as React's <CardElement>)
24
42
  const cardElement = provider.createCardElement({
25
- paymentId: "pay_xxx", // From your backend
26
- container: "#card-container",
43
+ paymentId: 'pay_xxx', // From your backend
44
+ container: '#card-container',
27
45
  onComplete: (result) => {
28
- if (result.status === "CHECKOUT_SUCCESS") {
29
- window.location.href = "/success";
46
+ if (result.status === 'CHECKOUT_SUCCESS') {
47
+ window.location.href = '/success';
30
48
  }
31
- },
49
+ }
32
50
  });
33
51
 
34
52
  // Step 3: Mount the CardElement
@@ -48,15 +66,19 @@ cardElement.mount();
48
66
 
49
67
  Payments progress through these statuses:
50
68
 
51
- | Status | Description | Success? |
52
- | ------------------ | ----------------- | -------- |
53
- | `CHECKOUT_SUCCESS` | Payment confirmed | ✅ Yes |
54
- | `PAYMENT_FAILED` | Failed | No |
69
+ | Status | Description | Success? |
70
+ |--------|-------------|----------|
71
+ | `CHECKOUT_SUCCESS` | Payment confirmed | ✅ Yes |
72
+ | `PAYMENT_RECEIVED` | Funds received | Yes |
73
+ | `PAYMENT_SUCCESS` | Complete | ✅ Yes |
74
+ | `PAYMENT_FAILED` | Failed | ❌ No |
55
75
 
56
76
  **Check for success:**
57
77
 
58
78
  ```javascript
59
- if (result.status === "CHECKOUT_SUCCESS") {
79
+ if (result.status === 'CHECKOUT_SUCCESS' ||
80
+ result.status === 'PAYMENT_RECEIVED' ||
81
+ result.status === 'PAYMENT_SUCCESS') {
60
82
  // Payment successful
61
83
  }
62
84
  ```
@@ -68,11 +90,11 @@ if (result.status === "CHECKOUT_SUCCESS") {
68
90
  ```javascript
69
91
  const provider = new InflowPayProvider({
70
92
  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
- },
93
+ apiKey: 'inflow_pub_xxx', // Required
94
+ iframeUrl: 'https://...', // Optional, auto-detected from API key
95
+ timeout: 30000, // Optional, default: 30000
96
+ debug: false // Optional, default: false
97
+ }
76
98
  });
77
99
  ```
78
100
 
@@ -80,34 +102,34 @@ const provider = new InflowPayProvider({
80
102
 
81
103
  ```javascript
82
104
  const cardElement = provider.createCardElement({
83
- paymentId: "pay_xxx", // Required
84
- container: "#card-container", // Required (CSS selector or HTMLElement)
85
-
105
+ paymentId: 'pay_xxx', // Required
106
+ container: '#card-container', // Required (CSS selector or HTMLElement)
107
+
86
108
  // Callbacks (same as React SDK)
87
109
  onReady: () => {
88
110
  // Card element is mounted and ready
89
111
  },
90
-
112
+
91
113
  onChange: (state) => {
92
114
  // Track validation state
93
115
  // state.complete - whether form is valid
94
116
  },
95
-
117
+
96
118
  onComplete: (result) => {
97
119
  // Payment complete (success or failure)
98
120
  if (result.error) {
99
121
  console.error(result.error.message);
100
122
  }
101
123
  },
102
-
124
+
103
125
  onError: (error) => {
104
126
  // SDK-level errors (network, validation)
105
127
  console.error(error);
106
128
  },
107
-
129
+
108
130
  onClose: () => {
109
131
  // User closed the payment
110
- },
132
+ }
111
133
  });
112
134
 
113
135
  // Mount the CardElement
@@ -137,32 +159,33 @@ cardElement.destroy();
137
159
  ```html
138
160
  <!DOCTYPE html>
139
161
  <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>
162
+ <head>
163
+ <title>My Payment Page</title>
164
+ </head>
165
+ <body>
166
+ <div id="card-container"></div>
167
+
168
+ <script src="https://cdn.inflowpay.com/sdk/v2/sdk.umd.js"></script>
169
+ <script>
170
+ // Same API as React SDK!
171
+ // SDK is available as window.InflowPaySDK
172
+ const provider = new InflowPaySDK.InflowPayProvider({
173
+ config: { apiKey: 'inflow_pub_xxx' }
174
+ });
175
+
176
+ const cardElement = provider.createCardElement({
177
+ paymentId: 'pay_xxx',
178
+ container: '#card-container',
179
+ onComplete: (result) => {
180
+ if (result.status === InflowPaySDK.PaymentStatus.CHECKOUT_SUCCESS) {
181
+ alert('Payment successful!');
182
+ }
183
+ }
184
+ });
185
+
186
+ cardElement.mount();
187
+ </script>
188
+ </body>
166
189
  </html>
167
190
  ```
168
191
 
@@ -203,25 +226,25 @@ Create payments on your backend with your **private key**:
203
226
 
204
227
  ```javascript
205
228
  // Your backend (Node.js example)
206
- const response = await fetch("https://api.inflowpay.xyz/api/server/payment", {
207
- method: "POST",
229
+ const response = await fetch('https://api.inflowpay.xyz/api/server/payment', {
230
+ method: 'POST',
208
231
  headers: {
209
- Accept: "application/json",
210
- "Content-Type": "application/json",
211
- "X-Inflow-Api-Key": "inflow_priv_xxx", // Private key
232
+ 'Accept': 'application/json',
233
+ 'Content-Type': 'application/json',
234
+ 'X-Inflow-Api-Key': 'inflow_priv_xxx' // Private key
212
235
  },
213
236
  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",
237
+ products: [{ name: 'Product', price: 4999, quantity: 1 }],
238
+ currency: 'EUR',
239
+ customerEmail: 'customer@example.com',
240
+ billingCountry: 'FR',
241
+ postalCode: '75001',
242
+ firstName: 'John',
243
+ lastName: 'Doe',
221
244
  purchasingAsBusiness: false,
222
- successUrl: "https://yourdomain.com/success",
223
- cancelUrl: "https://yourdomain.com/cancel",
224
- }),
245
+ successUrl: 'https://yourdomain.com/success',
246
+ cancelUrl: 'https://yourdomain.com/cancel'
247
+ })
225
248
  });
226
249
 
227
250
  const { payment } = await response.json();
@@ -240,16 +263,16 @@ If you're using React, you can use the React components which work **exactly lik
240
263
 
241
264
  ```tsx
242
265
  // Just change the import path!
243
- import { InflowPayProvider, CardElement } from "@inflow_pay/sdk/react";
266
+ import { InflowPayProvider, CardElement } from '@inflow_pay/sdk/react';
244
267
 
245
268
  function App() {
246
269
  return (
247
- <InflowPayProvider config={{ apiKey: "inflow_pub_xxx" }}>
270
+ <InflowPayProvider config={{ apiKey: 'inflow_pub_xxx' }}>
248
271
  <CardElement
249
272
  paymentId={paymentId}
250
273
  onComplete={(result) => {
251
- if (result.status === "CHECKOUT_SUCCESS") {
252
- window.location.href = "/success";
274
+ if (result.status === 'CHECKOUT_SUCCESS') {
275
+ window.location.href = '/success';
253
276
  }
254
277
  }}
255
278
  />
@@ -265,27 +288,26 @@ function App() {
265
288
  If you're not using React, you can use the vanilla JavaScript API:
266
289
 
267
290
  ```javascript
268
- import { InflowPayProvider } from "@inflow_pay/sdk";
291
+ import { InflowPayProvider } from '@inflow_pay/sdk';
269
292
 
270
293
  const provider = new InflowPayProvider({
271
- config: { apiKey: "inflow_pub_xxx" },
294
+ config: { apiKey: 'inflow_pub_xxx' }
272
295
  });
273
296
 
274
297
  const cardElement = provider.createCardElement({
275
298
  paymentId: paymentId,
276
- container: "#card-container",
299
+ container: '#card-container',
277
300
  onComplete: (result) => {
278
- if (result.status === "CHECKOUT_SUCCESS") {
279
- window.location.href = "/success";
301
+ if (result.status === 'CHECKOUT_SUCCESS') {
302
+ window.location.href = '/success';
280
303
  }
281
- },
304
+ }
282
305
  });
283
306
 
284
307
  cardElement.mount();
285
308
  ```
286
309
 
287
310
  **Key differences from React version:**
288
-
289
311
  - No React required - works with vanilla JavaScript
290
312
  - Explicit `container` prop (CSS selector or HTMLElement) instead of JSX
291
313
  - Call `mount()` explicitly instead of automatic React mounting
@@ -296,16 +318,16 @@ cardElement.mount();
296
318
  Full type definitions included:
297
319
 
298
320
  ```typescript
299
- import { InflowPayProvider, PaymentStatus } from "@inflow_pay/sdk";
300
- import type { PaymentResult, PaymentError } from "@inflow_pay/sdk";
321
+ import { InflowPayProvider, PaymentStatus } from '@inflow_pay/sdk';
322
+ import type { PaymentResult, PaymentError } from '@inflow_pay/sdk';
301
323
 
302
324
  const provider = new InflowPayProvider({
303
- config: { apiKey: "inflow_pub_xxx" },
325
+ config: { apiKey: 'inflow_pub_xxx' }
304
326
  });
305
327
 
306
328
  const cardElement = provider.createCardElement({
307
- paymentId: "pay_xxx",
308
- container: "#card-container",
329
+ paymentId: 'pay_xxx',
330
+ container: '#card-container',
309
331
  onComplete: (result: PaymentResult) => {
310
332
  if (result.status === PaymentStatus.CHECKOUT_SUCCESS) {
311
333
  // Success
@@ -313,7 +335,7 @@ const cardElement = provider.createCardElement({
313
335
  },
314
336
  onError: (error: PaymentError) => {
315
337
  console.error(error);
316
- },
338
+ }
317
339
  });
318
340
  ```
319
341