@adonis-agora/payments 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/commands/main.d.ts +16 -0
- package/dist/commands/main.d.ts.map +1 -0
- package/dist/commands/main.js +17 -0
- package/dist/commands/main.js.map +1 -0
- package/dist/commands/make_billable.d.ts +16 -0
- package/dist/commands/make_billable.d.ts.map +1 -0
- package/dist/commands/make_billable.js +30 -0
- package/dist/commands/make_billable.js.map +1 -0
- package/dist/commands/make_webhook_handler.d.ts +20 -0
- package/dist/commands/make_webhook_handler.d.ts.map +1 -0
- package/dist/commands/make_webhook_handler.js +34 -0
- package/dist/commands/make_webhook_handler.js.map +1 -0
- package/dist/commands/payments_sync.d.ts +20 -0
- package/dist/commands/payments_sync.d.ts.map +1 -0
- package/dist/commands/payments_sync.js +95 -0
- package/dist/commands/payments_sync.js.map +1 -0
- package/dist/commands/payments_webhook.d.ts +19 -0
- package/dist/commands/payments_webhook.d.ts.map +1 -0
- package/dist/commands/payments_webhook.js +123 -0
- package/dist/commands/payments_webhook.js.map +1 -0
- package/dist/configure.d.ts +12 -0
- package/dist/configure.d.ts.map +1 -0
- package/dist/configure.js +34 -0
- package/dist/configure.js.map +1 -0
- package/dist/providers/payments_provider.d.ts +15 -0
- package/dist/providers/payments_provider.d.ts.map +1 -0
- package/dist/providers/payments_provider.js +155 -0
- package/dist/providers/payments_provider.js.map +1 -0
- package/dist/src/billing/billing_overview.d.ts +26 -0
- package/dist/src/billing/billing_overview.d.ts.map +1 -0
- package/dist/src/billing/billing_overview.js +27 -0
- package/dist/src/billing/billing_overview.js.map +1 -0
- package/dist/src/billing/billing_store.d.ts +73 -0
- package/dist/src/billing/billing_store.d.ts.map +1 -0
- package/dist/src/billing/billing_store.js +2 -0
- package/dist/src/billing/billing_store.js.map +1 -0
- package/dist/src/billing/index.d.ts +8 -0
- package/dist/src/billing/index.d.ts.map +1 -0
- package/dist/src/billing/index.js +6 -0
- package/dist/src/billing/index.js.map +1 -0
- package/dist/src/billing/lucid_billing_store.d.ts +84 -0
- package/dist/src/billing/lucid_billing_store.d.ts.map +1 -0
- package/dist/src/billing/lucid_billing_store.js +143 -0
- package/dist/src/billing/lucid_billing_store.js.map +1 -0
- package/dist/src/billing/metered_bill.d.ts +60 -0
- package/dist/src/billing/metered_bill.d.ts.map +1 -0
- package/dist/src/billing/metered_bill.js +46 -0
- package/dist/src/billing/metered_bill.js.map +1 -0
- package/dist/src/billing/mixins/index.d.ts +6 -0
- package/dist/src/billing/mixins/index.d.ts.map +1 -0
- package/dist/src/billing/mixins/index.js +6 -0
- package/dist/src/billing/mixins/index.js.map +1 -0
- package/dist/src/billing/mixins/with_billable.d.ts +23 -0
- package/dist/src/billing/mixins/with_billable.d.ts.map +1 -0
- package/dist/src/billing/mixins/with_billable.js +33 -0
- package/dist/src/billing/mixins/with_billable.js.map +1 -0
- package/dist/src/billing/mixins/with_payment.d.ts +45 -0
- package/dist/src/billing/mixins/with_payment.d.ts.map +1 -0
- package/dist/src/billing/mixins/with_payment.js +94 -0
- package/dist/src/billing/mixins/with_payment.js.map +1 -0
- package/dist/src/billing/mixins/with_subscription.d.ts +50 -0
- package/dist/src/billing/mixins/with_subscription.d.ts.map +1 -0
- package/dist/src/billing/mixins/with_subscription.js +95 -0
- package/dist/src/billing/mixins/with_subscription.js.map +1 -0
- package/dist/src/billing/mixins/with_usage_event.d.ts +22 -0
- package/dist/src/billing/mixins/with_usage_event.d.ts.map +1 -0
- package/dist/src/billing/mixins/with_usage_event.js +39 -0
- package/dist/src/billing/mixins/with_usage_event.js.map +1 -0
- package/dist/src/billing/mixins/with_webhook_event.d.ts +21 -0
- package/dist/src/billing/mixins/with_webhook_event.d.ts.map +1 -0
- package/dist/src/billing/mixins/with_webhook_event.js +42 -0
- package/dist/src/billing/mixins/with_webhook_event.js.map +1 -0
- package/dist/src/billing/webhook_dispatcher.d.ts +79 -0
- package/dist/src/billing/webhook_dispatcher.d.ts.map +1 -0
- package/dist/src/billing/webhook_dispatcher.js +125 -0
- package/dist/src/billing/webhook_dispatcher.js.map +1 -0
- package/dist/src/billing/webhook_events.d.ts +49 -0
- package/dist/src/billing/webhook_events.d.ts.map +1 -0
- package/dist/src/billing/webhook_events.js +44 -0
- package/dist/src/billing/webhook_events.js.map +1 -0
- package/dist/src/billing/webhook_processor.d.ts +39 -0
- package/dist/src/billing/webhook_processor.d.ts.map +1 -0
- package/dist/src/billing/webhook_processor.js +209 -0
- package/dist/src/billing/webhook_processor.js.map +1 -0
- package/dist/src/define_config.d.ts +251 -0
- package/dist/src/define_config.d.ts.map +1 -0
- package/dist/src/define_config.js +67 -0
- package/dist/src/define_config.js.map +1 -0
- package/dist/src/diagnostics.d.ts +155 -0
- package/dist/src/diagnostics.d.ts.map +1 -0
- package/dist/src/diagnostics.js +153 -0
- package/dist/src/diagnostics.js.map +1 -0
- package/dist/src/driver.d.ts +222 -0
- package/dist/src/driver.d.ts.map +1 -0
- package/dist/src/driver.js +2 -0
- package/dist/src/driver.js.map +1 -0
- package/dist/src/drivers/abacate.d.ts +35 -0
- package/dist/src/drivers/abacate.d.ts.map +1 -0
- package/dist/src/drivers/abacate.js +381 -0
- package/dist/src/drivers/abacate.js.map +1 -0
- package/dist/src/drivers/asaas.d.ts +36 -0
- package/dist/src/drivers/asaas.d.ts.map +1 -0
- package/dist/src/drivers/asaas.js +455 -0
- package/dist/src/drivers/asaas.js.map +1 -0
- package/dist/src/drivers/stripe.d.ts +36 -0
- package/dist/src/drivers/stripe.d.ts.map +1 -0
- package/dist/src/drivers/stripe.js +392 -0
- package/dist/src/drivers/stripe.js.map +1 -0
- package/dist/src/drivers/woovi.d.ts +49 -0
- package/dist/src/drivers/woovi.d.ts.map +1 -0
- package/dist/src/drivers/woovi.js +339 -0
- package/dist/src/drivers/woovi.js.map +1 -0
- package/dist/src/ensure_customer.d.ts +23 -0
- package/dist/src/ensure_customer.d.ts.map +1 -0
- package/dist/src/ensure_customer.js +25 -0
- package/dist/src/ensure_customer.js.map +1 -0
- package/dist/src/hooks/webhook_handlers.d.ts +50 -0
- package/dist/src/hooks/webhook_handlers.d.ts.map +1 -0
- package/dist/src/hooks/webhook_handlers.js +53 -0
- package/dist/src/hooks/webhook_handlers.js.map +1 -0
- package/dist/src/http.d.ts +24 -0
- package/dist/src/http.d.ts.map +1 -0
- package/dist/src/http.js +52 -0
- package/dist/src/http.js.map +1 -0
- package/dist/src/index.d.ts +29 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +15 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/invoice/drivers/asaas.d.ts +23 -0
- package/dist/src/invoice/drivers/asaas.d.ts.map +1 -0
- package/dist/src/invoice/drivers/asaas.js +85 -0
- package/dist/src/invoice/drivers/asaas.js.map +1 -0
- package/dist/src/invoice/drivers/enotas.d.ts +23 -0
- package/dist/src/invoice/drivers/enotas.d.ts.map +1 -0
- package/dist/src/invoice/drivers/enotas.js +83 -0
- package/dist/src/invoice/drivers/enotas.js.map +1 -0
- package/dist/src/invoice/drivers/focus.d.ts +23 -0
- package/dist/src/invoice/drivers/focus.d.ts.map +1 -0
- package/dist/src/invoice/drivers/focus.js +90 -0
- package/dist/src/invoice/drivers/focus.js.map +1 -0
- package/dist/src/invoice/drivers/plugnotas.d.ts +22 -0
- package/dist/src/invoice/drivers/plugnotas.d.ts.map +1 -0
- package/dist/src/invoice/drivers/plugnotas.js +81 -0
- package/dist/src/invoice/drivers/plugnotas.js.map +1 -0
- package/dist/src/invoice/drivers/tecnospeed.d.ts +29 -0
- package/dist/src/invoice/drivers/tecnospeed.d.ts.map +1 -0
- package/dist/src/invoice/drivers/tecnospeed.js +87 -0
- package/dist/src/invoice/drivers/tecnospeed.js.map +1 -0
- package/dist/src/invoice/emit_invoice.d.ts +45 -0
- package/dist/src/invoice/emit_invoice.d.ts.map +1 -0
- package/dist/src/invoice/emit_invoice.js +72 -0
- package/dist/src/invoice/emit_invoice.js.map +1 -0
- package/dist/src/invoice/invoice_manager.d.ts +12 -0
- package/dist/src/invoice/invoice_manager.d.ts.map +1 -0
- package/dist/src/invoice/invoice_manager.js +35 -0
- package/dist/src/invoice/invoice_manager.js.map +1 -0
- package/dist/src/invoice/invoice_provider.d.ts +48 -0
- package/dist/src/invoice/invoice_provider.d.ts.map +1 -0
- package/dist/src/invoice/invoice_provider.js +2 -0
- package/dist/src/invoice/invoice_provider.js.map +1 -0
- package/dist/src/money.d.ts +11 -0
- package/dist/src/money.d.ts.map +1 -0
- package/dist/src/money.js +14 -0
- package/dist/src/money.js.map +1 -0
- package/dist/src/payments_manager.d.ts +40 -0
- package/dist/src/payments_manager.d.ts.map +1 -0
- package/dist/src/payments_manager.js +94 -0
- package/dist/src/payments_manager.js.map +1 -0
- package/dist/src/services/main.d.ts +6 -0
- package/dist/src/services/main.d.ts.map +1 -0
- package/dist/src/services/main.js +17 -0
- package/dist/src/services/main.js.map +1 -0
- package/dist/src/telescope/index.d.ts +3 -0
- package/dist/src/telescope/index.d.ts.map +1 -0
- package/dist/src/telescope/index.js +2 -0
- package/dist/src/telescope/index.js.map +1 -0
- package/dist/src/telescope/payments_watcher.d.ts +27 -0
- package/dist/src/telescope/payments_watcher.d.ts.map +1 -0
- package/dist/src/telescope/payments_watcher.js +58 -0
- package/dist/src/telescope/payments_watcher.js.map +1 -0
- package/dist/src/telescope/telescope-sdk.d.ts +21 -0
- package/dist/src/telescope/telescope-sdk.d.ts.map +1 -0
- package/dist/src/telescope/telescope-sdk.js +11 -0
- package/dist/src/telescope/telescope-sdk.js.map +1 -0
- package/dist/src/testing/fake_payments_driver.d.ts +64 -0
- package/dist/src/testing/fake_payments_driver.d.ts.map +1 -0
- package/dist/src/testing/fake_payments_driver.js +171 -0
- package/dist/src/testing/fake_payments_driver.js.map +1 -0
- package/dist/src/testing/in_memory_billing_store.d.ts +110 -0
- package/dist/src/testing/in_memory_billing_store.d.ts.map +1 -0
- package/dist/src/testing/in_memory_billing_store.js +136 -0
- package/dist/src/testing/in_memory_billing_store.js.map +1 -0
- package/dist/src/testing/index.d.ts +6 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +4 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/mutable_clock.d.ts +12 -0
- package/dist/src/testing/mutable_clock.d.ts.map +1 -0
- package/dist/src/testing/mutable_clock.js +20 -0
- package/dist/src/testing/mutable_clock.js.map +1 -0
- package/dist/src/types.d.ts +178 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +9 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/webhook_handlers.d.ts +76 -0
- package/dist/src/webhook_handlers.d.ts.map +1 -0
- package/dist/src/webhook_handlers.js +128 -0
- package/dist/src/webhook_handlers.js.map +1 -0
- package/dist/src/webhook_security.d.ts +29 -0
- package/dist/src/webhook_security.d.ts.map +1 -0
- package/dist/src/webhook_security.js +53 -0
- package/dist/src/webhook_security.js.map +1 -0
- package/dist/stubs/config/payments.stub +101 -0
- package/dist/stubs/database/migrations/create_billing_tables.stub +90 -0
- package/dist/stubs/main.d.ts +9 -0
- package/dist/stubs/main.d.ts.map +1 -0
- package/dist/stubs/main.js +16 -0
- package/dist/stubs/main.js.map +1 -0
- package/dist/stubs/make/billable/main.stub +28 -0
- package/dist/stubs/make/webhook_handler/main.stub +29 -0
- package/package.json +150 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tecnospeed invoice provider — NFS-e across municipalities. Uses `fetch` directly (no
|
|
3
|
+
* SDK dependency). The exact JSON layout varies per municipality and standard (Tecnospeed
|
|
4
|
+
* also offers an XML DPS flow and steers toward PlugNotas for JSON NFS-e) — this adapter
|
|
5
|
+
* sends the common JSON shape and normalizes the response; if your municipality differs,
|
|
6
|
+
* extend this driver (see Custom providers).
|
|
7
|
+
*/
|
|
8
|
+
export class TecnospeedInvoiceProvider {
|
|
9
|
+
provider = 'tecnospeed';
|
|
10
|
+
#token;
|
|
11
|
+
#baseUrl;
|
|
12
|
+
constructor(_ctx, config = {}) {
|
|
13
|
+
const token = config.token ?? process.env.TECNOSPEED_TOKEN;
|
|
14
|
+
if (!token) {
|
|
15
|
+
throw new Error('[payments] Tecnospeed invoice provider requires a token. Set `TECNOSPEED_TOKEN` env or pass `token` to `invoice.tecnospeed()`.');
|
|
16
|
+
}
|
|
17
|
+
this.#token = token;
|
|
18
|
+
this.#baseUrl = config.baseUrl ?? 'https://api-tecnospeed.com.br/v1';
|
|
19
|
+
}
|
|
20
|
+
async emit(input) {
|
|
21
|
+
const body = {
|
|
22
|
+
tomador: {
|
|
23
|
+
cpf_cnpj: input.customer.taxId.replace(/\D/g, ''),
|
|
24
|
+
razao_social: input.customer.name ?? 'Cliente',
|
|
25
|
+
...(input.customer.email !== undefined ? { email: input.customer.email } : {}),
|
|
26
|
+
...(input.customer.address !== undefined ? { endereco: input.customer.address } : {}),
|
|
27
|
+
},
|
|
28
|
+
servico: {
|
|
29
|
+
descricao: input.service.description,
|
|
30
|
+
...(input.service.code !== undefined ? { codigo_servico: input.service.code } : {}),
|
|
31
|
+
...(input.service.cityServiceCode !== undefined
|
|
32
|
+
? { codigo_servico_municipio: input.service.cityServiceCode }
|
|
33
|
+
: {}),
|
|
34
|
+
},
|
|
35
|
+
valor: input.amount / 100,
|
|
36
|
+
...(input.tax !== undefined ? { impostos: input.tax } : {}),
|
|
37
|
+
};
|
|
38
|
+
const response = await fetch(`${this.#baseUrl}/nfse`, {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: this.#token,
|
|
42
|
+
'Content-Type': 'application/json',
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify(body),
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const text = await response.text();
|
|
48
|
+
throw new Error(`[payments] Tecnospeed invoice request failed (${response.status}): ${text}`);
|
|
49
|
+
}
|
|
50
|
+
const data = (await response.json());
|
|
51
|
+
return this.#mapInvoice(data);
|
|
52
|
+
}
|
|
53
|
+
async find(invoiceId) {
|
|
54
|
+
const response = await fetch(`${this.#baseUrl}/nfse/${encodeURIComponent(invoiceId)}`, {
|
|
55
|
+
headers: { Authorization: this.#token },
|
|
56
|
+
});
|
|
57
|
+
if (response.status === 404)
|
|
58
|
+
return null;
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
const text = await response.text();
|
|
61
|
+
throw new Error(`[payments] Tecnospeed invoice request failed (${response.status}): ${text}`);
|
|
62
|
+
}
|
|
63
|
+
const data = (await response.json());
|
|
64
|
+
return this.#mapInvoice(data);
|
|
65
|
+
}
|
|
66
|
+
#mapInvoice(data) {
|
|
67
|
+
const status = data.status ?? '';
|
|
68
|
+
const normalized = status === 'autorizado' || status === 'AUTORIZADO' || status === 'emitido'
|
|
69
|
+
? 'issued'
|
|
70
|
+
: status === 'cancelado' || status === 'CANCELADO' || status === 'rejeitado'
|
|
71
|
+
? 'canceled'
|
|
72
|
+
: 'pending';
|
|
73
|
+
return {
|
|
74
|
+
id: data.id ?? data.chave ?? data.numero ?? String(Math.random()),
|
|
75
|
+
gatewayId: data.id ?? data.chave ?? data.numero ?? '',
|
|
76
|
+
provider: this.provider,
|
|
77
|
+
...(data.numero !== undefined ? { number: data.numero } : {}),
|
|
78
|
+
...(data.chave !== undefined ? { key: data.chave } : {}),
|
|
79
|
+
...(data.url !== undefined ? { url: data.url, hostedPdfUrl: data.url } : {}),
|
|
80
|
+
status: normalized,
|
|
81
|
+
amount: { amount: Math.round(Number(data.valor ?? 0) * 100), currency: 'brl' },
|
|
82
|
+
createdAt: new Date().toISOString(),
|
|
83
|
+
payload: data,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=tecnospeed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tecnospeed.js","sourceRoot":"","sources":["../../../../src/invoice/drivers/tecnospeed.ts"],"names":[],"mappings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AK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxD,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5E,MAAM,EAAE,UAAU;YAClB,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE;YAC9E,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO,EAAE,IAA0C;SACpD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ChargeInput, PaymentsDriver } from '../driver.js';
|
|
2
|
+
import type { InvoiceOptions, Payment } from '../types.js';
|
|
3
|
+
import type { InvoiceProvider } from './invoice_provider.js';
|
|
4
|
+
/** The invoice-resolution surface a payment driver receives (from the factory ctx). */
|
|
5
|
+
export interface EmitInvoiceContext {
|
|
6
|
+
/** Resolve an invoice provider by name; falls back to the configured default. */
|
|
7
|
+
invoice?: (name?: string) => InvoiceProvider;
|
|
8
|
+
}
|
|
9
|
+
export interface EmitInvoiceData {
|
|
10
|
+
/** The billing customer's fiscal data. */
|
|
11
|
+
customer: {
|
|
12
|
+
name?: string;
|
|
13
|
+
taxId: string;
|
|
14
|
+
email?: string;
|
|
15
|
+
address?: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
/** Amount in the currency's smallest unit (e.g. cents). */
|
|
18
|
+
amount: number;
|
|
19
|
+
currency: string;
|
|
20
|
+
/** The gateway payment this invoice is attached to, when available. */
|
|
21
|
+
payment?: {
|
|
22
|
+
gatewayId: string;
|
|
23
|
+
provider: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Emit an invoice for a charge when the call asked for one. The `invoice` option on a
|
|
28
|
+
* charge/subscription/checkout resolves the provider by NAME, independent of the payment
|
|
29
|
+
* gateway:
|
|
30
|
+
*
|
|
31
|
+
* - `true` — use the default invoice provider from `config.invoice.providers`.
|
|
32
|
+
* - `'tecnospeed'` — use the named invoice provider (a key of `invoice.providers`).
|
|
33
|
+
* - `{ provider?, ... }` — named provider (or default) with these overrides.
|
|
34
|
+
*
|
|
35
|
+
* Returns `undefined` when the call did not request an invoice.
|
|
36
|
+
*/
|
|
37
|
+
export declare function emitInvoice(ctx: EmitInvoiceContext, option: boolean | string | InvoiceOptions | undefined, data: EmitInvoiceData): Promise<ReturnType<InvoiceProvider['emit']> | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* The per-driver charge helper: when `input.invoice` is present, resolve the payer's
|
|
40
|
+
* fiscal data from `input.customer` (falling back to `card.holder`), emit through the
|
|
41
|
+
* configured invoice provider, and attach the result to the payment. One call replaces
|
|
42
|
+
* the ~15-line block that used to be copy-pasted in every driver's `charge()`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function emitInvoiceIfRequested(ctx: EmitInvoiceContext, input: Pick<ChargeInput, 'invoice' | 'customer' | 'card'>, payment: Payment, driver: Pick<PaymentsDriver, 'provider'>): Promise<void>;
|
|
45
|
+
//# sourceMappingURL=emit_invoice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit_invoice.d.ts","sourceRoot":"","sources":["../../../src/invoice/emit_invoice.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,uFAAuF;AACvF,MAAM,WAAW,kBAAkB;IACjC,iFAAiF;IACjF,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,eAAe,CAAC;CAC9C;AAED,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,QAAQ,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,CAAC;IACF,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,OAAO,CAAC,EAAE;QACR,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,kBAAkB,EACvB,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,cAAc,GAAG,SAAS,EACrD,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC,CA6B1D;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,kBAAkB,EACvB,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,UAAU,GAAG,MAAM,CAAC,EACzD,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,GACvC,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { publishInvoiceEmittedDiagnostics } from '../diagnostics.js';
|
|
2
|
+
/**
|
|
3
|
+
* Emit an invoice for a charge when the call asked for one. The `invoice` option on a
|
|
4
|
+
* charge/subscription/checkout resolves the provider by NAME, independent of the payment
|
|
5
|
+
* gateway:
|
|
6
|
+
*
|
|
7
|
+
* - `true` — use the default invoice provider from `config.invoice.providers`.
|
|
8
|
+
* - `'tecnospeed'` — use the named invoice provider (a key of `invoice.providers`).
|
|
9
|
+
* - `{ provider?, ... }` — named provider (or default) with these overrides.
|
|
10
|
+
*
|
|
11
|
+
* Returns `undefined` when the call did not request an invoice.
|
|
12
|
+
*/
|
|
13
|
+
export async function emitInvoice(ctx, option, data) {
|
|
14
|
+
if (option === undefined || option === false)
|
|
15
|
+
return undefined;
|
|
16
|
+
const providerName = typeof option === 'string' ? option : typeof option === 'object' ? option.provider : undefined;
|
|
17
|
+
const provider = ctx.invoice?.(providerName);
|
|
18
|
+
if (!provider) {
|
|
19
|
+
throw new Error('[payments] invoice was requested but no invoice provider is configured. ' +
|
|
20
|
+
'Add `invoice.providers` to config/payments.ts (and an `invoice.default`).');
|
|
21
|
+
}
|
|
22
|
+
const overrides = typeof option === 'object' ? option : {};
|
|
23
|
+
return provider.emit({
|
|
24
|
+
customer: {
|
|
25
|
+
...data.customer,
|
|
26
|
+
...(overrides.customer !== undefined ? overrides.customer : {}),
|
|
27
|
+
},
|
|
28
|
+
amount: data.amount,
|
|
29
|
+
currency: data.currency,
|
|
30
|
+
service: {
|
|
31
|
+
description: 'Payment',
|
|
32
|
+
...(overrides.service !== undefined ? overrides.service : {}),
|
|
33
|
+
},
|
|
34
|
+
...(overrides.tax !== undefined ? { tax: overrides.tax } : {}),
|
|
35
|
+
...(data.payment !== undefined ? { payment: data.payment } : {}),
|
|
36
|
+
...(overrides.metadata !== undefined ? { metadata: overrides.metadata } : {}),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The per-driver charge helper: when `input.invoice` is present, resolve the payer's
|
|
41
|
+
* fiscal data from `input.customer` (falling back to `card.holder`), emit through the
|
|
42
|
+
* configured invoice provider, and attach the result to the payment. One call replaces
|
|
43
|
+
* the ~15-line block that used to be copy-pasted in every driver's `charge()`.
|
|
44
|
+
*/
|
|
45
|
+
export async function emitInvoiceIfRequested(ctx, input, payment, driver) {
|
|
46
|
+
if (input.invoice === undefined || input.invoice === false)
|
|
47
|
+
return;
|
|
48
|
+
const holder = input.card?.holder;
|
|
49
|
+
const taxId = input.customer?.taxId ?? holder?.cpfCnpj ?? '';
|
|
50
|
+
const name = input.customer?.name ?? holder?.name;
|
|
51
|
+
const email = input.customer?.email ?? holder?.email;
|
|
52
|
+
const invoice = await emitInvoice(ctx, input.invoice, {
|
|
53
|
+
customer: {
|
|
54
|
+
taxId,
|
|
55
|
+
...(name !== undefined ? { name } : {}),
|
|
56
|
+
...(email !== undefined ? { email } : {}),
|
|
57
|
+
},
|
|
58
|
+
amount: payment.amount.amount,
|
|
59
|
+
currency: payment.amount.currency,
|
|
60
|
+
payment: { gatewayId: payment.gatewayId, provider: driver.provider },
|
|
61
|
+
});
|
|
62
|
+
if (invoice) {
|
|
63
|
+
payment.invoice = invoice;
|
|
64
|
+
publishInvoiceEmittedDiagnostics({
|
|
65
|
+
gatewayId: invoice.gatewayId,
|
|
66
|
+
provider: invoice.provider,
|
|
67
|
+
...(invoice.number !== undefined ? { number: invoice.number } : {}),
|
|
68
|
+
...(invoice.hostedPdfUrl !== undefined ? { url: invoice.hostedPdfUrl } : {}),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=emit_invoice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit_invoice.js","sourceRoot":"","sources":["../../../src/invoice/emit_invoice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AA6BrE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAuB,EACvB,MAAqD,EACrD,IAAqB;IAErB,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK;QAAE,OAAO,SAAS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AAC;QACZ,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;QAC1B,gCAAgC,CAAC;YAC/B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnE,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC7E,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InvoiceConfig } from '../define_config.js';
|
|
2
|
+
import type { InvoiceProvider } from './invoice_provider.js';
|
|
3
|
+
/** Resolves named invoice providers from config, mirroring the payment providers map. */
|
|
4
|
+
export declare class InvoiceManager {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(providers: Map<string, InvoiceProvider>);
|
|
7
|
+
/** Resolve a provider by name. Falls back to the configured default when `name` is omitted. */
|
|
8
|
+
provider(name?: string): InvoiceProvider;
|
|
9
|
+
}
|
|
10
|
+
/** Build the invoice provider map from config. */
|
|
11
|
+
export declare function resolveInvoiceProviders(config: InvoiceConfig): Promise<Map<string, InvoiceProvider>>;
|
|
12
|
+
//# sourceMappingURL=invoice_manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice_manager.d.ts","sourceRoot":"","sources":["../../../src/invoice/invoice_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,yFAAyF;AACzF,qBAAa,cAAc;;gBAGb,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC;IAInD,+FAA+F;IAC/F,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe;CAqBzC;AAED,kDAAkD;AAClD,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAQvC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Resolves named invoice providers from config, mirroring the payment providers map. */
|
|
2
|
+
export class InvoiceManager {
|
|
3
|
+
#providers;
|
|
4
|
+
constructor(providers) {
|
|
5
|
+
this.#providers = providers;
|
|
6
|
+
}
|
|
7
|
+
/** Resolve a provider by name. Falls back to the configured default when `name` is omitted. */
|
|
8
|
+
provider(name) {
|
|
9
|
+
const resolved = name ?? this.#defaultName;
|
|
10
|
+
const driver = this.#providers.get(resolved);
|
|
11
|
+
if (!driver) {
|
|
12
|
+
throw new Error(`[payments] Invoice provider "${resolved}" is not configured. ` +
|
|
13
|
+
`Available providers: ${[...this.#providers.keys()].join(', ') || '(none)'}.`);
|
|
14
|
+
}
|
|
15
|
+
return driver;
|
|
16
|
+
}
|
|
17
|
+
get #defaultName() {
|
|
18
|
+
const names = [...this.#providers.keys()];
|
|
19
|
+
if (names.length === 0) {
|
|
20
|
+
throw new Error('[payments] No invoice providers configured. Add a provider to invoice.providers in config/payments.ts.');
|
|
21
|
+
}
|
|
22
|
+
return names[0];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Build the invoice provider map from config. */
|
|
26
|
+
export async function resolveInvoiceProviders(config) {
|
|
27
|
+
const factories = config.providers ?? {};
|
|
28
|
+
const ctx = { config: () => config };
|
|
29
|
+
const map = new Map();
|
|
30
|
+
for (const [name, factory] of Object.entries(factories)) {
|
|
31
|
+
map.set(name, await factory(ctx));
|
|
32
|
+
}
|
|
33
|
+
return map;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=invoice_manager.js.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C,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACxD,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Invoice, InvoiceOptions } from '../types.js';
|
|
2
|
+
/** Context handed to invoice provider factories. */
|
|
3
|
+
export interface InvoiceContext {
|
|
4
|
+
config: () => unknown;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The invoice emission provider contract. Gateways that emit invoices natively and
|
|
8
|
+
* dedicated providers (Focus, Tecnospeed, eNotas, PlugNotas) implement this so a charge
|
|
9
|
+
* call with `invoice: true` can emit an invoice no matter which gateway backs the payment.
|
|
10
|
+
*/
|
|
11
|
+
export interface InvoiceProvider {
|
|
12
|
+
readonly provider: string;
|
|
13
|
+
/** Emit an invoice. Returns the issued/pending invoice. */
|
|
14
|
+
emit(input: InvoiceEmitInput): Promise<Invoice>;
|
|
15
|
+
/** Look up an issued invoice by its id at the provider. */
|
|
16
|
+
find(invoiceId: string): Promise<Invoice | null>;
|
|
17
|
+
}
|
|
18
|
+
export interface InvoiceEmitInput {
|
|
19
|
+
/** The billing customer's data (name, taxId, address...). */
|
|
20
|
+
customer: {
|
|
21
|
+
name?: string;
|
|
22
|
+
taxId: string;
|
|
23
|
+
email?: string;
|
|
24
|
+
address?: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
/** Amount in the currency's smallest unit (e.g. cents). */
|
|
27
|
+
amount: number;
|
|
28
|
+
currency: string;
|
|
29
|
+
/** Service details for service invoices. */
|
|
30
|
+
service: {
|
|
31
|
+
description: string;
|
|
32
|
+
/** Service code. */
|
|
33
|
+
code?: string;
|
|
34
|
+
/** Municipal service code. */
|
|
35
|
+
cityServiceCode?: string;
|
|
36
|
+
};
|
|
37
|
+
/** Tax configuration (ISS, etc.). */
|
|
38
|
+
tax?: Record<string, unknown>;
|
|
39
|
+
/** The gateway payment this invoice is attached to, when available. */
|
|
40
|
+
payment?: {
|
|
41
|
+
gatewayId: string;
|
|
42
|
+
provider: string;
|
|
43
|
+
};
|
|
44
|
+
/** Extra provider-specific fields. */
|
|
45
|
+
metadata?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
export type { Invoice, InvoiceOptions };
|
|
48
|
+
//# sourceMappingURL=invoice_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice_provider.d.ts","sourceRoot":"","sources":["../../../src/invoice/invoice_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3D,oDAAoD;AACpD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,OAAO,CAAC;CACvB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,2DAA2D;IAC3D,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhD,2DAA2D;IAC3D,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,gBAAgB;IAC/B,6DAA6D;IAC7D,QAAQ,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,CAAC;IACF,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,CAAC;QACpB,oBAAoB;QACpB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,8BAA8B;QAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,qCAAqC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,uEAAuE;IACvE,OAAO,CAAC,EAAE;QACR,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice_provider.js","sourceRoot":"","sources":["../../../src/invoice/invoice_provider.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Money } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Money helpers shared by the fetch-based drivers.
|
|
4
|
+
*
|
|
5
|
+
* The billing layer and the `PaymentsDriver` contract work in the currency's smallest
|
|
6
|
+
* unit (cents); the BR gateway APIs (Asaas, AbacatePay, Woovi) work in decimal reais.
|
|
7
|
+
* These two conversions are the only place that mapping lives.
|
|
8
|
+
*/
|
|
9
|
+
export declare function toDecimal(amount: Money): number;
|
|
10
|
+
export declare function fromDecimal(value: number): Money;
|
|
11
|
+
//# sourceMappingURL=money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../src/money.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,CAE/C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAEhD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Money helpers shared by the fetch-based drivers.
|
|
3
|
+
*
|
|
4
|
+
* The billing layer and the `PaymentsDriver` contract work in the currency's smallest
|
|
5
|
+
* unit (cents); the BR gateway APIs (Asaas, AbacatePay, Woovi) work in decimal reais.
|
|
6
|
+
* These two conversions are the only place that mapping lives.
|
|
7
|
+
*/
|
|
8
|
+
export function toDecimal(amount) {
|
|
9
|
+
return amount / 100;
|
|
10
|
+
}
|
|
11
|
+
export function fromDecimal(value) {
|
|
12
|
+
return Math.round(value * 100);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=money.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.js","sourceRoot":"","sources":["../../src/money.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,MAAa;IACrC,OAAO,MAAM,GAAG,GAAG,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PaymentsConfig } from './define_config.js';
|
|
2
|
+
import type { PaymentsDriver } from './driver.js';
|
|
3
|
+
import type { InvoiceManager } from './invoice/invoice_manager.js';
|
|
4
|
+
import type { PaymentMethodName } from './types.js';
|
|
5
|
+
export interface PaymentsManagerOptions {
|
|
6
|
+
drivers: Map<string, PaymentsDriver>;
|
|
7
|
+
invoices?: InvoiceManager;
|
|
8
|
+
/** Method → provider name routing (`config.methods`). */
|
|
9
|
+
methods?: Partial<Record<PaymentMethodName, string>>;
|
|
10
|
+
/** Explicit default provider name (`config.default`). */
|
|
11
|
+
defaultName?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class PaymentsManager {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(options: PaymentsManagerOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a driver by payment method (e.g. `'pix'`), by provider name, or by the
|
|
18
|
+
* configured default when nothing is given.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* payments.driver() // default provider
|
|
22
|
+
* payments.driver('pix') // provider routed in config.methods.pix
|
|
23
|
+
* payments.driver('stripe') // provider by name
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
driver(methodOrName?: PaymentMethodName | string): PaymentsDriver;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve an invoice provider by name (falls back to the configured default). Throws
|
|
29
|
+
* when no invoice provider is configured — a charge with `invoice: true` needs one.
|
|
30
|
+
*/
|
|
31
|
+
invoice(name?: string): import("./define_config.js").InvoiceProvider;
|
|
32
|
+
/**
|
|
33
|
+
* Check a driver capability before delegating, so callers discover the limitation
|
|
34
|
+
* early (e.g. Woovi/OpenPix has no refunds) instead of at the gateway.
|
|
35
|
+
*/
|
|
36
|
+
assertCapability(driver: PaymentsDriver, capability: 'refunds' | 'invoices' | 'subscriptions'): void;
|
|
37
|
+
}
|
|
38
|
+
/** Build the driver map from config, resolving every configured factory. */
|
|
39
|
+
export declare function resolveDrivers(config: PaymentsConfig, invoices?: InvoiceManager): Promise<Map<string, PaymentsDriver>>;
|
|
40
|
+
//# sourceMappingURL=payments_manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments_manager.d.ts","sourceRoot":"","sources":["../../src/payments_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACrC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,yDAAyD;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC;IACrD,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,eAAe;;gBAMd,OAAO,EAAE,sBAAsB;IAW3C;;;;;;;;;OASG;IACH,MAAM,CAAC,YAAY,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,cAAc;IAqBjE;;;OAGG;IACH,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM;IASrB;;;OAGG;IACH,gBAAgB,CACd,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,SAAS,GAAG,UAAU,GAAG,eAAe,GACnD,IAAI;CA6BR;AAED,4EAA4E;AAC5E,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,EACtB,QAAQ,CAAC,EAAE,cAAc,GACxB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAatC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export class PaymentsManager {
|
|
2
|
+
#drivers;
|
|
3
|
+
#invoices;
|
|
4
|
+
#methods;
|
|
5
|
+
#defaultName;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.#drivers = options.drivers;
|
|
8
|
+
this.#invoices = options.invoices;
|
|
9
|
+
this.#methods = options.methods ?? {};
|
|
10
|
+
const names = [...this.#drivers.keys()];
|
|
11
|
+
if (names.length === 0) {
|
|
12
|
+
throw new Error('[payments] No drivers configured. Add a provider to config/payments.ts.');
|
|
13
|
+
}
|
|
14
|
+
this.#defaultName = options.defaultName ?? names[0];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a driver by payment method (e.g. `'pix'`), by provider name, or by the
|
|
18
|
+
* configured default when nothing is given.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* payments.driver() // default provider
|
|
22
|
+
* payments.driver('pix') // provider routed in config.methods.pix
|
|
23
|
+
* payments.driver('stripe') // provider by name
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
driver(methodOrName) {
|
|
27
|
+
const { name: resolved, method } = this.#resolveName(methodOrName);
|
|
28
|
+
const driver = this.#drivers.get(resolved);
|
|
29
|
+
if (!driver) {
|
|
30
|
+
throw new Error(`[payments] Driver "${resolved}" is not configured. ` +
|
|
31
|
+
`Available drivers: ${[...this.#drivers.keys()].join(', ') || '(none)'}.`);
|
|
32
|
+
}
|
|
33
|
+
// When the call routed a payment method, make sure the provider actually supports it —
|
|
34
|
+
// e.g. routing credit_card to a Pix-only gateway (AbacatePay, Woovi) is a config error.
|
|
35
|
+
if (method !== undefined && !driver.supportedMethods.includes(method)) {
|
|
36
|
+
throw new Error(`[payments] Driver "${resolved}" does not support payment method "${method}". ` +
|
|
37
|
+
`Supported methods: ${[...driver.supportedMethods].join(', ')}. ` +
|
|
38
|
+
`Route "${method}" to a different provider in config.methods.`);
|
|
39
|
+
}
|
|
40
|
+
return driver;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve an invoice provider by name (falls back to the configured default). Throws
|
|
44
|
+
* when no invoice provider is configured — a charge with `invoice: true` needs one.
|
|
45
|
+
*/
|
|
46
|
+
invoice(name) {
|
|
47
|
+
if (!this.#invoices) {
|
|
48
|
+
throw new Error('[payments] No invoice providers configured. Add `invoice.providers` to config/payments.ts.');
|
|
49
|
+
}
|
|
50
|
+
return this.#invoices.provider(name);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check a driver capability before delegating, so callers discover the limitation
|
|
54
|
+
* early (e.g. Woovi/OpenPix has no refunds) instead of at the gateway.
|
|
55
|
+
*/
|
|
56
|
+
assertCapability(driver, capability) {
|
|
57
|
+
if (driver.capabilities?.[capability] === false ||
|
|
58
|
+
driver.capabilities?.[capability] === undefined) {
|
|
59
|
+
throw new Error(`[payments] Driver "${driver.provider}" does not support ${capability}. ` +
|
|
60
|
+
`Supported capabilities: ${Object.keys(driver.capabilities ?? {}).join(', ') || '(none)'}.`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
#resolveName(methodOrName) {
|
|
64
|
+
if (methodOrName === undefined)
|
|
65
|
+
return { name: this.#defaultName };
|
|
66
|
+
// If it names a configured provider, use it directly.
|
|
67
|
+
if (this.#drivers.has(methodOrName))
|
|
68
|
+
return { name: methodOrName };
|
|
69
|
+
// Otherwise treat it as a payment method and route via config.methods.
|
|
70
|
+
const method = methodOrName;
|
|
71
|
+
const routed = this.#methods[method];
|
|
72
|
+
if (routed !== undefined)
|
|
73
|
+
return { name: routed, method };
|
|
74
|
+
// Unknown method/name: throw a helpful error pointing at the routing config.
|
|
75
|
+
const providers = [...this.#drivers.keys()].join(', ') || '(none)';
|
|
76
|
+
throw new Error(`[payments] "${methodOrName}" is neither a configured provider nor a method routed in config.methods. Configured providers: ${providers}. Known methods: pix, credit_card, debit_card, boleto, undefined.`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Build the driver map from config, resolving every configured factory. */
|
|
80
|
+
export async function resolveDrivers(config, invoices) {
|
|
81
|
+
const factories = config.providers ?? {};
|
|
82
|
+
const ctx = {
|
|
83
|
+
config: () => config,
|
|
84
|
+
// Hand drivers the invoice resolver so a charge with `invoice: true|'name'` can emit
|
|
85
|
+
// a fiscal note through the configured invoice provider — independent of the gateway.
|
|
86
|
+
...(invoices !== undefined ? { invoice: (name) => invoices.provider(name) } : {}),
|
|
87
|
+
};
|
|
88
|
+
const map = new Map();
|
|
89
|
+
for (const [name, factory] of Object.entries(factories)) {
|
|
90
|
+
map.set(name, await factory(ctx));
|
|
91
|
+
}
|
|
92
|
+
return map;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=payments_manager.js.map
|
|
@@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
/** Set by the provider once the manager is built. */
|
|
4
|
+
export declare function setPayments(manager: PaymentsManager): void;
|
|
5
|
+
export default getPayments;
|
|
6
|
+
//# sourceMappingURL=main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/services/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAQzD,wBAAgB,WAAW,IAAI,eAAe,CAO7C;AAED,qDAAqD;AACrD,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAE1D;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy singleton accessor for the payments manager. Set by the provider when it builds
|
|
3
|
+
* the manager; importing this module never triggers the app boot (media/authkit pattern).
|
|
4
|
+
*/
|
|
5
|
+
let payments;
|
|
6
|
+
export function getPayments() {
|
|
7
|
+
if (!payments) {
|
|
8
|
+
throw new Error('[payments] PaymentsManager is not ready yet. Make sure the PaymentsProvider is registered and the app has booted.');
|
|
9
|
+
}
|
|
10
|
+
return payments;
|
|
11
|
+
}
|
|
12
|
+
/** Set by the provider once the manager is built. */
|
|
13
|
+
export function setPayments(manager) {
|
|
14
|
+
payments = manager;
|
|
15
|
+
}
|
|
16
|
+
export default getPayments;
|
|
17
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/services/main.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,IAAI,QAAqC,CAAC;AAE1C,MAAM,UAAU,WAAW;IACzB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,mHAAmH,CACpH,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,WAAW,CAAC,OAAwB;IAClD,QAAQ,GAAG,OAAO,CAAC;AACrB,CAAC;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/telescope/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/telescope/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { WatcherContext } from './telescope-sdk.js';
|
|
2
|
+
/**
|
|
3
|
+
* A payments-specific Telescope watcher: records a typed `payments` entry for every
|
|
4
|
+
* milestone `agora:payments:*` event the library emits (charges, refunds,
|
|
5
|
+
* subscriptions, invoice emission, webhook lifecycle), flattening the event's payload
|
|
6
|
+
* into structured content rather than storing the raw envelope like the generic
|
|
7
|
+
* diagnostics bridge does.
|
|
8
|
+
*
|
|
9
|
+
* Zero coupling: payments publishes via the structural `@adonis-agora/diagnostics`
|
|
10
|
+
* emit slot; this subscribes to the same `node:diagnostics_channel` channels — neither
|
|
11
|
+
* package is imported.
|
|
12
|
+
*
|
|
13
|
+
* De-dup: `register()` CLAIMS every recorded channel via
|
|
14
|
+
* {@link claimPaymentsDiagnostics} (the reference-counted
|
|
15
|
+
* `Symbol.for('@agora/diagnostics:claims')` registry), so the generic
|
|
16
|
+
* `DiagnosticsWatcher` (its `recordClaimed: false` default) skips them and no event is
|
|
17
|
+
* recorded twice. `dispose()` releases the claim and detaches every subscription.
|
|
18
|
+
*/
|
|
19
|
+
export declare class PaymentsWatcher {
|
|
20
|
+
readonly type = "payments";
|
|
21
|
+
private readonly disposers;
|
|
22
|
+
/** Claim the recorded channels and start recording a typed `payments` entry per event. */
|
|
23
|
+
register(ctx: WatcherContext): void;
|
|
24
|
+
/** Release the channel claims and detach every subscription (e.g. on shutdown). */
|
|
25
|
+
dispose(): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=payments_watcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments_watcher.d.ts","sourceRoot":"","sources":["../../../src/telescope/payments_watcher.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAkBzD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,eAAe;IAC1B,QAAQ,CAAC,IAAI,cAAc;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyB;IAEnD,0FAA0F;IAC1F,QAAQ,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI;IAuBnC,mFAAmF;IACnF,OAAO,IAAI,IAAI;CAGhB"}
|