@olympio/payment-gateway 0.1.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/README.md +118 -0
- package/dist/index.cjs +1071 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +351 -0
- package/dist/index.d.ts +351 -0
- package/dist/index.js +1019 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1019 @@
|
|
|
1
|
+
// src/adapters/stripe/StripeGateway.ts
|
|
2
|
+
import Stripe from "stripe";
|
|
3
|
+
|
|
4
|
+
// src/domain/capabilities/Capability.ts
|
|
5
|
+
var Capability = {
|
|
6
|
+
PIX: "pix",
|
|
7
|
+
BOLETO: "boleto",
|
|
8
|
+
CARD: "card",
|
|
9
|
+
REFUND: "refund",
|
|
10
|
+
SUBSCRIPTIONS: "subscriptions"
|
|
11
|
+
};
|
|
12
|
+
function hasCapability(caps, capability) {
|
|
13
|
+
return caps.has(capability);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/domain/errors/index.ts
|
|
17
|
+
var GatewayError = class extends Error {
|
|
18
|
+
constructor(provider, message, options = {}) {
|
|
19
|
+
super(message, { cause: options.cause });
|
|
20
|
+
this.provider = provider;
|
|
21
|
+
this.name = new.target.name;
|
|
22
|
+
this.raw = options.raw;
|
|
23
|
+
}
|
|
24
|
+
provider;
|
|
25
|
+
raw;
|
|
26
|
+
};
|
|
27
|
+
var CardDeclinedError = class extends GatewayError {
|
|
28
|
+
code = "card_declined";
|
|
29
|
+
constructor(provider, options) {
|
|
30
|
+
super(provider, "Cart\xE3o recusado.", options);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var AuthenticationError = class extends GatewayError {
|
|
34
|
+
code = "authentication";
|
|
35
|
+
constructor(provider, options) {
|
|
36
|
+
super(provider, "Falha de autentica\xE7\xE3o com o gateway.", options);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var RateLimitError = class extends GatewayError {
|
|
40
|
+
code = "rate_limit";
|
|
41
|
+
constructor(provider, options) {
|
|
42
|
+
super(provider, "Limite de requisi\xE7\xF5es do gateway excedido.", options);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var ValidationError = class extends GatewayError {
|
|
46
|
+
code = "validation";
|
|
47
|
+
constructor(provider, message, options) {
|
|
48
|
+
super(provider, message, options);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var GatewayUnavailableError = class extends GatewayError {
|
|
52
|
+
code = "gateway_unavailable";
|
|
53
|
+
constructor(provider, options) {
|
|
54
|
+
super(provider, "Gateway indispon\xEDvel.", options);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var UnknownGatewayError = class extends GatewayError {
|
|
58
|
+
code = "unknown";
|
|
59
|
+
constructor(provider, message, options) {
|
|
60
|
+
super(provider, message, options);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var UnsupportedCapabilityError = class extends GatewayError {
|
|
64
|
+
constructor(provider, capability, options) {
|
|
65
|
+
super(
|
|
66
|
+
provider,
|
|
67
|
+
`O gateway "${provider}" n\xE3o suporta a capability "${capability}".`,
|
|
68
|
+
options
|
|
69
|
+
);
|
|
70
|
+
this.capability = capability;
|
|
71
|
+
}
|
|
72
|
+
capability;
|
|
73
|
+
code = "unsupported_capability";
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/domain/models/Money.ts
|
|
77
|
+
var Money = class _Money {
|
|
78
|
+
constructor(cents, currency) {
|
|
79
|
+
this.cents = cents;
|
|
80
|
+
this.currency = currency;
|
|
81
|
+
}
|
|
82
|
+
cents;
|
|
83
|
+
currency;
|
|
84
|
+
static fromCents(cents, currency) {
|
|
85
|
+
if (!Number.isInteger(cents)) {
|
|
86
|
+
throw new RangeError(`Money.cents deve ser inteiro, recebido: ${cents}`);
|
|
87
|
+
}
|
|
88
|
+
return new _Money(cents, currency.toUpperCase());
|
|
89
|
+
}
|
|
90
|
+
static fromDecimal(amount, currency) {
|
|
91
|
+
return _Money.fromCents(Math.round(amount * 100), currency);
|
|
92
|
+
}
|
|
93
|
+
toDecimal() {
|
|
94
|
+
return this.cents / 100;
|
|
95
|
+
}
|
|
96
|
+
equals(other) {
|
|
97
|
+
return this.cents === other.cents && this.currency === other.currency;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/adapters/stripe/mappers.ts
|
|
102
|
+
var PROVIDER = "stripe";
|
|
103
|
+
function toChargeStatus(pi) {
|
|
104
|
+
switch (pi.status) {
|
|
105
|
+
case "succeeded":
|
|
106
|
+
return "paid";
|
|
107
|
+
case "canceled":
|
|
108
|
+
return "canceled";
|
|
109
|
+
case "requires_payment_method":
|
|
110
|
+
return pi.last_payment_error ? "failed" : "pending";
|
|
111
|
+
default:
|
|
112
|
+
return "pending";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function toPaymentMethod(types) {
|
|
116
|
+
if (types?.includes("pix")) return "pix";
|
|
117
|
+
if (types?.includes("boleto")) return "boleto";
|
|
118
|
+
return "card";
|
|
119
|
+
}
|
|
120
|
+
function customerId(customer) {
|
|
121
|
+
if (!customer) return void 0;
|
|
122
|
+
return typeof customer === "string" ? customer : customer.id;
|
|
123
|
+
}
|
|
124
|
+
function toCharge(pi) {
|
|
125
|
+
return {
|
|
126
|
+
id: pi.id,
|
|
127
|
+
status: toChargeStatus(pi),
|
|
128
|
+
amount: Money.fromCents(pi.amount, pi.currency),
|
|
129
|
+
paymentMethod: toPaymentMethod(pi.payment_method_types),
|
|
130
|
+
customerId: customerId(pi.customer),
|
|
131
|
+
description: pi.description ?? void 0,
|
|
132
|
+
createdAt: new Date(pi.created * 1e3),
|
|
133
|
+
metadata: pi.metadata ?? void 0
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function toCustomer(c) {
|
|
137
|
+
return {
|
|
138
|
+
id: c.id,
|
|
139
|
+
name: c.name ?? "",
|
|
140
|
+
email: c.email ?? void 0,
|
|
141
|
+
phone: c.phone ?? void 0,
|
|
142
|
+
metadata: c.metadata ?? void 0
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function toSubscriptionStatus(status) {
|
|
146
|
+
switch (status) {
|
|
147
|
+
case "active":
|
|
148
|
+
case "trialing":
|
|
149
|
+
return "active";
|
|
150
|
+
case "canceled":
|
|
151
|
+
return "canceled";
|
|
152
|
+
default:
|
|
153
|
+
return "past_due";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function toInterval(interval) {
|
|
157
|
+
switch (interval) {
|
|
158
|
+
case "week":
|
|
159
|
+
return "weekly";
|
|
160
|
+
case "year":
|
|
161
|
+
return "yearly";
|
|
162
|
+
default:
|
|
163
|
+
return "monthly";
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function toSubscription(sub) {
|
|
167
|
+
const price = sub.items.data[0]?.price;
|
|
168
|
+
return {
|
|
169
|
+
id: sub.id,
|
|
170
|
+
status: toSubscriptionStatus(sub.status),
|
|
171
|
+
customerId: customerId(sub.customer) ?? "",
|
|
172
|
+
amount: Money.fromCents(price?.unit_amount ?? 0, price?.currency ?? "brl"),
|
|
173
|
+
interval: toInterval(price?.recurring?.interval),
|
|
174
|
+
createdAt: new Date(sub.created * 1e3),
|
|
175
|
+
metadata: sub.metadata ?? void 0
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function mapStripeError(err) {
|
|
179
|
+
const e = err;
|
|
180
|
+
const opts = { cause: err, raw: err };
|
|
181
|
+
switch (e.type) {
|
|
182
|
+
case "StripeCardError":
|
|
183
|
+
return new CardDeclinedError(PROVIDER, opts);
|
|
184
|
+
case "StripeAuthenticationError":
|
|
185
|
+
return new AuthenticationError(PROVIDER, opts);
|
|
186
|
+
case "StripeRateLimitError":
|
|
187
|
+
return new RateLimitError(PROVIDER, opts);
|
|
188
|
+
case "StripeInvalidRequestError":
|
|
189
|
+
return new ValidationError(PROVIDER, e.message ?? "Requisi\xE7\xE3o inv\xE1lida.", opts);
|
|
190
|
+
default:
|
|
191
|
+
return new UnknownGatewayError(PROVIDER, e.message ?? "Erro do Stripe.", opts);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function toWebhookEvent(event) {
|
|
195
|
+
switch (event.type) {
|
|
196
|
+
case "payment_intent.succeeded":
|
|
197
|
+
return {
|
|
198
|
+
type: "charge.paid",
|
|
199
|
+
data: toCharge(event.data.object),
|
|
200
|
+
raw: event
|
|
201
|
+
};
|
|
202
|
+
case "payment_intent.payment_failed":
|
|
203
|
+
return {
|
|
204
|
+
type: "charge.failed",
|
|
205
|
+
data: toCharge(event.data.object),
|
|
206
|
+
raw: event
|
|
207
|
+
};
|
|
208
|
+
case "customer.subscription.deleted":
|
|
209
|
+
return {
|
|
210
|
+
type: "subscription.canceled",
|
|
211
|
+
data: toSubscription(event.data.object),
|
|
212
|
+
raw: event
|
|
213
|
+
};
|
|
214
|
+
default:
|
|
215
|
+
return { type: "unknown", data: null, raw: event };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/adapters/stripe/StripeGateway.ts
|
|
220
|
+
var PROVIDER2 = "stripe";
|
|
221
|
+
var CAPABILITY_BY_METHOD = {
|
|
222
|
+
card: Capability.CARD,
|
|
223
|
+
pix: Capability.PIX,
|
|
224
|
+
boleto: Capability.BOLETO
|
|
225
|
+
};
|
|
226
|
+
var STRIPE_INTERVAL = {
|
|
227
|
+
weekly: "week",
|
|
228
|
+
monthly: "month",
|
|
229
|
+
yearly: "year"
|
|
230
|
+
};
|
|
231
|
+
async function normalizeErrors(fn) {
|
|
232
|
+
try {
|
|
233
|
+
return await fn();
|
|
234
|
+
} catch (err) {
|
|
235
|
+
throw mapStripeError(err);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function isResourceMissing(err) {
|
|
239
|
+
return err.code === "resource_missing";
|
|
240
|
+
}
|
|
241
|
+
var StripeGateway = class {
|
|
242
|
+
constructor(config, client) {
|
|
243
|
+
this.config = config;
|
|
244
|
+
this.client = client ?? new Stripe(config.apiKey);
|
|
245
|
+
this.customers = this.buildCustomerPort();
|
|
246
|
+
this.charges = this.buildChargePort();
|
|
247
|
+
this.subscriptions = this.buildSubscriptionPort();
|
|
248
|
+
this.webhooks = this.buildWebhookPort();
|
|
249
|
+
}
|
|
250
|
+
config;
|
|
251
|
+
provider = PROVIDER2;
|
|
252
|
+
capabilities = /* @__PURE__ */ new Set([
|
|
253
|
+
Capability.CARD,
|
|
254
|
+
Capability.REFUND,
|
|
255
|
+
Capability.SUBSCRIPTIONS
|
|
256
|
+
]);
|
|
257
|
+
client;
|
|
258
|
+
customers;
|
|
259
|
+
charges;
|
|
260
|
+
subscriptions;
|
|
261
|
+
webhooks;
|
|
262
|
+
supports(capability) {
|
|
263
|
+
return this.capabilities.has(capability);
|
|
264
|
+
}
|
|
265
|
+
raw() {
|
|
266
|
+
return this.client;
|
|
267
|
+
}
|
|
268
|
+
requireMethod(method) {
|
|
269
|
+
const cap = CAPABILITY_BY_METHOD[method];
|
|
270
|
+
if (!this.capabilities.has(cap)) {
|
|
271
|
+
throw new UnsupportedCapabilityError(PROVIDER2, cap);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
buildCustomerPort() {
|
|
275
|
+
const client = this.client;
|
|
276
|
+
return {
|
|
277
|
+
create: (input) => normalizeErrors(
|
|
278
|
+
async () => toCustomer(
|
|
279
|
+
await client.customers.create(
|
|
280
|
+
{
|
|
281
|
+
name: input.name,
|
|
282
|
+
email: input.email,
|
|
283
|
+
phone: input.phone,
|
|
284
|
+
metadata: input.metadata
|
|
285
|
+
},
|
|
286
|
+
input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : void 0
|
|
287
|
+
)
|
|
288
|
+
)
|
|
289
|
+
),
|
|
290
|
+
get: async (id) => {
|
|
291
|
+
try {
|
|
292
|
+
const c = await client.customers.retrieve(id);
|
|
293
|
+
if (c.deleted) return null;
|
|
294
|
+
return toCustomer(c);
|
|
295
|
+
} catch (err) {
|
|
296
|
+
if (isResourceMissing(err)) return null;
|
|
297
|
+
throw mapStripeError(err);
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
update: (id, input) => normalizeErrors(
|
|
301
|
+
async () => toCustomer(
|
|
302
|
+
await client.customers.update(id, {
|
|
303
|
+
name: input.name,
|
|
304
|
+
email: input.email,
|
|
305
|
+
phone: input.phone,
|
|
306
|
+
metadata: input.metadata
|
|
307
|
+
})
|
|
308
|
+
)
|
|
309
|
+
),
|
|
310
|
+
delete: (id) => normalizeErrors(async () => {
|
|
311
|
+
await client.customers.del(id);
|
|
312
|
+
})
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
buildChargePort() {
|
|
316
|
+
const client = this.client;
|
|
317
|
+
return {
|
|
318
|
+
create: async (input) => {
|
|
319
|
+
this.requireMethod(input.paymentMethod);
|
|
320
|
+
return normalizeErrors(
|
|
321
|
+
async () => toCharge(
|
|
322
|
+
await client.paymentIntents.create(
|
|
323
|
+
{
|
|
324
|
+
amount: input.amount.cents,
|
|
325
|
+
currency: input.amount.currency.toLowerCase(),
|
|
326
|
+
customer: input.customerId,
|
|
327
|
+
description: input.description,
|
|
328
|
+
payment_method: input.cardToken,
|
|
329
|
+
payment_method_types: ["card"],
|
|
330
|
+
confirm: input.cardToken !== void 0,
|
|
331
|
+
metadata: input.metadata
|
|
332
|
+
},
|
|
333
|
+
input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : void 0
|
|
334
|
+
)
|
|
335
|
+
)
|
|
336
|
+
);
|
|
337
|
+
},
|
|
338
|
+
get: async (id) => {
|
|
339
|
+
try {
|
|
340
|
+
return toCharge(await client.paymentIntents.retrieve(id));
|
|
341
|
+
} catch (err) {
|
|
342
|
+
if (isResourceMissing(err)) return null;
|
|
343
|
+
throw mapStripeError(err);
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
cancel: (id) => normalizeErrors(async () => toCharge(await client.paymentIntents.cancel(id))),
|
|
347
|
+
refund: (input) => normalizeErrors(async () => {
|
|
348
|
+
await client.refunds.create({
|
|
349
|
+
payment_intent: input.chargeId,
|
|
350
|
+
amount: input.amount?.cents
|
|
351
|
+
});
|
|
352
|
+
const pi = await client.paymentIntents.retrieve(input.chargeId);
|
|
353
|
+
return { ...toCharge(pi), status: "refunded" };
|
|
354
|
+
})
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
buildSubscriptionPort() {
|
|
358
|
+
const client = this.client;
|
|
359
|
+
return {
|
|
360
|
+
create: (input) => normalizeErrors(async () => {
|
|
361
|
+
const price = await client.prices.create({
|
|
362
|
+
unit_amount: input.amount.cents,
|
|
363
|
+
currency: input.amount.currency.toLowerCase(),
|
|
364
|
+
recurring: { interval: STRIPE_INTERVAL[input.interval] },
|
|
365
|
+
product_data: { name: `subscription-${input.customerId}` }
|
|
366
|
+
});
|
|
367
|
+
const sub = await client.subscriptions.create(
|
|
368
|
+
{
|
|
369
|
+
customer: input.customerId,
|
|
370
|
+
items: [{ price: price.id }],
|
|
371
|
+
metadata: input.metadata
|
|
372
|
+
},
|
|
373
|
+
input.idempotencyKey ? { idempotencyKey: input.idempotencyKey } : void 0
|
|
374
|
+
);
|
|
375
|
+
return toSubscription(sub);
|
|
376
|
+
}),
|
|
377
|
+
get: async (id) => {
|
|
378
|
+
try {
|
|
379
|
+
return toSubscription(await client.subscriptions.retrieve(id));
|
|
380
|
+
} catch (err) {
|
|
381
|
+
if (isResourceMissing(err)) return null;
|
|
382
|
+
throw mapStripeError(err);
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
cancel: (id) => normalizeErrors(async () => toSubscription(await client.subscriptions.cancel(id)))
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
buildWebhookPort() {
|
|
389
|
+
const client = this.client;
|
|
390
|
+
const secret = this.config.webhookSecret;
|
|
391
|
+
return {
|
|
392
|
+
verifyAndParse: (input) => {
|
|
393
|
+
if (!secret) {
|
|
394
|
+
throw new ValidationError(PROVIDER2, "webhookSecret n\xE3o configurado.");
|
|
395
|
+
}
|
|
396
|
+
const signature = input.headers["stripe-signature"];
|
|
397
|
+
try {
|
|
398
|
+
const event = client.webhooks.constructEvent(input.payload, signature ?? "", secret);
|
|
399
|
+
return toWebhookEvent(event);
|
|
400
|
+
} catch (err) {
|
|
401
|
+
throw new ValidationError(PROVIDER2, "Assinatura de webhook inv\xE1lida.", {
|
|
402
|
+
cause: err
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// src/adapters/asaas/AsaasHttpClient.ts
|
|
411
|
+
var AsaasApiError = class extends Error {
|
|
412
|
+
constructor(status, body) {
|
|
413
|
+
super(`Asaas API respondeu ${status}`);
|
|
414
|
+
this.status = status;
|
|
415
|
+
this.body = body;
|
|
416
|
+
this.name = "AsaasApiError";
|
|
417
|
+
}
|
|
418
|
+
status;
|
|
419
|
+
body;
|
|
420
|
+
};
|
|
421
|
+
var DEFAULT_BASE_URL = "https://api.asaas.com/v3";
|
|
422
|
+
function createAsaasHttpClient(config) {
|
|
423
|
+
const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
424
|
+
async function request(method, path, body) {
|
|
425
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
426
|
+
method,
|
|
427
|
+
headers: {
|
|
428
|
+
access_token: config.apiKey,
|
|
429
|
+
"Content-Type": "application/json"
|
|
430
|
+
},
|
|
431
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
432
|
+
});
|
|
433
|
+
const text = await res.text();
|
|
434
|
+
const json = text ? JSON.parse(text) : {};
|
|
435
|
+
if (!res.ok) {
|
|
436
|
+
throw new AsaasApiError(res.status, json);
|
|
437
|
+
}
|
|
438
|
+
return json;
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
get: (path) => request("GET", path),
|
|
442
|
+
post: (path, body) => request("POST", path, body),
|
|
443
|
+
delete: (path) => request("DELETE", path)
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// src/adapters/asaas/mappers.ts
|
|
448
|
+
var PROVIDER3 = "asaas";
|
|
449
|
+
var CURRENCY = "BRL";
|
|
450
|
+
function toChargeStatus2(status) {
|
|
451
|
+
switch (status) {
|
|
452
|
+
case "RECEIVED":
|
|
453
|
+
case "CONFIRMED":
|
|
454
|
+
case "RECEIVED_IN_CASH":
|
|
455
|
+
return "paid";
|
|
456
|
+
case "OVERDUE":
|
|
457
|
+
return "failed";
|
|
458
|
+
case "REFUNDED":
|
|
459
|
+
case "REFUND_REQUESTED":
|
|
460
|
+
return "refunded";
|
|
461
|
+
default:
|
|
462
|
+
return "pending";
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function toPaymentMethod2(billingType) {
|
|
466
|
+
switch (billingType) {
|
|
467
|
+
case "PIX":
|
|
468
|
+
return "pix";
|
|
469
|
+
case "BOLETO":
|
|
470
|
+
return "boleto";
|
|
471
|
+
default:
|
|
472
|
+
return "card";
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function toCharge2(p) {
|
|
476
|
+
return {
|
|
477
|
+
id: p.id,
|
|
478
|
+
status: toChargeStatus2(p.status),
|
|
479
|
+
amount: Money.fromDecimal(p.value, CURRENCY),
|
|
480
|
+
paymentMethod: toPaymentMethod2(p.billingType),
|
|
481
|
+
customerId: p.customer,
|
|
482
|
+
description: p.description ?? void 0,
|
|
483
|
+
boleto: p.bankSlipUrl ? { url: p.bankSlipUrl } : void 0,
|
|
484
|
+
createdAt: new Date(p.dateCreated)
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function toCustomer2(c) {
|
|
488
|
+
return {
|
|
489
|
+
id: c.id,
|
|
490
|
+
name: c.name,
|
|
491
|
+
email: c.email ?? void 0,
|
|
492
|
+
taxId: c.cpfCnpj ?? void 0,
|
|
493
|
+
phone: c.phone ?? c.mobilePhone ?? void 0
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function toSubscriptionStatus2(status) {
|
|
497
|
+
switch (status) {
|
|
498
|
+
case "ACTIVE":
|
|
499
|
+
return "active";
|
|
500
|
+
case "EXPIRED":
|
|
501
|
+
return "past_due";
|
|
502
|
+
default:
|
|
503
|
+
return "canceled";
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function toInterval2(cycle) {
|
|
507
|
+
switch (cycle) {
|
|
508
|
+
case "WEEKLY":
|
|
509
|
+
return "weekly";
|
|
510
|
+
case "YEARLY":
|
|
511
|
+
return "yearly";
|
|
512
|
+
default:
|
|
513
|
+
return "monthly";
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function toSubscription2(s) {
|
|
517
|
+
return {
|
|
518
|
+
id: s.id,
|
|
519
|
+
status: toSubscriptionStatus2(s.status),
|
|
520
|
+
customerId: s.customer,
|
|
521
|
+
amount: Money.fromDecimal(s.value, CURRENCY),
|
|
522
|
+
interval: toInterval2(s.cycle),
|
|
523
|
+
createdAt: new Date(s.dateCreated)
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
function mapAsaasError(status, body) {
|
|
527
|
+
const description = body.errors?.[0]?.description;
|
|
528
|
+
const opts = { raw: body };
|
|
529
|
+
if (status === 401 || status === 403) return new AuthenticationError(PROVIDER3, opts);
|
|
530
|
+
if (status === 429) return new RateLimitError(PROVIDER3, opts);
|
|
531
|
+
if (status >= 500) return new GatewayUnavailableError(PROVIDER3, opts);
|
|
532
|
+
if (status === 400) {
|
|
533
|
+
return new ValidationError(PROVIDER3, description ?? "Requisi\xE7\xE3o inv\xE1lida.", opts);
|
|
534
|
+
}
|
|
535
|
+
return new UnknownGatewayError(PROVIDER3, description ?? "Erro do Asaas.", opts);
|
|
536
|
+
}
|
|
537
|
+
function toWebhookEvent2(body) {
|
|
538
|
+
const payment = body.payment;
|
|
539
|
+
switch (body.event) {
|
|
540
|
+
case "PAYMENT_RECEIVED":
|
|
541
|
+
case "PAYMENT_CONFIRMED":
|
|
542
|
+
return { type: "charge.paid", data: toCharge2(payment), raw: body };
|
|
543
|
+
case "PAYMENT_OVERDUE":
|
|
544
|
+
return { type: "charge.failed", data: toCharge2(payment), raw: body };
|
|
545
|
+
case "PAYMENT_REFUNDED":
|
|
546
|
+
return { type: "charge.refunded", data: toCharge2(payment), raw: body };
|
|
547
|
+
default:
|
|
548
|
+
return { type: "unknown", data: null, raw: body };
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// src/adapters/asaas/AsaasGateway.ts
|
|
553
|
+
var PROVIDER4 = "asaas";
|
|
554
|
+
var BILLING_TYPE = {
|
|
555
|
+
pix: "PIX",
|
|
556
|
+
boleto: "BOLETO",
|
|
557
|
+
card: "CREDIT_CARD"
|
|
558
|
+
};
|
|
559
|
+
var ASAAS_CYCLE = {
|
|
560
|
+
weekly: "WEEKLY",
|
|
561
|
+
monthly: "MONTHLY",
|
|
562
|
+
yearly: "YEARLY"
|
|
563
|
+
};
|
|
564
|
+
function today() {
|
|
565
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
566
|
+
}
|
|
567
|
+
async function normalizeErrors2(fn) {
|
|
568
|
+
try {
|
|
569
|
+
return await fn();
|
|
570
|
+
} catch (err) {
|
|
571
|
+
if (err instanceof GatewayError) throw err;
|
|
572
|
+
if (err instanceof AsaasApiError) throw mapAsaasError(err.status, err.body);
|
|
573
|
+
throw new UnknownGatewayError(PROVIDER4, "Erro inesperado no Asaas.", { cause: err });
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
function isNotFound(err) {
|
|
577
|
+
return err instanceof AsaasApiError && err.status === 404;
|
|
578
|
+
}
|
|
579
|
+
var AsaasGateway = class {
|
|
580
|
+
constructor(config, http) {
|
|
581
|
+
this.config = config;
|
|
582
|
+
this.http = http ?? createAsaasHttpClient(config);
|
|
583
|
+
this.customers = this.buildCustomerPort();
|
|
584
|
+
this.charges = this.buildChargePort();
|
|
585
|
+
this.subscriptions = this.buildSubscriptionPort();
|
|
586
|
+
this.webhooks = this.buildWebhookPort();
|
|
587
|
+
}
|
|
588
|
+
config;
|
|
589
|
+
provider = PROVIDER4;
|
|
590
|
+
capabilities = /* @__PURE__ */ new Set([
|
|
591
|
+
Capability.PIX,
|
|
592
|
+
Capability.BOLETO,
|
|
593
|
+
Capability.CARD,
|
|
594
|
+
Capability.REFUND,
|
|
595
|
+
Capability.SUBSCRIPTIONS
|
|
596
|
+
]);
|
|
597
|
+
http;
|
|
598
|
+
customers;
|
|
599
|
+
charges;
|
|
600
|
+
subscriptions;
|
|
601
|
+
webhooks;
|
|
602
|
+
supports(capability) {
|
|
603
|
+
return this.capabilities.has(capability);
|
|
604
|
+
}
|
|
605
|
+
raw() {
|
|
606
|
+
return this.http;
|
|
607
|
+
}
|
|
608
|
+
buildCustomerPort() {
|
|
609
|
+
const http = this.http;
|
|
610
|
+
return {
|
|
611
|
+
create: (input) => normalizeErrors2(
|
|
612
|
+
async () => toCustomer2(
|
|
613
|
+
await http.post("/customers", {
|
|
614
|
+
name: input.name,
|
|
615
|
+
email: input.email,
|
|
616
|
+
cpfCnpj: input.taxId,
|
|
617
|
+
mobilePhone: input.phone,
|
|
618
|
+
externalReference: input.idempotencyKey
|
|
619
|
+
})
|
|
620
|
+
)
|
|
621
|
+
),
|
|
622
|
+
get: async (id) => {
|
|
623
|
+
try {
|
|
624
|
+
return toCustomer2(await http.get(`/customers/${id}`));
|
|
625
|
+
} catch (err) {
|
|
626
|
+
if (isNotFound(err)) return null;
|
|
627
|
+
throw mapAsaasError(err.status, err.body);
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
update: (id, input) => normalizeErrors2(
|
|
631
|
+
async () => toCustomer2(
|
|
632
|
+
await http.post(`/customers/${id}`, {
|
|
633
|
+
name: input.name,
|
|
634
|
+
email: input.email,
|
|
635
|
+
cpfCnpj: input.taxId,
|
|
636
|
+
mobilePhone: input.phone
|
|
637
|
+
})
|
|
638
|
+
)
|
|
639
|
+
),
|
|
640
|
+
delete: (id) => normalizeErrors2(async () => {
|
|
641
|
+
await http.delete(`/customers/${id}`);
|
|
642
|
+
})
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
buildChargePort() {
|
|
646
|
+
const http = this.http;
|
|
647
|
+
return {
|
|
648
|
+
create: (input) => normalizeErrors2(
|
|
649
|
+
async () => toCharge2(
|
|
650
|
+
await http.post("/payments", {
|
|
651
|
+
customer: input.customerId,
|
|
652
|
+
billingType: BILLING_TYPE[input.paymentMethod],
|
|
653
|
+
value: input.amount.toDecimal(),
|
|
654
|
+
dueDate: (input.dueDate ?? /* @__PURE__ */ new Date()).toISOString().slice(0, 10),
|
|
655
|
+
description: input.description,
|
|
656
|
+
creditCardToken: input.cardToken,
|
|
657
|
+
remoteIp: input.remoteIp,
|
|
658
|
+
externalReference: input.idempotencyKey
|
|
659
|
+
})
|
|
660
|
+
)
|
|
661
|
+
),
|
|
662
|
+
get: async (id) => {
|
|
663
|
+
try {
|
|
664
|
+
return toCharge2(await http.get(`/payments/${id}`));
|
|
665
|
+
} catch (err) {
|
|
666
|
+
if (isNotFound(err)) return null;
|
|
667
|
+
throw mapAsaasError(err.status, err.body);
|
|
668
|
+
}
|
|
669
|
+
},
|
|
670
|
+
cancel: (id) => normalizeErrors2(async () => {
|
|
671
|
+
const payment = await http.get(`/payments/${id}`);
|
|
672
|
+
await http.delete(`/payments/${id}`);
|
|
673
|
+
return { ...toCharge2(payment), status: "canceled" };
|
|
674
|
+
}),
|
|
675
|
+
refund: (input) => normalizeErrors2(
|
|
676
|
+
async () => toCharge2(
|
|
677
|
+
await http.post(`/payments/${input.chargeId}/refund`, {
|
|
678
|
+
value: input.amount?.toDecimal()
|
|
679
|
+
})
|
|
680
|
+
)
|
|
681
|
+
)
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
buildSubscriptionPort() {
|
|
685
|
+
const http = this.http;
|
|
686
|
+
return {
|
|
687
|
+
create: (input) => normalizeErrors2(
|
|
688
|
+
async () => toSubscription2(
|
|
689
|
+
await http.post("/subscriptions", {
|
|
690
|
+
customer: input.customerId,
|
|
691
|
+
billingType: BILLING_TYPE[input.paymentMethod],
|
|
692
|
+
value: input.amount.toDecimal(),
|
|
693
|
+
cycle: ASAAS_CYCLE[input.interval],
|
|
694
|
+
nextDueDate: today(),
|
|
695
|
+
creditCardToken: input.cardToken,
|
|
696
|
+
externalReference: input.idempotencyKey
|
|
697
|
+
})
|
|
698
|
+
)
|
|
699
|
+
),
|
|
700
|
+
get: async (id) => {
|
|
701
|
+
try {
|
|
702
|
+
return toSubscription2(await http.get(`/subscriptions/${id}`));
|
|
703
|
+
} catch (err) {
|
|
704
|
+
if (isNotFound(err)) return null;
|
|
705
|
+
throw mapAsaasError(err.status, err.body);
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
cancel: (id) => normalizeErrors2(async () => {
|
|
709
|
+
const sub = await http.get(`/subscriptions/${id}`);
|
|
710
|
+
await http.delete(`/subscriptions/${id}`);
|
|
711
|
+
return { ...toSubscription2(sub), status: "canceled" };
|
|
712
|
+
})
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
buildWebhookPort() {
|
|
716
|
+
const expectedToken = this.config.webhookToken;
|
|
717
|
+
return {
|
|
718
|
+
verifyAndParse: (input) => {
|
|
719
|
+
const received = input.headers["asaas-access-token"];
|
|
720
|
+
if (!expectedToken || received !== expectedToken) {
|
|
721
|
+
throw new ValidationError(PROVIDER4, "Token de webhook do Asaas inv\xE1lido.");
|
|
722
|
+
}
|
|
723
|
+
const body = JSON.parse(input.payload.toString());
|
|
724
|
+
return toWebhookEvent2(body);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
// src/adapters/dom/DomHttpClient.ts
|
|
731
|
+
var DomHttpClient = class {
|
|
732
|
+
baseUrl;
|
|
733
|
+
apiKey;
|
|
734
|
+
constructor(config) {
|
|
735
|
+
this.baseUrl = config.baseUrl ?? "https://apiv3.dompagamentos.com.br/checkout/production";
|
|
736
|
+
this.apiKey = config.apiKey;
|
|
737
|
+
}
|
|
738
|
+
async request(path, options) {
|
|
739
|
+
const url = `${this.baseUrl}${path}`;
|
|
740
|
+
const response = await fetch(url, {
|
|
741
|
+
...options,
|
|
742
|
+
headers: {
|
|
743
|
+
"Content-Type": "application/json",
|
|
744
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
745
|
+
...options.headers
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
if (!response.ok) {
|
|
749
|
+
const body = await response.text();
|
|
750
|
+
throw new Error(`DOM API Error: ${response.status} ${response.statusText} - ${body}`);
|
|
751
|
+
}
|
|
752
|
+
if (response.status === 204) {
|
|
753
|
+
return {};
|
|
754
|
+
}
|
|
755
|
+
return await response.json();
|
|
756
|
+
}
|
|
757
|
+
async get(path) {
|
|
758
|
+
return this.request(path, { method: "GET" });
|
|
759
|
+
}
|
|
760
|
+
async post(path, body) {
|
|
761
|
+
return this.request(path, {
|
|
762
|
+
method: "POST",
|
|
763
|
+
body: body ? JSON.stringify(body) : void 0
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
async put(path, body) {
|
|
767
|
+
return this.request(path, {
|
|
768
|
+
method: "PUT",
|
|
769
|
+
body: body ? JSON.stringify(body) : void 0
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
async delete(path) {
|
|
773
|
+
return this.request(path, { method: "DELETE" });
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
// src/adapters/dom/mappers.ts
|
|
778
|
+
function toDomCustomer(input) {
|
|
779
|
+
const data = {
|
|
780
|
+
name: input.name,
|
|
781
|
+
email: input.email,
|
|
782
|
+
mobile_phone: input.phone || "00000000000",
|
|
783
|
+
code_external: input.metadata?.code_external
|
|
784
|
+
};
|
|
785
|
+
if (input.taxId) {
|
|
786
|
+
data.document = input.taxId;
|
|
787
|
+
data.document_type = input.taxId.length === 11 ? "CPF" : "CNPJ";
|
|
788
|
+
}
|
|
789
|
+
return data;
|
|
790
|
+
}
|
|
791
|
+
function toDomainCustomer(domCustomer) {
|
|
792
|
+
return {
|
|
793
|
+
id: domCustomer.id,
|
|
794
|
+
name: domCustomer.name,
|
|
795
|
+
email: domCustomer.email,
|
|
796
|
+
taxId: domCustomer.document,
|
|
797
|
+
phone: domCustomer.mobile_phone,
|
|
798
|
+
metadata: domCustomer.code_external ? { code_external: domCustomer.code_external } : void 0
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
function mapDomStatus(domStatus) {
|
|
802
|
+
switch (domStatus) {
|
|
803
|
+
case "pending":
|
|
804
|
+
return "pending";
|
|
805
|
+
case "paid":
|
|
806
|
+
return "paid";
|
|
807
|
+
case "canceled":
|
|
808
|
+
return "canceled";
|
|
809
|
+
case "failed":
|
|
810
|
+
return "failed";
|
|
811
|
+
case "refunded":
|
|
812
|
+
return "refunded";
|
|
813
|
+
default:
|
|
814
|
+
return "pending";
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
function toDomainCharge(domTransaction) {
|
|
818
|
+
return {
|
|
819
|
+
id: domTransaction.id,
|
|
820
|
+
status: mapDomStatus(domTransaction.status),
|
|
821
|
+
amount: Money.fromCents(domTransaction.amount, domTransaction.currency || "BRL"),
|
|
822
|
+
paymentMethod: domTransaction.payment_method === "credit_card" ? "card" : domTransaction.payment_method,
|
|
823
|
+
customerId: domTransaction.customer?.id,
|
|
824
|
+
description: domTransaction.items?.[0]?.description,
|
|
825
|
+
createdAt: new Date(domTransaction.created_at),
|
|
826
|
+
boleto: domTransaction.payment_method === "boleto" ? {
|
|
827
|
+
url: domTransaction.boleto_url,
|
|
828
|
+
barcode: domTransaction.boleto_digitable_line
|
|
829
|
+
} : void 0,
|
|
830
|
+
pix: domTransaction.payment_method === "pix" ? {
|
|
831
|
+
copyPaste: domTransaction.pix_content,
|
|
832
|
+
qrCode: domTransaction.pix_qrcode
|
|
833
|
+
} : void 0
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
function toWebhookEvent3(payload) {
|
|
837
|
+
const transaction = payload.data?.transaction;
|
|
838
|
+
if (!transaction) return { type: "unknown", data: null, raw: payload };
|
|
839
|
+
const charge = toDomainCharge(transaction);
|
|
840
|
+
switch (payload.event) {
|
|
841
|
+
case "transaction.paid":
|
|
842
|
+
return { type: "charge.paid", data: charge, raw: payload };
|
|
843
|
+
case "transaction.failed":
|
|
844
|
+
return { type: "charge.failed", data: charge, raw: payload };
|
|
845
|
+
case "transaction.refunded":
|
|
846
|
+
return { type: "charge.refunded", data: charge, raw: payload };
|
|
847
|
+
default:
|
|
848
|
+
return { type: "unknown", data: null, raw: payload };
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// src/adapters/dom/ports.ts
|
|
853
|
+
var PROVIDER5 = "dom";
|
|
854
|
+
function buildDomCustomerPort(http) {
|
|
855
|
+
return {
|
|
856
|
+
create: async (input) => {
|
|
857
|
+
const response = await http.post("/customers", toDomCustomer(input));
|
|
858
|
+
return toDomainCustomer(response);
|
|
859
|
+
},
|
|
860
|
+
get: async (id) => {
|
|
861
|
+
try {
|
|
862
|
+
const response = await http.get(`/customers/${id}`);
|
|
863
|
+
return toDomainCustomer(response);
|
|
864
|
+
} catch (err) {
|
|
865
|
+
if (err.message.includes("404")) return null;
|
|
866
|
+
throw err;
|
|
867
|
+
}
|
|
868
|
+
},
|
|
869
|
+
update: async (id, input) => {
|
|
870
|
+
const response = await http.post(`/customers/${id}`, toDomCustomer(input));
|
|
871
|
+
return toDomainCustomer(response);
|
|
872
|
+
},
|
|
873
|
+
delete: async (id) => {
|
|
874
|
+
await http.delete(`/customers/${id}`);
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
function buildDomChargePort(http, customerPort) {
|
|
879
|
+
return {
|
|
880
|
+
create: async (input) => {
|
|
881
|
+
let customerData;
|
|
882
|
+
if (!input.cardToken) {
|
|
883
|
+
const c = await customerPort.get(input.customerId);
|
|
884
|
+
if (!c) throw new Error("Cliente n\xE3o encontrado para criar transa\xE7\xE3o (DOM Pagamentos exige customer para Pix/Boleto)");
|
|
885
|
+
customerData = toDomCustomer({ ...c, phone: c.phone || "00000000000", taxId: c.taxId });
|
|
886
|
+
}
|
|
887
|
+
const isBoleto = input.paymentMethod === "boleto";
|
|
888
|
+
const isPix = input.paymentMethod === "pix";
|
|
889
|
+
const isCard = input.paymentMethod === "card";
|
|
890
|
+
const payload = {
|
|
891
|
+
cod_external: input.metadata?.cod_external || input.idempotencyKey,
|
|
892
|
+
items: [{ description: input.description || "Cobran\xE7a", price: input.amount.toDecimal(), quantity: 1 }],
|
|
893
|
+
payment: {
|
|
894
|
+
total: input.amount.toDecimal(),
|
|
895
|
+
payment_method: isCard ? "credit_card" : input.paymentMethod
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
if (customerData) payload.customer = customerData;
|
|
899
|
+
if (isCard && input.cardToken) payload.payment.credit_card = { token: input.cardToken, installments: 1 };
|
|
900
|
+
if (isBoleto) payload.payment.boleto = { boleto_due_days: 3 };
|
|
901
|
+
if (isPix) payload.payment.pix = {};
|
|
902
|
+
const response = await http.post("/transactions", payload);
|
|
903
|
+
return toDomainCharge(response);
|
|
904
|
+
},
|
|
905
|
+
get: async (id) => {
|
|
906
|
+
try {
|
|
907
|
+
const response = await http.get(`/transactions/${id}`);
|
|
908
|
+
return toDomainCharge(response);
|
|
909
|
+
} catch (err) {
|
|
910
|
+
if (err.message.includes("404")) return null;
|
|
911
|
+
throw err;
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
cancel: async (id) => {
|
|
915
|
+
const response = await http.post(`/transactions/${id}/cancel`);
|
|
916
|
+
return toDomainCharge(response);
|
|
917
|
+
},
|
|
918
|
+
refund: async (input) => {
|
|
919
|
+
const payload = {};
|
|
920
|
+
if (input.amount) {
|
|
921
|
+
payload.amount = input.amount.toDecimal();
|
|
922
|
+
}
|
|
923
|
+
const response = await http.post(`/transactions/${input.chargeId}/refund`, payload);
|
|
924
|
+
return toDomainCharge(response);
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
function buildDomSubscriptionPort(http) {
|
|
929
|
+
return {
|
|
930
|
+
create: async (input) => {
|
|
931
|
+
throw new UnknownGatewayError(PROVIDER5, "DOM SubscriptionPort.create n\xE3o implementado.", { cause: null });
|
|
932
|
+
},
|
|
933
|
+
get: async (id) => {
|
|
934
|
+
throw new UnknownGatewayError(PROVIDER5, "DOM SubscriptionPort.get n\xE3o implementado.", { cause: null });
|
|
935
|
+
},
|
|
936
|
+
cancel: async (id) => {
|
|
937
|
+
throw new UnknownGatewayError(PROVIDER5, "DOM SubscriptionPort.cancel n\xE3o implementado.", { cause: null });
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
function buildDomWebhookPort(webhookSecret) {
|
|
942
|
+
return {
|
|
943
|
+
verifyAndParse: (input) => {
|
|
944
|
+
const receivedToken = input.headers["authorization"] || input.headers["x-dom-token"];
|
|
945
|
+
if (webhookSecret && receivedToken !== webhookSecret) {
|
|
946
|
+
throw new ValidationError(PROVIDER5, "Token de webhook inv\xE1lido.");
|
|
947
|
+
}
|
|
948
|
+
const payload = typeof input.payload === "string" ? JSON.parse(input.payload) : JSON.parse(input.payload.toString());
|
|
949
|
+
return toWebhookEvent3(payload);
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// src/adapters/dom/DomGateway.ts
|
|
955
|
+
var PROVIDER6 = "dom";
|
|
956
|
+
var DomGateway = class {
|
|
957
|
+
constructor(config, http) {
|
|
958
|
+
this.config = config;
|
|
959
|
+
this.http = http ?? new DomHttpClient(config);
|
|
960
|
+
this.customers = buildDomCustomerPort(this.http);
|
|
961
|
+
this.charges = buildDomChargePort(this.http, this.customers);
|
|
962
|
+
this.subscriptions = buildDomSubscriptionPort(this.http);
|
|
963
|
+
this.webhooks = buildDomWebhookPort(config.webhookToken);
|
|
964
|
+
}
|
|
965
|
+
config;
|
|
966
|
+
provider = PROVIDER6;
|
|
967
|
+
capabilities = /* @__PURE__ */ new Set([
|
|
968
|
+
Capability.PIX,
|
|
969
|
+
Capability.CARD,
|
|
970
|
+
Capability.BOLETO,
|
|
971
|
+
Capability.REFUND
|
|
972
|
+
]);
|
|
973
|
+
http;
|
|
974
|
+
customers;
|
|
975
|
+
charges;
|
|
976
|
+
subscriptions;
|
|
977
|
+
webhooks;
|
|
978
|
+
supports(capability) {
|
|
979
|
+
return this.capabilities.has(capability);
|
|
980
|
+
}
|
|
981
|
+
raw() {
|
|
982
|
+
return this.http;
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
// src/createGateway.ts
|
|
987
|
+
function createGateway(config) {
|
|
988
|
+
switch (config.provider) {
|
|
989
|
+
case "stripe":
|
|
990
|
+
return new StripeGateway(config);
|
|
991
|
+
case "asaas":
|
|
992
|
+
return new AsaasGateway(config);
|
|
993
|
+
case "dom":
|
|
994
|
+
return new DomGateway(config);
|
|
995
|
+
default: {
|
|
996
|
+
const exhaustive = config;
|
|
997
|
+
throw new Error(`Provider n\xE3o suportado: ${JSON.stringify(exhaustive)}`);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
export {
|
|
1002
|
+
AsaasApiError,
|
|
1003
|
+
AsaasGateway,
|
|
1004
|
+
AuthenticationError,
|
|
1005
|
+
Capability,
|
|
1006
|
+
CardDeclinedError,
|
|
1007
|
+
GatewayError,
|
|
1008
|
+
GatewayUnavailableError,
|
|
1009
|
+
Money,
|
|
1010
|
+
RateLimitError,
|
|
1011
|
+
StripeGateway,
|
|
1012
|
+
UnknownGatewayError,
|
|
1013
|
+
UnsupportedCapabilityError,
|
|
1014
|
+
ValidationError,
|
|
1015
|
+
createAsaasHttpClient,
|
|
1016
|
+
createGateway,
|
|
1017
|
+
hasCapability
|
|
1018
|
+
};
|
|
1019
|
+
//# sourceMappingURL=index.js.map
|