Skip to content

Commit

Permalink
feat: atualizar para v307
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Oct 5, 2024
1 parent ca64f7c commit 53e9d7f
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 102 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"aliquota",
"Amazônia",
"autoload",
"boletos",
"borderô",
"Borderos",
"borderôs",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Pacote de integração com a [API v3 do ERP Bling](https://developer.bling.com.br)
para Javascript/TypeScript. O mais completo existente.

Atualizado com a versão `v306` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-08-16)).
Atualizado com a versão `v307` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-08-21)).

**Atenção**: a versão 5.0.0+ do `bling-erp-api` para Javascript/TypeScript
utiliza a API v3 do Bling. Caso deseja utilizar a API v2 do Bling,
Expand Down
16 changes: 11 additions & 5 deletions src/entities/contasReceber/__tests__/cancel-bank-slips-response.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export default null

export const cancelBankSlipRequest = {
type2FA: 1,
code2FA: '111111',
idOrigem: 16853468718,
idDuplicata: 16853468712,
reason: 'motivo'
autenticacao: {
tipo: 1 as const,
codigo: "111111"
},
origem: {
id: 5436875653
},
conta: {
id: 6423836115
},
motivo: "Cancelado por força maior"
}
24 changes: 12 additions & 12 deletions src/entities/contasReceber/__tests__/get-bank-slips-response.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export default {
numberSale: '149',
numberNF: '000001',
amountAccounts: 1,
amountValuesAccounts: 111.2,
haveAccountWithIntegration: true,
accounts: [
venda: {
numero: "123"
},
notaFiscal: {
numero: "000001"
},
valorTotal: 111.2,
contas: [
{
id: 1328793273,
idExternal: 'BWbXB',
dueDate: '2023-09-12',
value: 111.2,
situation: 'aberto' as const,
iconSituation: 'aberto',
descriptionSituation: 'Em aberto'
numeroExterno: "BWbXB",
vencimento: "2023-09-12",
valor: 111.2,
situacao: 1 as const
}
]
}
10 changes: 5 additions & 5 deletions src/entities/contasReceber/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@ export class ContasReceber extends Entity {
}

/**
* Obtém os boletos - Bling conta.
* Obtém boletos de contas a receber.
*
* @param {IGetBankSlipsParams} params Parâmetros da busca.
*
* @returns {Promise<IGetBankSlipsResponse>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Contas%20a%20Receber/get_contas_receber_view_bankslips
* @see https://developer.bling.com.br/referencia#/Contas%20a%20Receber/get_contas_receber_boletos
*/
public async getBankSlips(
params: IGetBankSlipsParams
): Promise<IGetBankSlipsResponse> {
return await this.repository.index({
endpoint: 'contas/receber/view/bankslips',
endpoint: 'contas/receber/boletos',
params: {
idOrigem: params.idOrigem,
situations: params.situations
situacoes: params.situacoes
}
})
}
Expand Down Expand Up @@ -158,7 +158,7 @@ export class ContasReceber extends Entity {
*/
public async cancelBankSlips(body: ICancelBankSlipsBody): Promise<null> {
return await this.repository.store({
endpoint: 'contas/receber/cancel/bankslips',
endpoint: 'contas/receber/boletos/cancelar',
body
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
interface ContasReceberBankSlipsCancelUnicoDTO {
type2FA: number
code2FA: string
/**
* caso for cancelar uma conta sem idOrigem enviar o valor `0`
*/
idOrigem: number
idDuplicata: number
reason: string
import { ITipoAutenticacao } from "../types/tipo-autenticacao.type"

export interface ICancelBankSlipsBody {
autenticacao?: {
tipo: ITipoAutenticacao
codigo: string
},
origem?: {
id: number
},
conta?: {
id: number
},
motivo: string
}

interface ContasReceberBankSlipsCancelTodosDTO {
type2FA: number
code2FA: string
idOrigem: number
reason: string
}

interface ContasReceberBankSlipsCancelUnicoSem2FADTO {
/**
* caso for cancelar uma conta sem idOrigem enviar o valor `0`
*/
idOrigem: number
idDuplicata: number
reason: string
}

interface ContasReceberBankSlipsCancelTodosSem2FADTO {
idOrigem: number
reason: string
}

export type ICancelBankSlipsBody =
| ContasReceberBankSlipsCancelUnicoDTO
| ContasReceberBankSlipsCancelTodosDTO
| ContasReceberBankSlipsCancelUnicoSem2FADTO
| ContasReceberBankSlipsCancelTodosSem2FADTO
28 changes: 14 additions & 14 deletions src/entities/contasReceber/interfaces/get-bank-slips.interface.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { ISituacaoString } from '../types/situacao.type'
import { ISituacao } from '../types/situacao.type'

export interface IGetBankSlipsParams {
idOrigem: number
situations?: ISituacaoString[]
situacoes?: ISituacao[]
}

export interface IGetBankSlipsResponse {
numberSale: string
numberNF: string
amountAccounts: number
amountValuesAccounts: number
haveAccountWithIntegration: boolean
accounts: {
venda: {
numero: string
},
notaFiscal: {
numero: string
},
valorTotal: number
contas: {
id: number
idExternal: string
dueDate: string
value: number
situation: ISituacaoString
iconSituation: string
descriptionSituation: string
numeroExterno: string
vencimento: string
valor: number
situacao: ISituacao
}[]
}
5 changes: 5 additions & 0 deletions src/entities/contasReceber/types/tipo-autenticacao.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* - `1`: Código de autenticação por dois fatores
* - `4`: Senha de 6 dígitos do app Bling Conta
*/
export type ITipoAutenticacao = 1 | 4
26 changes: 13 additions & 13 deletions src/entities/naturezasDeOperacoes/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Chance } from 'chance'
import { NaturezasDeOperacoes } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import { ICalculateItemTaxResponse } from '../interfaces/calculate-item-tax.interface'
import { IObtainTaxResponse } from '../interfaces/obtain-tax.interface'
import { IGetResponse } from '../interfaces/get.interface'
import calculateItemTaxResponse, {
calculateItemTaxRequestBody
} from './calculate-item-tax-response'
import obtainTaxResponse, {
obtainTaxRequestBody
} from './obtain-tax-response'
import getResponse from './get-response'

const chance = Chance()
Expand Down Expand Up @@ -44,24 +44,24 @@ describe('Naturezas de Operação entity', () => {
expect(typingResponseTest).toBe(getResponse)
})

it('should calculate item tax successfully', async () => {
it('should obtain tax successfully', async () => {
const spy = jest.spyOn(repository, 'store')
const idNaturezaOperacao = chance.natural()
repository.setResponse(calculateItemTaxResponse)
repository.setResponse(obtainTaxResponse)

const response = await entity.calculateItemTax({
const response = await entity.obtainTax({
idNaturezaOperacao,
...calculateItemTaxRequestBody
...obtainTaxRequestBody
})

expect(spy).toHaveBeenCalledWith({
endpoint: `naturezas-operacoes/${idNaturezaOperacao}/calcular-imposto-item`,
body: calculateItemTaxRequestBody
body: obtainTaxRequestBody
})
expect(response).toBe(calculateItemTaxResponse)
expect(response).toBe(obtainTaxResponse)

const typingResponseTest: ICalculateItemTaxResponse =
calculateItemTaxResponse
expect(typingResponseTest).toBe(calculateItemTaxResponse)
const typingResponseTest: IObtainTaxResponse =
obtainTaxResponse
expect(typingResponseTest).toBe(obtainTaxResponse)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export default {
}
}

export const calculateItemTaxRequestBody = {
export const obtainTaxRequestBody = {
tipoNota: 1 as const,
uf: 'RS' as const,
municipio: {
Expand Down
24 changes: 12 additions & 12 deletions src/entities/naturezasDeOperacoes/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Entity } from '../@shared/entity'
import {
ICalculateItemTaxBody,
ICalculateItemTaxParams,
ICalculateItemTaxResponse
} from './interfaces/calculate-item-tax.interface'
IObtainTaxBody,
IObtainTaxParams,
IObtainTaxResponse
} from './interfaces/obtain-tax.interface'
import { IGetParams, IGetResponse } from './interfaces/get.interface'

/**
Expand Down Expand Up @@ -35,21 +35,21 @@ export class NaturezasDeOperacoes extends Entity {
}

/**
* Calcula os impostos de um item.
* Obtém regras de tributação da natureza de operação.
*
* @param {ICalculateItemTaxParams & ICalculateItemTaxBody} params O conteúdo para o cálculo.
* @param {IObtainTaxParams & IObtainTaxBody} params O conteúdo para o cálculo.
*
* @returns {Promise<ICalculateItemTaxResponse>}
* @returns {Promise<IObtainTaxResponse>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Naturezas%20de%20Opera%C3%A7%C3%B5es/post_naturezas_operacoes__idNaturezaOperacao__calcular_imposto_item
* @see https://developer.bling.com.br/referencia#/Naturezas%20de%20Opera%C3%A7%C3%B5es/post_naturezas_operacoes__idNaturezaOperacao__obter_tributacao
*/
public async calculateItemTax(
params: ICalculateItemTaxParams & ICalculateItemTaxBody
): Promise<ICalculateItemTaxResponse> {
public async obtainTax(
params: IObtainTaxParams & IObtainTaxBody
): Promise<IObtainTaxResponse> {
const { idNaturezaOperacao, ...body } = params
return await this.repository.store({
endpoint: `naturezas-operacoes/${idNaturezaOperacao}/calcular-imposto-item`,
endpoint: `naturezas-operacoes/${idNaturezaOperacao}/obter-tributacao`,
body
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { IMotivoDesoneracaoICMS } from '../types/motivo-desoneracao-icms.type'
import { ITipoNota } from '../types/tipo-nota.type'
import { ITributacao } from '../types/tributacao.type'

export interface ICalculateItemTaxParams {
export interface IObtainTaxParams {
/**
* ID da natureza de operação
*/
idNaturezaOperacao: number
}

export interface ICalculateItemTaxBody {
export interface IObtainTaxBody {
tipoNota: ITipoNota
uf: IUF
municipio: { id: number }
Expand All @@ -32,7 +32,7 @@ export interface ICalculateItemTaxBody {
}
}

export interface ICalculateItemTaxResponse {
export interface IObtainTaxResponse {
data: {
faturada?: boolean
observacoes?: string
Expand Down

0 comments on commit 53e9d7f

Please sign in to comment.