@setup-automatizado/sicredi-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1384 @@
1
+ interface DevedorCpf {
2
+ /** @required CPF of the debtor (11 digits) */
3
+ cpf: string;
4
+ /** @required Full name of the debtor */
5
+ nome: string;
6
+ /** @optional Street address (required for cobv with boleto) */
7
+ logradouro?: string;
8
+ /** @optional City name (required for cobv with boleto) */
9
+ cidade?: string;
10
+ /** @optional State abbreviation (2 chars, e.g. "SP") */
11
+ uf?: string;
12
+ /** @optional Postal code (8 digits) */
13
+ cep?: string;
14
+ }
15
+ interface DevedorCnpj {
16
+ /** @required CNPJ of the debtor (14 digits) */
17
+ cnpj: string;
18
+ /** @required Company name of the debtor */
19
+ nome: string;
20
+ /** @optional Street address (required for cobv with boleto) */
21
+ logradouro?: string;
22
+ /** @optional City name (required for cobv with boleto) */
23
+ cidade?: string;
24
+ /** @optional State abbreviation (2 chars, e.g. "SP") */
25
+ uf?: string;
26
+ /** @optional Postal code (8 digits) */
27
+ cep?: string;
28
+ }
29
+ /** Debtor: either a person (CPF) or company (CNPJ) */
30
+ type Devedor = DevedorCpf | DevedorCnpj;
31
+ interface PagadorCpf {
32
+ /** @required CPF of the payer (11 digits) */
33
+ cpf: string;
34
+ /** @required Full name of the payer */
35
+ nome: string;
36
+ }
37
+ interface PagadorCnpj {
38
+ /** @required CNPJ of the payer (14 digits) */
39
+ cnpj: string;
40
+ /** @required Company name of the payer */
41
+ nome: string;
42
+ }
43
+ /** Payer: either a person (CPF) or company (CNPJ) */
44
+ type Pagador = PagadorCpf | PagadorCnpj;
45
+ /** Receiver/payee information */
46
+ interface Recebedor {
47
+ /** @optional CPF of the receiver (mutually exclusive with cnpj) */
48
+ cpf?: string;
49
+ /** @optional CNPJ of the receiver (mutually exclusive with cpf) */
50
+ cnpj?: string;
51
+ /** @required Full name or company name of the receiver */
52
+ nome: string;
53
+ /** @optional Trading name / brand name */
54
+ nomeFantasia?: string;
55
+ /** @optional Street address */
56
+ logradouro?: string;
57
+ /** @optional City name */
58
+ cidade?: string;
59
+ /** @optional State abbreviation (2 chars) */
60
+ uf?: string;
61
+ /** @optional Postal code (8 digits) */
62
+ cep?: string;
63
+ /** @optional Bank account number */
64
+ conta?: string;
65
+ /** @optional Bank branch number */
66
+ agencia?: string;
67
+ }
68
+ interface Valor {
69
+ /** @required Decimal value as string, e.g. "100.00" (max 2 decimal places) */
70
+ original: string;
71
+ }
72
+ interface ValorComDesconto extends Valor {
73
+ /** @optional Modality for discount/interest/penalty calculation */
74
+ modalidade?: number;
75
+ /** @optional Discount configuration */
76
+ desconto?: {
77
+ /** @required Discount modality (1-6) */
78
+ modalidade: number;
79
+ /** @optional Fixed value or percentage (depending on modality) */
80
+ valorPerc?: string;
81
+ /** @optional Date-specific discount entries (for modalities 1-2) */
82
+ descontoDataFixa?: Array<{
83
+ data: string;
84
+ valorPerc: string;
85
+ }>;
86
+ };
87
+ /** @optional Interest configuration */
88
+ juros?: {
89
+ /** @required Interest modality (1-8) */
90
+ modalidade: number;
91
+ /** @required Interest value or percentage */
92
+ valorPerc: string;
93
+ };
94
+ /** @optional Penalty configuration */
95
+ multa?: {
96
+ /** @required Penalty modality: 1 = Fixed, 2 = Percentage */
97
+ modalidade: number;
98
+ /** @required Penalty value or percentage */
99
+ valorPerc: string;
100
+ };
101
+ /** @optional Rebate/reduction configuration */
102
+ abatimento?: {
103
+ /** @required Rebate modality: 1 = Fixed, 2 = Percentage */
104
+ modalidade: number;
105
+ /** @required Rebate value or percentage */
106
+ valorPerc: string;
107
+ };
108
+ }
109
+ /** Calendar for immediate charges (cob) */
110
+ interface Calendario {
111
+ /** @optional ISO 8601 timestamp of creation (set by server) */
112
+ criacao?: string;
113
+ /** @optional ISO 8601 timestamp when the charge was presented to the payer */
114
+ apresentacao?: string;
115
+ /** @optional Expiration in seconds from creation (default: 86400 = 24h) */
116
+ expiracao?: number;
117
+ }
118
+ /** Calendar for charges with due date (cobv) */
119
+ interface CalendarioVencimento {
120
+ /** @optional ISO 8601 timestamp of creation (set by server) */
121
+ criacao?: string;
122
+ /** @required Due date in YYYY-MM-DD format */
123
+ dataDeVencimento: string;
124
+ /** @optional Validity in days after due date (default: 30) */
125
+ validadeAposVencimento?: number;
126
+ }
127
+ /** Additional information key-value pair displayed to the payer */
128
+ interface InfoAdicional {
129
+ /** @required Field name (max 50 chars) */
130
+ nome: string;
131
+ /** @required Field value (max 200 chars) */
132
+ valor: string;
133
+ }
134
+ /** Pagination metadata returned by list endpoints */
135
+ interface Paginacao {
136
+ /** @required Current page number (0-indexed) */
137
+ paginaAtual: number;
138
+ /** @required Number of items per page */
139
+ itensPorPagina: number;
140
+ /** @required Total number of pages */
141
+ quantidadeDePaginas: number;
142
+ /** @required Total number of items across all pages */
143
+ quantidadeTotalDeItens: number;
144
+ }
145
+ /** Pagination parameters for list requests */
146
+ interface PaginacaoParams {
147
+ /** @optional Page number to retrieve (0-indexed, default: 0) */
148
+ paginaAtual?: number;
149
+ /** @optional Items per page (default: 100) */
150
+ itensPorPagina?: number;
151
+ }
152
+ /** Payload location (loc) - used to generate PIX QR codes */
153
+ interface Loc {
154
+ /** @required Unique identifier of the payload location */
155
+ id: number;
156
+ /** @required URL of the payload location */
157
+ location: string;
158
+ /** @required Type of charge: 'cob' (immediate) or 'cobv' (with due date) */
159
+ tipoCob: 'cob' | 'cobv';
160
+ /** @optional ISO 8601 timestamp of creation */
161
+ criacao?: string;
162
+ /** @optional Transaction ID linked to this location */
163
+ txid?: string;
164
+ }
165
+ /** Extended location with activation/deactivation timestamps */
166
+ interface LocCompleta extends Loc {
167
+ /** @optional ISO 8601 timestamp when the location was activated */
168
+ ativacao?: string;
169
+ /** @optional ISO 8601 timestamp when the location was deactivated */
170
+ inativacao?: string;
171
+ }
172
+ /**
173
+ * Breakdown of payment value into components.
174
+ * Present in received PIX payments. For cobv payments, may include juros, multa, desconto, abatimento.
175
+ *
176
+ * Formula: valor = (original + saque + troco) + multa + juros - abatimento - desconto
177
+ * (only present fields are included in the calculation)
178
+ */
179
+ interface ComponentesValor {
180
+ /** @optional Original payment amount (may be omitted for pure Pix Saque, or 0.00) */
181
+ original?: {
182
+ valor: string;
183
+ };
184
+ /** @optional Withdrawal (saque) component - PIX Saque */
185
+ saque?: {
186
+ /** @required Withdrawal amount as decimal string */
187
+ valor: string;
188
+ /**
189
+ * @required Agent modality:
190
+ * - AGTEC: Agente Estabelecimento Comercial
191
+ * - AGTOT: Agente Outra Especie de PJ
192
+ * - AGPSS: Agente Facilitador de Servico de Saque
193
+ */
194
+ modalidadeAgente: 'AGTEC' | 'AGTOT' | 'AGPSS';
195
+ /** @optional ISPB of the withdrawal service provider */
196
+ prestadorDeServicoDeSaque?: string;
197
+ };
198
+ /** @optional Change (troco) component - PIX Troco (mutually exclusive with saque) */
199
+ troco?: {
200
+ /** @required Change amount as decimal string */
201
+ valor: string;
202
+ /**
203
+ * @required Agent modality:
204
+ * - AGTEC: Agente Estabelecimento Comercial
205
+ * - AGTOT: Agente Outra Especie de PJ
206
+ * - AGPSS: Agente Facilitador de Servico de Saque
207
+ */
208
+ modalidadeAgente: 'AGTEC' | 'AGTOT' | 'AGPSS';
209
+ /** @optional ISPB of the withdrawal service provider */
210
+ prestadorDeServicoDeSaque?: string;
211
+ };
212
+ /** @optional Interest amount (only for cobv payments after due date) */
213
+ juros?: {
214
+ valor: string;
215
+ };
216
+ /** @optional Penalty amount (only for cobv payments after due date) */
217
+ multa?: {
218
+ valor: string;
219
+ };
220
+ /** @optional Rebate/reduction amount (only for cobv payments) */
221
+ abatimento?: {
222
+ valor: string;
223
+ };
224
+ /** @optional Discount amount (only for cobv payments before due date) */
225
+ desconto?: {
226
+ valor: string;
227
+ };
228
+ }
229
+ /** Configuration for Saque (withdrawal) or Troco (change) in a charge */
230
+ interface SaqueTroco {
231
+ /** @required Amount as decimal string (e.g. "20.00") */
232
+ valor: string;
233
+ /** @optional Whether the payer can modify the amount: 0 = No, 1 = Yes */
234
+ modalidadeAlteracao?: 0 | 1;
235
+ /** @optional ISPB of the withdrawal service provider */
236
+ prestadorDeServicoDeSaque?: string;
237
+ /**
238
+ * @required Agent modality:
239
+ * - AGTEC: Agente Estabelecimento Comercial
240
+ * - AGTOT: Agente Outra Especie de PJ
241
+ * - AGPSS: Agente Facilitador de Servico de Saque
242
+ */
243
+ modalidadeAgente: 'AGTEC' | 'AGTOT' | 'AGPSS';
244
+ }
245
+ /**
246
+ * Status for refund/return operations.
247
+ * Includes both legacy (v2) and current (v2.9+) status names for compatibility.
248
+ * - EM_PROCESSAMENTO / PENDENTE: Refund is being processed
249
+ * - DEVOLVIDO / LIQUIDADO: Refund has been settled
250
+ * - NAO_REALIZADO: Refund could not be completed
251
+ */
252
+ type DevolucaoStatus = 'EM_PROCESSAMENTO' | 'DEVOLVIDO' | 'NAO_REALIZADO' | 'PENDENTE' | 'LIQUIDADO';
253
+ /**
254
+ * Nature of the refund/return (response - all possible values from PSP).
255
+ * - ORIGINAL (MD06): Refund of a regular Pix or the purchase value in Pix Troco
256
+ * - RETIRADA (SL02): Refund of a Pix Saque or the change value in Pix Troco
257
+ * - MED_OPERACIONAL (BE08): MED refund due to operational failure
258
+ * - MED_FRAUDE (FR01): MED refund due to suspected fraud
259
+ * - MED_PIX_AUTOMATICO (REFU): MED reimbursement for Pix Automatico
260
+ *
261
+ * When absent, defaults to ORIGINAL.
262
+ */
263
+ type DevolucaoNatureza = 'ORIGINAL' | 'RETIRADA' | 'MED_OPERACIONAL' | 'MED_FRAUDE' | 'MED_PIX_AUTOMATICO';
264
+ /**
265
+ * Nature of a refund/return request (request - only user-initiated values).
266
+ * - ORIGINAL (MD06): Refund of a regular Pix or the purchase value in Pix Troco
267
+ * - RETIRADA (SL02): Refund of a Pix Saque or the change value in Pix Troco
268
+ *
269
+ * When absent, defaults to ORIGINAL.
270
+ */
271
+ type DevolucaoSolicitadaNatureza = 'ORIGINAL' | 'RETIRADA';
272
+ /** Type guard: checks if a Devedor is identified by CPF */
273
+ declare function isDevedorCpf(devedor: Devedor): devedor is DevedorCpf;
274
+ /** Type guard: checks if a Devedor is identified by CNPJ */
275
+ declare function isDevedorCnpj(devedor: Devedor): devedor is DevedorCnpj;
276
+ /** Type guard: checks if a Pagador is identified by CPF */
277
+ declare function isPagadorCpf(pagador: Pagador): pagador is PagadorCpf;
278
+ /** Type guard: checks if a Pagador is identified by CNPJ */
279
+ declare function isPagadorCnpj(pagador: Pagador): pagador is PagadorCnpj;
280
+
281
+ /**
282
+ * Status of an immediate PIX charge (cob).
283
+ * - ATIVA: Charge is active and can be paid
284
+ * - CONCLUIDA: Charge has been paid
285
+ * - REMOVIDA_PELO_USUARIO_RECEBEDOR: Cancelled by the receiver
286
+ * - REMOVIDA_PELO_PSP: Removed by the Payment Service Provider
287
+ */
288
+ type CobStatus = 'ATIVA' | 'CONCLUIDA' | 'REMOVIDA_PELO_USUARIO_RECEBEDOR' | 'REMOVIDA_PELO_PSP';
289
+ /** Refund/return attached to a PIX payment */
290
+ interface Devolucao {
291
+ /** @required Refund ID assigned by PSP */
292
+ id: string;
293
+ /** @required Return Transaction Reference ID (32 alphanumeric chars, e.g. "D12345678202009091000abcde123456") */
294
+ rtrId: string;
295
+ /** @required Refund amount as decimal string (e.g. "10.00") */
296
+ valor: string;
297
+ /** @optional Nature of the refund (defaults to ORIGINAL when absent) */
298
+ natureza?: DevolucaoNatureza;
299
+ /** @optional Description/reason for the refund (max 140 chars) */
300
+ descricao?: string;
301
+ /** @required Timestamps for the refund */
302
+ horario: {
303
+ /** @required ISO 8601 timestamp when refund was requested */
304
+ solicitacao: string;
305
+ /** @optional ISO 8601 timestamp when refund was settled */
306
+ liquidacao?: string;
307
+ };
308
+ /** @required Current status of the refund */
309
+ status: DevolucaoStatus;
310
+ /** @optional Reason/description of the status (e.g. explains NAO_REALIZADO reason) */
311
+ motivo?: string;
312
+ }
313
+ /** PIX payment received against a charge */
314
+ interface PixPayment {
315
+ /** @required End-to-end ID (unique payment identifier from Bacen) */
316
+ endToEndId: string;
317
+ /** @optional Transaction ID (present if payment is linked to a charge) */
318
+ txid?: string;
319
+ /** @required Payment amount as decimal string */
320
+ valor: string;
321
+ /** @optional PIX key that received the payment */
322
+ chave?: string;
323
+ /** @optional Payer identification (CPF or CNPJ with name) */
324
+ pagador?: Pagador;
325
+ /** @required Payment timestamps */
326
+ horario: {
327
+ /** @required ISO 8601 timestamp when payment was requested */
328
+ solicitacao: string;
329
+ /** @optional ISO 8601 timestamp when payment was settled */
330
+ liquidacao?: string;
331
+ };
332
+ /** @optional Free-text information from the payer */
333
+ infoPagador?: string;
334
+ /** @optional Breakdown of payment value (original, saque, troco) */
335
+ componentesValor?: ComponentesValor;
336
+ /** @optional List of refunds/returns associated with this payment */
337
+ devolucoes?: Devolucao[];
338
+ }
339
+ /** Request body for creating an immediate PIX charge */
340
+ interface CreateCobRequest {
341
+ /** @required Calendar with expiration settings */
342
+ calendario: {
343
+ /** @required Expiration in seconds from creation */
344
+ expiracao: number;
345
+ };
346
+ /** @optional Debtor information (person or company) */
347
+ devedor?: Devedor;
348
+ /** @required Charge amount */
349
+ valor: Valor;
350
+ /** @required PIX key of the receiver */
351
+ chave: string;
352
+ /** @optional Free-text message requesting payment info from payer (max 140 chars) */
353
+ solicitacaoPagador?: string;
354
+ /** @optional Additional information fields displayed to the payer */
355
+ infoAdicionais?: InfoAdicional[];
356
+ /** @optional Link to an existing payload location by ID */
357
+ loc?: {
358
+ id: number;
359
+ };
360
+ /** @optional Withdrawal (Saque) configuration - PIX Saque */
361
+ saque?: SaqueTroco;
362
+ /** @optional Change (Troco) configuration - PIX Troco */
363
+ troco?: SaqueTroco;
364
+ }
365
+ /** Response from creating/querying an immediate PIX charge */
366
+ interface CobResponse {
367
+ /** @required Calendar with creation and expiration info */
368
+ calendario: Calendario;
369
+ /** @required Transaction ID (26-35 alphanumeric chars) */
370
+ txid: string;
371
+ /** @required Revision number (increments on each update) */
372
+ revisao: number;
373
+ /** @optional Payload location details */
374
+ loc?: Loc;
375
+ /** @optional Payload location URL string */
376
+ location?: string;
377
+ /** @required Current status of the charge */
378
+ status: CobStatus;
379
+ /** @optional Debtor information */
380
+ devedor?: Devedor;
381
+ /** @required Charge amount */
382
+ valor: Valor;
383
+ /** @required PIX key of the receiver */
384
+ chave: string;
385
+ /** @optional Free-text message requesting payment info from payer */
386
+ solicitacaoPagador?: string;
387
+ /** @optional Additional information fields */
388
+ infoAdicionais?: InfoAdicional[];
389
+ /** @optional PIX Copia e Cola string (BR Code payload for copy-paste) */
390
+ pixCopiaECola?: string;
391
+ /** @optional BR Code string (raw QR code content) */
392
+ brcode?: string;
393
+ /** @optional List of PIX payments received for this charge */
394
+ pix?: PixPayment[];
395
+ /** @optional Withdrawal (Saque) configuration */
396
+ saque?: SaqueTroco;
397
+ /** @optional Change (Troco) configuration */
398
+ troco?: SaqueTroco;
399
+ }
400
+ /** Request body for updating (PATCH) an immediate PIX charge */
401
+ interface UpdateCobRequest {
402
+ /** @optional Updated calendar/expiration settings */
403
+ calendario?: {
404
+ /** @required Expiration in seconds */
405
+ expiracao: number;
406
+ };
407
+ /** @optional Updated debtor information */
408
+ devedor?: Devedor;
409
+ /** @optional Updated charge amount */
410
+ valor?: Valor;
411
+ /** @optional Updated PIX key */
412
+ chave?: string;
413
+ /** @optional Updated payment request message */
414
+ solicitacaoPagador?: string;
415
+ /** @optional Updated additional information fields */
416
+ infoAdicionais?: InfoAdicional[];
417
+ /** @optional Link to an existing payload location by ID */
418
+ loc?: {
419
+ id: number;
420
+ };
421
+ /** @optional Set to 'REMOVIDA_PELO_USUARIO_RECEBEDOR' to cancel the charge */
422
+ status?: 'REMOVIDA_PELO_USUARIO_RECEBEDOR';
423
+ }
424
+ /** Parameters for listing immediate PIX charges */
425
+ interface ListCobParams {
426
+ /** @required Start date filter (ISO 8601, e.g. "2024-01-01T00:00:00Z") */
427
+ inicio: string;
428
+ /** @required End date filter (ISO 8601) */
429
+ fim: string;
430
+ /** @optional Filter by debtor CPF (11 digits) */
431
+ cpf?: string;
432
+ /** @optional Filter by debtor CNPJ (14 digits) */
433
+ cnpj?: string;
434
+ /** @optional Filter by whether a payload location is present */
435
+ locationPresente?: boolean;
436
+ /** @optional Filter by charge status */
437
+ status?: CobStatus;
438
+ /** @optional Pagination parameters */
439
+ paginacao?: PaginacaoParams;
440
+ }
441
+ /** Response from listing immediate PIX charges */
442
+ interface ListCobResponse {
443
+ /** @required Query parameters and pagination metadata */
444
+ parametros: {
445
+ /** @required Start date used in the query */
446
+ inicio: string;
447
+ /** @required End date used in the query */
448
+ fim: string;
449
+ /** @required Pagination metadata */
450
+ paginacao: Paginacao;
451
+ };
452
+ /** @required List of charges matching the filters */
453
+ cobs: CobResponse[];
454
+ }
455
+
456
+ /** mTLS certificate configuration for Sicredi API authentication */
457
+ interface CertificateOptions {
458
+ /** @required PEM string or file path to client certificate (.cer/.crt/.pem) */
459
+ cert: string;
460
+ /** @required PEM string or file path to private key (.key/.pem) */
461
+ key: string;
462
+ /** @optional PEM string or file path to CA certificate chain (Sicredi root CA) */
463
+ ca?: string;
464
+ /** @optional Passphrase for the private key (if encrypted) */
465
+ passphrase?: string;
466
+ }
467
+ /** Main SDK configuration */
468
+ interface SicrediConfig {
469
+ /** @required OAuth2 client ID (provided by Sicredi) */
470
+ clientId: string;
471
+ /** @required OAuth2 client secret (provided by Sicredi) */
472
+ clientSecret: string;
473
+ /** @optional Default PIX key for operations (can be overridden per-call) */
474
+ pixKey?: string;
475
+ /** @required mTLS certificate options (cert + key are mandatory) */
476
+ certificate: CertificateOptions;
477
+ /** @optional Environment: 'production' or 'sandbox' (default: 'production') */
478
+ environment?: 'production' | 'sandbox';
479
+ /** @optional Custom base URL (overrides environment selection) */
480
+ baseUrl?: string;
481
+ /** @optional Request timeout in milliseconds (default: 30000) */
482
+ timeout?: number;
483
+ /** @optional Maximum retry attempts for failed requests (default: 3) */
484
+ maxRetries?: number;
485
+ /** @optional Enable debug logging to console (default: false) */
486
+ debug?: boolean;
487
+ }
488
+
489
+ interface HttpRequestOptions {
490
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
491
+ url: string;
492
+ headers?: Record<string, string>;
493
+ body?: string;
494
+ timeout?: number;
495
+ }
496
+ interface HttpResponse {
497
+ status: number;
498
+ headers: Record<string, string>;
499
+ body: string;
500
+ }
501
+ interface HttpClient {
502
+ request(options: HttpRequestOptions): Promise<HttpResponse>;
503
+ }
504
+
505
+ declare class AuthManager {
506
+ private readonly clientId;
507
+ private readonly clientSecret;
508
+ private readonly baseUrl;
509
+ private readonly httpClient;
510
+ private cachedToken;
511
+ private refreshPromise;
512
+ constructor(clientId: string, clientSecret: string, baseUrl: string, httpClient: HttpClient);
513
+ getAccessToken(): Promise<string>;
514
+ invalidateToken(): void;
515
+ private isTokenExpiringSoon;
516
+ private refreshToken;
517
+ }
518
+
519
+ interface RetryOptions {
520
+ maxRetries: number;
521
+ baseDelayMs?: number;
522
+ maxDelayMs?: number;
523
+ }
524
+
525
+ interface ResourceConfig {
526
+ baseUrl: string;
527
+ httpClient: HttpClient;
528
+ authManager: AuthManager;
529
+ retryOptions: RetryOptions;
530
+ debug: boolean;
531
+ }
532
+ declare abstract class BaseResource {
533
+ protected readonly baseUrl: string;
534
+ protected readonly httpClient: HttpClient;
535
+ protected readonly authManager: AuthManager;
536
+ protected readonly retryOptions: RetryOptions;
537
+ protected readonly debug: boolean;
538
+ constructor(config: ResourceConfig);
539
+ protected request<T>(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, body?: unknown, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
540
+ private buildUrl;
541
+ }
542
+
543
+ declare class CobResource extends BaseResource {
544
+ /**
545
+ * Create a PIX immediate charge with a specific txid.
546
+ * PUT /api/v2/cob/{txid}
547
+ */
548
+ create(txid: string, data: CreateCobRequest): Promise<CobResponse>;
549
+ /**
550
+ * Create a PIX immediate charge with auto-generated txid.
551
+ * POST /api/v2/cob
552
+ */
553
+ createAuto(data: CreateCobRequest): Promise<CobResponse>;
554
+ /**
555
+ * Get a PIX immediate charge by txid.
556
+ * GET /api/v3/cob/{txid} (note: v3!)
557
+ */
558
+ get(txid: string, revisao?: number): Promise<CobResponse>;
559
+ /**
560
+ * Update (patch) a PIX immediate charge.
561
+ * PATCH /api/v2/cob/{txid}
562
+ */
563
+ update(txid: string, data: UpdateCobRequest): Promise<CobResponse>;
564
+ /**
565
+ * Cancel a PIX immediate charge by setting status to REMOVIDA_PELO_USUARIO_RECEBEDOR.
566
+ * PATCH /api/v2/cob/{txid}
567
+ */
568
+ cancel(txid: string): Promise<CobResponse>;
569
+ /**
570
+ * List PIX immediate charges with filters.
571
+ * GET /api/v2/cob
572
+ */
573
+ list(params: ListCobParams): Promise<ListCobResponse>;
574
+ /**
575
+ * Generate a txid (helper utility).
576
+ */
577
+ generateTxId(length?: number): string;
578
+ }
579
+
580
+ /**
581
+ * Status of a charge with due date (cobv / Boleto Hibrido).
582
+ * - ATIVA: Charge is active and can be paid
583
+ * - CONCLUIDA: Charge has been paid
584
+ * - REMOVIDA_PELO_USUARIO_RECEBEDOR: Cancelled by the receiver
585
+ * - REMOVIDA_PELO_PSP: Removed by the Payment Service Provider
586
+ * - VENCIDA: Charge is past due date + validity period
587
+ */
588
+ type CobvStatus = 'ATIVA' | 'CONCLUIDA' | 'REMOVIDA_PELO_USUARIO_RECEBEDOR' | 'REMOVIDA_PELO_PSP' | 'VENCIDA';
589
+ /** Date-specific discount entry for modalities 1 and 2 */
590
+ interface DescontoDataFixa {
591
+ /** @required Date in YYYY-MM-DD format when this discount applies */
592
+ data: string;
593
+ /** @required Fixed value or percentage for this date */
594
+ valorPerc: string;
595
+ }
596
+ /** Discount configuration for charges with due date */
597
+ interface Desconto {
598
+ /**
599
+ * @required Discount modality:
600
+ * - 1 = Fixed value until specific dates
601
+ * - 2 = Percentage until specific dates
602
+ * - 3 = Fixed value per anticipation day
603
+ * - 4 = Percentage per anticipation day
604
+ * - 5 = Fixed value per anticipation day (up to a date)
605
+ * - 6 = Percentage per anticipation day (up to a date)
606
+ */
607
+ modalidade: 1 | 2 | 3 | 4 | 5 | 6;
608
+ /** @optional Date-specific discount entries (required for modalities 1-2) */
609
+ descontoDataFixa?: DescontoDataFixa[];
610
+ /** @optional Fixed value or percentage (required for modalities 3-6) */
611
+ valorPerc?: string;
612
+ }
613
+ /** Interest configuration for overdue charges */
614
+ interface Juros {
615
+ /**
616
+ * @required Interest modality:
617
+ * - 1 = Fixed daily value
618
+ * - 2 = Percentage per month (pro-rata per day)
619
+ * - 3 = Percentage per year (365 days)
620
+ * - 4 = Percentage per year (360 days)
621
+ * - 5 = Percentage per business day (252 days/year)
622
+ * - 6 = Percentage per business day (360 days/year)
623
+ * - 7 = Fixed monthly value
624
+ * - 8 = Exempt (no interest)
625
+ */
626
+ modalidade: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
627
+ /** @required Interest value or percentage as decimal string */
628
+ valorPerc: string;
629
+ }
630
+ /** Penalty (multa) configuration for overdue charges */
631
+ interface Multa {
632
+ /** @required Penalty modality: 1 = Fixed value, 2 = Percentage */
633
+ modalidade: 1 | 2;
634
+ /** @required Penalty value or percentage as decimal string */
635
+ valorPerc: string;
636
+ }
637
+ /** Rebate/reduction (abatimento) configuration */
638
+ interface Abatimento {
639
+ /** @required Rebate modality: 1 = Fixed value, 2 = Percentage */
640
+ modalidade: 1 | 2;
641
+ /** @required Rebate value or percentage as decimal string */
642
+ valorPerc: string;
643
+ }
644
+ /** Value configuration for charges with due date, including financial components */
645
+ interface ValorCobv {
646
+ /** @required Original charge amount as decimal string (e.g. "150.00") */
647
+ original: string;
648
+ /** @optional Final calculated amount after applying interest, penalty, discounts, and rebates (set by server) */
649
+ final?: string;
650
+ /** @optional Penalty configuration applied after due date */
651
+ multa?: Multa;
652
+ /** @optional Interest configuration applied after due date */
653
+ juros?: Juros;
654
+ /** @optional Rebate/reduction applied to the charge */
655
+ abatimento?: Abatimento;
656
+ /** @optional Discount configuration for early payment */
657
+ desconto?: Desconto;
658
+ }
659
+ /** Request body for creating a charge with due date (Boleto Hibrido) */
660
+ interface CreateCobvRequest {
661
+ /** @required Calendar with due date and validity settings */
662
+ calendario: CalendarioVencimento;
663
+ /** @required Debtor information (required for cobv, unlike cob) */
664
+ devedor: Devedor;
665
+ /** @required Charge amount with optional financial components */
666
+ valor: ValorCobv;
667
+ /** @required PIX key of the receiver */
668
+ chave: string;
669
+ /** @optional Free-text message requesting payment info from payer (max 140 chars) */
670
+ solicitacaoPagador?: string;
671
+ /** @optional Additional information fields displayed to the payer */
672
+ infoAdicionais?: InfoAdicional[];
673
+ /** @optional Link to an existing payload location by ID */
674
+ loc?: {
675
+ id: number;
676
+ };
677
+ }
678
+ /** Response from creating/querying a charge with due date */
679
+ interface CobvResponse {
680
+ /** @required Calendar with due date info */
681
+ calendario: CalendarioVencimento;
682
+ /** @required Transaction ID (26-35 alphanumeric chars) */
683
+ txid: string;
684
+ /** @required Revision number (increments on each update) */
685
+ revisao: number;
686
+ /** @optional Payload location details */
687
+ loc?: Loc;
688
+ /** @optional Payload location URL string */
689
+ location?: string;
690
+ /** @required Current status of the charge */
691
+ status: CobvStatus;
692
+ /** @required Debtor information */
693
+ devedor: Devedor;
694
+ /** @optional Receiver information (set by server) */
695
+ recebedor?: Recebedor;
696
+ /** @required Charge amount with financial components */
697
+ valor: ValorCobv;
698
+ /** @required PIX key of the receiver */
699
+ chave: string;
700
+ /** @optional Free-text message requesting payment info from payer */
701
+ solicitacaoPagador?: string;
702
+ /** @optional Additional information fields */
703
+ infoAdicionais?: InfoAdicional[];
704
+ /** @optional PIX Copia e Cola string (BR Code payload for copy-paste) */
705
+ pixCopiaECola?: string;
706
+ /** @optional BR Code string (raw QR code content) */
707
+ brcode?: string;
708
+ /** @optional List of PIX payments received for this charge */
709
+ pix?: PixPayment[];
710
+ }
711
+ /** Request body for updating (PATCH) a charge with due date */
712
+ interface UpdateCobvRequest {
713
+ /** @optional Updated calendar/due date settings */
714
+ calendario?: CalendarioVencimento;
715
+ /** @optional Updated debtor information */
716
+ devedor?: Devedor;
717
+ /** @optional Updated charge amount */
718
+ valor?: ValorCobv;
719
+ /** @optional Updated PIX key */
720
+ chave?: string;
721
+ /** @optional Updated payment request message */
722
+ solicitacaoPagador?: string;
723
+ /** @optional Updated additional information fields */
724
+ infoAdicionais?: InfoAdicional[];
725
+ /** @optional Link to an existing payload location by ID */
726
+ loc?: {
727
+ id: number;
728
+ };
729
+ /** @optional Set to 'REMOVIDA_PELO_USUARIO_RECEBEDOR' to cancel the charge */
730
+ status?: 'REMOVIDA_PELO_USUARIO_RECEBEDOR';
731
+ }
732
+ /** Parameters for listing charges with due date */
733
+ interface ListCobvParams {
734
+ /** @required Start date filter (ISO 8601, e.g. "2024-01-01T00:00:00Z") */
735
+ inicio: string;
736
+ /** @required End date filter (ISO 8601) */
737
+ fim: string;
738
+ /** @optional Filter by debtor CPF (11 digits) */
739
+ cpf?: string;
740
+ /** @optional Filter by debtor CNPJ (14 digits) */
741
+ cnpj?: string;
742
+ /** @optional Filter by whether a payload location is present */
743
+ locationPresente?: boolean;
744
+ /** @optional Filter by charge status */
745
+ status?: CobvStatus;
746
+ /** @optional Filter by batch ID (loteCobVId) */
747
+ loteCobVId?: number;
748
+ /** @optional Pagination parameters */
749
+ paginacao?: PaginacaoParams;
750
+ }
751
+ /** Response from listing charges with due date */
752
+ interface ListCobvResponse {
753
+ /** @required Query parameters and pagination metadata */
754
+ parametros: {
755
+ /** @required Start date used in the query */
756
+ inicio: string;
757
+ /** @required End date used in the query */
758
+ fim: string;
759
+ /** @required Pagination metadata */
760
+ paginacao: Paginacao;
761
+ };
762
+ /** @required List of charges matching the filters */
763
+ cobs: CobvResponse[];
764
+ }
765
+
766
+ declare class CobvResource extends BaseResource {
767
+ /**
768
+ * Create a Boleto Hibrido (PIX with due date) charge.
769
+ * PUT /api/v2/cobv/{txid}
770
+ */
771
+ create(txid: string, data: CreateCobvRequest): Promise<CobvResponse>;
772
+ /**
773
+ * Get a Boleto Hibrido charge by txid.
774
+ * GET /api/v2/cobv/{txid}
775
+ */
776
+ get(txid: string, revisao?: number): Promise<CobvResponse>;
777
+ /**
778
+ * Update (patch) a Boleto Hibrido charge.
779
+ * PATCH /api/v2/cobv/{txid}
780
+ */
781
+ update(txid: string, data: UpdateCobvRequest): Promise<CobvResponse>;
782
+ /**
783
+ * Cancel a Boleto Hibrido charge.
784
+ * PATCH /api/v2/cobv/{txid}
785
+ */
786
+ cancel(txid: string): Promise<CobvResponse>;
787
+ /**
788
+ * List Boleto Hibrido charges with filters.
789
+ * GET /api/v2/cobv
790
+ */
791
+ list(params: ListCobvParams): Promise<ListCobvResponse>;
792
+ }
793
+
794
+ /** Request body for creating a payload location */
795
+ interface CreateLocRequest {
796
+ /** @required Type of charge: 'cob' (immediate) or 'cobv' (with due date) */
797
+ tipoCob: 'cob' | 'cobv';
798
+ }
799
+ /** Response from creating/querying a payload location */
800
+ type LocResponse = LocCompleta;
801
+ /** Parameters for listing payload locations */
802
+ interface ListLocParams {
803
+ /** @required Start date filter (ISO 8601) */
804
+ inicio: string;
805
+ /** @required End date filter (ISO 8601) */
806
+ fim: string;
807
+ /** @optional Filter by charge type: 'cob' or 'cobv' */
808
+ tipoCob?: 'cob' | 'cobv';
809
+ /** @optional Filter by whether a txid is linked to the location */
810
+ txIdPresente?: boolean;
811
+ /** @optional Pagination parameters */
812
+ paginacao?: PaginacaoParams;
813
+ }
814
+ /** Response from listing payload locations */
815
+ interface ListLocResponse {
816
+ /** @required Query parameters and pagination metadata */
817
+ parametros: {
818
+ /** @required Start date used in the query */
819
+ inicio: string;
820
+ /** @required End date used in the query */
821
+ fim: string;
822
+ /** @required Pagination metadata */
823
+ paginacao: Paginacao;
824
+ };
825
+ /** @required List of payload locations */
826
+ loc: LocResponse[];
827
+ }
828
+
829
+ declare class LocResource extends BaseResource {
830
+ /**
831
+ * Create a payload location.
832
+ * POST /api/v2/loc
833
+ */
834
+ create(data: CreateLocRequest): Promise<LocResponse>;
835
+ /**
836
+ * Get a payload location by ID.
837
+ * GET /api/v2/loc/{id}
838
+ */
839
+ get(id: number): Promise<LocResponse>;
840
+ /**
841
+ * List payload locations.
842
+ * GET /api/v2/loc
843
+ */
844
+ list(params: ListLocParams): Promise<ListLocResponse>;
845
+ /**
846
+ * Unlink a charge from a payload location.
847
+ * DELETE /api/v2/loc/{id}/txid
848
+ */
849
+ unlink(id: number): Promise<LocResponse>;
850
+ }
851
+
852
+ /**
853
+ * Status of an individual charge within a batch.
854
+ * - EM_PROCESSAMENTO: Charge is being processed
855
+ * - CRIADA: Charge was successfully created
856
+ */
857
+ type LoteCobvItemStatus = 'EM_PROCESSAMENTO' | 'CRIADA';
858
+ /** A single cobv charge request within a batch, requiring a txid */
859
+ interface LoteCobvCobSolicitado extends CreateCobvRequest {
860
+ /** @required Transaction ID for this charge (26-35 alphanumeric chars) */
861
+ txid: string;
862
+ }
863
+ /** Request body for creating a batch of cobv charges (PUT /lotecobv/{id}) */
864
+ interface LoteCobvRequest {
865
+ /** @optional Description for the batch */
866
+ descricao?: string;
867
+ /** @required Array of cobv charges to create */
868
+ cobsv: LoteCobvCobSolicitado[];
869
+ }
870
+ /** Request body for updating specific charges within a batch (PATCH /lotecobv/{id}) */
871
+ interface LoteCobvPatchRequest {
872
+ /** @required Array of partial updates, each identified by txid */
873
+ cobsv: Array<Partial<CreateCobvRequest> & {
874
+ /** @required Transaction ID of the charge to update */
875
+ txid: string;
876
+ }>;
877
+ }
878
+ /** Response from querying a batch of cobv charges */
879
+ interface LoteCobvResponse {
880
+ /** @required Batch ID */
881
+ id: number;
882
+ /** @optional Description for the batch */
883
+ descricao?: string;
884
+ /** @required ISO 8601 timestamp of batch creation */
885
+ criacao: string;
886
+ /** @required Array of cobv charge items with batch-specific status */
887
+ cobsv: Array<{
888
+ /** @required Transaction ID for this charge */
889
+ txid: string;
890
+ /** @required Batch processing status for this charge */
891
+ status: LoteCobvItemStatus;
892
+ /** @optional Full charge details (present when status is CRIADA) */
893
+ criacao?: CobvResponse;
894
+ /** @optional Processing error for this specific charge */
895
+ problema?: {
896
+ /** @required Error type URI (Bacen error taxonomy) */
897
+ type: string;
898
+ /** @required Human-readable error title */
899
+ title: string;
900
+ /** @required HTTP status code */
901
+ status: number;
902
+ /** @optional Detailed error description */
903
+ detail?: string;
904
+ };
905
+ }>;
906
+ }
907
+ /** Parameters for listing batches of cobv charges */
908
+ interface ListLoteCobvParams {
909
+ /** @required Start date filter (ISO 8601) */
910
+ inicio: string;
911
+ /** @required End date filter (ISO 8601) */
912
+ fim: string;
913
+ /** @optional Pagination parameters */
914
+ paginacao?: PaginacaoParams;
915
+ }
916
+ /** Response from listing batches of cobv charges */
917
+ interface ListLoteCobvResponse {
918
+ /** @required Query parameters and pagination metadata */
919
+ parametros: {
920
+ /** @required Start date used in the query */
921
+ inicio: string;
922
+ /** @required End date used in the query */
923
+ fim: string;
924
+ /** @required Pagination metadata */
925
+ paginacao: Paginacao;
926
+ };
927
+ /** @required List of batch responses */
928
+ lotes: LoteCobvResponse[];
929
+ }
930
+
931
+ declare class LoteCobvResource extends BaseResource {
932
+ /**
933
+ * Create or replace a batch of cobv charges.
934
+ * PUT /api/v2/lotecobv/{id}
935
+ */
936
+ create(id: number, data: LoteCobvRequest): Promise<void>;
937
+ /**
938
+ * Revise specific charges within a batch.
939
+ * PATCH /api/v2/lotecobv/{id}
940
+ */
941
+ update(id: number, data: LoteCobvPatchRequest): Promise<void>;
942
+ /**
943
+ * Query a specific batch of cobv charges.
944
+ * GET /api/v2/lotecobv/{id}
945
+ */
946
+ get(id: number): Promise<LoteCobvResponse>;
947
+ /**
948
+ * List batches of cobv charges.
949
+ * GET /api/v2/lotecobv
950
+ */
951
+ list(params: ListLoteCobvParams): Promise<ListLoteCobvResponse>;
952
+ }
953
+
954
+ /** A received PIX payment (from GET /pix endpoints) */
955
+ interface PixRecebido {
956
+ /** @required End-to-end ID (unique payment identifier from Bacen) */
957
+ endToEndId: string;
958
+ /** @optional Transaction ID (present if payment is linked to a charge) */
959
+ txid?: string;
960
+ /** @required Payment amount as decimal string (e.g. "100.00") */
961
+ valor: string;
962
+ /** @required PIX key that received the payment */
963
+ chave: string;
964
+ /** @optional Payer identification (CPF or CNPJ with name) */
965
+ pagador?: Pagador;
966
+ /** @required Payment timestamps */
967
+ horario: {
968
+ /** @required ISO 8601 timestamp when payment was requested */
969
+ solicitacao: string;
970
+ /** @optional ISO 8601 timestamp when payment was settled */
971
+ liquidacao?: string;
972
+ };
973
+ /** @optional Free-text information from the payer */
974
+ infoPagador?: string;
975
+ /** @optional Receiver information */
976
+ recebedor?: Recebedor;
977
+ /** @optional Breakdown of payment value (original, saque, troco, juros, multa, desconto, abatimento) */
978
+ componentesValor?: ComponentesValor;
979
+ /** @optional List of refunds/returns associated with this payment */
980
+ devolucoes?: Devolucao[];
981
+ }
982
+ /** Request body for creating a refund/return */
983
+ interface DevolucaoRequest {
984
+ /** @required Refund amount as decimal string (e.g. "10.00", must be <= original payment) */
985
+ valor: string;
986
+ /** @optional Nature of the refund: ORIGINAL (default, MD06) or RETIRADA (SL02, for Saque/Troco) */
987
+ natureza?: DevolucaoSolicitadaNatureza;
988
+ /** @optional Description/reason for the refund (max 140 chars, shown in pacs.004 RemittanceInformation) */
989
+ descricao?: string;
990
+ }
991
+ /** Response from creating/querying a refund/return */
992
+ interface DevolucaoResponse {
993
+ /** @required Refund ID assigned by PSP */
994
+ id: string;
995
+ /** @required Return Transaction Reference ID */
996
+ rtrId: string;
997
+ /** @required Refund amount as decimal string */
998
+ valor: string;
999
+ /** @optional Nature of the refund */
1000
+ natureza?: DevolucaoNatureza;
1001
+ /** @optional Description/reason for the refund */
1002
+ descricao?: string;
1003
+ /** @required Timestamps for the refund */
1004
+ horario: {
1005
+ /** @required ISO 8601 timestamp when refund was requested */
1006
+ solicitacao: string;
1007
+ /** @optional ISO 8601 timestamp when refund was settled */
1008
+ liquidacao?: string;
1009
+ };
1010
+ /** @required Current status of the refund */
1011
+ status: DevolucaoStatus;
1012
+ /** @optional Reason/description of the status (e.g. explains NAO_REALIZADO reason) */
1013
+ motivo?: string;
1014
+ }
1015
+ /** Parameters for listing received PIX payments */
1016
+ interface ListPixParams {
1017
+ /** @required Start date filter (ISO 8601) */
1018
+ inicio: string;
1019
+ /** @required End date filter (ISO 8601) */
1020
+ fim: string;
1021
+ /** @optional Filter by specific transaction ID */
1022
+ txid?: string;
1023
+ /** @optional Filter by whether a txid is present */
1024
+ txIdPresente?: boolean;
1025
+ /** @optional Filter by whether refunds/returns are present */
1026
+ devolucaoPresente?: boolean;
1027
+ /** @optional Filter by payer CPF (11 digits) */
1028
+ cpf?: string;
1029
+ /** @optional Filter by payer CNPJ (14 digits) */
1030
+ cnpj?: string;
1031
+ /** @optional Pagination parameters */
1032
+ paginacao?: PaginacaoParams;
1033
+ }
1034
+ /** Response from listing received PIX payments */
1035
+ interface ListPixResponse {
1036
+ /** @required Query parameters and pagination metadata */
1037
+ parametros: {
1038
+ /** @required Start date used in the query */
1039
+ inicio: string;
1040
+ /** @required End date used in the query */
1041
+ fim: string;
1042
+ /** @required Pagination metadata */
1043
+ paginacao: Paginacao;
1044
+ };
1045
+ /** @required List of received PIX payments */
1046
+ pix: PixRecebido[];
1047
+ }
1048
+
1049
+ declare class PixResource extends BaseResource {
1050
+ /**
1051
+ * Query a received PIX payment by its end-to-end ID.
1052
+ * GET /api/v2/pix/{e2eid}
1053
+ */
1054
+ get(e2eid: string): Promise<PixRecebido>;
1055
+ /**
1056
+ * List received PIX payments with filters.
1057
+ * GET /api/v2/pix
1058
+ */
1059
+ list(params: ListPixParams): Promise<ListPixResponse>;
1060
+ /**
1061
+ * Request a refund/return for a received PIX payment.
1062
+ * PUT /api/v2/pix/{e2eid}/devolucao/{id}
1063
+ */
1064
+ requestReturn(e2eid: string, id: string, data: DevolucaoRequest): Promise<DevolucaoResponse>;
1065
+ /**
1066
+ * Query the status of a refund/return.
1067
+ * GET /api/v2/pix/{e2eid}/devolucao/{id}
1068
+ */
1069
+ getReturn(e2eid: string, id: string): Promise<DevolucaoResponse>;
1070
+ }
1071
+
1072
+ interface WebhookConfigRequest {
1073
+ /** @required URL where Sicredi will send webhook notifications */
1074
+ webhookUrl: string;
1075
+ }
1076
+ interface WebhookResponse {
1077
+ /** @required Configured webhook URL */
1078
+ webhookUrl: string;
1079
+ /** @required PIX key associated with this webhook */
1080
+ chave: string;
1081
+ /** @required ISO 8601 timestamp of webhook creation */
1082
+ criacao: string;
1083
+ }
1084
+ interface ListWebhookParams {
1085
+ /** @optional Start date filter (ISO 8601). Unlike other list endpoints, this is optional for webhooks. */
1086
+ inicio?: string;
1087
+ /** @optional End date filter (ISO 8601). Unlike other list endpoints, this is optional for webhooks. */
1088
+ fim?: string;
1089
+ /** @optional Pagination parameters */
1090
+ paginacao?: PaginacaoParams;
1091
+ }
1092
+ interface ListWebhookResponse {
1093
+ parametros: {
1094
+ /** @required Start date used in the query */
1095
+ inicio: string;
1096
+ /** @required End date used in the query */
1097
+ fim: string;
1098
+ /** @required Pagination metadata */
1099
+ paginacao: Paginacao;
1100
+ };
1101
+ /** @required List of webhook configurations */
1102
+ webhooks: WebhookResponse[];
1103
+ }
1104
+ /**
1105
+ * Refund/return entry within a webhook callback.
1106
+ * Matches the devolucao structure sent by Bacen/Sicredi in webhook notifications.
1107
+ */
1108
+ interface WebhookDevolucao {
1109
+ /** @required Refund ID assigned by PSP */
1110
+ id: string;
1111
+ /** @required Return Transaction Reference ID */
1112
+ rtrId: string;
1113
+ /** @required Refund amount as decimal string (e.g. "10.00") */
1114
+ valor: string;
1115
+ /** @optional Nature of the refund (defaults to ORIGINAL when absent) */
1116
+ natureza?: DevolucaoNatureza;
1117
+ /** @optional Description/reason for the refund */
1118
+ descricao?: string;
1119
+ /** @required Timestamps for the refund */
1120
+ horario: {
1121
+ /** @required ISO 8601 timestamp when refund was requested */
1122
+ solicitacao: string;
1123
+ /** @optional ISO 8601 timestamp when refund was settled */
1124
+ liquidacao?: string;
1125
+ };
1126
+ /** @required Current status of the refund */
1127
+ status: DevolucaoStatus;
1128
+ }
1129
+ /**
1130
+ * Single PIX payment entry within a webhook callback.
1131
+ *
1132
+ * NOTE: In webhook callbacks, `horario` is a plain ISO 8601 string,
1133
+ * unlike the GET /pix response where it's an object `{ solicitacao, liquidacao? }`.
1134
+ */
1135
+ interface WebhookPixEntry {
1136
+ /** @required End-to-end ID (unique payment identifier from Bacen) */
1137
+ endToEndId: string;
1138
+ /** @optional Transaction ID (present if charge was created via cob/cobv) */
1139
+ txid?: string;
1140
+ /** @required PIX key that received the payment */
1141
+ chave: string;
1142
+ /** @required Payment amount as decimal string (e.g. "100.00") */
1143
+ valor: string;
1144
+ /** @required ISO 8601 timestamp of the payment */
1145
+ horario: string;
1146
+ /** @optional Free-text information from the payer */
1147
+ infoPagador?: string;
1148
+ /** @optional Payer identification (CPF or CNPJ with name) */
1149
+ pagador?: Pagador;
1150
+ /** @optional Breakdown of payment value (original, saque, troco) */
1151
+ componentesValor?: ComponentesValor;
1152
+ /** @optional List of refunds/returns associated with this payment */
1153
+ devolucoes?: WebhookDevolucao[];
1154
+ }
1155
+ /**
1156
+ * Webhook callback payload sent by Sicredi/Bacen.
1157
+ *
1158
+ * IMPORTANT: Sicredi appends '/pix' to your configured webhook URL.
1159
+ * If you configure 'https://example.com/webhook', callbacks will be
1160
+ * sent to 'https://example.com/webhook/pix'.
1161
+ */
1162
+ interface WebhookCallbackPayload {
1163
+ /** @required Array of PIX payments received */
1164
+ pix: WebhookPixEntry[];
1165
+ }
1166
+
1167
+ declare class WebhookResource extends BaseResource {
1168
+ /**
1169
+ * Configure a webhook for a PIX key.
1170
+ * PUT /api/v2/webhook/{chave}
1171
+ */
1172
+ configure(chave: string, webhookUrl: string): Promise<void>;
1173
+ /**
1174
+ * Get webhook configuration for a PIX key.
1175
+ * GET /api/v2/webhook/{chave}
1176
+ */
1177
+ get(chave: string): Promise<WebhookResponse>;
1178
+ /**
1179
+ * Delete webhook configuration for a PIX key.
1180
+ * DELETE /api/v2/webhook/{chave}
1181
+ */
1182
+ delete(chave: string): Promise<void>;
1183
+ /**
1184
+ * List all webhook configurations.
1185
+ * GET /api/v2/webhook
1186
+ */
1187
+ list(params: ListWebhookParams): Promise<ListWebhookResponse>;
1188
+ }
1189
+
1190
+ declare class Sicredi {
1191
+ readonly cob: CobResource;
1192
+ readonly cobv: CobvResource;
1193
+ readonly pix: PixResource;
1194
+ readonly lotecobv: LoteCobvResource;
1195
+ readonly loc: LocResource;
1196
+ readonly webhook: WebhookResource;
1197
+ private readonly _config;
1198
+ private _initPromise;
1199
+ private _cob;
1200
+ private _cobv;
1201
+ private _pix;
1202
+ private _lotecobv;
1203
+ private _loc;
1204
+ private _webhook;
1205
+ constructor(config: SicrediConfig);
1206
+ private get baseUrl();
1207
+ private _ensureInit;
1208
+ private _initialize;
1209
+ }
1210
+
1211
+ /** Raw token response from Sicredi OAuth2 endpoint */
1212
+ interface TokenResponse {
1213
+ /** @required JWT access token */
1214
+ access_token: string;
1215
+ /** @required Token type (always "Bearer") */
1216
+ token_type: string;
1217
+ /** @required Token validity in seconds (typically 3600) */
1218
+ expires_in: number;
1219
+ /** @required Granted scopes (space-separated) */
1220
+ scope: string;
1221
+ }
1222
+ /** Internal cached token representation */
1223
+ interface CachedToken {
1224
+ /** @required JWT access token string */
1225
+ accessToken: string;
1226
+ /** @required Expiration timestamp in milliseconds (Date.now() based) */
1227
+ expiresAt: number;
1228
+ /** @required Granted scopes */
1229
+ scope: string;
1230
+ }
1231
+
1232
+ /** A single validation violation in a Bacen error response */
1233
+ interface Violacao {
1234
+ /** @required Reason for the validation failure */
1235
+ razao: string;
1236
+ /** @required Property/field that caused the violation (dot-notation path) */
1237
+ propriedade: string;
1238
+ }
1239
+ /**
1240
+ * Standard error response format from Bacen PIX API.
1241
+ * Returned by Sicredi for 4xx/5xx HTTP responses.
1242
+ */
1243
+ interface BacenErrorResponse {
1244
+ /** @optional Error type URI from Bacen taxonomy (e.g. "https://pix.bcb.gov.br/api/v2/error/CobOperacaoInvalida") */
1245
+ type?: string;
1246
+ /** @required Human-readable error title */
1247
+ title: string;
1248
+ /** @required HTTP status code */
1249
+ status: number;
1250
+ /** @optional Detailed error description */
1251
+ detail?: string;
1252
+ /** @optional URI identifying the specific occurrence of the problem (RFC 7807) */
1253
+ instance?: string;
1254
+ /** @optional List of field-level validation violations */
1255
+ violacoes?: Violacao[];
1256
+ }
1257
+
1258
+ declare class SicrediError extends Error {
1259
+ readonly code: string;
1260
+ readonly hint?: string;
1261
+ constructor(message: string, code: string, hint?: string);
1262
+ }
1263
+
1264
+ declare class SicrediApiError extends SicrediError {
1265
+ readonly statusCode: number;
1266
+ readonly type?: string;
1267
+ readonly title: string;
1268
+ readonly detail?: string;
1269
+ readonly violacoes?: Violacao[];
1270
+ constructor(statusCode: number, body: BacenErrorResponse);
1271
+ static fromResponse(statusCode: number, body: unknown): SicrediApiError;
1272
+ }
1273
+
1274
+ declare class SicrediAuthError extends SicrediError {
1275
+ constructor(message: string, hint?: string);
1276
+ static invalidCredentials(): SicrediAuthError;
1277
+ static tokenExpired(): SicrediAuthError;
1278
+ static insufficientScope(required: string): SicrediAuthError;
1279
+ }
1280
+
1281
+ declare class SicrediValidationError extends SicrediError {
1282
+ readonly field: string;
1283
+ readonly constraint: string;
1284
+ constructor(field: string, constraint: string, hint?: string);
1285
+ }
1286
+
1287
+ declare class SicrediConnectionError extends SicrediError {
1288
+ readonly cause?: Error;
1289
+ constructor(message: string, cause?: Error, hint?: string);
1290
+ static timeout(ms: number): SicrediConnectionError;
1291
+ static refused(host: string): SicrediConnectionError;
1292
+ static tlsFailure(detail: string): SicrediConnectionError;
1293
+ }
1294
+
1295
+ declare class SicrediCertificateError extends SicrediError {
1296
+ constructor(message: string, hint?: string);
1297
+ static notFound(path: string): SicrediCertificateError;
1298
+ static invalidFormat(detail: string): SicrediCertificateError;
1299
+ static keyMismatch(): SicrediCertificateError;
1300
+ static expired(): SicrediCertificateError;
1301
+ }
1302
+
1303
+ declare function generateTxId(length?: number): string;
1304
+ declare function isValidTxId(txid: string): boolean;
1305
+
1306
+ declare function isValidCpf(cpf: string): boolean;
1307
+ declare function isValidCnpj(cnpj: string): boolean;
1308
+ type PixKeyType = 'cpf' | 'cnpj' | 'email' | 'phone' | 'evp';
1309
+ declare function detectPixKeyType(key: string): PixKeyType | null;
1310
+ declare function isValidPixKey(key: string): boolean;
1311
+ declare function isValidMonetaryValue(value: string): boolean;
1312
+
1313
+ /**
1314
+ * Minimal QR Code generator (zero dependencies).
1315
+ * Supports only alphanumeric mode with error correction level M.
1316
+ * Optimized for PIX "copia e cola" strings.
1317
+ *
1318
+ * For production use with complex data, consider using a dedicated
1319
+ * QR code library. This implementation covers the common PIX use case.
1320
+ */
1321
+ /**
1322
+ * Generate a QR Code as an SVG string from a PIX "copia e cola" payload.
1323
+ */
1324
+ declare function generateQrCodeSvg(data: string, options?: {
1325
+ size?: number;
1326
+ margin?: number;
1327
+ darkColor?: string;
1328
+ lightColor?: string;
1329
+ }): string;
1330
+ /**
1331
+ * Generate a QR Code as a data URL (for embedding in img tags or HTML).
1332
+ */
1333
+ declare function generateQrCodeDataUrl(data: string, options?: {
1334
+ size?: number;
1335
+ margin?: number;
1336
+ darkColor?: string;
1337
+ lightColor?: string;
1338
+ }): string;
1339
+
1340
+ /**
1341
+ * Format Date to ISO 8601 string (Bacen format).
1342
+ */
1343
+ declare function toISOString(date: Date): string;
1344
+ /**
1345
+ * Create date range for list operations.
1346
+ * @param startDaysAgo Number of days in the past for the start date (default: 30)
1347
+ */
1348
+ declare function createDateRange(startDaysAgo?: number): {
1349
+ inicio: string;
1350
+ fim: string;
1351
+ };
1352
+ /**
1353
+ * Parse ISO date string to Date.
1354
+ * Throws if the string is not a valid date.
1355
+ */
1356
+ declare function parseDate(isoString: string): Date;
1357
+ /**
1358
+ * Format date as YYYY-MM-DD (for cobv vencimento).
1359
+ */
1360
+ declare function formatDateOnly(date: Date): string;
1361
+
1362
+ declare const SICREDI_URLS: {
1363
+ readonly production: "https://api-pix.sicredi.com.br";
1364
+ readonly sandbox: "https://api-pix-h.sicredi.com.br";
1365
+ };
1366
+ declare const SICREDI_ISPB = "01181521";
1367
+
1368
+ interface WebhookParseResult {
1369
+ valid: boolean;
1370
+ payload?: WebhookCallbackPayload;
1371
+ error?: string;
1372
+ }
1373
+ /**
1374
+ * Parse a webhook callback body from Sicredi/Bacen.
1375
+ * Works with both string and object inputs (for Express/Koa/Bun).
1376
+ *
1377
+ * IMPORTANT: Sicredi appends '/pix' to your configured webhook URL.
1378
+ * If you configure 'https://example.com/webhook', callbacks will be
1379
+ * sent to 'https://example.com/webhook/pix'.
1380
+ * Make sure your server handles the '/pix' suffix route.
1381
+ */
1382
+ declare function parseWebhookPayload(body: string | object): WebhookParseResult;
1383
+
1384
+ export { type Abatimento, type BacenErrorResponse, type CachedToken, type Calendario, type CalendarioVencimento, type CertificateOptions, type CobResponse, type CobStatus, type CobvResponse, type CobvStatus, type ComponentesValor, type CreateCobRequest, type CreateCobvRequest, type CreateLocRequest, type Desconto, type DescontoDataFixa, type Devedor, type DevedorCnpj, type DevedorCpf, type Devolucao, type DevolucaoNatureza, type DevolucaoRequest, type DevolucaoResponse, type DevolucaoSolicitadaNatureza, type DevolucaoStatus, type InfoAdicional, type Juros, type ListCobParams, type ListCobResponse, type ListCobvParams, type ListCobvResponse, type ListLocParams, type ListLocResponse, type ListLoteCobvParams, type ListLoteCobvResponse, type ListPixParams, type ListPixResponse, type ListWebhookParams, type ListWebhookResponse, type Loc, type LocCompleta, type LocResponse, type LoteCobvCobSolicitado, type LoteCobvItemStatus, type LoteCobvPatchRequest, type LoteCobvRequest, type LoteCobvResponse, type Multa, type Pagador, type PagadorCnpj, type PagadorCpf, type Paginacao, type PaginacaoParams, type PixKeyType, type PixPayment, type PixRecebido, type Recebedor, SICREDI_ISPB, SICREDI_URLS, type SaqueTroco, Sicredi, SicrediApiError, SicrediAuthError, SicrediCertificateError, type SicrediConfig, SicrediConnectionError, SicrediError, SicrediValidationError, type TokenResponse, type UpdateCobRequest, type UpdateCobvRequest, type Valor, type ValorCobv, type ValorComDesconto, type Violacao, type WebhookCallbackPayload, type WebhookConfigRequest, type WebhookDevolucao, type WebhookParseResult, type WebhookPixEntry, type WebhookResponse, createDateRange, detectPixKeyType, formatDateOnly, generateQrCodeDataUrl, generateQrCodeSvg, generateTxId, isDevedorCnpj, isDevedorCpf, isPagadorCnpj, isPagadorCpf, isValidCnpj, isValidCpf, isValidMonetaryValue, isValidPixKey, isValidTxId, parseDate, parseWebhookPayload, toISOString };