@easyflow/javascript-sdk 2.1.10 → 2.1.11
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 +163 -75
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Easyflow JavaScript SDK
|
|
2
2
|
|
|
3
3
|
[](https://github.com/easyflow-cash/easyflow-javascript-sdk/actions)
|
|
4
|
-
[](https://easyflow-sdk.pages.dev)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://github.com/easyflow-cash/easyflow-javascript-sdk)
|
|
7
7
|
[](https://github.com/easyflow-cash/easyflow-javascript-sdk)
|
|
@@ -84,7 +84,17 @@ The **Easyflow JavaScript SDK** is the official tool for developers to integrate
|
|
|
84
84
|
- **High Performance**: Optimized for production
|
|
85
85
|
- **Complete Documentation**: Practical examples for all use cases
|
|
86
86
|
|
|
87
|
-
## What's New in v2.1.
|
|
87
|
+
## What's New in v2.1.11
|
|
88
|
+
|
|
89
|
+
### Credit Card Token Validation Fix
|
|
90
|
+
|
|
91
|
+
- **Real Token Support**: Now accepts real encrypted/ciphered credit card tokens
|
|
92
|
+
- **Flexible Format**: Supports Base64, URL-safe, and mixed character tokens
|
|
93
|
+
- **Variable Length**: Accepts tokens from 16 to 2048 characters
|
|
94
|
+
- **Enhanced Security**: Maintains security while accepting real-world tokens
|
|
95
|
+
- **Backward Compatibility**: Works with all existing token formats
|
|
96
|
+
|
|
97
|
+
### Workflow Corrections
|
|
88
98
|
|
|
89
99
|
### Workflow Corrections
|
|
90
100
|
|
|
@@ -167,7 +177,7 @@ Add this script tag to your HTML:
|
|
|
167
177
|
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
168
178
|
|
|
169
179
|
<!-- Specific version -->
|
|
170
|
-
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.
|
|
180
|
+
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.11.min.js"></script>
|
|
171
181
|
```
|
|
172
182
|
|
|
173
183
|
#### Option 2: NPM Package (Documentation Only)
|
|
@@ -184,33 +194,81 @@ Download the latest obfuscated build from [GitHub Releases](https://github.com/e
|
|
|
184
194
|
|
|
185
195
|
### Basic Usage
|
|
186
196
|
|
|
187
|
-
|
|
188
|
-
import { EasyflowSDK } from '@easyflow/javascript-sdk'
|
|
197
|
+
#### Method 1: CDN Script (Recommended for Production)
|
|
189
198
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
})
|
|
199
|
+
```html
|
|
200
|
+
<!-- Load SDK via script tag -->
|
|
201
|
+
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
194
202
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
203
|
+
<script>
|
|
204
|
+
// Configure the global instance
|
|
205
|
+
easyflowSDK.configure({
|
|
206
|
+
businessId: 'demo-business-12345',
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
// Process a payment
|
|
210
|
+
easyflowSDK
|
|
211
|
+
.placeOrder('demo-offer-67890', {
|
|
212
|
+
customer: {
|
|
213
|
+
name: 'João Silva',
|
|
214
|
+
email: 'joao@exemplo.com',
|
|
215
|
+
document: {
|
|
216
|
+
type: 'CPF',
|
|
217
|
+
number: '12345678901',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
payments: [
|
|
221
|
+
{
|
|
222
|
+
method: 'credit-card',
|
|
223
|
+
numberInstallments: 1,
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
})
|
|
227
|
+
.then((orderId) => {
|
|
228
|
+
console.log('Pedido criado:', orderId)
|
|
229
|
+
})
|
|
230
|
+
.catch((error) => {
|
|
231
|
+
console.error('Erro ao criar pedido:', error.message)
|
|
232
|
+
})
|
|
233
|
+
</script>
|
|
234
|
+
```
|
|
212
235
|
|
|
213
|
-
|
|
236
|
+
#### Method 2: Global Instance (For Low-Code Platforms & Simple HTML)
|
|
237
|
+
|
|
238
|
+
```html
|
|
239
|
+
<!-- Load SDK via script tag -->
|
|
240
|
+
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
241
|
+
|
|
242
|
+
<script>
|
|
243
|
+
// Configure the global instance
|
|
244
|
+
easyflowSDK.configure({
|
|
245
|
+
businessId: 'demo-business-12345',
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
// Now you can use all methods directly
|
|
249
|
+
easyflowSDK
|
|
250
|
+
.createCustomer({
|
|
251
|
+
name: 'Maria Silva',
|
|
252
|
+
email: 'maria@exemplo.com',
|
|
253
|
+
document: { type: 'CPF', number: '12345678901' },
|
|
254
|
+
})
|
|
255
|
+
.then((customer) => {
|
|
256
|
+
console.log('Cliente criado:', customer)
|
|
257
|
+
})
|
|
258
|
+
.catch((error) => {
|
|
259
|
+
console.error('Erro ao criar cliente:', error.message)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
// Validation methods are always available
|
|
263
|
+
if (easyflowSDK.validate.email('teste@exemplo.com')) {
|
|
264
|
+
console.log('Email válido!')
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Listen to events
|
|
268
|
+
easyflowSDK.on('customerCreated', (data) => {
|
|
269
|
+
console.log('Evento cliente criado:', data)
|
|
270
|
+
})
|
|
271
|
+
</script>
|
|
214
272
|
```
|
|
215
273
|
|
|
216
274
|
## Features
|
|
@@ -237,6 +295,14 @@ console.log('Order created:', orderId)
|
|
|
237
295
|
- **Obfuscated Builds**: Production builds are obfuscated for enhanced security
|
|
238
296
|
- **Controlled Distribution**: Secure distribution via CDN and GitHub Releases
|
|
239
297
|
|
|
298
|
+
### Low-Code Platform Support
|
|
299
|
+
|
|
300
|
+
- **Lovable Integration**: Full compatibility with Lovable platform
|
|
301
|
+
- **Global Instance**: `window.easyflowSDK` for easy integration
|
|
302
|
+
- **Event System**: Built-in event handling for `on()` and `off()`
|
|
303
|
+
- **Validation Methods**: Always available validation functions
|
|
304
|
+
- **Configuration**: Simple setup with `easyflowSDK.configure()`
|
|
305
|
+
|
|
240
306
|
## API Reference
|
|
241
307
|
|
|
242
308
|
### Core Methods
|
|
@@ -246,13 +312,13 @@ console.log('Order created:', orderId)
|
|
|
246
312
|
Creates an order using an existing offer.
|
|
247
313
|
|
|
248
314
|
```javascript
|
|
249
|
-
const orderId = await
|
|
315
|
+
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
250
316
|
customer: {
|
|
251
|
-
|
|
317
|
+
name: 'João Silva',
|
|
318
|
+
email: 'joao@exemplo.com',
|
|
319
|
+
document: { type: 'CPF', number: '12345678901' },
|
|
252
320
|
},
|
|
253
|
-
payments: [
|
|
254
|
-
/* payment methods */
|
|
255
|
-
],
|
|
321
|
+
payments: [{ method: 'credit-card', numberInstallments: 1 }],
|
|
256
322
|
})
|
|
257
323
|
```
|
|
258
324
|
|
|
@@ -261,8 +327,8 @@ const orderId = await sdk.placeOrder('offer-id', {
|
|
|
261
327
|
Processes a direct charge without using an offer.
|
|
262
328
|
|
|
263
329
|
```javascript
|
|
264
|
-
const orderId = await
|
|
265
|
-
items: [{ name: '
|
|
330
|
+
const orderId = await easyflowSDK.charge({
|
|
331
|
+
items: [{ name: 'Produto Demo', price: 1000 }],
|
|
266
332
|
payments: [{ method: 'pix', numberInstallments: 1 }],
|
|
267
333
|
})
|
|
268
334
|
```
|
|
@@ -272,9 +338,9 @@ const orderId = await sdk.charge({
|
|
|
272
338
|
Encrypts credit card data for secure processing.
|
|
273
339
|
|
|
274
340
|
```javascript
|
|
275
|
-
const token = await
|
|
341
|
+
const token = await easyflowSDK.encrypt({
|
|
276
342
|
number: '4111111111111111',
|
|
277
|
-
holderName: '
|
|
343
|
+
holderName: 'João Silva',
|
|
278
344
|
expirationMonth: '12',
|
|
279
345
|
expirationYear: '2025',
|
|
280
346
|
cvv: '123',
|
|
@@ -288,9 +354,9 @@ const token = await sdk.encrypt({
|
|
|
288
354
|
Creates a new customer.
|
|
289
355
|
|
|
290
356
|
```javascript
|
|
291
|
-
const customer = await
|
|
292
|
-
name: '
|
|
293
|
-
email: '
|
|
357
|
+
const customer = await easyflowSDK.createCustomer({
|
|
358
|
+
name: 'João Silva',
|
|
359
|
+
email: 'joao@exemplo.com',
|
|
294
360
|
document: { type: 'CPF', number: '12345678901' },
|
|
295
361
|
})
|
|
296
362
|
```
|
|
@@ -300,7 +366,7 @@ const customer = await sdk.createCustomer({
|
|
|
300
366
|
Retrieves customer information.
|
|
301
367
|
|
|
302
368
|
```javascript
|
|
303
|
-
const customer = await
|
|
369
|
+
const customer = await easyflowSDK.getCustomer('demo-customer-12345')
|
|
304
370
|
```
|
|
305
371
|
|
|
306
372
|
#### `updateCustomer(customerId, updateData, headers)`
|
|
@@ -308,9 +374,9 @@ const customer = await sdk.getCustomer('customer-id')
|
|
|
308
374
|
Updates existing customer information.
|
|
309
375
|
|
|
310
376
|
```javascript
|
|
311
|
-
const result = await
|
|
312
|
-
name: '
|
|
313
|
-
email: '
|
|
377
|
+
const result = await easyflowSDK.updateCustomer('demo-customer-12345', {
|
|
378
|
+
name: 'João Atualizado',
|
|
379
|
+
email: 'joao.atualizado@exemplo.com',
|
|
314
380
|
})
|
|
315
381
|
```
|
|
316
382
|
|
|
@@ -321,7 +387,10 @@ const result = await sdk.updateCustomer('customer-id', {
|
|
|
321
387
|
Adds a credit card to a customer.
|
|
322
388
|
|
|
323
389
|
```javascript
|
|
324
|
-
const result = await
|
|
390
|
+
const result = await easyflowSDK.addCreditCard(
|
|
391
|
+
'demo-customer-12345',
|
|
392
|
+
'encrypted-token-demo'
|
|
393
|
+
)
|
|
325
394
|
```
|
|
326
395
|
|
|
327
396
|
#### `getCreditCard(customerId, creditCardId, headers)`
|
|
@@ -329,7 +398,10 @@ const result = await sdk.addCreditCard('customer-id', 'encrypted-token')
|
|
|
329
398
|
Retrieves credit card information.
|
|
330
399
|
|
|
331
400
|
```javascript
|
|
332
|
-
const creditCard = await
|
|
401
|
+
const creditCard = await easyflowSDK.getCreditCard(
|
|
402
|
+
'demo-customer-12345',
|
|
403
|
+
'demo-card-67890'
|
|
404
|
+
)
|
|
333
405
|
```
|
|
334
406
|
|
|
335
407
|
#### `removeCreditCard(customerId, creditCardId, headers)`
|
|
@@ -337,7 +409,10 @@ const creditCard = await sdk.getCreditCard('customer-id', 'credit-card-id')
|
|
|
337
409
|
Removes a credit card from a customer.
|
|
338
410
|
|
|
339
411
|
```javascript
|
|
340
|
-
const result = await
|
|
412
|
+
const result = await easyflowSDK.removeCreditCard(
|
|
413
|
+
'demo-customer-12345',
|
|
414
|
+
'demo-card-67890'
|
|
415
|
+
)
|
|
341
416
|
```
|
|
342
417
|
|
|
343
418
|
## Validation
|
|
@@ -382,20 +457,20 @@ The SDK provides an event system for monitoring operations:
|
|
|
382
457
|
|
|
383
458
|
```javascript
|
|
384
459
|
// Listen to events
|
|
385
|
-
|
|
386
|
-
console.log('
|
|
460
|
+
easyflowSDK.on('customerCreated', (data) => {
|
|
461
|
+
console.log('Cliente criado:', data)
|
|
387
462
|
})
|
|
388
463
|
|
|
389
|
-
|
|
390
|
-
console.log('
|
|
464
|
+
easyflowSDK.on('orderPlaced', (data) => {
|
|
465
|
+
console.log('Pedido criado:', data)
|
|
391
466
|
})
|
|
392
467
|
|
|
393
|
-
|
|
394
|
-
console.log('
|
|
468
|
+
easyflowSDK.on('paymentProcessed', (data) => {
|
|
469
|
+
console.log('Pagamento processado:', data)
|
|
395
470
|
})
|
|
396
471
|
|
|
397
472
|
// Remove event listeners
|
|
398
|
-
|
|
473
|
+
easyflowSDK.off('customerCreated', callback)
|
|
399
474
|
```
|
|
400
475
|
|
|
401
476
|
## Error Handling
|
|
@@ -404,25 +479,26 @@ The SDK provides comprehensive error handling:
|
|
|
404
479
|
|
|
405
480
|
```javascript
|
|
406
481
|
try {
|
|
407
|
-
const result = await
|
|
482
|
+
const result = await easyflowSDK.placeOrder('demo-offer-67890', orderData)
|
|
408
483
|
} catch (error) {
|
|
409
484
|
if (error.name === 'ValidationError') {
|
|
410
|
-
console.log('
|
|
485
|
+
console.log('Falha na validação:', error.message)
|
|
411
486
|
} else if (error.name === 'NetworkError') {
|
|
412
|
-
console.log('
|
|
487
|
+
console.log('Erro de rede:', error.message)
|
|
413
488
|
} else if (error.name === 'SecurityError') {
|
|
414
|
-
console.log('
|
|
489
|
+
console.log('Violação de segurança:', error.message)
|
|
415
490
|
}
|
|
416
491
|
}
|
|
417
492
|
```
|
|
418
493
|
|
|
419
494
|
## Configuration
|
|
420
495
|
|
|
421
|
-
### SDK Options
|
|
496
|
+
### SDK Options (CDN Implementation)
|
|
422
497
|
|
|
423
498
|
```javascript
|
|
424
|
-
|
|
425
|
-
|
|
499
|
+
// Configure the global instance
|
|
500
|
+
easyflowSDK.configure({
|
|
501
|
+
businessId: 'demo-business-12345',
|
|
426
502
|
environment: 'production', // 'production' or 'sandbox'
|
|
427
503
|
debug: false, // Enable debug logging
|
|
428
504
|
timeout: 30000, // Request timeout in milliseconds
|
|
@@ -432,7 +508,7 @@ const sdk = new EasyflowSDK({
|
|
|
432
508
|
### Environment Variables
|
|
433
509
|
|
|
434
510
|
```bash
|
|
435
|
-
EASYFLOW_BUSINESS_ID=
|
|
511
|
+
EASYFLOW_BUSINESS_ID=demo-business-12345
|
|
436
512
|
EASYFLOW_ENVIRONMENT=production
|
|
437
513
|
EASYFLOW_DEBUG=false
|
|
438
514
|
```
|
|
@@ -443,26 +519,26 @@ EASYFLOW_DEBUG=false
|
|
|
443
519
|
|
|
444
520
|
```javascript
|
|
445
521
|
// 1. Create customer
|
|
446
|
-
const customer = await
|
|
447
|
-
name: '
|
|
448
|
-
email: '
|
|
522
|
+
const customer = await easyflowSDK.createCustomer({
|
|
523
|
+
name: 'João Silva',
|
|
524
|
+
email: 'joao@exemplo.com',
|
|
449
525
|
document: { type: 'CPF', number: '12345678901' },
|
|
450
526
|
})
|
|
451
527
|
|
|
452
528
|
// 2. Encrypt credit card
|
|
453
|
-
const token = await
|
|
529
|
+
const token = await easyflowSDK.encrypt({
|
|
454
530
|
number: '4111111111111111',
|
|
455
|
-
holderName: '
|
|
531
|
+
holderName: 'João Silva',
|
|
456
532
|
expirationMonth: '12',
|
|
457
533
|
expirationYear: '2025',
|
|
458
534
|
cvv: '123',
|
|
459
535
|
})
|
|
460
536
|
|
|
461
537
|
// 3. Add credit card to customer
|
|
462
|
-
const creditCard = await
|
|
538
|
+
const creditCard = await easyflowSDK.addCreditCard(customer.id, token)
|
|
463
539
|
|
|
464
540
|
// 4. Place order
|
|
465
|
-
const orderId = await
|
|
541
|
+
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
466
542
|
customer: customer,
|
|
467
543
|
payments: [
|
|
468
544
|
{
|
|
@@ -477,9 +553,11 @@ const orderId = await sdk.placeOrder('offer-id', {
|
|
|
477
553
|
### PIX Payment
|
|
478
554
|
|
|
479
555
|
```javascript
|
|
480
|
-
const orderId = await
|
|
556
|
+
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
481
557
|
customer: {
|
|
482
|
-
|
|
558
|
+
name: 'Maria Santos',
|
|
559
|
+
email: 'maria@exemplo.com',
|
|
560
|
+
document: { type: 'CPF', number: '98765432100' },
|
|
483
561
|
},
|
|
484
562
|
payments: [
|
|
485
563
|
{
|
|
@@ -490,16 +568,18 @@ const orderId = await sdk.placeOrder('offer-id', {
|
|
|
490
568
|
})
|
|
491
569
|
|
|
492
570
|
// Get PIX data
|
|
493
|
-
const pixData = await
|
|
571
|
+
const pixData = await easyflowSDK.getPix(orderId)
|
|
494
572
|
console.log('PIX QR Code:', pixData.qrCode)
|
|
495
573
|
```
|
|
496
574
|
|
|
497
575
|
### Bank Billet Payment
|
|
498
576
|
|
|
499
577
|
```javascript
|
|
500
|
-
const orderId = await
|
|
578
|
+
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
501
579
|
customer: {
|
|
502
|
-
|
|
580
|
+
name: 'Pedro Costa',
|
|
581
|
+
email: 'pedro@exemplo.com',
|
|
582
|
+
document: { type: 'CPF', number: '11122233344' },
|
|
503
583
|
},
|
|
504
584
|
payments: [
|
|
505
585
|
{
|
|
@@ -510,7 +590,7 @@ const orderId = await sdk.placeOrder('offer-id', {
|
|
|
510
590
|
})
|
|
511
591
|
|
|
512
592
|
// Get bank billet data
|
|
513
|
-
const bankBillet = await
|
|
593
|
+
const bankBillet = await easyflowSDK.getBankBillet(orderId)
|
|
514
594
|
console.log('Bank Billet Link:', bankBillet.link)
|
|
515
595
|
```
|
|
516
596
|
|
|
@@ -534,7 +614,7 @@ console.log('Bank Billet Link:', bankBillet.link)
|
|
|
534
614
|
|
|
535
615
|
<!-- With SRI (Subresource Integrity) -->
|
|
536
616
|
<script
|
|
537
|
-
src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.
|
|
617
|
+
src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.11.min.js"
|
|
538
618
|
integrity="sha384-[hash]"
|
|
539
619
|
crossorigin="anonymous"
|
|
540
620
|
></script>
|
|
@@ -564,6 +644,14 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
564
644
|
|
|
565
645
|
## Changelog
|
|
566
646
|
|
|
647
|
+
### v2.1.11
|
|
648
|
+
|
|
649
|
+
- **Credit Card Token Fix**: Accepts real encrypted/ciphered tokens from vault services
|
|
650
|
+
- **Flexible Validation**: Supports Base64, URL-safe, and mixed character formats
|
|
651
|
+
- **Variable Length**: Accepts tokens from 16 to 2048 characters
|
|
652
|
+
- **Enhanced Security**: Maintains security while accepting real-world tokens
|
|
653
|
+
- **Backward Compatibility**: Works with all existing token formats
|
|
654
|
+
|
|
567
655
|
### v2.1.10
|
|
568
656
|
|
|
569
657
|
- **Workflow Fixed**: Resolved GitHub Actions permissions and SRI hash generation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyflow/javascript-sdk",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.11",
|
|
4
4
|
"description": "Easyflow JavaScript SDK - Documentation and TypeScript definitions. For production use, use the CDN script: https://easyflow-sdk.pages.dev/easyflow-sdk.min.js",
|
|
5
5
|
"main": "README.md",
|
|
6
6
|
"module": "README.md",
|