MCPcopy Index your code
hub / github.com/banzeh/cielo

github.com/banzeh/cielo @v2.4.8

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.4.8 ↗ · + Follow
164 symbols 256 edges 87 files 1 documented · 1%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

cielo

Client para a API 3.0 da Cielo em Typescript/Nodejs

MIT license Build Status Known Vulnerabilities codebeat badge JavaScript Style Guide Open Source Love svg2

Índice

Início

Cartão de Crédito

Cartão de Débito

Transferência Eletrônica

Boleto

Recorrência

Cartões

Consultas

API Reference

Testes

Autor

License

Installation

npm install --save cielo

Como utilizar?

Iniciando

import { CieloConstructor, Cielo } from 'cielo';

const cieloParams: CieloConstructor = {
    merchantId: 'xxxxxxxxxxxxxxxxxxxxxxx',
    merchantKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
    requestId: 'xxxxxxx', // Opcional - Identificação do Servidor na Cielo
    sandbox: true, // Opcional - Ambiente de Testes
    debug: true // Opcional - Exibe os dados enviados na requisição para a Cielo
}

const cielo = new Cielo(cieloParams);

Paramêtros de criação

Campo Descrição Obrigatório? Default
merchantId Identificador da loja na Cielo. Sim null
merchantKey Chave publica para autenticação dupla na Cielo. Sim null
requestId Identificador do Request, utilizado quando o lojista usa diferentes servidores para cada GET/POST/PUT. Não null
sandbox Ambiente de testes da Cielo Não false
debug Exibe requisição da transação no console Não false

Cartão de Crédito

Criando uma transação

Usando Promise

const vendaParams: TransactionCreditCardRequestModel = {
    customer: {
        name: "Comprador crédito",
    },
    merchantOrderId: "2014111703",
    payment: {
        amount: 10000, // R$100,00
        creditCard: {
            brand: EnumBrands.VISA,
            cardNumber: "4532117080573700",
            holder: "Comprador T Cielo",
            expirationDate: "12/2021",
        },
        installments: 1,
        softDescriptor: "Banzeh",
        type: EnumCardType.CREDIT,
        capture: false,
    },
};

cielo.creditCard.transaction(dadosSale)
    .then((data) => {
        return console.log(data);
    })
    .catch((err) => {
        return console.error('ERRO', err);
    })

Ou usando Async / Await

const transaction = await cielo.creditCard.transaction(dadosSale);
console.log(transaction);

Capturando uma venda

const capturaVendaParams: CaptureRequestModel = {
    paymentId: '24bc8366-fc31-4d6c-8555-17049a836a07',
    amount: 2000, // Caso o valor não seja definido, captura a venda no valor total
};

cielo.creditCard.captureSaleTransaction(capturaVendaParams)
    .then((data) => {
        return console.log(data);
    })
    .catch((err) => {
        return console.error('ERRO', err);
    })

Cancelando uma venda

const cancelamentoVendaParams: CancelTransactionRequestModel = {
    paymentId: '24bc8366-fc31-4d6c-8555-17049a836a07',
    amount: 100, // Caso o valor não seja definido, cancela a venda no valor total
};

cielo.creditCard.cancelTransaction(cancelamentoVendaParams)
    .then((data) => {
        return console.log(data);
    })
    .catch((err) => {
        return console.error('ERRO', err);
    })

Ou usando Async / Await

const cancel = await cielo.creditCard.cancelSale(dadosSale);
console.log(cancel);

Cartão de Débito

Criando uma venda simplificada

const debitCardTransactionParams: DebitCardSimpleTransactionRequestModel = {  
    merchantOrderId: "2014121201",
    customer:{  
      name: "Paulo Henrique"     
    },
    payment: {  
      type: EnumCardType.DEBIT,
      amount: 15700,
      provider: "Simulado",
      returnUrl: "http://www.google.com.br",
      debitCard:{  
          cardNumber: "4532117080573703",
          holder: "Teste Holder",
          expirationDate: "12/2022",
          securityCode: "023",
          brand: EnumBrands.VISA
      }
    }
 }

  cielo.debitCard.createSimpleTransaction(debitCardTransactionParams)
    .then((data) => {
        return console.log(data);
    })
    .catch((err) => {
        return console.error('ERRO', err);
    })

Pagamentos com Transferência Eletronica

Criando uma venda simplificada

