1.0.5 • Published 8 months ago

asaas v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

Unofficial Asaas Payment Gateway SDK

❗SDK and documentation under development.

A simple sdk made to abstract most of the Asaas payment gateway api requests.

last update: 01/09/2023 Items updated:

  • Documentation URL (Developer Center)
  • new API URL
  • Subscriptions
  • Starting API Tests with Jest

Author

Reference

SDK Documentation

Get Start

Import the package and instantitate a new Client:

import { AsaasClient } from 'asaas';

const asaas = new AsaasClient(process.env.ASAAS_API_KEY);

Authentication

Every request to the Asaas API needs an API Key, which must be passed as the first parameter in the constructor. To obtain your API Key, access the Integration Tab in the Account Settings area.

Optionally you can set base url, enable sandbox mode and set sandbox mode base url.

import { AsaasClient } from 'asaas';

//Instantiate a new client
const asaas = new AsaasClient(process.env.ASAAS_API_KEY, {
  //baseUrl?: string (default: https://api.asaas.com/v3);
  //sandbox?: boolean;
  //sandboxUrl?: string (default: https://sandbox.asaas.com/api/v3);
});

Sandbox Mode

To enable Sandbox Mode, pass to the client's constructor, as the second parameter, an object with sandbox information as true. The default sandbox URL is https://sandbox.asaas.com/api/v3

import { AsaasClient } from 'asaas';

const asaas = new AsaasClient(process.env.ASAAS_API_KEY, {
  sandbox: true;
  //sandboxUrl?: string (default: https://sandbox.asaas.com/api/v3);
  //baseUrl?: string (default: https://api.asaas.com/v3);
});

Customers

Return all customers

Returns customers. Filters can be applied, passing an object with the items allowed in the official documentation.

import { AsaasClient } from 'asaas';

const asaas = new AsaasClient(process.env.ASAAS_API_KEY, {
  // sandbox: boolean;
  //sandboxUrl?: string (default: https://sandbox.asaas.com/api/v3);
  //baseUrl?: string (default: https://api.asaas.com/v3);
});

//It lists all registered customers and makes a filter by email.
await asaas.customers.list({
  email: "email@email.com"
});
ParameterTypeDescription
namestringFilter by Name.
emailstringFilter by Email.
cpfCnpjstringFilter by CPF or CNPJ.
groupNamestringFilter by Group.
externalReferencestringFilter by External Reference.
offsetnumberOffset of search.
limitnumberLimit of results.

Return customer by ID

import { AsaasClient } from 'asaas';

const asaas = new AsaasClient(process.env.ASAAS_API_KEY, {
  // sandbox: boolean;
  //sandboxUrl?: string (default: https://sandbox.asaas.com/api/v3);
  //baseUrl?: string (default: https://api.asaas.com/v3);
});

//It returns a customer by ID.
await asaas.customers.getById("cus_123abcde456");
ParameterTypeDescription
idstringRequired. Customer ID

Payments

Return all payments

Returns payments. Filters can be applied, passing an object with the items allowed in the official documentation.

import { AsaasClient } from 'asaas';

const asaas = new AsaasClient(process.env.ASAAS_API_KEY, {
  // sandbox: boolean;
  //sandboxUrl?: string (default: https://sandbox.asaas.com/api/v3);
  //baseUrl?: string (default: https://api.asaas.com/v3);
});

//It lists all registered payments and makes a filter by customer ID.
await asaas.payments.list({
  customer: "cus_123abcde456"
});
ParameterTypeDescription
customerstringFilter by Customer ID.
customerGroupNamestringFilter by Customer group name.
billingTypestringFilter by Billing Type.
statusstringFilter by Status.
subscriptionstringFilter by Subscription ID.
installmentstringFilter by Installment ID.
externalReferencestringFilter by External Reference.
paymentDatestringFilter by Payment Date.
estimatedCreditDatestringFilter by Estimated Credit Date.
pixQrCodeIdstringFilter by Static Pix QR Code ID.
anticipatedbooleanFilter by Antecipated status.
"dateCreated[ge]"stringFilter by Initial Date Created.
"dateCreated[le]"stringFilter by End Date Created.
"paymentDate[ge]"stringFilter by Initial Payment Date.
"paymentDate[le]"stringFilter by End Payment Date.
"estimatedCreditDate[ge]"stringFilter by Initial Estimated Credit Date.
"estimatedCreditDate[le]"stringFilter by End Estimated Credit Date.
"dueDate[ge]"stringFilter by Initial Due Date.
"dueDate[le]"stringFilter by End Due Date.
userstringFilter by the Email address of the user who created the charge.
offsetnumberOffset of search.
limitnumberLimit of results.

Return payment by ID

import { AsaasClient } from 'asaas';

const asaas = new AsaasClient(process.env.ASAAS_API_KEY, {
  // sandbox: boolean;
  //sandboxUrl?: string (default: https://sandbox.asaas.com/api/v3);
  //baseUrl?: string (default: https://api.asaas.com/v3);
});

//It returns a payment object by ID.
await asaas.payments.getById("pay_0802152313252");
ParameterTypeDescription
idstringRequired. Payment ID

Subscriptions

Return all subscriptions

Returns subscriptions. Filters can be applied, passing an object with the items allowed in the official documentation.

import { AsaasClient } from 'asaas';

const asaas = new AsaasClient(process.env.ASAAS_API_KEY, {
  // sandbox: boolean;
  //sandboxUrl?: string (default: https://sandbox.asaas.com/api/v3);
  //baseUrl?: string (default: https://api.asaas.com/v3);
});

//List subscriptions for a specific customer ID.
await asaas.subscriptions.list({
  customer: "cus_123abcde456"
});

Contributing

Do you want to contribute? Found a bug? Feel free :)

1.0.5

8 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

1 year ago