@jackiemacklein/nettz-utils
Version:
Serviços de imagem, e-mail, códigos de barras, utilitários numéricos e componentes React para apps Node.js com TypeScript
194 lines (193 loc) • 5.63 kB
TypeScript
/**
* @author Jackiê Macklein
* @company Onside tecnologia/Nettz
* @copyright Todos direitos reservados.
* @description Tipos para integração com API do Asaas.
* Referência: https://docs.asaas.com/
*/
/** Sandbox: https://sandbox.asaas.com/api */
export declare const ASAAS_DEFAULT_BASE_URL = "https://sandbox.asaas.com/api";
/** Produção: https://api.asaas.com */
export declare const ASAAS_PRODUCTION_BASE_URL = "https://api.asaas.com";
export declare const AsaasBillingType: {
readonly BOLETO: "BOLETO";
readonly PIX: "PIX";
readonly CREDIT_CARD: "CREDIT_CARD";
};
export type AsaasBillingTypeCode = (typeof AsaasBillingType)[keyof typeof AsaasBillingType];
export declare const AsaasChargeStatus: {
readonly PENDING: "PENDING";
readonly RECEIVED: "RECEIVED";
readonly CONFIRMED: "CONFIRMED";
readonly RECEIVED_IN_CASH: "RECEIVED_IN_CASH";
readonly OVERDUE: "OVERDUE";
readonly REFUNDED: "REFUNDED";
};
export type AsaasChargeStatusCode = (typeof AsaasChargeStatus)[keyof typeof AsaasChargeStatus];
export interface AsaasClientConfig {
/** Chave de API do Asaas (`access_token`). */
apiKey: string;
/**
* Base da API, sem versão e sem barra final.
* @default https://sandbox.asaas.com/api
*/
baseUrl?: string;
/** Versão da API. @default v3 */
apiVersion?: string;
/** Timeout em ms para cada requisição HTTP. @default 30000 */
timeoutMs?: number;
/** `fetch` customizado (testes ou proxy). */
fetchImpl?: typeof fetch;
/**
* Se `true`, emite logs em `console` com prefixo `[Asaas]` (sem API key ou dados sensíveis).
* @default false
*/
debug?: boolean;
}
export interface AsaasCreditCardInput {
number: string;
expiry: string;
name: string;
cvc: string;
}
export interface AsaasCustomerInput {
id?: number;
name?: string;
email?: string;
cpf_cnpj?: string;
phone?: string;
cell_phone?: string;
birth_date?: string;
zipcode?: string;
number?: string;
}
export interface AsaasChargeInput {
id?: number;
/** Identificador livre enviado ao Asaas (`externalReference`), ex.: id da sessão do totem. */
external_reference?: string;
description?: string;
/** Valor em centavos. */
value?: number;
due_date?: string;
customer_provider_id?: string;
billing_type?: "BILLET" | "PIX" | "CREDIT_CARD";
credit_card?: AsaasCreditCardInput;
customer?: AsaasCustomerInput;
}
export interface AsaasCustomerNormalized {
id: string;
}
export interface AsaasChargeNormalized {
provider_id: string;
status: AsaasChargeStatusCode;
pix?: {
image_base64: string;
payload: string;
expiration_at: string | Date;
};
billet?: {
barcode: string;
number: string;
identification_field: string;
url: string;
};
credit_card?: {
number: string;
brand: string;
};
/** Valor líquido em centavos. */
net_value?: number;
paid_type?: string;
paid_date?: string;
}
export interface AsaasWebhookInput {
url: string;
email: string;
apiVersion: number;
enabled: boolean;
interrupted: boolean;
authToken?: string;
}
export type AsaasValidationKind = "CREATE-CUSTOMER" | "EDIT-CUSTOMER" | "CREATE-CHARGE" | "EDIT-CHARGE";
/** Payload enviado à API Asaas para clientes. */
export interface AsaasApiCustomerPayload {
name?: string;
cpfCnpj?: string;
email?: string;
mobilePhone?: string;
externalReference?: number;
postalCode?: string;
addressNumber?: string;
}
/** Payload enviado à API Asaas para cobranças. */
export interface AsaasApiChargePayload {
externalReference?: string | number;
customer?: string;
value?: number;
description?: string;
dueDate?: string;
billingType?: AsaasBillingTypeCode | string;
creditCard?: {
ccv?: string;
expiryMonth?: string;
expiryYear?: string;
holderName?: string;
number?: string;
};
creditCardHolderInfo?: {
name?: string;
cpfCnpj?: string;
email?: string;
postalCode?: string;
mobilePhone?: string;
addressNumber?: string;
};
}
export interface AsaasApiErrorItem {
code?: string;
description?: string;
}
export interface AsaasGetChargeOptions {
/** Busca dados complementares de PIX/boleto quando aplicável. @default true */
enrichPixBillet?: boolean;
}
/** Filtros para `GET /payments`. Referência: https://docs.asaas.com/reference/listar-cobrancas */
export interface AsaasListChargesParams {
offset?: number;
/** Máximo 100. */
limit?: number;
customer?: string;
customerGroupName?: string;
billingType?: AsaasBillingTypeCode | "UNDEFINED";
status?: AsaasChargeStatusCode | string;
subscription?: string;
installment?: string;
externalReference?: string;
paymentDate?: string;
dateCreatedGe?: string;
dateCreatedLe?: string;
paymentDateGe?: string;
paymentDateLe?: string;
dueDateGe?: string;
dueDateLe?: string;
user?: string;
checkoutSession?: string;
anticipated?: boolean;
anticipable?: boolean;
pixQrCodeId?: string;
}
export interface AsaasListChargesResponse {
object?: string;
hasMore?: boolean;
totalCount?: number;
limit?: number;
offset?: number;
data?: Record<string, unknown>[];
}
export interface AsaasListChargesResult {
hasMore: boolean;
totalCount: number;
limit: number;
offset: number;
charges: AsaasChargeNormalized[];
}