JSPM

  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q76660F
  • License ISC

Enterprise-grade JavaScript SDK for Easyflow payment processing platform - Documentation and TypeScript definitions only

Package Exports

  • @easyflow/javascript-sdk
  • @easyflow/javascript-sdk/package.json

Readme

Easyflow JavaScript SDK

Enterprise-grade JavaScript SDK for Easyflow payment processing platform - Documentation and TypeScript definitions only

Quick Start

Via CDN

<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>

TypeScript Integration

For TypeScript projects, the SDK is exposed globally when loaded via CDN. Add the following declarations to your project:

// O SDK está sendo carregado via CDN e exposto globalmente como window.easyflowSDK
declare global {
    interface Window {
        easyflowSDK: any
        EasyflowSDK: any
    }
}

Usage Example with TypeScript

// Configurar o SDK
window.easyflowSDK.configure({ businessId: 'your-business-id' })

// Usar métodos do SDK
const customer = await window.easyflowSDK.createCustomer(customerData)
const payment = await window.easyflowSDK.charge(paymentData)

Usage

Basic Configuration

// Configure the SDK with your business ID
window.easyflowSDK.configure({
    businessId: 'your-business-id',
})

Customer Management

// Create a customer
const customer = await window.easyflowSDK.createCustomer({
    name: 'John Doe',
    email: 'john@example.com',
    document: {
        type: 'CPF',
        number: '12345678901',
    },
    phone: {
        areaCode: '+55',
        ddd: '11',
        number: '999999999',
        isMobile: true,
    },
    address: {
        zipCode: '01234567',
        street: 'Rua das Flores',
        number: '123',
        complement: 'Apto 45',
        neighborhood: 'Centro',
        city: 'São Paulo',
        state: 'SP',
    },
    deliveryAddress: {
        zipCode: '04567890',
        street: 'Av. Paulista',
        number: '1000',
        complement: 'Sala 200',
        neighborhood: 'Bela Vista',
        city: 'São Paulo',
        state: 'SP',
    },
})

// Get customer by ID
const customerData = await window.easyflowSDK.getCustomer(customer.id)

// Update customer
const updatedCustomer = await window.easyflowSDK.updateCustomer(customer.id, {
    name: 'John Updated',
})

Payment Processing

// Process a payment - with PIX method
const payment = await window.easyflowSDK.charge({
    buyer: customerData,
    payments: [
        {
            method: 'pix',
            valueInCents: 10000,
            numberInstallments: 1,
        },
    ],
    items: [
        {
            description: 'Product Description',
            name: 'Product',
            priceInCents: 10000, // Price in cents - R$100,00
            quantity: 1,
        },
    ],
})

// Process a payment - with Credit Card method [One-time payment]
const encryptedCard = await window.easyflowSDK.encrypt({
    number: '4111111111111111',
    holderName: 'JOHN DOE',
    expirationMonth: '12',
    expirationYear: '2025',
    cvv: '123',
})

const orderId = await window.easyflowSDK.charge({
    buyer: customerData,
    payments: [
        {
            method: 'credit-card',
            valueInCents: 10000,
            numberInstallments: 1,
            creditCard: {
                token: encryptedCard,
                last4Numbers: '1234',
                holderName: 'JOHN DOE',
                expiresAtMonth: '12',
                expiresAtYear: '2025',
                flag: 'visa',
            },
        },
    ],
    items: [
        {
            description: 'Product Description',
            name: 'Product',
            priceInCents: 10000, // Price in cents - R$100,00
            quantity: 1,
        },
    ],
})

// Process a payment - with Credit Card method [Saving card for future use]
const encryptedCard = await window.easyflowSDK.encrypt({
    number: '4111111111111111',
    holderName: 'JOHN DOE',
    expirationMonth: '12',
    expirationYear: '2025',
    cvv: '123',
})

// Add credit card
const creditCard = await window.easyflowSDK.addCreditCard(
    customer.id,
    encryptedCard
)

const payment = await window.easyflowSDK.charge({
    buyer: { customerId: customer.id, ...customerData },
    payments: [
        {
            method: 'credit-card',
            valueInCents: 10000,
            numberInstallments: 1,
            creditCard: {
                cardId: creditCard.id,
            },
        },
    ],
    items: [
        {
            description: 'Product Description',
            name: 'Product',
            priceInCents: 10000, // Price in cents - R$100,00
            quantity: 1,
        },
    ],
})

Order Management