const transferenciaEletronicaParams: EletronicTransferCreateRequestModel = {
    merchantOrderId: '2017051109',
    customer: {
      name: 'Nome do Comprador',
      identity: '12345678909',
      identityType: 'CPF',
      email: 'comprador@cielo.com.br',
      address: {
        street: 'Alameda Xingu',
        number: '512',
        complement: '27 andar',
        zipCode: '12345987',
        city: 'São Paulo',
        state: 'SP',
        country: 'BRA',
        district: 'Alphaville',
      },
    },
    payment: {
      provider: 'Bradesco',
      type: 'EletronicTransfer',
      amount: 10000,
      returnUrl: 'http://www.cielo.com.br',
    },
  };

  cielo.eletronicTransfer.create(transferenciaEletronicaParams)(dadosSale)
  .then((data) => {
      return console.log(data);
  })
  .catch((err) => {
      return console.error('ERRO', err);
  })

Boleto

Criando uma venda de Boleto

const boletoParams: BankSlipCreateRequestModel = {
    merchantOrderId: '20180531',
    customer: {
      name: 'Comprádor Boleto Cíéló Áá',
      identity: '1234567890',
      address: {
        street: 'Avenida Marechal Câmara',
        number: '160',
        complement: 'Sala 934',
        zipCode: '22750012',
        district: 'Centro',
        city: 'Rio de Janeiro',
        state: 'RJ',
        country: 'BRA'
      }
    },
    payment: {
      type: 'Boleto',
      amount: 15700,
      provider: 'Bradesco2',
      address: 'Rua Teste',
      boletoNumber: '123',
      assignor: 'Empresa Teste',
      demonstrative: 'Desmonstrative Teste',
      expirationDate: '5/1/2020',
      identification: '11884926754',
      instructions: 'Aceitar somente até a data de vencimento, após essa data juros de 1% dia.'
    }
  }

  cielo.bankSlip.create(boletoParams)
    .then((data) => {
      return console.log(data);
    })
    .catch((err) => {
      return console.error('ERRO', err);
    })

Recorrência

Criando Recorrências

const createRecurrencyParams: RecurrentCreateModel = {
    merchantOrderId: '2014113245231706',
    customer: {
      name: 'Comprador rec programada'
    },
    payment: {
      type: EnumCardType.CREDIT,
      amount: 1500,
      installments: 1,
      softDescriptor: '123456789ABCD',
      currency: 'BRL',
      country: 'BRA',
      recurrentPayment: {
        authorizeNow: true,
        endDate: '2022-12-01',
        interval: EnumRecurrentPaymentInterval.SEMIANNUAL
      },
      creditCard: {
        cardNumber: '4024007197692931',
        holder: 'Teste Holder',
        expirationDate: '12/2030',
        securityCode: '262',
        saveCard: false,
        brand: 'Visa' as EnumBrands
      }
    }
  }

  cielo.recurrent.create(createRecurrencyParams)
    .then((data) => {
      return console.log(data);
    })
    .catch((err) => {
      return console.error('ERRO', err);
    })

Modificando Recorrências

Modificando dados do comprador

const updateCustomer: RecurrentModifyCustomerModel = {
    paymentId: firstRecurrency.payment.recurrentPayment.recurrentPaymentId,
    customer: {
      name: 'Customer',
      email: 'customer@teste.com',
      birthdate: '1999-12-12',
      identity: '22658954236',
      identityType: 'CPF',
      address: {
        street: 'Rua Teste',
        number: '174',
        complement: 'AP 201',
        zipCode: '21241140',
        city: 'Rio de Janeiro',
        state: 'RJ',
        country: 'BRA'
      },
      deliveryAddress: {
        street: 'Outra Rua Teste',
        number: '123',
        complement: 'AP 111',
        zipCode: '21241111',
        city: 'Qualquer Lugar',
        state: 'QL',
        country: 'BRA',
      }
    }
  }

cielo.recurrent.modifyCustomer(updateCustomer)
  .then((data) => {
    return console.log(data);
  })
  .catch((err) => {
    return console.error('ERRO', err);
  })

Modificando data final da Recorrência

const updateEndDate: RecurrentModifyEndDateModel = {
  paymentId: firstRecurrency.payment.recurrentPayment.recurrentPaymentId,
  endDate: '2021-01-09'
}

cielo.recurrent.modifyEndDate(updateEndDate)
  .then((data) => {
    return console.log(data);
  })
  .catch((err) => {
    return console.error('ERRO', err);
  })

