WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c5a8f96

Browse files
Merge pull request #3 from thihxm/main
Add support for multiple Asaas Client instances with different API keys
2 parents 392c1dc + ba678b8 commit c5a8f96

File tree

12 files changed

+523
-402
lines changed

12 files changed

+523
-402
lines changed

.eslintrc.json

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
{
2-
"env": {
3-
"browser": true,
4-
"es2021": true,
5-
"node": true
6-
},
7-
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
8-
"overrides": [],
9-
"parser": "@typescript-eslint/parser",
10-
"parserOptions": {
11-
"ecmaVersion": "latest",
12-
"sourceType": "module"
13-
},
14-
"plugins": ["@typescript-eslint"],
15-
"rules": {}
16-
}
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/recommended"
10+
],
11+
"overrides": [],
12+
"ignorePatterns": [
13+
"dist/**/*"
14+
],
15+
"parser": "@typescript-eslint/parser",
16+
"parserOptions": {
17+
"ecmaVersion": "latest",
18+
"sourceType": "module"
19+
},
20+
"plugins": [
21+
"@typescript-eslint"
22+
],
23+
"rules": {}
24+
}

dist/client/AsaasClient.d.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { AsaasOptions } from '../types/AsaasTypes';
2-
import { CustomersAPI } from "./Customers";
3-
import { PaymentsAPI } from './Payments';
2+
import { CustomersAPI } from './Customers';
43
import { InstallmentsAPI } from './Installments';
4+
import { PaymentsAPI } from './Payments';
55
import { SubscriptionsAPI } from './Subscriptions';
6+
import { Webhooks } from './Webhooks';
67
export declare class AsaasClient {
7-
private apiKey;
8-
customers: CustomersAPI;
9-
payments: PaymentsAPI;
10-
installments: InstallmentsAPI;
11-
subscriptions: SubscriptionsAPI;
12-
constructor(apiKey: string, options?: AsaasOptions);
8+
private apiKey;
9+
customers: CustomersAPI;
10+
payments: PaymentsAPI;
11+
installments: InstallmentsAPI;
12+
subscriptions: SubscriptionsAPI;
13+
webhooks: Webhooks;
14+
constructor(apiKey: string, options?: AsaasOptions);
1315
}

dist/client/AsaasClient.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
"use strict";
2-
Object.defineProperty(exports, "__esModule", { value: true });
1+
'use strict';
2+
Object.defineProperty(exports, '__esModule', { value: true });
33
exports.AsaasClient = void 0;
4-
const axios_1 = require("axios");
5-
const Customers_1 = require("./Customers");
6-
const Payments_1 = require("./Payments");
7-
const Installments_1 = require("./Installments");
8-
const Subscriptions_1 = require("./Subscriptions");
4+
const axios_1 = require('axios');
5+
const Customers_1 = require('./Customers');
6+
const Installments_1 = require('./Installments');
7+
const Payments_1 = require('./Payments');
8+
const Subscriptions_1 = require('./Subscriptions');
9+
const Webhooks_1 = require('./Webhooks');
910
class AsaasClient {
10-
constructor(apiKey, options = {}) {
11-
this.apiKey = apiKey;
12-
const apiClient = axios_1.default;
13-
apiClient.defaults.baseURL = options.sandbox ? (options.sandboxUrl || 'https://sandbox.asaas.com/api/v3') : options.baseUrl ? options.baseUrl : 'https://api.asaas.com/v3';
14-
apiClient.defaults.headers.common['access_token'] = this.apiKey;
15-
this.customers = new Customers_1.CustomersAPI(apiClient);
16-
this.payments = new Payments_1.PaymentsAPI(apiClient);
17-
this.installments = new Installments_1.InstallmentsAPI(apiClient);
18-
this.subscriptions = new Subscriptions_1.SubscriptionsAPI(apiClient);
19-
}
11+
constructor(apiKey, options = {}) {
12+
this.apiKey = apiKey;
13+
const apiClient = axios_1.default.create({
14+
baseURL: options.sandbox
15+
? options.sandboxUrl || 'https://sandbox.asaas.com/api/v3'
16+
: options.baseUrl
17+
? options.baseUrl
18+
: 'https://api.asaas.com/v3',
19+
headers: {
20+
common: {
21+
access_token: this.apiKey,
22+
},
23+
},
24+
});
25+
this.customers = new Customers_1.CustomersAPI(apiClient);
26+
this.payments = new Payments_1.PaymentsAPI(apiClient);
27+
this.installments = new Installments_1.InstallmentsAPI(apiClient);
28+
this.subscriptions = new Subscriptions_1.SubscriptionsAPI(apiClient);
29+
this.webhooks = new Webhooks_1.Webhooks();
30+
}
2031
}
2132
exports.AsaasClient = AsaasClient;

dist/client/PaymentsWebhook.d.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
export declare class PaymentsWebhook {
2+
/**
3+
* Geração de nova cobrança.
4+
*/
5+
readonly PAYMENT_CREATED: string;
6+
/**
7+
* Pagamento em cartão aguardando aprovação pela análise manual de risco.
8+
*/
9+
readonly PAYMENT_AWAITING_RISK_ANALYSIS: string;
10+
/**
11+
* Pagamento em cartão aprovado pela análise manual de risco.
12+
*/
13+
readonly PAYMENT_APPROVED_BY_RISK_ANALYSIS: string;
14+
/**
15+
* Pagamento em cartão reprovado pela análise manual de risco.
16+
*/
17+
readonly PAYMENT_REPROVED_BY_RISK_ANALYSIS: string;
18+
/**
19+
* Alteração no vencimento ou valor de cobrança existente.
20+
*/
21+
readonly PAYMENT_UPDATED: string;
22+
/**
23+
* Cobrança confirmada (pagamento efetuado, porém o saldo ainda não foi disponibilizado).
24+
*/
25+
readonly PAYMENT_CONFIRMED: string;
26+
/**
27+
* Cobrança recebida.
28+
*/
29+
readonly PAYMENT_RECEIVED: string;
30+
/**
31+
* Cobrança antecipada.
32+
*/
33+
readonly PAYMENT_ANTICIPATED: string;
34+
/**
35+
* Cobrança vencida.
36+
*/
37+
readonly PAYMENT_OVERDUE: string;
38+
/**
39+
* Cobrança removida.
40+
*/
41+
readonly PAYMENT_DELETED: string;
42+
/**
43+
* Cobrança restaurada.
44+
*/
45+
readonly PAYMENT_RESTORED: string;
46+
/**
47+
* Cobrança estornada.
48+
*/
49+
readonly PAYMENT_REFUNDED: string;
50+
/**
51+
* Estorno em processamento (liquidação já está agendada, cobrança será estornada após executar a liquidação).
52+
*/
53+
readonly PAYMENT_REFUND_IN_PROGRESS: string;
54+
/**
55+
* Recebimento em dinheiro desfeito.
56+
*/
57+
readonly PAYMENT_RECEIVED_IN_CASH_UNDONE: string;
58+
/**
59+
* Recebido chargeback.
60+
*/
61+
readonly PAYMENT_CHARGEBACK_REQUESTED: string;
62+
/**
63+
* Em disputa de chargeback (caso sejam apresentados documentos para contestação).
64+
*/
65+
readonly PAYMENT_CHARGEBACK_DISPUTE: string;
66+
/**
67+
* Disputa vencida, aguardando repasse da adquirente.
68+
*/
69+
readonly PAYMENT_AWAITING_CHARGEBACK_REVERSAL: string;
70+
/**
71+
* Recebimento de negativação.
72+
*/
73+
readonly PAYMENT_DUNNING_RECEIVED: string;
74+
/**
75+
* Requisição de negativação.
76+
*/
77+
readonly PAYMENT_DUNNING_REQUESTED: string;
78+
/**
79+
* Boleto da cobrança visualizado pelo cliente.
80+
*/
81+
readonly PAYMENT_BANK_SLIP_VIEWED: string;
82+
/**
83+
* Fatura da cobrança visualizada pelo cliente.
84+
*/
85+
readonly PAYMENT_CHECKOUT_VIEWED: string;
86+
}

dist/client/PaymentsWebhook.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
'use strict';
2+
Object.defineProperty(exports, '__esModule', { value: true });
3+
exports.PaymentsWebhook = void 0;
4+
class PaymentsWebhook {
5+
constructor() {
6+
/**
7+
* Geração de nova cobrança.
8+
*/
9+
this.PAYMENT_CREATED = 'PAYMENT_CREATED';
10+
/**
11+
* Pagamento em cartão aguardando aprovação pela análise manual de risco.
12+
*/
13+
this.PAYMENT_AWAITING_RISK_ANALYSIS = 'PAYMENT_AWAITING_RISK_ANALYSIS';
14+
/**
15+
* Pagamento em cartão aprovado pela análise manual de risco.
16+
*/
17+
this.PAYMENT_APPROVED_BY_RISK_ANALYSIS =
18+
'PAYMENT_APPROVED_BY_RISK_ANALYSIS';
19+
/**
20+
* Pagamento em cartão reprovado pela análise manual de risco.
21+
*/
22+
this.PAYMENT_REPROVED_BY_RISK_ANALYSIS =
23+
'PAYMENT_REPROVED_BY_RISK_ANALYSIS';
24+
/**
25+
* Alteração no vencimento ou valor de cobrança existente.
26+
*/
27+
this.PAYMENT_UPDATED = 'PAYMENT_UPDATED';
28+
/**
29+
* Cobrança confirmada (pagamento efetuado, porém o saldo ainda não foi disponibilizado).
30+
*/
31+
this.PAYMENT_CONFIRMED = 'PAYMENT_CONFIRMED';
32+
/**
33+
* Cobrança recebida.
34+
*/
35+
this.PAYMENT_RECEIVED = 'PAYMENT_RECEIVED';
36+
/**
37+
* Cobrança antecipada.
38+
*/
39+
this.PAYMENT_ANTICIPATED = 'PAYMENT_ANTICIPATED';
40+
/**
41+
* Cobrança vencida.
42+
*/
43+
this.PAYMENT_OVERDUE = 'PAYMENT_OVERDUE';
44+
/**
45+
* Cobrança removida.
46+
*/
47+
this.PAYMENT_DELETED = 'PAYMENT_DELETED';
48+
/**
49+
* Cobrança restaurada.
50+
*/
51+
this.PAYMENT_RESTORED = 'PAYMENT_RESTORED';
52+
/**
53+
* Cobrança estornada.
54+
*/
55+
this.PAYMENT_REFUNDED = 'PAYMENT_REFUNDED';
56+
/**
57+
* Estorno em processamento (liquidação já está agendada, cobrança será estornada após executar a liquidação).
58+
*/
59+
this.PAYMENT_REFUND_IN_PROGRESS = 'PAYMENT_REFUND_IN_PROGRESS';
60+
/**
61+
* Recebimento em dinheiro desfeito.
62+
*/
63+
this.PAYMENT_RECEIVED_IN_CASH_UNDONE = 'PAYMENT_RECEIVED_IN_CASH_UNDONE';
64+
/**
65+
* Recebido chargeback.
66+
*/
67+
this.PAYMENT_CHARGEBACK_REQUESTED = 'PAYMENT_CHARGEBACK_REQUESTED';
68+
/**
69+
* Em disputa de chargeback (caso sejam apresentados documentos para contestação).
70+
*/
71+
this.PAYMENT_CHARGEBACK_DISPUTE = 'PAYMENT_CHARGEBACK_DISPUTE';
72+
/**
73+
* Disputa vencida, aguardando repasse da adquirente.
74+
*/
75+
this.PAYMENT_AWAITING_CHARGEBACK_REVERSAL =
76+
'PAYMENT_AWAITING_CHARGEBACK_REVERSAL';
77+
/**
78+
* Recebimento de negativação.
79+
*/
80+
this.PAYMENT_DUNNING_RECEIVED = 'PAYMENT_DUNNING_RECEIVED';
81+
/**
82+
* Requisição de negativação.
83+
*/
84+
this.PAYMENT_DUNNING_REQUESTED = 'PAYMENT_DUNNING_REQUESTED';
85+
/**
86+
* Boleto da cobrança visualizado pelo cliente.
87+
*/
88+
this.PAYMENT_BANK_SLIP_VIEWED = 'PAYMENT_BANK_SLIP_VIEWED';
89+
/**
90+
* Fatura da cobrança visualizada pelo cliente.
91+
*/
92+
this.PAYMENT_CHECKOUT_VIEWED = 'PAYMENT_CHECKOUT_VIEWED';
93+
}
94+
}
95+
exports.PaymentsWebhook = PaymentsWebhook;

dist/client/Webhooks.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { PaymentsWebhook } from './PaymentsWebhook';
2+
export declare class Webhooks {
3+
readonly payments: PaymentsWebhook;
4+
constructor();
5+
}

dist/client/Webhooks.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
Object.defineProperty(exports, '__esModule', { value: true });
3+
exports.Webhooks = void 0;
4+
const PaymentsWebhook_1 = require('./PaymentsWebhook');
5+
class Webhooks {
6+
constructor() {
7+
this.payments = new PaymentsWebhook_1.PaymentsWebhook();
8+
}
9+
}
10+
exports.Webhooks = Webhooks;

dist/tests/index.test.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
"use strict";
2-
Object.defineProperty(exports, "__esModule", { value: true });
3-
const axios_1 = require("axios");
4-
const AsaasClient_1 = require("../client/AsaasClient");
1+
'use strict';
2+
Object.defineProperty(exports, '__esModule', { value: true });
3+
const AsaasClient_1 = require('../client/AsaasClient');
54
jest.mock('axios');
65
describe('AsaasClient', () => {
7-
test('construtor deve inicializar corretamente em modo Sandbox', () => {
8-
const apiKey = 'my-api-key';
9-
const options = { sandbox: true };
10-
const client = new AsaasClient_1.AsaasClient(apiKey, options);
11-
expect(client.customers).toBeDefined();
12-
expect(client.payments).toBeDefined();
13-
expect(client.installments).toBeDefined();
14-
expect(client.subscriptions).toBeDefined();
15-
const expectedBaseURL = 'https://sandbox.asaas.com/api/v3';
16-
expect(axios_1.default.defaults.baseURL).toBe(expectedBaseURL);
17-
});
6+
test('construtor deve inicializar corretamente em modo Sandbox', () => {
7+
const apiKey = 'my-api-key';
8+
const options = { sandbox: true };
9+
const client = new AsaasClient_1.AsaasClient(apiKey, options);
10+
expect(client.customers).toBeDefined();
11+
expect(client.payments).toBeDefined();
12+
expect(client.installments).toBeDefined();
13+
expect(client.subscriptions).toBeDefined();
14+
expect(client.webhooks.payments).toBeDefined();
15+
});
1816
});

0 commit comments

Comments
 (0)