forked from eduardobernardo/asaas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dc8240
commit 36bb297
Showing
18 changed files
with
9,921 additions
and
2,495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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); | ||
}); | ||
|
@@ -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]" | ||
}); | ||
``` | ||
|
@@ -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 | | ||
|
@@ -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" | ||
}); | ||
``` | ||
|
@@ -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 :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {presets: ['@babel/preset-env']} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.