diff --git a/.vscode/settings.json b/.vscode/settings.json index 1e69f7f..b203bbd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,6 +12,7 @@ "aliquota", "Amazônia", "autoload", + "boletos", "borderô", "Borderos", "borderôs", diff --git a/README.md b/README.md index 835efe4..05ea974 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/src/entities/contasReceber/__tests__/cancel-bank-slips-response.ts b/src/entities/contasReceber/__tests__/cancel-bank-slips-response.ts index 8ed70b2..30860da 100644 --- a/src/entities/contasReceber/__tests__/cancel-bank-slips-response.ts +++ b/src/entities/contasReceber/__tests__/cancel-bank-slips-response.ts @@ -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" } diff --git a/src/entities/contasReceber/__tests__/get-bank-slips-response.ts b/src/entities/contasReceber/__tests__/get-bank-slips-response.ts index cbbbac9..347929b 100644 --- a/src/entities/contasReceber/__tests__/get-bank-slips-response.ts +++ b/src/entities/contasReceber/__tests__/get-bank-slips-response.ts @@ -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 } ] } diff --git a/src/entities/contasReceber/index.ts b/src/entities/contasReceber/index.ts index 5646add..6160945 100644 --- a/src/entities/contasReceber/index.ts +++ b/src/entities/contasReceber/index.ts @@ -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} * @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 { return await this.repository.index({ - endpoint: 'contas/receber/view/bankslips', + endpoint: 'contas/receber/boletos', params: { idOrigem: params.idOrigem, - situations: params.situations + situacoes: params.situacoes } }) } @@ -158,7 +158,7 @@ export class ContasReceber extends Entity { */ public async cancelBankSlips(body: ICancelBankSlipsBody): Promise { return await this.repository.store({ - endpoint: 'contas/receber/cancel/bankslips', + endpoint: 'contas/receber/boletos/cancelar', body }) } diff --git a/src/entities/contasReceber/interfaces/cancel-bank-slips.interface.ts b/src/entities/contasReceber/interfaces/cancel-bank-slips.interface.ts index e891853..197980b 100644 --- a/src/entities/contasReceber/interfaces/cancel-bank-slips.interface.ts +++ b/src/entities/contasReceber/interfaces/cancel-bank-slips.interface.ts @@ -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 diff --git a/src/entities/contasReceber/interfaces/get-bank-slips.interface.ts b/src/entities/contasReceber/interfaces/get-bank-slips.interface.ts index 31a2c84..3514c67 100644 --- a/src/entities/contasReceber/interfaces/get-bank-slips.interface.ts +++ b/src/entities/contasReceber/interfaces/get-bank-slips.interface.ts @@ -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 }[] } diff --git a/src/entities/contasReceber/types/tipo-autenticacao.type.ts b/src/entities/contasReceber/types/tipo-autenticacao.type.ts new file mode 100644 index 0000000..6ecfd4e --- /dev/null +++ b/src/entities/contasReceber/types/tipo-autenticacao.type.ts @@ -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 diff --git a/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts b/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts index 478d472..61e89a5 100644 --- a/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts +++ b/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts @@ -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() @@ -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) }) }) diff --git a/src/entities/naturezasDeOperacoes/__tests__/calculate-item-tax-response.ts b/src/entities/naturezasDeOperacoes/__tests__/obtain-tax-response.ts similarity index 99% rename from src/entities/naturezasDeOperacoes/__tests__/calculate-item-tax-response.ts rename to src/entities/naturezasDeOperacoes/__tests__/obtain-tax-response.ts index b963690..dd52c14 100644 --- a/src/entities/naturezasDeOperacoes/__tests__/calculate-item-tax-response.ts +++ b/src/entities/naturezasDeOperacoes/__tests__/obtain-tax-response.ts @@ -213,7 +213,7 @@ export default { } } -export const calculateItemTaxRequestBody = { +export const obtainTaxRequestBody = { tipoNota: 1 as const, uf: 'RS' as const, municipio: { diff --git a/src/entities/naturezasDeOperacoes/index.ts b/src/entities/naturezasDeOperacoes/index.ts index 9db4e40..a0fabc4 100644 --- a/src/entities/naturezasDeOperacoes/index.ts +++ b/src/entities/naturezasDeOperacoes/index.ts @@ -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' /** @@ -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} + * @returns {Promise} * @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 { + public async obtainTax( + params: IObtainTaxParams & IObtainTaxBody + ): Promise { const { idNaturezaOperacao, ...body } = params return await this.repository.store({ - endpoint: `naturezas-operacoes/${idNaturezaOperacao}/calcular-imposto-item`, + endpoint: `naturezas-operacoes/${idNaturezaOperacao}/obter-tributacao`, body }) } diff --git a/src/entities/naturezasDeOperacoes/interfaces/calculate-item-tax.interface.ts b/src/entities/naturezasDeOperacoes/interfaces/obtain-tax.interface.ts similarity index 97% rename from src/entities/naturezasDeOperacoes/interfaces/calculate-item-tax.interface.ts rename to src/entities/naturezasDeOperacoes/interfaces/obtain-tax.interface.ts index 594e662..0e6494a 100644 --- a/src/entities/naturezasDeOperacoes/interfaces/calculate-item-tax.interface.ts +++ b/src/entities/naturezasDeOperacoes/interfaces/obtain-tax.interface.ts @@ -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 } @@ -32,7 +32,7 @@ export interface ICalculateItemTaxBody { } } -export interface ICalculateItemTaxResponse { +export interface IObtainTaxResponse { data: { faturada?: boolean observacoes?: string