Unofficial TypeScript SDK for the Asaas payment gateway API with domain-based architecture.
⚠️ Note: This is an unofficial SDK and is not affiliated with or endorsed by Asaas.
- ✅ Full TypeScript support with comprehensive type definitions
- 🏗️ Domain-based architecture (
client.domain.method()) - 🔒 Type-safe API with IntelliSense support
- 🚀 Built with modern tools (Bun, TypeScript, ESLint)
- 📦 Zero dependencies (except axios)
- 🌍 Support for both production and sandbox environments
# Using bun
bun add @gusnips/asaas
# Using npm
npm install @gusnips/asaas
# Using yarn
yarn add @gusnips/asaasimport { AsaasClient } from "@gusnips/asaas";
// Initialize the client
const client = new AsaasClient({
apiKey: "your-api-key-here",
environment: "production", // or 'sandbox'
});
// Create a customer
const customer = await client.customers.create({
name: "John Doe",
email: "john@example.com",
cpfCnpj: "12345678901",
});
// Create a subscription
const subscription = await client.subscriptions.create({
customer: customer.id,
billingType: "CREDIT_CARD",
value: 99.9,
cycle: "MONTHLY",
nextDueDate: "2025-11-01",
});const client = new AsaasClient({
apiKey: string; // Your Asaas API key
environment?: 'production' | 'sandbox'; // Default: 'production'
});Manage customer information.
Create a new customer.
const customer = await client.customers.create({
name: "John Doe",
email: "john@example.com",
cpfCnpj: "12345678901",
phone: "1234567890",
mobilePhone: "11987654321",
postalCode: "12345-678",
addressNumber: "123",
});Parameters:
name(string, required): Customer nameemail(string, required): Customer emailcpfCnpj(string, optional): Customer CPF or CNPJphone(string, optional): Phone numbermobilePhone(string, optional): Mobile phone numberpostalCode(string, optional): Postal codeaddressNumber(string, optional): Address number- Additional fields available in
AsaasCustomertype
Returns: Promise<AsaasCustomer>
Retrieve a customer by ID.
const customer = await client.customers.retrieve("cus_123456");Parameters:
customerId(string, required): Customer ID
Returns: Promise<AsaasCustomer>
Update customer information.
const customer = await client.customers.update("cus_123456", {
name: "Jane Doe",
email: "jane@example.com",
});Parameters:
customerId(string, required): Customer IDdata(object, required): Customer data to update
Returns: Promise<AsaasCustomer>
List customers.
const customers = await client.customers.list(100, 0);Parameters:
limit(number, optional): Maximum number of results (default: 100)offset(number, optional): Pagination offset (default: 0)
Returns: Promise<AsaasCustomer[]>
Manage recurring subscriptions.
Create a new subscription.
const subscription = await client.subscriptions.create({
customer: "cus_123456",
billingType: "CREDIT_CARD",
value: 99.9,
cycle: "MONTHLY",
nextDueDate: "2025-11-01",
description: "Monthly subscription",
});Parameters:
customer(string, required): Customer IDbillingType(string, required): Payment method (BOLETO,CREDIT_CARD,PIX, etc.)value(number, required): Subscription valuecycle(string, required): Billing cycle (WEEKLY,MONTHLY,YEARLY, etc.)nextDueDate(string, required): Next payment due date (YYYY-MM-DD)description(string, optional): Subscription description- Additional fields available in
AsaasSubscriptiontype
Returns: Promise<AsaasSubscription>
Retrieve a subscription by ID.
const subscription = await client.subscriptions.retrieve("sub_123456");Parameters:
subscriptionId(string, required): Subscription ID
Returns: Promise<AsaasSubscription>
List subscriptions for a customer (or all subscriptions if no customer specified).
// List for specific customer
const subscriptions = await client.subscriptions.list("cus_123456", "ACTIVE");
// List all subscriptions
const allSubscriptions = await client.subscriptions.list();Parameters:
customerId(string, optional): Customer ID to filter bystatus(string, optional): Filter by status (ACTIVE,INACTIVE)
Returns: Promise<AsaasSubscription[]>
Update a subscription.
const subscription = await client.subscriptions.update("sub_123456", {
value: 149.9,
nextDueDate: "2025-12-01",
});Parameters:
subscriptionId(string, required): Subscription IDdata(object, required): Subscription data to update
Returns: Promise<AsaasSubscription>
Reactivate a canceled subscription.
const subscription = await client.subscriptions.reactivate("sub_123456");Parameters:
subscriptionId(string, required): Subscription IDdata(object, optional): Additional subscription data
Returns: Promise<AsaasSubscription>
Cancel a subscription.
const subscription = await client.subscriptions.cancel("sub_123456");Parameters:
subscriptionId(string, required): Subscription ID
Returns: Promise<AsaasSubscription>
Manage individual payments and invoices.
Create a new payment.
const payment = await client.payments.create({
customer: "cus_123456",
billingType: "BOLETO",
value: 199.9,
dueDate: "2025-11-15",
description: "One-time payment",
});Parameters:
customer(string, required): Customer IDbillingType(string, required): Payment methodvalue(number, required): Payment valuedueDate(string, required): Payment due date (YYYY-MM-DD)description(string, optional): Payment description- Additional fields available in
AsaasPaymenttype
Returns: Promise<AsaasPayment>
Retrieve a payment by ID.
const payment = await client.payments.retrieve("pay_123456");Parameters:
paymentId(string, required): Payment ID
Returns: Promise<AsaasPayment>
Update a payment.
const payment = await client.payments.update("pay_123456", {
value: 249.9,
dueDate: "2025-12-15",
});Parameters:
paymentId(string, required): Payment IDdata(object, required): Payment data to update
Returns: Promise<AsaasPayment>
List payments for a customer.
const payments = await client.payments.list("cus_123456", {
status: "PENDING",
limit: 10,
offset: 0,
});Parameters:
customerId(string, required): Customer IDoptions(object, optional): Filter optionsstatus(string): Filter by statuslimit(number): Maximum number of resultsoffset(number): Pagination offset- Additional options in
AsaasListPaymentsOptionstype
Returns: Promise<AsaasPayment[]>
Get the latest payment for a customer.
const payment = await client.payments.getLatest("cus_123456");Parameters:
customerId(string, required): Customer ID
Returns: Promise<AsaasPayment | null>
Get all overdue payments for a customer.
const overduePayments = await client.payments.getOverdue("cus_123456", 100, 0);Parameters:
customerId(string, required): Customer IDlimit(number, optional): Maximum number of results (default: 100)offset(number, optional): Pagination offset (default: 0)
Returns: Promise<AsaasPayment[]>
Get billing information for a payment.
const billingInfo = await client.payments.getBillingInfo("pay_123456");Parameters:
paymentId(string, required): Payment ID
Returns: Promise<AsaasPaymentBillingInfo>
Get boleto information for a payment.
const boleto = await client.payments.getBoleto("pay_123456");
// Returns: { barCode, identificationField, nossoNumero }Parameters:
paymentId(string, required): Payment ID
Returns: Promise<AsaasBoletoInfo>
Get PIX QR code for a payment.
const pixQrCode = await client.payments.getPixQrCode("pay_123456");
// Returns: { encodedImage, payload, expirationDate }Parameters:
paymentId(string, required): Payment ID
Returns: Promise<AsaasPixQrCode>
Tokenize a credit card for future use.
const token = await client.payments.tokenizeCreditCard({
customer: "cus_123456",
creditCard: {
holderName: "John Doe",
number: "4111111111111111",
expiryMonth: "12",
expiryYear: "2028",
ccv: "123",
},
creditCardHolderInfo: {
name: "John Doe",
email: "john@example.com",
cpfCnpj: "12345678901",
postalCode: "12345-678",
addressNumber: "123",
},
remoteIp: "192.168.1.1",
});Parameters:
data(object, required): Credit card tokenization data (seeAsaasCreditCardTokenizationRequest)
Returns: Promise<AsaasCreditCardToken>
Create a payment link.
const paymentLink = await client.payments.createPaymentLink({
name: "Product Payment",
chargeType: "DETACHED",
billingType: "CREDIT_CARD",
value: 99.9,
});Parameters:
data(object, required): Payment link data
Returns: Promise<any>
client.payments.createProrated(customerId, subscriptionId, amount, description, paymentMethod, externalReference?)
Create a prorated payment.
const payment = await client.payments.createProrated(
"cus_123456",
"sub_123456",
5000, // Amount in cents
"Prorated payment for plan upgrade",
{ type: "CREDIT_CARD", creditCardToken: "tok_123456" }
);Parameters:
customerId(string, required): Customer IDsubscriptionId(string, required): Subscription IDamount(number, required): Amount in centsdescription(string, required): Payment descriptionpaymentMethod(object, required): Payment method configurationexternalReference(string, optional): External reference ID
Returns: Promise<AsaasPayment>
Cancel a payment.
const payment = await client.payments.cancel("pay_123456");Parameters:
paymentId(string, required): Payment ID
Returns: Promise<AsaasPayment>
Cancel all open invoices for a customer.
const canceledIds = await client.payments.cancelOpenInvoices(
"cus_123456",
"pay_exclude"
);Parameters:
customerId(string, required): Customer IDexcludePaymentId(string, optional): Payment ID to exclude from cancellation
Returns: Promise<string[]> - Array of canceled payment IDs
List all overdue payments (not filtered by customer).
const overduePayments = await client.payments.listAllOverdue(100, 0);Parameters:
limit(number, optional): Maximum number of results (default: 100)offset(number, optional): Pagination offset (default: 0)
Returns: Promise<AsaasPayment[]>
Manage sub-accounts, wallets, and commercial information.
Create a sub-account.
const subAccount = await client.accounts.createSubAccount({
name: "Partner Store",
email: "partner@store.com",
cpfCnpj: "12345678000199",
companyType: "LIMITED",
mobilePhone: "11987654321",
address: "Main Street",
addressNumber: "123",
province: "Downtown",
postalCode: "12345-678",
incomeValue: 10000,
});Parameters:
data(object, required): Sub-account data (seeAsaasSubAccountRequest)
Returns: Promise<AsaasSubAccount>
Retrieve a sub-account by ID.
const subAccount = await client.accounts.retrieveSubAccount("acc_123456");Parameters:
subAccountId(string, required): Sub-account ID
Returns: Promise<AsaasSubAccount>
Update a sub-account.
const subAccount = await client.accounts.updateSubAccount("acc_123456", {
name: "Updated Store Name",
mobilePhone: "11999999999",
});Parameters:
subAccountId(string, required): Sub-account IDdata(object, required): Sub-account data to update
Returns: Promise<AsaasSubAccount>
List all sub-accounts.
const subAccounts = await client.accounts.listSubAccounts({
limit: 10,
offset: 0,
});Parameters:
options(object, optional): Pagination optionslimit(number): Maximum number of resultsoffset(number): Pagination offset
Returns: Promise<AsaasSubAccount[]>
Get wallets for the account.
const wallets = await client.accounts.getWallets();Returns: Promise<AsaasWalletsResponse>
Get commercial information for the account.
const commercialInfo = await client.accounts.getCommercialInfo();Returns: Promise<AsaasCommercialInfo>
The SDK provides comprehensive TypeScript type definitions for all API entities:
AsaasBillingType- Payment method typesAsaasDiscountType- Discount typesAsaasEnvironment- Environment typesAsaasApiError- Error classAsaasApiPaginatedResponse<T>- Paginated response wrapper
AsaasCustomer- Customer entity
AsaasSubscription- Subscription entityAsaasSubscriptionCycle- Billing cyclesAsaasSubscriptionStatus- Subscription statusesAsaasSubscriptionRequest- Create/update requestAsaasSplit- Split configuration
AsaasPayment- Payment entityAsaasPaymentStatus- Payment statusesAsaasPaymentBillingInfo- Billing informationAsaasPixQrCode- PIX QR code dataAsaasBoletoInfo- Boleto informationAsaasCreditCardToken- Tokenized credit cardAsaasListPaymentsOptions- Payment list filters
AsaasSubAccount- Sub-account entityAsaasSubAccountRequest- Sub-account creationAsaasWalletsResponse- Wallet informationAsaasCommercialInfo- Commercial informationAsaasPersonType- Person typesAsaasCompanyType- Company types
The SDK throws AsaasApiError for API errors:
import { AsaasApiError } from "@gusnips/asaas";
try {
const customer = await client.customers.create({
name: "John Doe",
email: "invalid-email",
});
} catch (error) {
if (error instanceof AsaasApiError) {
console.error("Status:", error.status);
console.error("Message:", error.message);
console.error("Errors:", error.errors);
}
}# Install dependencies
bun install
# Run type checking
bun run typecheck
# Run linter
bun run lint
# Build the package
bun run buildsrc/
├── client.ts # Main client class
├── index.ts # Main export file
├── modules/ # Domain modules
│ ├── customers.ts
│ ├── subscriptions.ts
│ ├── payments.ts
│ └── accounts.ts
├── types/ # Type definitions
│ ├── common.ts
│ ├── customer.ts
│ ├── subscription.ts
│ ├── payment.ts
│ ├── account.ts
│ └── index.ts
└── utils/ # Utilities
└── client.ts # HTTP client configuration
Contributions are welcome! Please follow these guidelines:
- Follow the existing code style
- Use DRY principles
- Create modular, reusable, and maintainable code
- Reuse existing patterns
- Never change code unrelated to the task
- Add tests for new features
MIT