Modificando intevalo da Recorrência

const modifyRecurrencyParams: RecurrentModifyIntervalModel = {
  paymentId: firstRecurrency.payment.recurrentPayment.recurrentPaymentId,
  interval: EnumRecurrentPaymentUpdateInterval.MONTHLY
}

cielo.recurrent.modifyInterval(modifyRecurrencyParams)
  .then((data) => {
    return console.log(data);
  })
  .catch((err) => {
    return console.error('ERRO', err);
  })

Modificando dia da Recorrência

const updateRecurrencyDay: RecurrentModifyDayModel = {
    paymentId: firstRecurrency.payment.recurrentPayment.recurrentPaymentId,
    recurrencyDay: 10
  }

cielo.recurrent.modifyRecurrencyDay(updateRecurrencyDay)
  .then((data) => {
    return console.log(data);
  })
  .catch((err) => {
    return console.error('ERRO', err);
  })

Modificando o valor da Recorrência

const updateAmount: RecurrentModifyAmountModel = {
  paymentId: firstRecurrency.payment.recurrentPayment.recurrentPaymentId,
  amount: 156 // Valor do Pedido em centavos: 156 equivale a R$ 1,56
}

cielo.recurrent.modifyAmount(updateAmount)
  .then((data) => {
    return console.log(data);
  })
  .catch((err) => {
    return console.error('ERRO', err);
  })

Modificando data do próximo Pagamento

const updateNextPaymentDate: RecurrentModifyNextPaymentDateModel = {
  paymentId: firstRecurrency.payment.recurrentPayment.recurrentPaymentId,
  nextPaymentDate: '2020-05-20'
}

cielo.recurrent.modifyNextPaymentDate
  .then((data) => {
    return console.log(data);
  })
  .catch((err) => {
    return console.error('ERRO', err);
  })

Modificando dados do Pagamento da Recorrência (@todo)

```ts const updatePayment: RecurrentModifyPaymentModel = { recurrentPaymentId: RecurrentPaymentId, payment: {
type: EnumCardType.CREDIT, amount: "123", installments: 3, country: "USA", currency: "BRL", softDescriptor: "123456789ABCD", creditCard: {
brand: EnumBrands.VISA, holder: "Teset card", cardNumber: "1234123412341232", expirationDate: "12/2030" } } }

cielo.recurrent.modifyPayment(updatePayment) .then((data) => { return console.log(data); }) .catch((err) => { re

Extension points exported contracts — how you extend this code

CieloConstructor (Interface)
(no doc)
src/cielo.ts
CieloTransactionInterface (Interface)
(no doc)
src/interface/cielo-transaction.interface.ts
IHttpRequestOptions (Interface)
(no doc)
src/class/utils.ts
Link (Interface)
(no doc)
src/models/link-model.ts
IHttpRequestReject (Interface)
(no doc)
src/class/utils.ts
AirlineDataModel (Interface)
(no doc)
src/models/airline-data.model.ts
IHttpResponse (Interface)
(no doc)
src/class/utils.ts
PaymentRequestModel (Interface)
(no doc)
src/models/payment.request.model.ts

Core symbols most depended-on inside this repo

getHttpRequestOptions
called by 12
src/class/utils.ts
modify
called by 9
src/class/recurrent.ts
httpRequest
called by 7
src/class/utils.ts
get
called by 5
src/class/utils.ts
postToSales
called by 5
src/class/utils.ts
request
called by 4
src/class/utils.ts
validateJSON
called by 4
src/class/utils.ts
create
called by 4
src/class/bank-slip.ts

Shape

Interface 77
Method 42
Enum 22
Class 18
Function 5

Languages

TypeScript100%

Modules by API surface

src/enums.ts21 symbols
src/class/utils.ts16 symbols
src/class/recurrent.ts14 symbols
src/class/consult.ts8 symbols
src/class/creditcard.ts6 symbols
src/cielo.ts5 symbols
src/models/recurrent-payment/recurrent-create.response.model.ts4 symbols
src/models/debit-card/debit-card-simple-transaction.response.model.ts4 symbols
src/class/eletronic-transfer.ts4 symbols
src/class/debit-card.ts4 symbols
src/class/cards.ts4 symbols
src/class/bank-slip.ts4 symbols

For agents

$ claude mcp add cielo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact