Skip to content

Commit

Permalink
Latest updates 2023-09-01
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardobernardo committed Sep 1, 2023
1 parent 6dc8240 commit 36bb297
Show file tree
Hide file tree
Showing 18 changed files with 9,921 additions and 2,495 deletions.
79 changes: 53 additions & 26 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

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

last update: 07/03/2023
last update: 01/09/2023
Items updated:
- Documentation URL (Developer Center)
- new API URL
- Subscriptions
- Starting API Tests with Jest


## Author
Expand All @@ -14,14 +19,14 @@ last update: 07/03/2023

## Reference

- [Asaas API Manual](https://asaasv3.docs.apiary.io/)
- [Asaas API Manual](https://docs.asaas.com/)

## Features
- [x] Customers [(Customers Documentation)](https://asaasv3.docs.apiary.io/#reference/0/clientes/criar-novo-cliente)
- [x] Payments [(Payments Documentation)](https://asaasv3.docs.apiary.io/#reference/0/cobrancas/criar-nova-cobranca)
- [x] Installments [(Installments Documentation)](https://asaasv3.docs.apiary.io/#reference/0/parcelamentos/recuperar-um-unico-parcelamento)
- [ ] Subscriptions (soon) [(Subscriptions Documentation)](https://asaasv3.docs.apiary.io/#reference/0/assinaturas/criar-nova-assinatura)
- [ ] Payment Links (soon) [(Payment Links Documentation)](https://asaasv3.docs.apiary.io/#reference/0/link-de-pagamentos/criar-nova-assinatura)
- [x] Customers [(Customers Documentation)](https://docs.asaas.com/reference/criar-novo-cliente)
- [x] Payments [(Payments Documentation)](https://docs.asaas.com/reference/criar-nova-cobranca)
- [x] Installments [(Installments Documentation)](https://docs.asaas.com/reference/repurar-um-unico-parcelamento)
- [x] Subscriptions [(Subscriptions Documentation)](https://docs.asaas.com/reference/criar-nova-assinatura)
- [ ] Payment Links (soon) [(Payment Links Documentation)](https://docs.asaas.com/reference/criar-um-link-de-pagamentos)


## SDK Documentation
Expand All @@ -31,7 +36,7 @@ Import the package and instantitate a new Client:
```javascript
import { AsaasClient } from 'asaas';

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

### Authentication
Expand All @@ -43,8 +48,8 @@ Optionally you can set base url, enable sandbox mode and set sandbox mode base u
import { AsaasClient } from 'asaas';

//Instantiate a new client
const client = new AsaasClient(process.env.ASAAS_API_KEY, {
//baseUrl?: string (default: https://www.asaas.com/api/v3);
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);
});
Expand All @@ -56,29 +61,29 @@ To enable Sandbox Mode, pass to the client's constructor, as the second paramete
```javascript
import { AsaasClient } from 'asaas';

const client = new AsaasClient(process.env.ASAAS_API_KEY, {
const asaas = new AsaasClient(process.env.ASAAS_API_KEY, {
sandbox: true;
//sandboxUrl?: string (default: https://sandbox.asaas.com/api/v3);
//baseUrl?: string (default: https://www.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](https://asaasv3.docs.apiary.io/#reference/0/clientes/listar-clientes).
Returns customers. Filters can be applied, passing an object with the items allowed in the [official documentation](https://docs.asaas.com/reference/listar-clientes).

```javascript
import { AsaasClient } from 'asaas';

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

//It lists all registered customers and makes a filter by email.
await client.customers.list({
await asaas.customers.list({
email: "[email protected]"
});
```
Expand All @@ -98,14 +103,14 @@ await client.customers.list({
```javascript
import { AsaasClient } from 'asaas';

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

//It returns a customer by ID.
await client.customers.getById("cus_123abcde456");
await asaas.customers.getById("cus_123abcde456");
```

| Parameter | Type | Description |
Expand All @@ -116,19 +121,19 @@ await client.customers.getById("cus_123abcde456");
### Payments

#### Return all payments
Returns payments. Filters can be applied, passing an object with the items allowed in the [official documentation](https://asaasv3.docs.apiary.io/#reference/0/cobrancas/listar-cobrancas).
Returns payments. Filters can be applied, passing an object with the items allowed in the [official documentation](https://docs.asaas.com/reference/listar-cobrancas).

```javascript
import { AsaasClient } from 'asaas';

const client = new AsaasClient(process.env.ASAAS_API_KEY, {
const asaas = new AsaasClient(process.env.ASAAS_API_KEY, {
// sandbox: boolean;
//sandboxUrl?: string (default: https://sandbox.asaas.com/api/v3);
//baseUrl?: string (default: https://www.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 client.payments.list({
await asaas.payments.list({
customer: "cus_123abcde456"
});
```
Expand Down Expand Up @@ -163,21 +168,43 @@ await client.payments.list({
```javascript
import { AsaasClient } from 'asaas';

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

//It returns a payment object by ID.
await client.payments.getById("pay_080225913252");
await asaas.payments.getById("pay_0802152313252");
```

| Parameter | Type | Description |
| :---------- | :--------- | :------------------------------------------ |
| `id` | `string` | **Required**. Payment ID |


### Subscriptions

#### Return all subscriptions
Returns subscriptions. Filters can be applied, passing an object with the items allowed in the [official documentation](https://docs.asaas.com/reference/listar-assinaturas).

```javascript
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 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {presets: ['@babel/preset-env']}
4 changes: 3 additions & 1 deletion dist/client/AsaasClient.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { AsaasOptions } from '../types/AsaasTypes';
import { CustomersAPI } from "../client/Customers";
import { CustomersAPI } from "./Customers";
import { PaymentsAPI } from './Payments';
import { InstallmentsAPI } from './Installments';
import { SubscriptionsAPI } from './Subscriptions';
export declare class AsaasClient {
private apiKey;
customers: CustomersAPI;
payments: PaymentsAPI;
installments: InstallmentsAPI;
subscriptions: SubscriptionsAPI;
constructor(apiKey: string, options?: AsaasOptions);
}
14 changes: 6 additions & 8 deletions dist/client/AsaasClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsaasClient = void 0;
const axios_1 = require("axios");
const Customers_1 = require("../client/Customers");
const Customers_1 = require("./Customers");
const Payments_1 = require("./Payments");
const Installments_1 = require("./Installments");
const Subscriptions_1 = require("./Subscriptions");
class AsaasClient {
constructor(apiKey, options = {}) {
this.apiKey = apiKey;
const baseURL = options.sandbox ? (options.sandboxUrl || 'https://sandbox.asaas.com/api/v3') : options.baseUrl ? options.baseUrl : 'https://www.asaas.com/api/v3';
const apiClient = axios_1.default.create({
baseURL,
headers: {
'access_token': this.apiKey
}
});
const apiClient = axios_1.default;
apiClient.defaults.baseURL = options.sandbox ? (options.sandboxUrl || 'https://sandbox.asaas.com/api/v3') : options.baseUrl ? options.baseUrl : 'https://api.asaas.com/v3';
apiClient.defaults.headers.common['access_token'] = this.apiKey;
this.customers = new Customers_1.CustomersAPI(apiClient);
this.payments = new Payments_1.PaymentsAPI(apiClient);
this.installments = new Installments_1.InstallmentsAPI(apiClient);
this.subscriptions = new Subscriptions_1.SubscriptionsAPI(apiClient);
}
}
exports.AsaasClient = AsaasClient;
12 changes: 12 additions & 0 deletions dist/client/Subscriptions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AxiosInstance } from "axios";
import { IAsaasDeleteResponse, IListSubscriptionPaymentsResponse, ISubscription, ICreateSubscriptionParams, IUpdateSubscriptionParams, IListSubscriptionsResponse, IListSubscriptionsParams } from "../types/AsaasTypes";
export declare class SubscriptionsAPI {
private apiClient;
constructor(apiClient: AxiosInstance);
create(params?: ICreateSubscriptionParams): Promise<ISubscription>;
list(params?: IListSubscriptionsParams): Promise<IListSubscriptionsResponse>;
getById(id: string): Promise<ISubscription>;
getPayments(id: string): Promise<IListSubscriptionPaymentsResponse>;
delete(id: string): Promise<IAsaasDeleteResponse>;
updateById(id: string, params?: IUpdateSubscriptionParams): Promise<ISubscription>;
}
90 changes: 90 additions & 0 deletions dist/client/Subscriptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubscriptionsAPI = void 0;
class SubscriptionsAPI {
constructor(apiClient) {
this.apiClient = apiClient;
}
create(params) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield this.apiClient.post('/subscriptions', params);
return response.data;
}
catch (error) {
console.error('Erro ao criar uma nova assinatura:', error);
throw error;
}
});
}
list(params) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield this.apiClient.get('/subscriptions', { params });
return response.data;
}
catch (error) {
console.error('Erro ao obter a lista de assinaturas:', error);
throw error;
}
});
}
getById(id) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield this.apiClient.get(`/subscriptions/${id}`);
return response.data;
}
catch (error) {
console.error('Erro ao obter a assinatura:', error);
throw error;
}
});
}
getPayments(id) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield this.apiClient.get(`/subscriptions/${id}/payments`);
return response.data;
}
catch (error) {
console.error('Erro ao obter as cobranças da assinatura:', error);
throw error;
}
});
}
delete(id) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield this.apiClient.delete(`/subscriptions/${id}`);
return response.data;
}
catch (error) {
console.error('Erro ao deletar a assinatura:', error);
throw error;
}
});
}
updateById(id, params) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield this.apiClient.post(`/subscriptions/${id}`, params);
return response.data;
}
catch (error) {
console.error('Erro ao atualizar a assinatura:', error);
throw error;
}
});
}
}
exports.SubscriptionsAPI = SubscriptionsAPI;
Loading

0 comments on commit 36bb297

Please sign in to comment.