@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,339 @@
|
|
|
1
|
+
import { createClient } from '@woovi/node-sdk';
|
|
2
|
+
import { publishPaymentDiagnostics, publishSubscriptionDiagnostics } from '../diagnostics.js';
|
|
3
|
+
import { headerValue } from '../http.js';
|
|
4
|
+
import { emitInvoiceIfRequested } from '../invoice/emit_invoice.js';
|
|
5
|
+
import { fromDecimal, toDecimal } from '../money.js';
|
|
6
|
+
import { verifyHmacSignature, verifyRsaSha256Signature } from '../webhook_security.js';
|
|
7
|
+
export class WooviDriver {
|
|
8
|
+
provider = 'woovi';
|
|
9
|
+
// Woovi/OpenPix is Pix-only and has no refunds or invoice concept.
|
|
10
|
+
supportedMethods = ['pix', 'undefined'];
|
|
11
|
+
capabilities = { subscriptions: true };
|
|
12
|
+
#client;
|
|
13
|
+
#invoiceCtx;
|
|
14
|
+
/** HMAC secret of the specific webhook config (dashboard → API/Plugins). */
|
|
15
|
+
#webhookSecret;
|
|
16
|
+
/** Woovi account public key, used to verify `x-webhook-signature` (recommended). */
|
|
17
|
+
#webhookPublicKey;
|
|
18
|
+
#appId;
|
|
19
|
+
constructor(ctx, config = {}) {
|
|
20
|
+
this.#invoiceCtx = ctx;
|
|
21
|
+
const appId = config.appId ?? process.env.WOOVI_APP_ID;
|
|
22
|
+
if (!appId) {
|
|
23
|
+
throw new Error('[payments] Woovi driver requires an app id. Set `WOOVI_APP_ID` env or pass `appId` to `payments.woovi()`.');
|
|
24
|
+
}
|
|
25
|
+
this.#appId = appId;
|
|
26
|
+
this.#webhookSecret = config.webhookSecret ?? process.env.WOOVI_WEBHOOK_SECRET;
|
|
27
|
+
this.#webhookPublicKey = config.webhookPublicKey ?? process.env.WOOVI_WEBHOOK_PUBLIC_KEY;
|
|
28
|
+
// Lazy import happens in the factory (see `define_config.ts`), so the SDK module is
|
|
29
|
+
// only loaded when this driver is actually selected.
|
|
30
|
+
this.#client = createClient({ appId });
|
|
31
|
+
}
|
|
32
|
+
// ── Customers ────────────────────────────────────────────────────────────────────────
|
|
33
|
+
async createCustomer(input) {
|
|
34
|
+
const data = await this.#client.customer.create({
|
|
35
|
+
name: input.name ?? input.email ?? 'Customer',
|
|
36
|
+
...(input.email !== undefined ? { email: input.email } : {}),
|
|
37
|
+
...(input.taxId !== undefined ? { taxID: { taxID: input.taxId, type: 'BR:CPF' } } : {}),
|
|
38
|
+
});
|
|
39
|
+
return this.#mapCustomer(data);
|
|
40
|
+
}
|
|
41
|
+
async findCustomer(customerId) {
|
|
42
|
+
try {
|
|
43
|
+
const data = await this.#client.customer.get({ id: customerId });
|
|
44
|
+
return this.#mapCustomer(data);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async updateCustomer(customerId, input) {
|
|
51
|
+
// OpenPix customers are immutable; return the existing customer best-effort.
|
|
52
|
+
const data = await this.#client.customer.create({
|
|
53
|
+
correlationID: customerId,
|
|
54
|
+
name: input.name ?? 'Customer',
|
|
55
|
+
...(input.email !== undefined ? { email: input.email } : {}),
|
|
56
|
+
});
|
|
57
|
+
return this.#mapCustomer(data);
|
|
58
|
+
}
|
|
59
|
+
// ── Payments ─────────────────────────────────────────────────────────────────────────
|
|
60
|
+
async charge(input) {
|
|
61
|
+
const data = await this.#client.charge.create({
|
|
62
|
+
// Woovi's `correlationID` is the app's own reference — the routing key webhook
|
|
63
|
+
// handlers read. Prefer the explicit `externalReference`, fall back to the
|
|
64
|
+
// idempotency key (legacy behavior).
|
|
65
|
+
correlationID: input.externalReference ?? input.idempotencyKey ?? `charge_${Date.now()}`,
|
|
66
|
+
value: toDecimal(input.amount),
|
|
67
|
+
...(input.description !== undefined ? { comment: input.description } : {}),
|
|
68
|
+
...(input.customerId !== undefined ? { customer: input.customerId } : {}),
|
|
69
|
+
});
|
|
70
|
+
const payment = this.#mapPayment(data);
|
|
71
|
+
await emitInvoiceIfRequested(this.#invoiceCtx, input, payment, this);
|
|
72
|
+
publishPaymentDiagnostics(payment);
|
|
73
|
+
return payment;
|
|
74
|
+
}
|
|
75
|
+
async findPayment(gatewayId) {
|
|
76
|
+
try {
|
|
77
|
+
const data = await this.#client.charge.get({ id: gatewayId });
|
|
78
|
+
return this.#mapPayment(data);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async refund(_paymentGatewayId, _amount) {
|
|
85
|
+
throw new Error('[payments] Woovi/OpenPix does not support refunds via API.');
|
|
86
|
+
}
|
|
87
|
+
// ── Subaccounts (Woovi for Platforms) ────────────────────────────────────────────────
|
|
88
|
+
/** Create a subaccount (marketplace receiver) keyed by a Pix key. */
|
|
89
|
+
async createSubAccount(input) {
|
|
90
|
+
const data = await this.#client.subAccount.create(input);
|
|
91
|
+
return this.#mapSubAccount(data.SubAccount);
|
|
92
|
+
}
|
|
93
|
+
/** Find a subaccount by its id. */
|
|
94
|
+
async findSubAccount(id) {
|
|
95
|
+
try {
|
|
96
|
+
const data = await this.#client.subAccount.get({ id });
|
|
97
|
+
return this.#mapSubAccount(data.SubAccount);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** List every subaccount. */
|
|
104
|
+
async listSubAccounts() {
|
|
105
|
+
const data = await this.#client.subAccount.list();
|
|
106
|
+
return data.subAccounts.map((s) => this.#mapSubAccount(s));
|
|
107
|
+
}
|
|
108
|
+
#mapSubAccount(data) {
|
|
109
|
+
return {
|
|
110
|
+
name: data.name ?? '',
|
|
111
|
+
pixKey: data.pixKey ?? '',
|
|
112
|
+
balance: Number(data.balance ?? 0),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// ── Checkout ─────────────────────────────────────────────────────────────────────────
|
|
116
|
+
async createCheckout(input) {
|
|
117
|
+
const data = await this.#client.charge.create({
|
|
118
|
+
correlationID: input.idempotencyKey ?? `checkout_${Date.now()}`,
|
|
119
|
+
value: toDecimal(input.amount),
|
|
120
|
+
...(input.description !== undefined ? { comment: input.description } : {}),
|
|
121
|
+
});
|
|
122
|
+
const charge = data;
|
|
123
|
+
const brCode = charge.pixQrCode?.brCode ?? charge.brCode?.brCode ?? '';
|
|
124
|
+
return {
|
|
125
|
+
id: String(charge.id ?? ''),
|
|
126
|
+
gatewayId: String(charge.id ?? ''),
|
|
127
|
+
provider: this.provider,
|
|
128
|
+
url: '',
|
|
129
|
+
status: 'open',
|
|
130
|
+
amount: { amount: input.amount, currency: 'brl' },
|
|
131
|
+
...(brCode !== '' ? { pixCopiaECola: brCode } : {}),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// ── Subscriptions (Pix Automático) ──────────────────────────────────────────────────
|
|
135
|
+
async createSubscription(input) {
|
|
136
|
+
// Woovi creates subscriptions with an inline customer (no customer-id flow).
|
|
137
|
+
const customer = await this.#resolveSubscriptionCustomer(input);
|
|
138
|
+
const body = {
|
|
139
|
+
customer,
|
|
140
|
+
value: toDecimal(input.amount ?? 0),
|
|
141
|
+
dayGenerateCharge: this.#dayOfMonth(input.startDate) ?? 1,
|
|
142
|
+
...(input.cycle !== undefined ? { frequency: this.#mapFrequency(input.cycle) } : {}),
|
|
143
|
+
// Pix Automático journey 3 (pay-on-approval): `DYNAMIC` generates each charge and
|
|
144
|
+
// asks the payer to approve it. Override via `metadata.chargeType` if needed.
|
|
145
|
+
...(input.metadata?.chargeType !== undefined
|
|
146
|
+
? { chargeType: input.metadata.chargeType }
|
|
147
|
+
: { chargeType: 'DYNAMIC' }),
|
|
148
|
+
...(input.metadata?.dayDue !== undefined ? { dayDue: input.metadata.dayDue } : {}),
|
|
149
|
+
};
|
|
150
|
+
const data = await this.#client.subscription.create(body);
|
|
151
|
+
// The SDK wraps the created subscription in `{ subscription }` (get/find return it bare).
|
|
152
|
+
const subscription = this.#mapSubscription(data.subscription ??
|
|
153
|
+
data);
|
|
154
|
+
publishSubscriptionDiagnostics(subscription, 'subscription.created');
|
|
155
|
+
return subscription;
|
|
156
|
+
}
|
|
157
|
+
/** Woovi's inline customer: `input.customer`, else the gateway customer (needs name+taxId). */
|
|
158
|
+
async #resolveSubscriptionCustomer(input) {
|
|
159
|
+
if (input.customer?.name && input.customer.taxId) {
|
|
160
|
+
return {
|
|
161
|
+
name: input.customer.name,
|
|
162
|
+
email: input.customer.email ?? '',
|
|
163
|
+
taxID: input.customer.taxId.replace(/\D/g, ''),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (input.customerId) {
|
|
167
|
+
const customer = await this.findCustomer(input.customerId);
|
|
168
|
+
if (customer?.name && customer.taxId) {
|
|
169
|
+
return {
|
|
170
|
+
name: customer.name,
|
|
171
|
+
email: customer.email ?? '',
|
|
172
|
+
taxID: customer.taxId.replace(/\D/g, ''),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
throw new Error('[payments] Woovi subscription needs the payer name + taxId — pass `customer` on the subscription, or create the gateway customer with them.');
|
|
177
|
+
}
|
|
178
|
+
#mapFrequency(cycle) {
|
|
179
|
+
switch (cycle) {
|
|
180
|
+
case 'WEEKLY':
|
|
181
|
+
return 'WEEKLY';
|
|
182
|
+
case 'MONTHLY':
|
|
183
|
+
return 'MONTHLY';
|
|
184
|
+
case 'QUARTERLY':
|
|
185
|
+
return 'TRIMONTHLY';
|
|
186
|
+
case 'SEMIANNUALLY':
|
|
187
|
+
return 'SEMIANNUALY';
|
|
188
|
+
case 'YEARLY':
|
|
189
|
+
return 'ANNUALY';
|
|
190
|
+
default:
|
|
191
|
+
return 'MONTHLY';
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async cancelSubscription(subscriptionGatewayId, _options) {
|
|
195
|
+
const data = await this.#client.subscription.get({ id: subscriptionGatewayId });
|
|
196
|
+
const subscription = this.#mapSubscription({ ...data, status: 'INACTIVE' });
|
|
197
|
+
publishSubscriptionDiagnostics(subscription, 'subscription.canceled');
|
|
198
|
+
return subscription;
|
|
199
|
+
}
|
|
200
|
+
async findSubscription(gatewayId) {
|
|
201
|
+
try {
|
|
202
|
+
const data = await this.#client.subscription.get({ id: gatewayId });
|
|
203
|
+
return this.#mapSubscription(data);
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async updateSubscription(subscriptionGatewayId, input) {
|
|
210
|
+
// OpenPix subscriptions are immutable — best-effort: fetch and return with the new
|
|
211
|
+
// amount/description applied locally (the change takes effect on the next cycle by
|
|
212
|
+
// recreating the subscription in a real integration).
|
|
213
|
+
const data = await this.#client.subscription.get({ id: subscriptionGatewayId });
|
|
214
|
+
const updated = {
|
|
215
|
+
...data,
|
|
216
|
+
...(input.amount !== undefined ? { value: toDecimal(input.amount) } : {}),
|
|
217
|
+
...(input.description !== undefined ? { comment: input.description } : {}),
|
|
218
|
+
};
|
|
219
|
+
return this.#mapSubscription(updated);
|
|
220
|
+
}
|
|
221
|
+
// ── Invoices ─────────────────────────────────────────────────────────────────────────
|
|
222
|
+
async listInvoices(_customerId) {
|
|
223
|
+
// OpenPix has no invoice concept — charges are the billing record.
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
// ── Webhooks ─────────────────────────────────────────────────────────────────────────
|
|
227
|
+
parseWebhook(rawBody, headers) {
|
|
228
|
+
// Woovi signs webhooks two ways: the recommended `x-webhook-signature`
|
|
229
|
+
// (RSA-SHA256 with Woovi's account public key — validates the SENDER) and the
|
|
230
|
+
// per-webhook HMAC (`X-OpenPix-Signature`, deprecated but validates YOUR webhook
|
|
231
|
+
// config). Whichever credential is configured is enforced strictly; without one
|
|
232
|
+
// only the app id header (when set) guards the endpoint.
|
|
233
|
+
if (this.#webhookPublicKey !== undefined) {
|
|
234
|
+
const signature = headerValue(headers, 'x-webhook-signature');
|
|
235
|
+
if (!verifyRsaSha256Signature(rawBody, signature, this.#webhookPublicKey)) {
|
|
236
|
+
throw new Error('[payments] Invalid or missing Woovi webhook signature.');
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else if (this.#webhookSecret !== undefined) {
|
|
240
|
+
const hmac = headerValue(headers, 'x-openpix-signature');
|
|
241
|
+
if (!verifyHmacSignature(rawBody, hmac, this.#webhookSecret, 'sha1')) {
|
|
242
|
+
throw new Error('[payments] Invalid or missing Woovi webhook HMAC.');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const appId = headerValue(headers, 'app_id') ?? headerValue(headers, 'x-woovi-app-id');
|
|
246
|
+
if (this.#appId && appId && appId !== this.#appId) {
|
|
247
|
+
throw new Error('[payments] Invalid Woovi webhook app id.');
|
|
248
|
+
}
|
|
249
|
+
const payload = JSON.parse(rawBody);
|
|
250
|
+
const event = String(payload.event ?? 'unknown');
|
|
251
|
+
return {
|
|
252
|
+
id: String(payload.id ?? payload.globalID ?? `${event}-${Math.random()}`),
|
|
253
|
+
provider: this.provider,
|
|
254
|
+
type: this.#mapWebhookType(event),
|
|
255
|
+
createdAt: new Date().toISOString(),
|
|
256
|
+
data: payload,
|
|
257
|
+
raw: payload,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
// ── Mappers ──────────────────────────────────────────────────────────────────────────
|
|
261
|
+
#mapCustomer(data) {
|
|
262
|
+
const taxId = data.taxID?.taxID;
|
|
263
|
+
return {
|
|
264
|
+
id: String(data.id ?? data.correlationID ?? ''),
|
|
265
|
+
...(typeof data.name === 'string' ? { name: data.name } : {}),
|
|
266
|
+
...(typeof data.email === 'string' ? { email: data.email } : {}),
|
|
267
|
+
...(taxId !== undefined ? { taxId } : {}),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
#mapPayment(data) {
|
|
271
|
+
const value = typeof data.value === 'number' ? data.value : 0;
|
|
272
|
+
const status = String(data.status ?? 'ACTIVE').toUpperCase();
|
|
273
|
+
const pixQrCode = data.pixQrCode?.brCode ??
|
|
274
|
+
data.brCode?.brCode;
|
|
275
|
+
return {
|
|
276
|
+
id: String(data.id ?? data.globalID ?? ''),
|
|
277
|
+
gatewayId: String(data.globalID ?? data.id ?? ''),
|
|
278
|
+
provider: this.provider,
|
|
279
|
+
amount: { amount: fromDecimal(value), currency: 'brl' },
|
|
280
|
+
status: status === 'COMPLETED' || status === 'PAID'
|
|
281
|
+
? 'paid'
|
|
282
|
+
: status === 'EXPIRED' || status === 'CANCELED' || status === 'REJECTED'
|
|
283
|
+
? 'canceled'
|
|
284
|
+
: 'pending',
|
|
285
|
+
...(pixQrCode !== undefined ? { pixCopiaECola: pixQrCode } : {}),
|
|
286
|
+
...(typeof data.correlationID === 'string' ? { customerId: data.correlationID } : {}),
|
|
287
|
+
payload: data,
|
|
288
|
+
createdAt: typeof data.createdAt === 'string' ? data.createdAt : new Date().toISOString(),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
#mapSubscription(data) {
|
|
292
|
+
const value = typeof data.value === 'number' ? data.value : 0;
|
|
293
|
+
const status = String(data.status ?? 'ACTIVE').toUpperCase();
|
|
294
|
+
const globalId = String(data.globalID ?? data.id ?? '');
|
|
295
|
+
return {
|
|
296
|
+
id: globalId,
|
|
297
|
+
gatewayId: globalId,
|
|
298
|
+
provider: this.provider,
|
|
299
|
+
customerId: String(data.correlationID ?? ''),
|
|
300
|
+
status: status === 'ACTIVE' || status === 'APPROVED'
|
|
301
|
+
? 'active'
|
|
302
|
+
: status === 'INACTIVE' || status === 'CANCELED'
|
|
303
|
+
? 'canceled'
|
|
304
|
+
: status === 'REJECTED'
|
|
305
|
+
? 'past_due'
|
|
306
|
+
: 'trialing',
|
|
307
|
+
planId: String(data.pixRecurring?.recurrencyId ?? ''),
|
|
308
|
+
amount: { amount: fromDecimal(value), currency: 'brl' },
|
|
309
|
+
payload: data,
|
|
310
|
+
createdAt: typeof data.createdAt === 'string' ? data.createdAt : new Date().toISOString(),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
#mapWebhookType(event) {
|
|
314
|
+
switch (event) {
|
|
315
|
+
case 'PIX_AUTOMATIC_APPROVED':
|
|
316
|
+
return 'subscription.created';
|
|
317
|
+
case 'PIX_AUTOMATIC_REJECTED':
|
|
318
|
+
return 'subscription.canceled';
|
|
319
|
+
case 'PIX_AUTOMATIC_COBR_COMPLETED':
|
|
320
|
+
return 'payment.succeeded';
|
|
321
|
+
case 'PIX_AUTOMATIC_COBR_REJECTED':
|
|
322
|
+
case 'PIX_AUTOMATIC_COBR_TRY_REJECTED':
|
|
323
|
+
return 'payment.failed';
|
|
324
|
+
case 'CHARGE_COMPLETED':
|
|
325
|
+
return 'payment.succeeded';
|
|
326
|
+
case 'CHARGE_EXPIRED':
|
|
327
|
+
return 'payment.failed';
|
|
328
|
+
default:
|
|
329
|
+
return event.toLowerCase();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
#dayOfMonth(date) {
|
|
333
|
+
if (!date)
|
|
334
|
+
return undefined;
|
|
335
|
+
const day = new Date(date).getDate();
|
|
336
|
+
return Number.isNaN(day) ? undefined : day;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=woovi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"woovi.js","sourceRoot":"","sources":["../../../src/drivers/woovi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AAU9F,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAWrD,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAcvF,MAAM,OAAO,WAAW;IACb,QAAQ,GAAG,OAAO,CAAC;IAC5B,mEAAmE;IAC1D,gBAAgB,GAAG,CAAC,KAAK,EAAE,WAAW,CAAU,CAAC;IACjD,YAAY,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IAEhD,OAAO,CAkBL;IAEF,WAAW,CAAqB;IAChC,4EAA4E;IAC5E,cAAc,CAAqB;IACnC,oFAAoF;IACpF,iBAAiB,CAAqB;IACtC,MAAM,CAAS;IAEf,YAAY,GAAuB,EAAE,SAA4B,EAAE;QACjE,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC;QACvB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,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,WAAW,EAAE;SAC1F,CAAC;IACJ,CAAC;IAED,eAAe,CAAC,KAAa;QAC3B,QAAQ,KAAK,EAAE,CAAC;YACd,KAAK,wBAAwB;gBAC3B,OAAO,sBAAsB,CAAC;YAChC,KAAK,wBAAwB;gBAC3B,OAAO,uBAAuB,CAAC;YACjC,KAAK,8BAA8B;gBACjC,OAAO,mBAAmB,CAAC;YAC7B,KAAK,6BAA6B,CAAC;YACnC,KAAK,iCAAiC;gBACpC,OAAO,gBAAgB,CAAC;YAC1B,KAAK,kBAAkB;gBACrB,OAAO,mBAAmB,CAAC;YAC7B,KAAK,gBAAgB;gBACnB,OAAO,gBAAgB,CAAC;YAC1B;gBACE,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAAa;QACvB,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QACrC,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CreateCustomerInput, PaymentsDriver } from './driver.js';
|
|
2
|
+
import type { Customer } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Get-or-create a gateway customer: when the app already stores a gateway customer id,
|
|
5
|
+
* return it as-is; otherwise create the customer at the gateway and return the created
|
|
6
|
+
* record (so the caller persists the new id).
|
|
7
|
+
*
|
|
8
|
+
* The app owns the mapping between its users and gateway customer ids — this helper only
|
|
9
|
+
* does the "reuse or create" branch every payments flow needs:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const customer = await ensureCustomer(driver, user.asaasCustomerId, {
|
|
13
|
+
* name: user.fullName,
|
|
14
|
+
* email: user.email,
|
|
15
|
+
* taxId: user.cpfCnpj ?? undefined,
|
|
16
|
+
* metadata: { phone: user.phone },
|
|
17
|
+
* })
|
|
18
|
+
* user.asaasCustomerId = customer.id
|
|
19
|
+
* await user.save()
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensureCustomer(driver: PaymentsDriver, existingId: string | null | undefined, input: CreateCustomerInput): Promise<Customer>;
|
|
23
|
+
//# sourceMappingURL=ensure_customer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure_customer.d.ts","sourceRoot":"","sources":["../../src/ensure_customer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACrC,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,QAAQ,CAAC,CAGnB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get-or-create a gateway customer: when the app already stores a gateway customer id,
|
|
3
|
+
* return it as-is; otherwise create the customer at the gateway and return the created
|
|
4
|
+
* record (so the caller persists the new id).
|
|
5
|
+
*
|
|
6
|
+
* The app owns the mapping between its users and gateway customer ids — this helper only
|
|
7
|
+
* does the "reuse or create" branch every payments flow needs:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const customer = await ensureCustomer(driver, user.asaasCustomerId, {
|
|
11
|
+
* name: user.fullName,
|
|
12
|
+
* email: user.email,
|
|
13
|
+
* taxId: user.cpfCnpj ?? undefined,
|
|
14
|
+
* metadata: { phone: user.phone },
|
|
15
|
+
* })
|
|
16
|
+
* user.asaasCustomerId = customer.id
|
|
17
|
+
* await user.save()
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export async function ensureCustomer(driver, existingId, input) {
|
|
21
|
+
if (existingId)
|
|
22
|
+
return { id: existingId };
|
|
23
|
+
return driver.createCustomer(input);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ensure_customer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure_customer.js","sourceRoot":"","sources":["../../src/ensure_customer.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAsB,EACtB,UAAqC,EACrC,KAA0B;IAE1B,IAAI,UAAU;QAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC;IAC1C,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { IndexGenerator } from '@adonisjs/assembler/index_generator';
|
|
2
|
+
/**
|
|
3
|
+
* Where the generated webhook-handlers barrel is written, relative to the app root. The
|
|
4
|
+
* payments provider imports THIS path at boot (build-time codegen) instead of scanning
|
|
5
|
+
* `app/payment_handlers` with `readdir` at runtime. Kept in sync with the provider.
|
|
6
|
+
*/
|
|
7
|
+
export declare const GENERATED_WEBHOOK_HANDLERS_OUTPUT = ".adonisjs/payments/webhook_handlers.ts";
|
|
8
|
+
/**
|
|
9
|
+
* Options for {@link webhookHandlersHook} — mirror the relevant `IndexGenerator.add`
|
|
10
|
+
* knobs so an app can point the generator at a non-default handlers directory or import
|
|
11
|
+
* alias.
|
|
12
|
+
*/
|
|
13
|
+
export interface WebhookHandlersHookOptions {
|
|
14
|
+
/** Directory the generator scans for handler modules, relative to the app root. Default `app/payment_handlers`. */
|
|
15
|
+
source?: string;
|
|
16
|
+
/** Import alias the generated barrel uses for each handler module. Default `#payment_handlers`. */
|
|
17
|
+
importAlias?: string;
|
|
18
|
+
/** Output path for the generated barrel, relative to the app root. Default `.adonisjs/payments/webhook_handlers.ts`. */
|
|
19
|
+
output?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* An AdonisJS **Assembler `init` hook** that generates a typed barrel of the app's
|
|
23
|
+
* `app/payment_handlers/` directory at build/dev time — exactly how the durable package
|
|
24
|
+
* generates `app/workflows` and `@adonisjs/core` generates the controllers/events
|
|
25
|
+
* barrels (`indexEntities`). The build-time barrel replaces the provider's runtime
|
|
26
|
+
* `readdir` scan; the file watcher re-runs the generator whenever a handler file
|
|
27
|
+
* changes.
|
|
28
|
+
*
|
|
29
|
+
* The generated file is a lazy barrel — `export const webhookHandlers = { Name: () =>
|
|
30
|
+
* import('#payment_handlers/…') }` — which the payments provider imports at boot and
|
|
31
|
+
* registers alongside `config.billing.handlers`.
|
|
32
|
+
*
|
|
33
|
+
* Register it in `adonisrc.ts`:
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* export default defineConfig({
|
|
37
|
+
* hooks: {
|
|
38
|
+
* init: [() => import('@adonis-agora/payments/hooks/webhook_handlers')],
|
|
39
|
+
* },
|
|
40
|
+
* })
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function webhookHandlersHook(options?: WebhookHandlersHookOptions): (parent: unknown, hooksManager: unknown, indexGenerator: IndexGenerator) => void;
|
|
44
|
+
/** The default export is the hook itself, so `() => import('@adonis-agora/payments/hooks/webhook_handlers')`
|
|
45
|
+
* in `adonisrc.ts` resolves to a ready hook (the assembler calls it). Annotated
|
|
46
|
+
* explicitly so the declaration emit stays portable (same as collaboration's
|
|
47
|
+
* `codegen_init`). */
|
|
48
|
+
declare const _default: (parent: unknown, hooksManager: unknown, indexGenerator: IndexGenerator) => void;
|
|
49
|
+
export default _default;
|
|
50
|
+
//# sourceMappingURL=webhook_handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook_handlers.d.ts","sourceRoot":"","sources":["../../../src/hooks/webhook_handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAG1E;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,2CAA2C,CAAC;AAE1F;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IACzC,mHAAmH;IACnH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mGAAmG;IACnG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wHAAwH;IACxH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,KAAK,IAAI,CA0BlF;AAED;;;uBAGuB;wBACiB,CACtC,MAAM,EAAE,OAAO,EACf,YAAY,EAAE,OAAO,EACrB,cAAc,EAAE,cAAc,KAC3B,IAAI;AAJT,wBAIU"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { hooks } from '@adonisjs/core/app';
|
|
2
|
+
/**
|
|
3
|
+
* Where the generated webhook-handlers barrel is written, relative to the app root. The
|
|
4
|
+
* payments provider imports THIS path at boot (build-time codegen) instead of scanning
|
|
5
|
+
* `app/payment_handlers` with `readdir` at runtime. Kept in sync with the provider.
|
|
6
|
+
*/
|
|
7
|
+
export const GENERATED_WEBHOOK_HANDLERS_OUTPUT = '.adonisjs/payments/webhook_handlers.ts';
|
|
8
|
+
/**
|
|
9
|
+
* An AdonisJS **Assembler `init` hook** that generates a typed barrel of the app's
|
|
10
|
+
* `app/payment_handlers/` directory at build/dev time — exactly how the durable package
|
|
11
|
+
* generates `app/workflows` and `@adonisjs/core` generates the controllers/events
|
|
12
|
+
* barrels (`indexEntities`). The build-time barrel replaces the provider's runtime
|
|
13
|
+
* `readdir` scan; the file watcher re-runs the generator whenever a handler file
|
|
14
|
+
* changes.
|
|
15
|
+
*
|
|
16
|
+
* The generated file is a lazy barrel — `export const webhookHandlers = { Name: () =>
|
|
17
|
+
* import('#payment_handlers/…') }` — which the payments provider imports at boot and
|
|
18
|
+
* registers alongside `config.billing.handlers`.
|
|
19
|
+
*
|
|
20
|
+
* Register it in `adonisrc.ts`:
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* export default defineConfig({
|
|
24
|
+
* hooks: {
|
|
25
|
+
* init: [() => import('@adonis-agora/payments/hooks/webhook_handlers')],
|
|
26
|
+
* },
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function webhookHandlersHook(options = {}) {
|
|
31
|
+
const source = options.source ?? 'app/payment_handlers';
|
|
32
|
+
const importAlias = options.importAlias ?? '#payment_handlers';
|
|
33
|
+
const output = options.output ?? GENERATED_WEBHOOK_HANDLERS_OUTPUT;
|
|
34
|
+
return hooks.init((_parent, _hooksManager, indexGenerator) => {
|
|
35
|
+
indexGenerator.add('webhookHandlers', {
|
|
36
|
+
source,
|
|
37
|
+
as: 'barrelFile',
|
|
38
|
+
exportName: 'webhookHandlers',
|
|
39
|
+
importAlias,
|
|
40
|
+
// `app/payment_handlers/payment_succeeded.ts` → barrel key `Payment/Succeeded`;
|
|
41
|
+
// the event type itself comes from each module's `type`/`eventType`.
|
|
42
|
+
skipSegments: ['payment_handlers'],
|
|
43
|
+
output,
|
|
44
|
+
comment: true,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** The default export is the hook itself, so `() => import('@adonis-agora/payments/hooks/webhook_handlers')`
|
|
49
|
+
* in `adonisrc.ts` resolves to a ready hook (the assembler calls it). Annotated
|
|
50
|
+
* explicitly so the declaration emit stays portable (same as collaboration's
|
|
51
|
+
* `codegen_init`). */
|
|
52
|
+
export default webhookHandlersHook();
|
|
53
|
+
//# sourceMappingURL=webhook_handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook_handlers.js","sourceRoot":"","sources":["../../../src/hooks/webhook_handlers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,wCAAwC,CAAC;AAgB1F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAsC,EAAE;IAExC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,sBAAsB,CAAC;IACxD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,mBAAmB,CAAC;IAC/D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,iCAAiC,CAAC;IAEnE,OAAO,KAAK,CAAC,IAAI,CACf,CACE,OAAgB,EAChB,aAAsB,EACtB,cAEC,EACD,EAAE;QACF,cAAc,CAAC,GAAG,CAAC,iBAAiB,EAAE;YACpC,MAAM;YACN,EAAE,EAAE,YAAY;YAChB,UAAU,EAAE,iBAAiB;YAC7B,WAAW;YACX,gFAAgF;YAChF,qEAAqE;YACrE,YAAY,EAAE,CAAC,kBAAkB,CAAC;YAClC,MAAM;YACN,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;IACL,CAAC,CACkF,CAAC;AACxF,CAAC;AAED;;;uBAGuB;AACvB,eAAe,mBAAmB,EAIzB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface HttpRequestOptions {
|
|
2
|
+
method?: string;
|
|
3
|
+
body?: Record<string, unknown>;
|
|
4
|
+
/** Auth header sent as `Authorization: Bearer <token>`. */
|
|
5
|
+
bearerToken?: string;
|
|
6
|
+
/** Auth header sent as a raw header name/value (e.g. Asaas `access_token`). */
|
|
7
|
+
authHeader?: {
|
|
8
|
+
name: string;
|
|
9
|
+
value: string;
|
|
10
|
+
};
|
|
11
|
+
/** Base URL the path is resolved against. */
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Thin `fetch` wrapper shared by the fetch-based drivers (Asaas, AbacatePay, Woovi).
|
|
16
|
+
* Normalizes errors into an `Error` with a `status` property so `isNotFound` can check
|
|
17
|
+
* it uniformly.
|
|
18
|
+
*/
|
|
19
|
+
export declare function httpRequest<T>(path: string, options: HttpRequestOptions): Promise<T>;
|
|
20
|
+
/** Read a header value (handles arrays, case variants and multiple spellings). */
|
|
21
|
+
export declare function headerValue(headers: Record<string, string | string[] | undefined>, name: string): string | undefined;
|
|
22
|
+
/** Whether an error is an HTTP 404 (resource not found). */
|
|
23
|
+
export declare function isNotFound(error: unknown): boolean;
|
|
24
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC,CA2B1F;AAED,kFAAkF;AAClF,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,EACtD,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAWpB;AAED,4DAA4D;AAC5D,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOlD"}
|
package/dist/src/http.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin `fetch` wrapper shared by the fetch-based drivers (Asaas, AbacatePay, Woovi).
|
|
3
|
+
* Normalizes errors into an `Error` with a `status` property so `isNotFound` can check
|
|
4
|
+
* it uniformly.
|
|
5
|
+
*/
|
|
6
|
+
export async function httpRequest(path, options) {
|
|
7
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
8
|
+
if (options.bearerToken !== undefined) {
|
|
9
|
+
headers.Authorization = `Bearer ${options.bearerToken}`;
|
|
10
|
+
}
|
|
11
|
+
if (options.authHeader !== undefined) {
|
|
12
|
+
headers[options.authHeader.name] = options.authHeader.value;
|
|
13
|
+
}
|
|
14
|
+
const requestInit = {
|
|
15
|
+
method: options.method ?? 'GET',
|
|
16
|
+
headers,
|
|
17
|
+
};
|
|
18
|
+
if (options.body !== undefined) {
|
|
19
|
+
requestInit.body = JSON.stringify(options.body);
|
|
20
|
+
}
|
|
21
|
+
const response = await fetch(`${options.baseUrl}${path}`, requestInit);
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
const text = await response.text();
|
|
24
|
+
const status = response.status;
|
|
25
|
+
throw Object.assign(new Error(`[payments] HTTP request failed (${status}): ${text}`), {
|
|
26
|
+
status,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return (await response.json());
|
|
30
|
+
}
|
|
31
|
+
/** Read a header value (handles arrays, case variants and multiple spellings). */
|
|
32
|
+
export function headerValue(headers, name) {
|
|
33
|
+
const direct = headers[name];
|
|
34
|
+
if (direct !== undefined)
|
|
35
|
+
return Array.isArray(direct) ? direct[0] : direct;
|
|
36
|
+
// Case-insensitive fallback: scan the actual keys.
|
|
37
|
+
const lower = name.toLowerCase();
|
|
38
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
39
|
+
if (key.toLowerCase() === lower) {
|
|
40
|
+
return Array.isArray(value) ? value[0] : value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
/** Whether an error is an HTTP 404 (resource not found). */
|
|
46
|
+
export function isNotFound(error) {
|
|
47
|
+
return (typeof error === 'object' &&
|
|
48
|
+
error !== null &&
|
|
49
|
+
'status' in error &&
|
|
50
|
+
error.status === 404);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAI,IAAY,EAAE,OAA2B;IAC5E,MAAM,OAAO,GAA2B,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;IAC/E,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,CAAC,aAAa,GAAG,UAAU,OAAO,CAAC,WAAW,EAAE,CAAC;IAC1D,CAAC;IACD,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;IAC9D,CAAC;IAED,MAAM,WAAW,GAAgB;QAC/B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK;QAC/B,OAAO;KACR,CAAC;IACF,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE,WAAW,CAAC,CAAC;IAEvE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,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