0.1.2 • Published 3 years ago

iugu-node-sdk v0.1.2

Weekly downloads
80
License
BSD-3-Clause
Repository
github
Last release
3 years ago

Iugu SDK para Node.JS

Com o objetivo de fornecer um SDK Node para acesso a API da Iugu de forma fácil e tipada.

Para instalar a biblioteca:

npm install iugu-node-sdk

Como usar

Com sua API key gerada pela plataformada da Iugu inicialize o sdk:

import Iugu, { IuguCustomer } from 'iugu-node-sdk'

Iugu.setApiKey('<SUA API KEY>')

Existe alguns models que foram criados para padronizar as respostas e requisição para a API. Um exemplo de utilização da API em TypeScript para criação de um cliente:

const client: IuguCustomer = {
    name: 'Vinicius Picanco',
    email: 'teste@teste.com'
}

// Pode ser utilizar com await
const resultClient : IuguCustomer = await Iugu.customers.create(client, undefined)

// Ou
Iugu.customers.create(client, undefined).then((cli: IuguCustomer) => {
    // On success
}).catch((error: Error) => {
    // On error
})

Todas os métodos seguem o parametro de Iugu.{recurso}.{método}(model,urlParams)

Os parâmetros de URL devem ser passados pelo segundo parâmetro dos métodos, da seguinte forma:

const client: IuguCustomer = {
    name: 'Vinicius Picanco',
    email: 'teste@teste.com'
}

const urlParams: Map<string, string> = new Map()
urlParams.set('id', '558958DB714B389EA6B1FF0A33D75505')

// Pode ser utilizar com await
const resultClient : IuguCustomer = await Iugu.customers.update(client, urlParams)

// Ao invés de map pode utilizar o objeto diretamente
const resultClient : IuguCustomer = await Iugu.customers.update(client,
  {
    id: "558958DB714B389EA6B1FF0A33D75505"
  })

// Ou
Iugu.customers.create(client, urlParams).then((cli: IuguCustomer) => {
    // On success
}).catch((error: Error) => {
    // On error
})

Observação

Para saber quais requisições estão disponíveis e quais parâmetros passar acesse a documentação dev.iugu.com/reference para referência.

Testes

Para o funcionamento dos testes crie um arquivo chamado iugu_services.json na pasta tests com os seguintes dados:

{
    "accountId": "<SUA ACCOUNT ID>",
    "apiKey": "<API KEY PREFERENCIALMENTE DE TESTES>",
    "clientId": "<UM CLIENT ID VÁLIDO>",
    "paymentMethodToken": "<<UM TOKEN DE FORMA DE PAGAMENTO VÁLIDO>>"
}

Se for contribuir sempre crie e execute os testes:

npm run test

Créditos

Escrito por Vinícius Picanço (viniciusspicanco@gmail.com). Agradeço a contribuição de:

0.1.2

3 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago