@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 +105 -83
- package/dist/payment-sdk-DCTbabp6.mjs +539 -0
- package/dist/payment-sdk-DCTbabp6.mjs.map +1 -0
- package/dist/payment-sdk-DRIfoXw9.js +177 -0
- package/dist/payment-sdk-DRIfoXw9.js.map +1 -0
- package/dist/react/index.d.ts +314 -0
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.esm.js +64 -719
- package/dist/react.esm.js.map +1 -1
- package/dist/react.umd.js +119 -13
- package/dist/react.umd.js.map +1 -1
- package/dist/sdk.cjs +2 -0
- package/dist/sdk.cjs.map +1 -0
- package/dist/sdk.d.ts +338 -5
- package/dist/sdk.esm.js +29 -420
- package/dist/sdk.esm.js.map +1 -1
- package/dist/sdk.umd.js +98 -8
- package/dist/sdk.umd.js.map +1 -1
- package/package.json +21 -28
- package/dist/react.d.ts +0 -104
- package/dist/react.d.ts.map +0 -1
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
|
|
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:
|
|
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:
|
|
26
|
-
container:
|
|
43
|
+
paymentId: 'pay_xxx', // From your backend
|
|
44
|
+
container: '#card-container',
|
|
27
45
|
onComplete: (result) => {
|
|
28
|
-
if (result.status ===
|
|
29
|
-
window.location.href =
|
|
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
|
|
52
|
-
|
|
53
|
-
| `CHECKOUT_SUCCESS` | Payment confirmed | ✅ Yes
|
|
54
|
-
| `
|
|
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 ===
|
|
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:
|
|
72
|
-
iframeUrl:
|
|
73
|
-
timeout: 30000,
|
|
74
|
-
debug: 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:
|
|
84
|
-
container:
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
</
|
|
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(
|
|
207
|
-
method:
|
|
229
|
+
const response = await fetch('https://api.inflowpay.xyz/api/server/payment', {
|
|
230
|
+
method: 'POST',
|
|
208
231
|
headers: {
|
|
209
|
-
Accept:
|
|
210
|
-
|
|
211
|
-
|
|
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:
|
|
215
|
-
currency:
|
|
216
|
-
customerEmail:
|
|
217
|
-
billingCountry:
|
|
218
|
-
postalCode:
|
|
219
|
-
firstName:
|
|
220
|
-
lastName:
|
|
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:
|
|
223
|
-
cancelUrl:
|
|
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
|
|
266
|
+
import { InflowPayProvider, CardElement } from '@inflow_pay/sdk/react';
|
|
244
267
|
|
|
245
268
|
function App() {
|
|
246
269
|
return (
|
|
247
|
-
<InflowPayProvider config={{ apiKey:
|
|
270
|
+
<InflowPayProvider config={{ apiKey: 'inflow_pub_xxx' }}>
|
|
248
271
|
<CardElement
|
|
249
272
|
paymentId={paymentId}
|
|
250
273
|
onComplete={(result) => {
|
|
251
|
-
if (result.status ===
|
|
252
|
-
window.location.href =
|
|
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
|
|
291
|
+
import { InflowPayProvider } from '@inflow_pay/sdk';
|
|
269
292
|
|
|
270
293
|
const provider = new InflowPayProvider({
|
|
271
|
-
config: { apiKey:
|
|
294
|
+
config: { apiKey: 'inflow_pub_xxx' }
|
|
272
295
|
});
|
|
273
296
|
|
|
274
297
|
const cardElement = provider.createCardElement({
|
|
275
298
|
paymentId: paymentId,
|
|
276
|
-
container:
|
|
299
|
+
container: '#card-container',
|
|
277
300
|
onComplete: (result) => {
|
|
278
|
-
if (result.status ===
|
|
279
|
-
window.location.href =
|
|
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
|
|
300
|
-
import type { PaymentResult, PaymentError } from
|
|
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:
|
|
325
|
+
config: { apiKey: 'inflow_pub_xxx' }
|
|
304
326
|
});
|
|
305
327
|
|
|
306
328
|
const cardElement = provider.createCardElement({
|
|
307
|
-
paymentId:
|
|
308
|
-
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
|
|