// Place an order
const orderId = await window.easyflowSDK.placeOrder('offer-id', {
    buyer: customerData,
    payments: [
        {
            method: 'pix',
            numberInstallments: 1,
        },
    ],
})

// Get order by ID
const orderData = await window.easyflowSDK.getOrder(orderId)

Credit Card Management

// Encrypt credit card data
const encryptedCard = await window.easyflowSDK.encrypt({
    number: '4111111111111111',
    holderName: 'JOHN DOE',
    expirationMonth: '12',
    expirationYear: '2025',
    cvv: '123',
})

// Add credit card
const creditCard = await window.easyflowSDK.addCreditCard(
    'customer-id',
    'encrypted-token'
)

// Get credit card
const cardData = await window.easyflowSDK.getCreditCard(
    'customer-id',
    'card-id'
)

// Remove credit card
const result = await window.easyflowSDK.removeCreditCard(
    'customer-id',
    'card-id'
)

Utility Methods

// Get SDK status
const status = window.easyflowSDK.getStatus()

Events

// SDK Ready
window.easyflowSDK.on('SDKReady', (data) => {
    console.log('SDK loaded:', data)
})

// Customer created
window.easyflowSDK.on('customerCreated', (customer) => {
    console.log('Customer created:', customer)
})

// Payment processed
window.easyflowSDK.on('paymentProcessed', (payment) => {
    console.log('Payment processed:', payment)
})

// Order placed
window.easyflowSDK.on('orderPlaced', (order) => {
    console.log('Order placed:', order)
})

// Error
window.easyflowSDK.on('error', (error) => {
    console.error('Error:', error)
})

Security Features

  • HTTPS/SSL Strict - All communications are encrypted
  • CORS with domain validation - Strict cross-origin protection
  • Rate limiting - Protection against abuse
  • Input validation - Comprehensive data validation
  • Replay protection - Protection against replay attacks
  • Iframe protection - Protection against clickjacking
  • XSS protection - Protection against cross-site scripting

Authentication

  • ECDSA (P-256) - Elliptic curve digital signature algorithm
  • SHA256 - Secure hash algorithm
  • Browser fingerprinting - Device identification
  • Domain validation - Origin verification

Compliance

  • PCI-DSS - Payment Card Industry Data Security Standard
  • LGPD - Brazilian General Data Protection Law
  • GDPR - General Data Protection Regulation

Compatibility

  • Browsers: Chrome, Firefox, Safari, Edge
  • Frameworks: React, Vue, Angular, vanilla JS
  • Mobile: Web, PWA, Hybrid apps
  • TypeScript: Full support
  • NPM: Installation via package manager
  • CDN: Direct loading

Performance

  • Size: ~97KB (minified and obfuscated)
  • Loading: Asynchronous and non-blocking
  • Cache: CDN optimized
  • Bundle: Compatible with modern bundlers

Support

Documentation

E2E Testing

This project includes a complete E2E application in e2e/react-ts-e2e/ that demonstrates SDK integration via NPM in a React + TypeScript project.

This E2E project proves that the Easyflow SDK works perfectly via NPM in TypeScript/React projects with a complete and functional interface! 🚀✨

Installation

npm install @easyflow/javascript-sdk

Via CDN

<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>

Quick Integration

// Load SDK
const sdk = new EasyflowSDK('your-business-id')

sdk.on('paymentProcessed', (payment) => {
    console.log('Payment processed:', payment)
})

sdk.on('error', (error) => {
    console.log('Error on payment process:', error)
})

// Process payment with charge using PIX method
const payment = await sdk.charge({
    buyer: {
        name: 'John Doe',
        email: 'john@example.com',
        document: {
            type: 'CPF',
            number: '12345678901',
        },
        phone: {
            areaCode: '+55',
            ddd: '11',
            number: '999999999',
            isMobile: true,
        },
        address: {
            zipCode: '01234567',
            street: 'Rua das Flores',
            number: '123',
            complement: 'Apto 45',
            neighborhood: 'Centro',
            city: 'São Paulo',
            state: 'SP',
        },
    },
    payments: [{ method: 'pix', valueInCents: 10000, numberInstallments: 1 }],
    items: [
        {
            description: 'Product Description',
            name: 'Product',
            priceInCents: 10000, // Price in cents - R$100,00
            quantity: 1,
        },
    ],
})

License

ISC License - see LICENSE file for details.

Contributing

For contributions, please visit our GitHub repository.


Built with ❤️ by the Easyflow Team