@easyflow/javascript-sdk 2.1.25 → 2.1.27
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/DATA-STRUCTURES.md +28 -10
- package/INDEX.md +41 -0
- package/README.md +141 -1144
- package/dist/easyflow-sdk.min.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,1251 +1,248 @@
|
|
|
1
1
|
# Easyflow JavaScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](LICENSE)
|
|
5
|
-
[](https://easyflow-sdk.pages.dev)
|
|
6
|
-
[](https://easyflow-sdk.pages.dev)
|
|
7
|
-
|
|
8
|
-
<div align="center">
|
|
9
|
-
|
|
10
|
-

|
|
11
|
-
|
|
12
|
-
**Freedom to sell more, better and longer**
|
|
13
|
-
|
|
14
|
-
> **Enterprise-grade JavaScript SDK** for integration with the Easyflow payment processing platform with robust
|
|
15
|
-
> validation, comprehensive security and Brazilian compliance
|
|
16
|
-
|
|
17
|
-
[](https://www.easyflow.digital/)
|
|
18
|
-
[](https://www.easyflow.digital/)
|
|
19
|
-
[](https://docs.easyflow.digital)
|
|
20
|
-
|
|
21
|
-
</div>
|
|
22
|
-
|
|
23
|
-
## About Easyflow
|
|
24
|
-
|
|
25
|
-
[Easyflow](https://www.easyflow.digital/) is a payment platform that **facilitates the sales process** of digital
|
|
26
|
-
products and services in a simple and intuitive way. Our mission is to transform Digital Commerce by offering a complete
|
|
27
|
-
sales structure to maximize your LTV.
|
|
28
|
-
|
|
29
|
-
### Why Choose Easyflow?
|
|
30
|
-
|
|
31
|
-
- **Outstanding approval rate**: 95% to 98% credit card approval rate
|
|
32
|
-
- **High conversion checkout**: Fastest loading in the market
|
|
33
|
-
- **Simplified recurrence**: Recurring payments with your own rules
|
|
34
|
-
- **Bank-level security**: PCI Compliance and advanced encryption
|
|
35
|
-
- **Same-day withdrawal**: Same day, no bureaucracy
|
|
36
|
-
- **Simple integrations**: Webhooks and API with few clicks
|
|
37
|
-
|
|
38
|
-
### Payment Methods
|
|
39
|
-
|
|
40
|
-
- **Credit Card**: Highest approval rate in the market
|
|
41
|
-
- **PIX**: Instant Brazilian payment
|
|
42
|
-
- **Bank Billet**: For those who prefer to pay via bank
|
|
43
|
-
|
|
44
|
-
### Main Features
|
|
45
|
-
|
|
46
|
-
- **Optimized checkout** for maximum conversion
|
|
47
|
-
- **AI-powered sales recovery** (up to 40% increase)
|
|
48
|
-
- **Upsell, downsell and cross-sell** to increase average ticket
|
|
49
|
-
- **Automated payment splitting** for co-producers
|
|
50
|
-
- **Smart metrics and insights** in real time
|
|
51
|
-
- **Integration with CRM, ERPs** and third-party platforms
|
|
52
|
-
|
|
53
|
-
### Plans and Fees
|
|
54
|
-
|
|
55
|
-
**Clear and fair rate: 6.99% + R$2.50**
|
|
56
|
-
|
|
57
|
-
- **Revenue +100k per month?** [Click here for special conditions](https://www.easyflow.digital/)
|
|
58
|
-
- **You only pay when you generate results**
|
|
59
|
-
- **No hidden fees or surprises**
|
|
60
|
-
|
|
61
|
-
## Try It Now
|
|
62
|
-
|
|
63
|
-
<div align="center">
|
|
64
|
-
|
|
65
|
-
[](https://easyflow-sdk.pages.dev)
|
|
66
|
-
|
|
67
|
-
**Experience the Easyflow SDK in action with our interactive demo**
|
|
68
|
-
|
|
69
|
-
</div>
|
|
70
|
-
|
|
71
|
-
## What is the Easyflow JavaScript SDK?
|
|
72
|
-
|
|
73
|
-
The **Easyflow JavaScript SDK** is the official tool for developers to integrate their applications with the Easyflow
|
|
74
|
-
platform. With this SDK, you can:
|
|
75
|
-
|
|
76
|
-
- **Process payments** securely and reliably
|
|
77
|
-
- **Manage customers** with complete Brazilian data validation
|
|
78
|
-
- **Create offers** and process orders automatically
|
|
79
|
-
- **Implement recurrence** with custom rules
|
|
80
|
-
- **Integrate with any system** via REST API
|
|
81
|
-
|
|
82
|
-
### SDK Advantages
|
|
83
|
-
|
|
84
|
-
- **100% Plug & Play**: Works with any type of business
|
|
85
|
-
- **Brazilian Compliance**: CPF/CNPJ, phone, address validation
|
|
86
|
-
- **Enterprise Security**: Multiple layers of protection
|
|
87
|
-
- **High Performance**: Optimized for production
|
|
88
|
-
- **Complete Documentation**: Practical examples for all use cases
|
|
89
|
-
|
|
90
|
-
## What's New in v2.1.19
|
|
91
|
-
|
|
92
|
-
### Complete Implementation Examples
|
|
93
|
-
|
|
94
|
-
- **Full Data Models**: Comprehensive examples for placeOrder, charge, createCustomer, and addCreditCard
|
|
95
|
-
- **Real-World Scenarios**: Complete workflows with all available data fields
|
|
96
|
-
- **Brazilian Data**: Realistic Brazilian addresses, phone numbers, and document formats
|
|
97
|
-
- **End-to-End Workflows**: Complete customer → credit card → order examples
|
|
98
|
-
- **Code Quality**: Improved formatting and consistency across all examples
|
|
99
|
-
|
|
100
|
-
### Credit Card Token Validation Fix
|
|
101
|
-
|
|
102
|
-
- **Real Token Support**: Now accepts real encrypted/ciphered credit card tokens
|
|
103
|
-
- **Flexible Format**: Supports Base64, URL-safe, and mixed character tokens
|
|
104
|
-
- **Variable Length**: Accepts tokens from 16 to 2048 characters
|
|
105
|
-
- **Enhanced Security**: Maintains security while accepting real-world tokens
|
|
106
|
-
- **Backward Compatibility**: Works with all existing token formats
|
|
107
|
-
|
|
108
|
-
### Workflow Corrections
|
|
109
|
-
|
|
110
|
-
- **GitHub Actions Fixed**: Resolved release workflow permissions and SRI hash generation
|
|
111
|
-
- **CDN Deployment**: Automated deployment to Cloudflare Pages working correctly
|
|
112
|
-
- **Release Automation**: GitHub releases created automatically with proper SRI hashes
|
|
113
|
-
- **Build Process**: Streamlined build and deployment pipeline
|
|
114
|
-
|
|
115
|
-
### Hybrid Distribution Strategy
|
|
116
|
-
|
|
117
|
-
- **NPM Package**: Contains only documentation and TypeScript definitions
|
|
118
|
-
- **CDN Scripts**: Production-ready obfuscated builds via Cloudflare Pages and jsDelivr
|
|
119
|
-
- **Enhanced Security**: Code source protected while maintaining accessibility
|
|
120
|
-
- **Better UX**: Easy discovery via NPM, secure usage via CDN
|
|
121
|
-
|
|
122
|
-
### Security & Privacy Improvements
|
|
123
|
-
|
|
124
|
-
- **README Anonymization**: Removed all personal information and sensitive data
|
|
125
|
-
- **Privacy Protection**: No personal emails, URLs, or contact information exposed
|
|
126
|
-
- **Professional Documentation**: Clean, business-focused documentation
|
|
127
|
-
- **NPM Safety**: Safe for public NPM publication
|
|
128
|
-
|
|
129
|
-
### Test Suite Improvements
|
|
130
|
-
|
|
131
|
-
- **Test Coverage Optimization**: Fixed all failing unit tests for complete 250 test coverage
|
|
132
|
-
- **Mock Structure Corrections**: Updated test mocks to align with actual API response patterns
|
|
133
|
-
- **Customer Management Tests**: Corrected mock structures for `createCustomer` and `getCustomer` methods
|
|
134
|
-
- **Credit Card Tests**: Fixed mock data structures for `addCreditCard` and `getCreditCard` methods
|
|
135
|
-
- **Consistent Test Patterns**: Standardized mock response structures across all endpoints
|
|
136
|
-
|
|
137
|
-
### API Response Pattern Standardization
|
|
138
|
-
|
|
139
|
-
- **Customer Methods**: Properly handle `response.data.customer` structure
|
|
140
|
-
- **Credit Card Methods**: Correctly process `response.data.creditCard` structure
|
|
141
|
-
- **Order Methods**: Maintain existing `response.data` pattern
|
|
142
|
-
- **Improved Reliability**: Enhanced test reliability and maintainability
|
|
143
|
-
|
|
144
|
-
### Enhanced ID Validation Support
|
|
145
|
-
|
|
146
|
-
- **Multiple ID Format Support**: Now accepts UUID v4, UUID v7, and MongoDB ObjectId formats
|
|
147
|
-
- **UUID v4**: Standard format `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx` (y = 8,9,A,B)
|
|
148
|
-
- **UUID v7**: Modern format `xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx` (y = 8,9,A,B)
|
|
149
|
-
- **MongoDB ObjectId**: 24-character hexadecimal format `507f1f77bcf86cd799439011`
|
|
150
|
-
- **Strict Validation**: Rejects any other formats for enhanced security
|
|
3
|
+
Enterprise-grade JavaScript SDK for Easyflow payment processing platform - Documentation and TypeScript definitions only
|
|
151
4
|
|
|
152
5
|
## Quick Start
|
|
153
6
|
|
|
154
|
-
###
|
|
155
|
-
|
|
156
|
-
#### Option 1: CDN Script (Recommended)
|
|
157
|
-
|
|
158
|
-
Add this script tag to your HTML:
|
|
159
|
-
|
|
160
|
-
```html
|
|
161
|
-
<!-- Latest version -->
|
|
162
|
-
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
163
|
-
|
|
164
|
-
<!-- Specific version -->
|
|
165
|
-
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.19.min.js"></script>
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
#### Option 2: CDN jsDelivr (Alternative)
|
|
169
|
-
|
|
170
|
-
```html
|
|
171
|
-
<!-- Latest version -->
|
|
172
|
-
<script src="https://cdn.jsdelivr.net/npm/@easyflow/javascript-sdk@latest/dist/easyflow-sdk.min.js"></script>
|
|
173
|
-
|
|
174
|
-
<!-- Specific version -->
|
|
175
|
-
<script src="https://cdn.jsdelivr.net/npm/@easyflow/javascript-sdk@2.1.20/dist/easyflow-sdk.min.js"></script>
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
#### Option 3: NPM Package (Documentation Only)
|
|
7
|
+
### Via NPM
|
|
179
8
|
|
|
180
9
|
```bash
|
|
181
10
|
npm install @easyflow/javascript-sdk
|
|
182
11
|
```
|
|
183
12
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
### Basic Usage
|
|
13
|
+
### Via CDN
|
|
187
14
|
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
easyflowSDK.configure({
|
|
191
|
-
businessId: 'demo-business-12345',
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
// Process a payment
|
|
195
|
-
easyflowSDK
|
|
196
|
-
.placeOrder('demo-offer-67890', {
|
|
197
|
-
customer: {
|
|
198
|
-
name: 'João Silva',
|
|
199
|
-
email: 'joao@exemplo.com',
|
|
200
|
-
document: {
|
|
201
|
-
type: 'CPF',
|
|
202
|
-
number: '12345678901',
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
payments: [
|
|
206
|
-
{
|
|
207
|
-
method: 'credit-card',
|
|
208
|
-
numberInstallments: 1,
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
})
|
|
212
|
-
.then((orderId) => {
|
|
213
|
-
console.log('Pedido criado:', orderId)
|
|
214
|
-
})
|
|
215
|
-
.catch((error) => {
|
|
216
|
-
console.error('Erro ao criar pedido:', error.message)
|
|
217
|
-
})
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
218
17
|
```
|
|
219
18
|
|
|
220
|
-
##
|
|
221
|
-
|
|
222
|
-
- **[INDEX.md](INDEX.md)** - Central documentation hub
|
|
223
|
-
- **[DATA-STRUCTURES.md](DATA-STRUCTURES.md)** - Complete data structure reference
|
|
224
|
-
- **[PLATFORM-INTEGRATION.md](PLATFORM-INTEGRATION.md)** - Platform integration guide with `initializeForPlatform`
|
|
225
|
-
|
|
226
|
-
## Features
|
|
227
|
-
|
|
228
|
-
### Payment Processing
|
|
229
|
-
|
|
230
|
-
- **Credit Card**: Highest approval rate with advanced fraud detection
|
|
231
|
-
- **PIX**: Instant Brazilian payment method
|
|
232
|
-
- **Bank Billet**: Traditional bank payment option
|
|
233
|
-
- **Recurring Payments**: Custom subscription rules
|
|
234
|
-
|
|
235
|
-
### Customer Management
|
|
236
|
-
|
|
237
|
-
- **Complete Validation**: CPF/CNPJ, phone, address validation
|
|
238
|
-
- **Data Sanitization**: XSS protection and input cleaning
|
|
239
|
-
- **Secure Storage**: Encrypted sensitive data handling
|
|
240
|
-
|
|
241
|
-
### Security Features
|
|
242
|
-
|
|
243
|
-
- **PCI Compliance**: Bank-level security standards
|
|
244
|
-
- **Fingerprinting**: Advanced fraud detection
|
|
245
|
-
- **Rate Limiting**: Protection against abuse
|
|
246
|
-
- **Input Validation**: Comprehensive data validation
|
|
247
|
-
- **Obfuscated Builds**: Production builds are obfuscated for enhanced security
|
|
248
|
-
- **Controlled Distribution**: Secure distribution via CDN (Cloudflare Pages + jsDelivr)
|
|
249
|
-
|
|
250
|
-
## API Reference
|
|
251
|
-
|
|
252
|
-
### Core Methods
|
|
253
|
-
|
|
254
|
-
#### `placeOrder(offerId, data, headers)`
|
|
19
|
+
## TypeScript Integration
|
|
255
20
|
|
|
256
|
-
|
|
21
|
+
Para projetos TypeScript, o SDK é exposto globalmente quando carregado via CDN. Adicione as seguintes declarações ao seu projeto:
|
|
257
22
|
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
type: 'CPF',
|
|
267
|
-
},
|
|
268
|
-
phone: {
|
|
269
|
-
areaCode: '+55',
|
|
270
|
-
ddd: '92',
|
|
271
|
-
number: '*****2191',
|
|
272
|
-
isMobile: true,
|
|
273
|
-
},
|
|
274
|
-
address: {
|
|
275
|
-
zipCode: '37537***',
|
|
276
|
-
street: 'Rua R. C. M. de A.',
|
|
277
|
-
complement: '',
|
|
278
|
-
neighborhood: 'M. do S.',
|
|
279
|
-
city: 'Santa Rita do Sapucaí',
|
|
280
|
-
state: 'MG',
|
|
281
|
-
number: '***',
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
payments: [
|
|
285
|
-
{
|
|
286
|
-
method: 'credit-card',
|
|
287
|
-
creditCard: {
|
|
288
|
-
token: 'valid token here',
|
|
289
|
-
},
|
|
290
|
-
numberInstallments: 1,
|
|
291
|
-
},
|
|
292
|
-
],
|
|
293
|
-
metadata: [],
|
|
294
|
-
})
|
|
23
|
+
```typescript
|
|
24
|
+
// O SDK está sendo carregado via CDN e exposto globalmente como window.easyflowSDK
|
|
25
|
+
declare global {
|
|
26
|
+
interface Window {
|
|
27
|
+
easyflowSDK: any
|
|
28
|
+
EasyflowSDK: any
|
|
29
|
+
}
|
|
30
|
+
}
|
|
295
31
|
```
|
|
296
32
|
|
|
297
|
-
|
|
33
|
+
### Exemplo de Uso com TypeScript
|
|
298
34
|
|
|
299
|
-
|
|
35
|
+
```typescript
|
|
36
|
+
// Configurar o SDK
|
|
37
|
+
window.easyflowSDK.configure({ businessId: 'your-business-id' })
|
|
300
38
|
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
name: 'João Silva Santos',
|
|
305
|
-
email: 'joao.silva@exemplo.com',
|
|
306
|
-
document: {
|
|
307
|
-
number: '12345678901',
|
|
308
|
-
type: 'CPF',
|
|
309
|
-
},
|
|
310
|
-
phone: {
|
|
311
|
-
areaCode: '+55',
|
|
312
|
-
ddd: '11',
|
|
313
|
-
number: '9988776655',
|
|
314
|
-
isMobile: true,
|
|
315
|
-
},
|
|
316
|
-
address: {
|
|
317
|
-
zipCode: '01234567',
|
|
318
|
-
street: 'Rua das Flores',
|
|
319
|
-
complement: 'Apto 101',
|
|
320
|
-
neighborhood: 'Centro',
|
|
321
|
-
city: 'São Paulo',
|
|
322
|
-
state: 'SP',
|
|
323
|
-
number: '123',
|
|
324
|
-
},
|
|
325
|
-
customerId: 'demo-customer-12345', // ID do cliente existente (opcional)
|
|
326
|
-
},
|
|
327
|
-
payments: [
|
|
328
|
-
{
|
|
329
|
-
method: 'credit-card',
|
|
330
|
-
numberInstallments: 1,
|
|
331
|
-
valueInCents: 500,
|
|
332
|
-
creditCard: {
|
|
333
|
-
cardId: 'demo-card-id-here', // cardId e token são opcionais, mas pelo menos 1 deve ser fornecido
|
|
334
|
-
token: 'demo-token-credit-card-here',
|
|
335
|
-
},
|
|
336
|
-
},
|
|
337
|
-
],
|
|
338
|
-
items: [
|
|
339
|
-
{
|
|
340
|
-
description: 'Carregador de celular com cabo USB-C',
|
|
341
|
-
name: 'Carregador de Celular',
|
|
342
|
-
quantity: 1,
|
|
343
|
-
priceInCents: 500,
|
|
344
|
-
},
|
|
345
|
-
],
|
|
346
|
-
})
|
|
39
|
+
// Usar métodos do SDK
|
|
40
|
+
const customer = await window.easyflowSDK.createCustomer(customerData)
|
|
41
|
+
const payment = await window.easyflowSDK.charge(paymentData)
|
|
347
42
|
```
|
|
348
43
|
|
|
349
|
-
|
|
44
|
+
## Usage
|
|
350
45
|
|
|
351
|
-
|
|
46
|
+
### Basic Configuration
|
|
352
47
|
|
|
353
48
|
```javascript
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
expirationMonth: '12',
|
|
358
|
-
expirationYear: '2025',
|
|
359
|
-
cvv: '123',
|
|
49
|
+
// Configure the SDK with your business ID
|
|
50
|
+
window.easyflowSDK.configure({
|
|
51
|
+
businessId: 'your-business-id',
|
|
360
52
|
})
|
|
361
53
|
```
|
|
362
54
|
|
|
363
55
|
### Customer Management
|
|
364
56
|
|
|
365
|
-
#### `createCustomer(customerData, headers)`
|
|
366
|
-
|
|
367
|
-
Creates a new customer.
|
|
368
|
-
|
|
369
|
-
```javascript
|
|
370
|
-
const customer = await easyflowSDK.createCustomer({
|
|
371
|
-
name: 'João Silva',
|
|
372
|
-
email: 'joao@exemplo.com',
|
|
373
|
-
document: { type: 'CPF', number: '12345678901' },
|
|
374
|
-
})
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
#### `getCustomer(customerId, headers)`
|
|
378
|
-
|
|
379
|
-
Retrieves customer information.
|
|
380
|
-
|
|
381
|
-
```javascript
|
|
382
|
-
const customer = await easyflowSDK.getCustomer('demo-customer-12345')
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
#### `updateCustomer(customerId, updateData, headers)`
|
|
386
|
-
|
|
387
|
-
Updates existing customer information.
|
|
388
|
-
|
|
389
|
-
```javascript
|
|
390
|
-
const result = await easyflowSDK.updateCustomer('demo-customer-12345', {
|
|
391
|
-
name: 'João Atualizado',
|
|
392
|
-
email: 'joao.atualizado@exemplo.com',
|
|
393
|
-
})
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
### Credit Card Management
|
|
397
|
-
|
|
398
|
-
#### `addCreditCard(customerId, creditCardToken, headers)`
|
|
399
|
-
|
|
400
|
-
Adds a credit card to a customer.
|
|
401
|
-
|
|
402
|
-
```javascript
|
|
403
|
-
const result = await easyflowSDK.addCreditCard(
|
|
404
|
-
'demo-customer-12345',
|
|
405
|
-
'encrypted-token-demo'
|
|
406
|
-
)
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
#### `getCreditCard(customerId, creditCardId, headers)`
|
|
410
|
-
|
|
411
|
-
Retrieves credit card information.
|
|
412
|
-
|
|
413
|
-
```javascript
|
|
414
|
-
const creditCard = await easyflowSDK.getCreditCard(
|
|
415
|
-
'demo-customer-12345',
|
|
416
|
-
'demo-card-67890'
|
|
417
|
-
)
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
#### `removeCreditCard(customerId, creditCardId, headers)`
|
|
421
|
-
|
|
422
|
-
Removes a credit card from a customer.
|
|
423
|
-
|
|
424
|
-
```javascript
|
|
425
|
-
const result = await easyflowSDK.removeCreditCard(
|
|
426
|
-
'demo-customer-12345',
|
|
427
|
-
'demo-card-67890'
|
|
428
|
-
)
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
## Validation
|
|
432
|
-
|
|
433
|
-
### ID Validation
|
|
434
|
-
|
|
435
|
-
All entity IDs must follow specific formats:
|
|
436
|
-
|
|
437
|
-
- **UUID v4**: `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx` (y = 8,9,A,B)
|
|
438
|
-
- **UUID v7**: `xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx` (y = 8,9,A,B)
|
|
439
|
-
- **MongoDB ObjectId**: 24-character hexadecimal format
|
|
440
|
-
|
|
441
|
-
```javascript
|
|
442
|
-
// Valid IDs
|
|
443
|
-
Validator.validateOrderId('f47ac10b-58cc-4372-a567-0e02b2c3d479') // UUID v4
|
|
444
|
-
Validator.validateOrderId('01890b24-2d7f-7c3f-8f1a-123456789abc') // UUID v7
|
|
445
|
-
Validator.validateOrderId('507f1f77bcf86cd799439011') // MongoDB ObjectId
|
|
446
|
-
```
|
|
447
|
-
|
|
448
|
-
### Data Validation
|
|
449
|
-
|
|
450
|
-
Comprehensive validation for all input data:
|
|
451
|
-
|
|
452
57
|
```javascript
|
|
453
|
-
//
|
|
454
|
-
|
|
58
|
+
// Create a customer
|
|
59
|
+
const customer = await window.easyflowSDK.createCustomer({
|
|
455
60
|
name: 'John Doe',
|
|
456
61
|
email: 'john@example.com',
|
|
457
|
-
document: {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
// Payment validation
|
|
461
|
-
Validator.validateOrderData({
|
|
462
|
-
items: [{ name: 'Product', price: 1000 }],
|
|
463
|
-
payments: [{ method: 'credit-card', numberInstallments: 1 }],
|
|
464
|
-
})
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
## Events
|
|
468
|
-
|
|
469
|
-
The SDK provides an event system for monitoring operations:
|
|
470
|
-
|
|
471
|
-
```javascript
|
|
472
|
-
// Listen to events
|
|
473
|
-
easyflowSDK.on('customerCreated', (data) => {
|
|
474
|
-
console.log('Cliente criado:', data)
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
easyflowSDK.on('orderPlaced', (data) => {
|
|
478
|
-
console.log('Pedido criado:', data)
|
|
479
|
-
})
|
|
480
|
-
|
|
481
|
-
easyflowSDK.on('paymentProcessed', (data) => {
|
|
482
|
-
console.log('Pagamento processado:', data)
|
|
483
|
-
})
|
|
484
|
-
|
|
485
|
-
// Remove event listeners
|
|
486
|
-
easyflowSDK.off('customerCreated', callback)
|
|
487
|
-
```
|
|
488
|
-
|
|
489
|
-
## Error Handling
|
|
490
|
-
|
|
491
|
-
The SDK provides comprehensive error handling:
|
|
492
|
-
|
|
493
|
-
```javascript
|
|
494
|
-
try {
|
|
495
|
-
const result = await easyflowSDK.placeOrder('demo-offer-67890', orderData)
|
|
496
|
-
} catch (error) {
|
|
497
|
-
if (error.name === 'ValidationError') {
|
|
498
|
-
console.log('Falha na validação:', error.message)
|
|
499
|
-
} else if (error.name === 'NetworkError') {
|
|
500
|
-
console.log('Erro de rede:', error.message)
|
|
501
|
-
} else if (error.name === 'SecurityError') {
|
|
502
|
-
console.log('Violação de segurança:', error.message)
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
## Configuration
|
|
508
|
-
|
|
509
|
-
### Business ID
|
|
510
|
-
|
|
511
|
-
The `businessId` parameter is a required configuration that identifies your business within the Easyflow platform. You
|
|
512
|
-
can find this value in your business configuration at [https://app.easyflow.digital/](https://app.easyflow.digital/).
|
|
513
|
-
|
|
514
|
-
**Important:** Never share your business ID publicly. Keep it secure and use it only in your application code.
|
|
515
|
-
|
|
516
|
-
### SDK Options
|
|
517
|
-
|
|
518
|
-
```javascript
|
|
519
|
-
// Configure the global instance
|
|
520
|
-
easyflowSDK.configure({
|
|
521
|
-
businessId: 'demo-business-12345',
|
|
522
|
-
environment: 'production', // 'production' or 'sandbox'
|
|
523
|
-
debug: false, // Enable debug logging
|
|
524
|
-
timeout: 30000, // Request timeout in milliseconds
|
|
525
|
-
})
|
|
526
|
-
```
|
|
527
|
-
|
|
528
|
-
### Environment Variables
|
|
529
|
-
|
|
530
|
-
```bash
|
|
531
|
-
EASYFLOW_BUSINESS_ID=demo-business-12345
|
|
532
|
-
EASYFLOW_ENVIRONMENT=production
|
|
533
|
-
EASYFLOW_DEBUG=false
|
|
534
|
-
```
|
|
535
|
-
|
|
536
|
-
## Examples
|
|
537
|
-
|
|
538
|
-
### Complete Checkout Flow
|
|
539
|
-
|
|
540
|
-
```javascript
|
|
541
|
-
// 1. Create customer
|
|
542
|
-
const customer = await easyflowSDK.createCustomer({
|
|
543
|
-
name: 'João Silva',
|
|
544
|
-
email: 'joao@exemplo.com',
|
|
545
|
-
document: { type: 'CPF', number: '12345678901' },
|
|
546
|
-
})
|
|
547
|
-
|
|
548
|
-
// 2. Encrypt credit card
|
|
549
|
-
const token = await easyflowSDK.encrypt({
|
|
550
|
-
number: '4111111111111111',
|
|
551
|
-
holderName: 'João Silva',
|
|
552
|
-
expirationMonth: '12',
|
|
553
|
-
expirationYear: '2025',
|
|
554
|
-
cvv: '123',
|
|
555
|
-
})
|
|
556
|
-
|
|
557
|
-
// 3. Add credit card to customer
|
|
558
|
-
const creditCard = await easyflowSDK.addCreditCard(customer.id, token)
|
|
559
|
-
|
|
560
|
-
// 4. Place order
|
|
561
|
-
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
562
|
-
buyer: {
|
|
563
|
-
customerId: customer.id,
|
|
564
|
-
name: 'E. R.',
|
|
565
|
-
email: 'e***o@gmail.com',
|
|
566
|
-
document: {
|
|
567
|
-
number: '***202266**',
|
|
568
|
-
type: 'CPF',
|
|
569
|
-
},
|
|
570
|
-
phone: {
|
|
571
|
-
areaCode: '+55',
|
|
572
|
-
ddd: '92',
|
|
573
|
-
number: '*****2191',
|
|
574
|
-
isMobile: true,
|
|
575
|
-
},
|
|
576
|
-
address: {
|
|
577
|
-
zipCode: '37537***',
|
|
578
|
-
street: 'Rua R. C. M. de A.',
|
|
579
|
-
complement: '',
|
|
580
|
-
neighborhood: 'M. do S.',
|
|
581
|
-
city: 'Santa Rita do Sapucaí',
|
|
582
|
-
state: 'MG',
|
|
583
|
-
number: '***',
|
|
584
|
-
},
|
|
585
|
-
},
|
|
586
|
-
payments: [
|
|
587
|
-
{
|
|
588
|
-
method: 'credit-card',
|
|
589
|
-
creditCard: {
|
|
590
|
-
cardId: creditCard.id,
|
|
591
|
-
},
|
|
592
|
-
numberInstallments: 1,
|
|
593
|
-
},
|
|
594
|
-
],
|
|
595
|
-
metadata: [],
|
|
596
|
-
})
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
### PIX Payment
|
|
600
|
-
|
|
601
|
-
```javascript
|
|
602
|
-
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
603
|
-
buyer: {
|
|
604
|
-
name: 'E. R.',
|
|
605
|
-
email: 'e***o@gmail.com',
|
|
606
|
-
document: {
|
|
607
|
-
number: '***202266**',
|
|
608
|
-
type: 'CPF',
|
|
609
|
-
},
|
|
610
|
-
phone: {
|
|
611
|
-
areaCode: '+55',
|
|
612
|
-
ddd: '92',
|
|
613
|
-
number: '*****2191',
|
|
614
|
-
isMobile: true,
|
|
615
|
-
},
|
|
616
|
-
address: {
|
|
617
|
-
zipCode: '37537***',
|
|
618
|
-
street: 'Rua R. C. M. de A.',
|
|
619
|
-
complement: '',
|
|
620
|
-
neighborhood: 'M. do S.',
|
|
621
|
-
city: 'Santa Rita do Sapucaí',
|
|
622
|
-
state: 'MG',
|
|
623
|
-
number: '***',
|
|
624
|
-
},
|
|
625
|
-
},
|
|
626
|
-
payments: [
|
|
627
|
-
{
|
|
628
|
-
method: 'pix',
|
|
629
|
-
numberInstallments: 1,
|
|
630
|
-
},
|
|
631
|
-
],
|
|
632
|
-
})
|
|
633
|
-
|
|
634
|
-
// Get PIX data
|
|
635
|
-
const pixData = await easyflowSDK.getPix(orderId)
|
|
636
|
-
console.log('PIX QR Code:', pixData.qrCode)
|
|
637
|
-
```
|
|
638
|
-
|
|
639
|
-
### Bank Billet Payment
|
|
640
|
-
|
|
641
|
-
```javascript
|
|
642
|
-
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
643
|
-
buyer: {
|
|
644
|
-
name: 'E. R.',
|
|
645
|
-
email: 'e***o@gmail.com',
|
|
646
|
-
document: {
|
|
647
|
-
number: '***202266**',
|
|
648
|
-
type: 'CPF',
|
|
649
|
-
},
|
|
650
|
-
phone: {
|
|
651
|
-
areaCode: '+55',
|
|
652
|
-
ddd: '92',
|
|
653
|
-
number: '*****2191',
|
|
654
|
-
isMobile: true,
|
|
655
|
-
},
|
|
656
|
-
address: {
|
|
657
|
-
zipCode: '37537***',
|
|
658
|
-
street: 'Rua R. C. M. de A.',
|
|
659
|
-
complement: '',
|
|
660
|
-
neighborhood: 'M. do S.',
|
|
661
|
-
city: 'Santa Rita do Sapucaí',
|
|
662
|
-
state: 'MG',
|
|
663
|
-
number: '***',
|
|
664
|
-
},
|
|
62
|
+
document: {
|
|
63
|
+
type: 'CPF',
|
|
64
|
+
number: '12345678901',
|
|
665
65
|
},
|
|
666
|
-
metadata: [],
|
|
667
|
-
payments: [
|
|
668
|
-
{
|
|
669
|
-
method: 'bank-billet',
|
|
670
|
-
numberInstallments: 1,
|
|
671
|
-
},
|
|
672
|
-
],
|
|
673
66
|
})
|
|
674
67
|
|
|
675
|
-
// Get
|
|
676
|
-
const
|
|
677
|
-
console.log('Bank Billet Link:', bankBillet.link)
|
|
678
|
-
```
|
|
679
|
-
|
|
680
|
-
## Complete Implementation Examples
|
|
681
|
-
|
|
682
|
-
### 1. placeOrder - Complete Data Model
|
|
68
|
+
// Get customer by ID
|
|
69
|
+
const customerData = await window.easyflowSDK.getCustomer('customer-id')
|
|
683
70
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
// Configure SDK
|
|
688
|
-
easyflowSDK.configure({
|
|
689
|
-
businessId: 'demo-business-12345',
|
|
71
|
+
// Update customer
|
|
72
|
+
const updatedCustomer = await window.easyflowSDK.updateCustomer('customer-id', {
|
|
73
|
+
name: 'John Updated',
|
|
690
74
|
})
|
|
691
|
-
|
|
692
|
-
// Complete placeOrder example with PIX payment
|
|
693
|
-
const orderId = await easyflowSDK.placeOrder(
|
|
694
|
-
'3df92ac7-9d7f-4948-b54f-7e082492f6d2',
|
|
695
|
-
{
|
|
696
|
-
buyer: {
|
|
697
|
-
name: 'João Silva Santos',
|
|
698
|
-
email: 'joao.silva@exemplo.com',
|
|
699
|
-
document: {
|
|
700
|
-
number: '12345678901',
|
|
701
|
-
type: 'CPF',
|
|
702
|
-
},
|
|
703
|
-
phone: {
|
|
704
|
-
areaCode: '+55',
|
|
705
|
-
ddd: '11',
|
|
706
|
-
number: '9988776655',
|
|
707
|
-
isMobile: true,
|
|
708
|
-
},
|
|
709
|
-
address: {
|
|
710
|
-
zipCode: '01234567',
|
|
711
|
-
street: 'Rua das Flores',
|
|
712
|
-
complement: 'Apto 101',
|
|
713
|
-
neighborhood: 'Centro',
|
|
714
|
-
city: 'São Paulo',
|
|
715
|
-
state: 'SP',
|
|
716
|
-
number: '123',
|
|
717
|
-
},
|
|
718
|
-
},
|
|
719
|
-
payments: [
|
|
720
|
-
{
|
|
721
|
-
method: 'pix',
|
|
722
|
-
numberInstallments: 1,
|
|
723
|
-
},
|
|
724
|
-
],
|
|
725
|
-
metadata: [],
|
|
726
|
-
}
|
|
727
|
-
)
|
|
728
|
-
|
|
729
|
-
console.log('Order created with PIX payment:', orderId)
|
|
730
75
|
```
|
|
731
76
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
```javascript
|
|
735
|
-
// Complete placeOrder example with credit card payment
|
|
736
|
-
const orderId = await easyflowSDK.placeOrder(
|
|
737
|
-
'3df92ac7-9d7f-4948-b54f-7e082492f6d2',
|
|
738
|
-
{
|
|
739
|
-
buyer: {
|
|
740
|
-
name: 'João Silva Santos',
|
|
741
|
-
email: 'joao.silva@exemplo.com',
|
|
742
|
-
document: {
|
|
743
|
-
number: '12345678901',
|
|
744
|
-
type: 'CPF',
|
|
745
|
-
},
|
|
746
|
-
phone: {
|
|
747
|
-
areaCode: '+55',
|
|
748
|
-
ddd: '11',
|
|
749
|
-
number: '9988776655',
|
|
750
|
-
isMobile: true,
|
|
751
|
-
},
|
|
752
|
-
address: {
|
|
753
|
-
zipCode: '01234567',
|
|
754
|
-
street: 'Rua das Flores',
|
|
755
|
-
complement: 'Apto 101',
|
|
756
|
-
neighborhood: 'Centro',
|
|
757
|
-
city: 'São Paulo',
|
|
758
|
-
state: 'SP',
|
|
759
|
-
number: '123',
|
|
760
|
-
},
|
|
761
|
-
},
|
|
762
|
-
payments: [
|
|
763
|
-
{
|
|
764
|
-
method: 'credit-card',
|
|
765
|
-
numberInstallments: 1,
|
|
766
|
-
creditCard: {
|
|
767
|
-
cardId: 'demo-credit-card-67890', // cardId e token são opcionais, mas pelo menos 1 deve ser fornecido
|
|
768
|
-
token: 'demo-credit-card-token-here',
|
|
769
|
-
last4Numbers: '1234',
|
|
770
|
-
holderName: 'JOAO SILVA SANTOS',
|
|
771
|
-
expiresAtMonth: '12',
|
|
772
|
-
expiresAtYear: '2025',
|
|
773
|
-
flag: 'visa',
|
|
774
|
-
},
|
|
775
|
-
},
|
|
776
|
-
],
|
|
777
|
-
metadata: [],
|
|
778
|
-
}
|
|
779
|
-
)
|
|
780
|
-
|
|
781
|
-
console.log('Order created with credit card payment:', orderId)
|
|
782
|
-
```
|
|
783
|
-
|
|
784
|
-
### 2. charge - Complete Data Model
|
|
785
|
-
|
|
786
|
-
#### charge com Cartão de Crédito
|
|
77
|
+
### Payment Processing
|
|
787
78
|
|
|
788
79
|
```javascript
|
|
789
|
-
//
|
|
790
|
-
const
|
|
791
|
-
buyer:
|
|
792
|
-
name: 'João Silva Santos',
|
|
793
|
-
email: 'joao.silva@exemplo.com',
|
|
794
|
-
document: {
|
|
795
|
-
number: '12345678901',
|
|
796
|
-
type: 'CPF',
|
|
797
|
-
},
|
|
798
|
-
phone: {
|
|
799
|
-
areaCode: '+55',
|
|
800
|
-
ddd: '11',
|
|
801
|
-
number: '9988776655',
|
|
802
|
-
isMobile: true,
|
|
803
|
-
},
|
|
804
|
-
address: {
|
|
805
|
-
zipCode: '01234567',
|
|
806
|
-
street: 'Rua das Flores',
|
|
807
|
-
complement: 'Apto 101',
|
|
808
|
-
neighborhood: 'Centro',
|
|
809
|
-
city: 'São Paulo',
|
|
810
|
-
state: 'SP',
|
|
811
|
-
number: '123',
|
|
812
|
-
},
|
|
813
|
-
customerId: 'demo-customer-12345', // ID do cliente existente (opcional)
|
|
814
|
-
},
|
|
80
|
+
// Process a payment
|
|
81
|
+
const payment = await window.easyflowSDK.charge({
|
|
82
|
+
buyer: customerData,
|
|
815
83
|
payments: [
|
|
816
84
|
{
|
|
817
|
-
method: '
|
|
85
|
+
method: 'pix',
|
|
86
|
+
valueInCents: 10000,
|
|
818
87
|
numberInstallments: 1,
|
|
819
|
-
valueInCents: 500,
|
|
820
|
-
creditCard: {
|
|
821
|
-
cardId: 'demo-card-id-here', // cardId e token são opcionais, mas pelo menos 1 deve ser fornecido
|
|
822
|
-
token: 'demo-token-credit-card-here',
|
|
823
|
-
},
|
|
824
88
|
},
|
|
825
89
|
],
|
|
826
90
|
items: [
|
|
827
91
|
{
|
|
828
|
-
|
|
829
|
-
|
|
92
|
+
name: 'Product',
|
|
93
|
+
priceInCents: 10000,
|
|
830
94
|
quantity: 1,
|
|
831
|
-
priceInCents: 500,
|
|
832
95
|
},
|
|
833
96
|
],
|
|
834
97
|
})
|
|
835
|
-
|
|
836
|
-
console.log('Charge processed with credit card:', orderId)
|
|
837
98
|
```
|
|
838
99
|
|
|
839
|
-
|
|
100
|
+
### Order Management
|
|
840
101
|
|
|
841
102
|
```javascript
|
|
842
|
-
//
|
|
843
|
-
const
|
|
844
|
-
buyer:
|
|
845
|
-
name: 'João Silva Santos',
|
|
846
|
-
email: 'joao.silva@exemplo.com',
|
|
847
|
-
document: {
|
|
848
|
-
number: '12345678901',
|
|
849
|
-
type: 'CPF',
|
|
850
|
-
},
|
|
851
|
-
phone: {
|
|
852
|
-
areaCode: '+55',
|
|
853
|
-
ddd: '11',
|
|
854
|
-
number: '9988776655',
|
|
855
|
-
isMobile: true,
|
|
856
|
-
},
|
|
857
|
-
address: {
|
|
858
|
-
zipCode: '01234567',
|
|
859
|
-
street: 'Rua das Flores',
|
|
860
|
-
complement: 'Apto 101',
|
|
861
|
-
neighborhood: 'Centro',
|
|
862
|
-
city: 'São Paulo',
|
|
863
|
-
state: 'SP',
|
|
864
|
-
number: '123',
|
|
865
|
-
},
|
|
866
|
-
customerId: 'demo-customer-12345', // ID do cliente existente (opcional)
|
|
867
|
-
},
|
|
103
|
+
// Place an order
|
|
104
|
+
const order = await window.easyflowSDK.placeOrder('offer-id', {
|
|
105
|
+
buyer: customerData,
|
|
868
106
|
payments: [
|
|
869
107
|
{
|
|
870
|
-
method: '
|
|
108
|
+
method: 'credit-card',
|
|
871
109
|
numberInstallments: 1,
|
|
872
|
-
valueInCents: 500,
|
|
873
110
|
},
|
|
874
111
|
],
|
|
875
112
|
items: [
|
|
876
113
|
{
|
|
877
|
-
|
|
878
|
-
|
|
114
|
+
name: 'Product',
|
|
115
|
+
priceInCents: 10000,
|
|
879
116
|
quantity: 1,
|
|
880
|
-
priceInCents: 500,
|
|
881
117
|
},
|
|
882
118
|
],
|
|
883
|
-
businessId: 'demo-business-12345',
|
|
884
119
|
})
|
|
885
120
|
|
|
886
|
-
|
|
121
|
+
// Get order by ID
|
|
122
|
+
const orderData = await window.easyflowSDK.getOrder('order-id')
|
|
887
123
|
```
|
|
888
124
|
|
|
889
|
-
###
|
|
125
|
+
### Credit Card Management
|
|
890
126
|
|
|
891
127
|
```javascript
|
|
892
|
-
//
|
|
893
|
-
const
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
number: '9988776655',
|
|
904
|
-
isMobile: true,
|
|
905
|
-
},
|
|
906
|
-
address: {
|
|
907
|
-
zipCode: '01234567',
|
|
908
|
-
street: 'Rua das Flores',
|
|
909
|
-
complement: 'Apto 101',
|
|
910
|
-
neighborhood: 'Centro',
|
|
911
|
-
city: 'São Paulo',
|
|
912
|
-
state: 'SP',
|
|
913
|
-
number: '123',
|
|
914
|
-
},
|
|
915
|
-
deliveryAddress: {
|
|
916
|
-
zipCode: '01234567',
|
|
917
|
-
street: 'Rua das Flores',
|
|
918
|
-
complement: 'Apto 101',
|
|
919
|
-
neighborhood: 'Centro',
|
|
920
|
-
city: 'São Paulo',
|
|
921
|
-
state: 'SP',
|
|
922
|
-
number: '123',
|
|
923
|
-
},
|
|
924
|
-
})
|
|
128
|
+
// Add credit card
|
|
129
|
+
const creditCard = await window.easyflowSDK.addCreditCard(
|
|
130
|
+
'customer-id',
|
|
131
|
+
'encrypted-token'
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
// Get credit card
|
|
135
|
+
const cardData = await window.easyflowSDK.getCreditCard(
|
|
136
|
+
'customer-id',
|
|
137
|
+
'card-id'
|
|
138
|
+
)
|
|
925
139
|
|
|
926
|
-
|
|
140
|
+
// Remove credit card
|
|
141
|
+
const result = await window.easyflowSDK.removeCreditCard(
|
|
142
|
+
'customer-id',
|
|
143
|
+
'card-id'
|
|
144
|
+
)
|
|
927
145
|
```
|
|
928
146
|
|
|
929
|
-
###
|
|
147
|
+
### Utility Methods
|
|
930
148
|
|
|
931
149
|
```javascript
|
|
932
|
-
//
|
|
933
|
-
const
|
|
934
|
-
|
|
150
|
+
// Encrypt credit card data
|
|
151
|
+
const encryptedCard = await window.easyflowSDK.encrypt({
|
|
152
|
+
number: '4111111111111111',
|
|
153
|
+
holderName: 'JOHN DOE',
|
|
154
|
+
expirationMonth: '12',
|
|
155
|
+
expirationYear: '2025',
|
|
935
156
|
cvv: '123',
|
|
936
|
-
month: '12',
|
|
937
|
-
year: '2025',
|
|
938
|
-
holderName: 'PEDRO OLIVEIRA LIMA',
|
|
939
157
|
})
|
|
940
158
|
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
// Then add the encrypted token to the customer
|
|
944
|
-
const creditCard = await easyflowSDK.addCreditCard(
|
|
945
|
-
customer.id, // customer ID from createCustomer
|
|
946
|
-
encryptedToken
|
|
947
|
-
)
|
|
948
|
-
|
|
949
|
-
console.log('Credit card added successfully:', creditCard)
|
|
950
|
-
|
|
951
|
-
// Now you can use the credit card for payments
|
|
952
|
-
const orderWithSavedCard = await easyflowSDK.placeOrder(
|
|
953
|
-
'3df92ac7-9d7f-4948-b54f-7e082492f6d2',
|
|
954
|
-
{
|
|
955
|
-
buyer: {
|
|
956
|
-
customerId: customer.id, // Use existing customer
|
|
957
|
-
name: 'João Silva Santos',
|
|
958
|
-
email: 'joao.silva@exemplo.com',
|
|
959
|
-
document: {
|
|
960
|
-
number: '12345678901',
|
|
961
|
-
type: 'CPF',
|
|
962
|
-
},
|
|
963
|
-
},
|
|
964
|
-
payments: [
|
|
965
|
-
{
|
|
966
|
-
method: 'credit-card',
|
|
967
|
-
numberInstallments: 6,
|
|
968
|
-
creditCard: {
|
|
969
|
-
cardId: creditCard.id, // Use saved credit card
|
|
970
|
-
},
|
|
971
|
-
},
|
|
972
|
-
],
|
|
973
|
-
offerItems: [
|
|
974
|
-
{
|
|
975
|
-
offerItemId: '3df92ac7-9d7f-4948-b54f-7e082492f6d2',
|
|
976
|
-
quantity: 1,
|
|
977
|
-
},
|
|
978
|
-
],
|
|
979
|
-
metadata: [],
|
|
980
|
-
}
|
|
981
|
-
)
|
|
982
|
-
|
|
983
|
-
console.log('Order with saved credit card:', orderWithSavedCard)
|
|
159
|
+
// Get SDK status
|
|
160
|
+
const status = window.easyflowSDK.getStatus()
|
|
984
161
|
```
|
|
985
162
|
|
|
986
|
-
|
|
163
|
+
## Events
|
|
987
164
|
|
|
988
165
|
```javascript
|
|
989
|
-
//
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
easyflowSDK.configure({
|
|
994
|
-
businessId: 'demo-business-12345',
|
|
995
|
-
})
|
|
996
|
-
|
|
997
|
-
// 2. Create customer with complete data
|
|
998
|
-
const customer = await easyflowSDK.createCustomer({
|
|
999
|
-
name: 'Ana Silva Costa',
|
|
1000
|
-
email: 'ana.silva@exemplo.com',
|
|
1001
|
-
document: { type: 'CPF', number: '55566677788' },
|
|
1002
|
-
phone: {
|
|
1003
|
-
areaCode: '+55',
|
|
1004
|
-
ddd: '41',
|
|
1005
|
-
number: '765432109',
|
|
1006
|
-
isMobile: true,
|
|
1007
|
-
},
|
|
1008
|
-
address: {
|
|
1009
|
-
zipCode: '80000000',
|
|
1010
|
-
street: 'Rua das Palmeiras',
|
|
1011
|
-
complement: 'Apto 202',
|
|
1012
|
-
neighborhood: 'Batel',
|
|
1013
|
-
city: 'Curitiba',
|
|
1014
|
-
state: 'PR',
|
|
1015
|
-
number: '321',
|
|
1016
|
-
},
|
|
1017
|
-
})
|
|
1018
|
-
|
|
1019
|
-
// 3. Encrypt and add credit card
|
|
1020
|
-
const token = await easyflowSDK.encrypt({
|
|
1021
|
-
cardNumber: '5555555555554444',
|
|
1022
|
-
cvv: '321',
|
|
1023
|
-
month: '10',
|
|
1024
|
-
year: '2026',
|
|
1025
|
-
holderName: 'ANA SILVA COSTA',
|
|
1026
|
-
})
|
|
166
|
+
// SDK Ready
|
|
167
|
+
window.easyflowSDK.on('SDKReady', (data) => {
|
|
168
|
+
console.log('SDK loaded:', data)
|
|
169
|
+
})
|
|
1027
170
|
|
|
1028
|
-
|
|
171
|
+
// Customer created
|
|
172
|
+
window.easyflowSDK.on('customerCreated', (customer) => {
|
|
173
|
+
console.log('Customer created:', customer)
|
|
174
|
+
})
|
|
1029
175
|
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
buyer: {
|
|
1035
|
-
customerId: customer.id,
|
|
1036
|
-
name: customer.name,
|
|
1037
|
-
email: customer.email,
|
|
1038
|
-
document: customer.document,
|
|
1039
|
-
},
|
|
1040
|
-
payments: [
|
|
1041
|
-
{
|
|
1042
|
-
method: 'credit-card',
|
|
1043
|
-
numberInstallments: 12,
|
|
1044
|
-
creditCard: { cardId: creditCard.id },
|
|
1045
|
-
},
|
|
1046
|
-
],
|
|
1047
|
-
offerItems: [
|
|
1048
|
-
{
|
|
1049
|
-
offerItemId: '3df92ac7-9d7f-4948-b54f-7e082492f6d2',
|
|
1050
|
-
quantity: 1,
|
|
1051
|
-
},
|
|
1052
|
-
],
|
|
1053
|
-
metadata: [],
|
|
1054
|
-
}
|
|
1055
|
-
)
|
|
176
|
+
// Payment processed
|
|
177
|
+
window.easyflowSDK.on('paymentProcessed', (payment) => {
|
|
178
|
+
console.log('Payment processed:', payment)
|
|
179
|
+
})
|
|
1056
180
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
})
|
|
1062
|
-
} catch (error) {
|
|
1063
|
-
console.error('Workflow failed:', error.message)
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
181
|
+
// Order placed
|
|
182
|
+
window.easyflowSDK.on('orderPlaced', (order) => {
|
|
183
|
+
console.log('Order placed:', order)
|
|
184
|
+
})
|
|
1066
185
|
|
|
1067
|
-
//
|
|
1068
|
-
|
|
186
|
+
// Error
|
|
187
|
+
window.easyflowSDK.on('error', (error) => {
|
|
188
|
+
console.error('Error:', error)
|
|
189
|
+
})
|
|
1069
190
|
```
|
|
1070
191
|
|
|
1071
|
-
##
|
|
1072
|
-
|
|
1073
|
-
### Why CDN Scripts?
|
|
192
|
+
## Security Features
|
|
1074
193
|
|
|
1075
|
-
- **
|
|
1076
|
-
- **
|
|
1077
|
-
- **
|
|
1078
|
-
- **
|
|
194
|
+
- **HTTPS/SSL Strict** - All communications are encrypted
|
|
195
|
+
- **CORS with domain validation** - Strict cross-origin protection
|
|
196
|
+
- **Rate limiting** - Protection against abuse
|
|
197
|
+
- **Input validation** - Comprehensive data validation
|
|
198
|
+
- **Replay protection** - Protection against replay attacks
|
|
199
|
+
- **Iframe protection** - Protection against clickjacking
|
|
200
|
+
- **XSS protection** - Protection against cross-site scripting
|
|
1079
201
|
|
|
1080
|
-
|
|
202
|
+
## Authentication
|
|
1081
203
|
|
|
1082
|
-
|
|
204
|
+
- **ECDSA (P-256)** - Elliptic curve digital signature algorithm
|
|
205
|
+
- **SHA256** - Secure hash algorithm
|
|
206
|
+
- **Browser fingerprinting** - Device identification
|
|
207
|
+
- **Domain validation** - Origin verification
|
|
1083
208
|
|
|
1084
|
-
|
|
1085
|
-
<!-- Latest version -->
|
|
1086
|
-
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
1087
|
-
|
|
1088
|
-
<!-- Versioned (recommended for production) -->
|
|
1089
|
-
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.19.min.js"></script>
|
|
1090
|
-
|
|
1091
|
-
<!-- With SRI (Subresource Integrity) -->
|
|
1092
|
-
<script
|
|
1093
|
-
src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.19.min.js"
|
|
1094
|
-
integrity="sha384-[hash]"
|
|
1095
|
-
crossorigin="anonymous"
|
|
1096
|
-
></script>
|
|
1097
|
-
```
|
|
1098
|
-
|
|
1099
|
-
#### jsDelivr (Alternative)
|
|
209
|
+
## Compliance
|
|
1100
210
|
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
<!-- Specific version -->
|
|
1106
|
-
<script src="https://cdn.jsdelivr.net/npm/@easyflow/javascript-sdk@2.1.20/dist/easyflow-sdk.min.js"></script>
|
|
1107
|
-
```
|
|
211
|
+
- **PCI-DSS** - Payment Card Industry Data Security Standard
|
|
212
|
+
- **LGPD** - Brazilian General Data Protection Law
|
|
213
|
+
- **GDPR** - General Data Protection Regulation
|
|
1108
214
|
|
|
1109
|
-
##
|
|
215
|
+
## Compatibility
|
|
1110
216
|
|
|
1111
|
-
|
|
217
|
+
- **Browsers**: Chrome, Firefox, Safari, Edge
|
|
218
|
+
- **Frameworks**: React, Vue, Angular, vanilla JS
|
|
219
|
+
- **Mobile**: Web, PWA, Hybrid apps
|
|
220
|
+
- **TypeScript**: Full support
|
|
221
|
+
- **NPM**: Installation via package manager
|
|
222
|
+
- **CDN**: Direct loading
|
|
1112
223
|
|
|
1113
|
-
|
|
1114
|
-
- **npm**: 8+
|
|
1115
|
-
- **yarn**: 1.22+
|
|
224
|
+
## Performance
|
|
1116
225
|
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
226
|
+
- **Size**: ~97KB (minified and obfuscated)
|
|
227
|
+
- **Loading**: Asynchronous and non-blocking
|
|
228
|
+
- **Cache**: CDN optimized
|
|
229
|
+
- **Bundle**: Compatible with modern bundlers
|
|
1120
230
|
|
|
1121
231
|
## Support
|
|
1122
232
|
|
|
1123
|
-
- **
|
|
1124
|
-
- **
|
|
1125
|
-
- **
|
|
1126
|
-
|
|
1127
|
-
## License
|
|
1128
|
-
|
|
1129
|
-
This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details.
|
|
1130
|
-
|
|
1131
|
-
## Author
|
|
1132
|
-
|
|
1133
|
-
**Diego Moura** - Co-Found & CTO at Easyflow
|
|
1134
|
-
|
|
1135
|
-
- **Email**: [contato@easyflow.digital](mailto:contato@easyflow.digital)
|
|
1136
|
-
- **Website**: [https://www.easyflow.digital](https://www.easyflow.digital)
|
|
1137
|
-
|
|
1138
|
-
## Changelog
|
|
1139
|
-
|
|
1140
|
-
### v2.1.23
|
|
1141
|
-
|
|
1142
|
-
- **SDK Simplification**: Removed all platform-specific integrations for cleaner, focused codebase
|
|
1143
|
-
- **Streamlined Documentation**: Focused README on core SDK functionality and usage
|
|
1144
|
-
- **Enhanced Security**: Maintained all security features while simplifying the codebase
|
|
1145
|
-
- **Better Developer Experience**: Cleaner documentation focused on essential features
|
|
1146
|
-
|
|
1147
|
-
### v2.1.20
|
|
1148
|
-
|
|
1149
|
-
- **jsDelivr CDN Fix**: Fixed npm package to include easyflow-sdk.min.js for proper jsDelivr CDN support
|
|
1150
|
-
- **Package Structure**: Corrected package.json files field to include JavaScript build files
|
|
1151
|
-
- **CDN Availability**: jsDelivr now properly serves the SDK at specific version URLs
|
|
1152
|
-
- **Homepage Redirect**: Added automatic redirect from SDK homepage to NPM package for better discoverability
|
|
1153
|
-
|
|
1154
|
-
### v2.1.19
|
|
1155
|
-
|
|
1156
|
-
- **Documentation Updates**: Removed all references to private repository
|
|
1157
|
-
- **Business ID Information**: Added clear guidance on where to find BUSINESS_ID parameter
|
|
1158
|
-
- **Contact Information**: Added official contact email for support
|
|
1159
|
-
- **Author Information**: Updated author details and role information
|
|
1160
|
-
- **Repository Cleanup**: Cleaned up all private repository references
|
|
1161
|
-
- **CDN Options**: Added jsDelivr as alternative CDN option for installation
|
|
1162
|
-
|
|
1163
|
-
### v2.1.18
|
|
233
|
+
- **Email**: contato@easyflow.digital
|
|
234
|
+
- **Hours**: Mon-Fri, 9h to 18h (GMT-3)
|
|
235
|
+
- **Documentation**: https://docs.easyflow.digital
|
|
236
|
+
- **NPM**: https://www.npmjs.com/package/@easyflow/javascript-sdk
|
|
1164
237
|
|
|
1165
|
-
|
|
1166
|
-
- **Documentation**: Updated version references and CDN URLs
|
|
1167
|
-
- **Consistency**: All version references aligned to v2.1.18
|
|
238
|
+
## Documentation
|
|
1168
239
|
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
- **
|
|
1172
|
-
- **Full Data Models**: Examples showing all available fields for placeOrder, charge, createCustomer, addCreditCard
|
|
1173
|
-
- **Brazilian Data Examples**: Realistic Brazilian addresses, phone
|
|
1174
|
-
- **Version Update**: Patch release for latest improvements
|
|
1175
|
-
- **Documentation**: Updated version references and CDN URLs
|
|
1176
|
-
- **Consistency**: All version references aligned to v2.1.17
|
|
1177
|
-
|
|
1178
|
-
### v2.1.14
|
|
1179
|
-
|
|
1180
|
-
- **Version Update**: Patch release for latest improvements
|
|
1181
|
-
- **Documentation**: Updated version references and CDN URLs
|
|
1182
|
-
- **Consistency**: All version references aligned to v2.1.14
|
|
1183
|
-
|
|
1184
|
-
### v2.1.13
|
|
1185
|
-
|
|
1186
|
-
- **Code Formatting**: Improved readability of placeOrder examples with better line breaks
|
|
1187
|
-
- **Documentation**: Enhanced formatting for complex method calls
|
|
1188
|
-
- **Examples**: Better visual structure for placeOrder, charge, and workflow examples
|
|
1189
|
-
- **Consistency**: Unified formatting across all code examples
|
|
1190
|
-
|
|
1191
|
-
### v2.1.12
|
|
1192
|
-
|
|
1193
|
-
- **Complete Implementation Examples**: Added comprehensive examples for all major methods
|
|
1194
|
-
- **Full Data Models**: Examples showing all available fields for placeOrder, charge, createCustomer, addCreditCard
|
|
1195
|
-
- **Brazilian Data Examples**: Realistic Brazilian addresses, phone numbers, and document formats
|
|
1196
|
-
- **End-to-End Workflows**: Complete customer → credit card → order workflow examples
|
|
1197
|
-
- **Code Quality**: Improved formatting, consistency, and readability across all examples
|
|
1198
|
-
- **Documentation**: Fixed duplicate sections and improved overall structure
|
|
1199
|
-
|
|
1200
|
-
### v2.1.11
|
|
1201
|
-
|
|
1202
|
-
- **Credit Card Token Fix**: Accepts real encrypted/ciphered tokens from vault services
|
|
1203
|
-
- **Flexible Validation**: Supports Base64, URL-safe, and mixed character formats
|
|
1204
|
-
- **Variable Length**: Accepts tokens from 16 to 2048 characters
|
|
1205
|
-
- **Enhanced Security**: Maintains security while accepting real-world tokens
|
|
1206
|
-
- **Backward Compatibility**: Works with all existing token formats
|
|
1207
|
-
|
|
1208
|
-
### v2.1.10
|
|
1209
|
-
|
|
1210
|
-
- **Workflow Fixed**: Resolved GitHub Actions permissions and SRI hash generation
|
|
1211
|
-
- **CDN Automation**: Automated deployment to Cloudflare Pages working correctly
|
|
1212
|
-
- **Release Process**: GitHub releases created automatically with proper SRI hashes
|
|
1213
|
-
- **Build Pipeline**: Streamlined build and deployment process
|
|
1214
|
-
|
|
1215
|
-
### v2.1.9
|
|
1216
|
-
|
|
1217
|
-
- **Hybrid Distribution**: NPM for docs, CDN for secure obfuscated code
|
|
1218
|
-
- **Enhanced Security**: Code source protected while maintaining accessibility
|
|
1219
|
-
- **Better UX**: Easy discovery via NPM, secure usage via CDN
|
|
1220
|
-
- **Documentation**: Complete setup and usage instructions
|
|
1221
|
-
|
|
1222
|
-
### v2.1.8
|
|
1223
|
-
|
|
1224
|
-
- **Security & Privacy**: Anonymized README.md for safe NPM publication
|
|
1225
|
-
- **Documentation**: Removed all personal information and sensitive data
|
|
1226
|
-
- **Professional**: Clean, business-focused documentation
|
|
1227
|
-
|
|
1228
|
-
### v2.1.7
|
|
1229
|
-
|
|
1230
|
-
- Fixed all failing unit tests for complete 250 test coverage
|
|
1231
|
-
- Corrected mock structures for customer and credit card management
|
|
1232
|
-
- Standardized API response patterns across all endpoints
|
|
1233
|
-
- Enhanced test reliability and maintainability
|
|
1234
|
-
|
|
1235
|
-
### v2.1.6
|
|
1236
|
-
|
|
1237
|
-
- Enhanced ID validation with UUID v4, UUID v7, and MongoDB ObjectId support
|
|
1238
|
-
- Fixed iframe compatibility issues for low-code platforms
|
|
1239
|
-
- Implemented complete event system with `on()` and `off()` methods
|
|
1240
|
-
- Added global SDK instance for easier integration
|
|
1241
|
-
|
|
1242
|
-
### v2.1.5
|
|
240
|
+
- **[INDEX.md](INDEX.md)** - Central documentation hub
|
|
241
|
+
- **[DATA-STRUCTURES.md](DATA-STRUCTURES.md)** - Complete data structure reference
|
|
242
|
+
- **[PLATFORM-INTEGRATION.md](PLATFORM-INTEGRATION.md)** - Platform integration guide with `initializeForPlatform`
|
|
1243
243
|
|
|
1244
|
-
|
|
1245
|
-
- Implemented automatic `x-fingerprint-id` header generation
|
|
1246
|
-
- Enhanced security validation and error handling
|
|
1247
|
-
- Improved documentation and examples
|
|
244
|
+
## E2E Testing
|
|
1248
245
|
|
|
1249
|
-
|
|
246
|
+
Este projeto inclui uma aplicação E2E completa em `e2e/react-ts-e2e/` que demonstra a integração do SDK via NPM em um projeto React + TypeScript.
|
|
1250
247
|
|
|
1251
|
-
**
|
|
248
|
+
**Este projeto E2E prova que o Easyflow SDK funciona perfeitamente via NPM em projetos TypeScript/React com uma interface completa e funcional!** 🚀✨
|