UNPKG

asaasjs

Version:

An AsaasJS SDK for NodeJS

485 lines (481 loc) 14.3 kB
/** * Default class for Asaas exceptions and errors. * * It can be serialized to JSON through the `toJSON` method. */ declare class AsaasError extends Error { constructor(message: string); toJSON(): { name: string; message: string; }; } type PaginationResponse<T> = { object: string; hasMore: boolean; totalCount: number; limit: number; offset: number; data: T[]; }; type ICustomer = { object: "customer"; id: `cus_${string}`; dateCreated: string; name: string; email: string | null; company: string | null; phone: string | null; mobilePhone: string | null; address: string | null; addressNumber: number | null; complement: string | null; province: string | null; postalCode: string | null; cpfCnpj: string; personType: "FISICA" | "JURIDICA"; deleted: boolean; additionalEmails: string | null; externalReference: string | null; notificationDisabled: boolean; observations: string | null; municipalInscription: string | null; stateInscription: string | null; canDelete: boolean; cannotBeDeletedReason: string | null; canEdit: boolean; cannotEditReason: string | null; city: string | null; cityName: string | null; state: string | null; country: string; }; type ListCustomersData = { name?: string; cpfCnpj?: string; groupName?: string; externalReference?: string; email?: string; offset?: number; limit?: number; }; type ListCustomersResponse = { data: PaginationResponse<ICustomer>; errors: null; } | { data: null; errors: { code: string; description: string; }[]; }; type CreateCustomerData = { name: string; cpfCnpj: string; email?: string | null; phone?: string | null; mobilePhone?: string | null; address?: string | null; addressNumber?: string | null; complement?: string | null; province?: string | null; postalCode?: string | null; externalReference?: string | null; notificationDisabled?: boolean; additionalEmails?: string | null; municipalInscription?: string | null; stateInscription?: string | null; observations?: string | null; groupName?: string | null; company?: string | null; foreingCustomer?: boolean; }; type CreateCustomerResponse = { data: ICustomer; errors: null; } | { data: null; errors: { code: string; description: string; }[]; }; type BillingTypes = "UNDEFINED" | "BOLETO" | "CREDIT_CARD" | "DEBIT_CARD" | "TRANSFER" | "DEPOSIT" | "PIX"; type DiscountType = "PERCENTAGE" | "FIXED"; type FineType = "PERCENTAGE" | "FIXED"; type CreditCardBrand = "VISA" | "MASTERCARD" | "ELO" | "DINERS" | "DISCOVER" | "AMEX" | "HIPERCARD" | "CABAL" | "BANESCARD" | "CREDZ" | "SOROCRED" | "CREDSYSTEM" | "JCB" | "UNKNOWN"; type DisputeStatus = "REQUESTED" | "ACCEPTED" | "REJECTED"; type ChargebackStatus = "REQUESTED" | "IN_DISPUTE" | "DISPUTE_LOST" | "REVERSED" | "DONE"; type PaymentStatus = "PENDING" | "RECEIVED" | "CONFIRMED" | "OVERDUE" | "REFUNDED" | "RECEIVED_IN_CASH" | "REFUND_REQUESTED" | "REFUND_IN_PROGRESS" | "CHARGEBACK_REQUESTED" | "CHARGEBACK_DISPUTE" | "AWAITING_CHARGEBACK_REVERSAL" | "DUNNING_REQUESTED" | "DUNNING_RECEIVED" | "AWAITING_RISK_ANALYSIS"; type SplitCancelationReason = "PAYMENT_DELETED" | "PAYMENT_OVERDUE" | "PAYMENT_RECEIVED_IN_CASH" | "PAYMENT_REFUNDED" | "VALUE_DIVERGENCE_BLOCK" | "WALLET_UNABLE_TO_RECEIVE"; type SplitStatus = "PENDING" | "AWAITING_CREDIT" | "CANCELLED" | "DONE" | "REFUNDED" | "BLOCKED_BY_VALUE_DIVERGENCE"; type ChargebackReason = "ABSENCE_OF_PRINT" | "ABSENT_CARD_FRAUD" | "CARD_ACTIVATED_PHONE_TRANSACTION" | "CARD_FRAUD" | "CARD_RECOVERY_BULLETIN" | "COMMERCIAL_DISAGREEMENT" | "COPY_NOT_RECEIVED" | "CREDIT_OR_DEBIT_PRESENTATION_ERROR" | "DIFFERENT_PAY_METHOD" | "FRAUD" | "INCORRECT_TRANSACTION_VALUE" | "INVALID_CURRENCY" | "INVALID_DATA" | "LATE_PRESENTATION" | "LOCAL_REGULATORY_OR_LEGAL_DISPUTE" | "MULTIPLE_ROCS" | "ORIGINAL_CREDIT_TRANSACTION_NOT_ACCEPTED" | "OTHER_ABSENT_CARD_FRAUD" | "PROCESS_ERROR" | "RECEIVED_COPY_ILLEGIBLE_OR_INCOMPLETE" | "RECURRENCE_CANCELED" | "REQUIRED_AUTHORIZATION_NOT_GRANTED" | "RIGHT_OF_FULL_RECOURSE_FOR_FRAUD" | "SALE_CANCELED" | "SERVICE_DISAGREEMENT_OR_DEFECTIVE_PRODUCT" | "SERVICE_NOT_RECEIVED" | "SPLIT_SALE" | "TRANSFERS_OF_DIVERSE_RESPONSIBILITIES" | "UNQUALIFIED_CAR_RENTAL_DEBIT" | "USA_CARDHOLDER_DISPUTE" | "VISA_FRAUD_MONITORING_PROGRAM" | "WARNING_BULLETIN_FILE"; type EscrowFinishReason = "CHARGEBACK" | "EXPIRED" | "INSUFFICIENT_BALANCE" | "PAYMENT_REFUNDED" | "REQUESTED_BY_CUSTOMER" | "CUSTOMER_CONFIG_DISABLED"; type RefundStatus = "PENDING" | "AWAITING_CRITICAL_ACTION_AUTHORIZATION" | "AWAITING_CUSTOMER_EXTERNAL_AUTHORIZATION" | "CANCELLED" | "DONE"; type IPayment = { id: string; dateCreated: string; customer: string; value: number; netValue: number; status: PaymentStatus; dueDate: string; subscription?: string; installment?: string; checkoutSession?: string; paymentLink?: string; originalValue?: number; interestValue?: number; description?: string; billingType?: BillingTypes; creditCard?: { creditCardNumber?: string; creditCardBrand?: CreditCardBrand; creditCardToken?: string; disputeStatus?: DisputeStatus; deadlineToSendDisputeDocuments?: string; }; canBePaidAfterDueDate?: boolean; pixTransaction?: string; pixQrCodeId?: string; originalDueDate?: string; paymentDate?: string; clientPaymentDate?: string; installmentNumber?: number; invoiceUrl?: string; invoiceNumber?: string; externalReference?: string; deleted?: boolean; anticipated?: boolean; anticipable?: boolean; creditDate?: string; estimatedCreditDate?: string; transactionReceiptUrl?: string; nossoNumero?: string; bankSlipUrl?: string; discount?: { value: number; dueDateLimitDays: number; type: DiscountType; }; fine?: { value: number; }; interest?: { value: number; }; split?: { id: string; walletId: string; fixedValue?: number; percentualValue?: number; totalValue?: number; cancellationReason?: SplitCancelationReason; status: SplitStatus; externalReference?: string; description?: string; }[]; postalService?: boolean; daysAfterDueDateToRegistrationCancellation?: number; chargeback?: { id: string; payment: string; installment?: string; customerAccount: string; status: ChargebackStatus; reason: ChargebackReason; disputeStartDate: string; value: number; paymentDate: string; }; escrow?: { id: string; status: "ACTIVE" | "DONE"; expirationDate: string; finishDate?: string; finishReason?: EscrowFinishReason; }; refunds?: { dateCreated: string; status: RefundStatus; value: number; endToEndIdentifier?: string; description?: string; effectiveDate?: string; transactionReceiptUrl?: string; refundedSplits?: { id: string; value: number; done: boolean; }[]; }[]; }; type CreatePaymentWithoutCreditCardData = { customer: string; billingType: BillingTypes; value: number; /** * Data de vencimento no formato YYYY-MM-DD */ dueDate: string; description?: string; daysAfterDueDateToRegistrationCancellation?: number; externalReference?: string; intallmentCount?: number; totalValue?: number; intallmentValue?: number; discount?: { value?: number; dueDateLimitDays?: number; type?: DiscountType; }; interest?: { value?: number; }; fine?: { value?: number; type?: FineType; }; postalService?: boolean; split?: { walletId: string; fixedValue?: number; percentualValue?: number; totalFixedValue?: number; externalReference?: string; description?: string; }[]; callback?: { successUrl?: string; autoRedirect?: boolean; }; }; type CreatePaymentData = CreatePaymentWithoutCreditCardData; type CreatePaymentResponse = { data: IPayment; errors: null; } | { data: null; errors: { code: string; description: string; }[]; }; type CreatePaymentWithCreditCardBase = { customer: string; billingType: "CREDIT_CARD"; /** * Data de vencimento no formato YYYY-MM-DD */ dueDate: string; description?: string; daysAfterDueDateToRegistrationCancellation?: number; externalReference?: string; discount?: { value?: number; dueDateLimitDays?: number; type?: DiscountType; }; interest?: { value?: number; }; fine?: { value?: number; type?: FineType; }; postalService?: boolean; split?: { walletId: string; fixedValue?: number; percentualValue?: number; totalFixedValue?: number; externalReference?: string; description?: string; }[]; callback?: { successUrl?: string; autoRedirect?: boolean; }; creditCard: { holderName: string; number: string; /** * Mês de expiração com dos digitos */ expiryMonth: string; expiryYear: string; ccv: string; }; creditCardHolderInfo: { name: string; email: string; cpfCnpj: string; postalCode: string; addressNumber: string; addressComplement?: string; phone: string; mobilePhone?: string; }; creditCardToken?: string; authorizeOnly?: boolean; remoteIp?: string; }; type CreatePaymentWithCreditCardData = CreatePaymentWithCreditCardBase & ({ value: number; } | ({ installmentCount: number; installmentValue: number; } | { installmentCount: number; totalValue: number; })); type CreatePaymentWithCreditCardResponse = { data: IPayment; errors: null; } | { data: null; errors: { code: string; description: string; }[]; }; type ShowPaymentResponse = { data: IPayment; errors: null; } | { data: null; errors: { code: string; description: string; }[]; }; type IIDentificationField = { identificationField: string; nossoNumero: string; barCode: string; }; type ShowIdentificationFieldResponse = { data: IIDentificationField; errors: null; } | { data: null; errors: { code: string; description: string; }[]; }; type IPixQrCode = { encodedImage: string; payload: string; expirationDate: string; }; type ShowPixQrCodeResponse = { data: IPixQrCode; errors: null; } | { data: null; errors: { code: string; description: string; }[]; }; declare function asaasjs({ apiKey, sandbox, }: { sandbox?: boolean; apiKey: string; }): { /** * Gerencie seus clientes. */ customers: { /** * Permite que você recupere uma lista dos clientes criados. * * @returns Lista de clientes criados ou erro * @example * ```ts * const asaasjs = asaasjs('apiKey'); * * const response = await asaasjs.customers.list(); * /* ... * / */ list(data?: ListCustomersData): Promise<ListCustomersResponse>; /** * Permite que você cadastre um novo cliente * * @returns Cliente criado ou erro * @example * ```ts * const asaasjs = asaasjs('apiKey'); * * const response = await asaasjs.customers.create(data); * /* ... * / */ create(data: CreateCustomerData): Promise<CreateCustomerResponse>; }; /** * Gerencie suas cobranças. */ payments: { /** * Permite que você crie uma nova cobrança * * @returns Cobrança criada ou erro * @example * ```ts * const asaasjs = asaasjs('apiKey'); * * const response = await asaasjs.payments.create(data); * /* ... * / */ create(data: CreatePaymentData): Promise<CreatePaymentResponse>; /** * Permite que você crie uma nova cobrança pagando com cartão de crédito * * @returns Cobrança criada ou erro * @example * ```ts * const asaasjs = asaasjs('apiKey'); * * const response = await asaasjs.payments.create(data); * /* ... * / */ createWithCreditCard(data: CreatePaymentWithCreditCardData): Promise<CreatePaymentWithCreditCardResponse>; /** * Permite que você recupere uma única cobrança * * @returns Cobrança ou erro * @example * ```ts * const asaasjs = asaasjs('apiKey'); * * const response = await asaasjs.payments.show(cobrancaId); * /* ... * / */ show(id: string): Promise<ShowPaymentResponse>; /** * Permite que você recupere a linha digitável de uma cobrança única * * @returns Linha digitável ou erro * @example * ```ts * const asaasjs = asaasjs('apiKey'); * * const response = await asaasjs.payments.showIdentificationField(cobrancaId); * /* ... * / */ showIdentificationField(id: string): Promise<ShowIdentificationFieldResponse>; /** * Permite que você recupere o QR Code Pix de uma cobrança única * * @returns QRCode ou erro * @example * ```ts * const asaasjs = asaasjs('apiKey'); * * const response = await asaasjs.payments.showPixQrCode(cobrancaId); * /* ... * / */ showPixQrCode(id: string): Promise<ShowPixQrCodeResponse>; }; }; export { AsaasError, asaasjs };