@pagosrd/node 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/index.cjs +303 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +558 -0
- package/dist/index.d.ts +558 -0
- package/dist/index.js +268 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
export { SIGNATURE_HEADER, WebhookSignatureError, formatMoney, toCents } from '@pagosrd/core';
|
|
2
|
+
|
|
3
|
+
/** Tipos de los objetos de la API de PagosRD. Montos en centavos. */
|
|
4
|
+
type Livemode = boolean;
|
|
5
|
+
interface List<T> {
|
|
6
|
+
object: "list";
|
|
7
|
+
data: T[];
|
|
8
|
+
has_more: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Lo que el tarjetahabiente ve antes de pagar (requisito de Visa y Mastercard). */
|
|
11
|
+
interface CustomerInfo {
|
|
12
|
+
support_email: string | null;
|
|
13
|
+
support_phone: string | null;
|
|
14
|
+
address_line: string | null;
|
|
15
|
+
address_city: string | null;
|
|
16
|
+
/** País, ISO 3166-1 alfa-2 (por ejemplo "DO"). */
|
|
17
|
+
address_country: string;
|
|
18
|
+
refund_policy: string | null;
|
|
19
|
+
delivery_policy: string | null;
|
|
20
|
+
}
|
|
21
|
+
/** Campos omitidos no cambian; null o "" los borra. En live son obligatorios todos. */
|
|
22
|
+
type CustomerInfoParams = Partial<Omit<CustomerInfo, "address_country">> & {
|
|
23
|
+
address_country?: string;
|
|
24
|
+
};
|
|
25
|
+
interface Merchant {
|
|
26
|
+
id: string;
|
|
27
|
+
object: "merchant";
|
|
28
|
+
livemode: Livemode;
|
|
29
|
+
name: string;
|
|
30
|
+
rnc: string | null;
|
|
31
|
+
external_id: string | null;
|
|
32
|
+
processor: "simulador" | "azul" | "cardnet";
|
|
33
|
+
processor_configured: boolean;
|
|
34
|
+
processor_summary: Record<string, string>;
|
|
35
|
+
status: "active" | "disabled";
|
|
36
|
+
metadata: Record<string, string>;
|
|
37
|
+
customer_info: CustomerInfo;
|
|
38
|
+
/** true si ya tiene contacto, dirección y políticas: lo necesario para cobrar en vivo. */
|
|
39
|
+
customer_info_complete: boolean;
|
|
40
|
+
created_at: string;
|
|
41
|
+
updated_at: string;
|
|
42
|
+
}
|
|
43
|
+
interface AzulConfig {
|
|
44
|
+
environment: "pruebas" | "produccion";
|
|
45
|
+
merchant_id: string;
|
|
46
|
+
auth1: string;
|
|
47
|
+
auth2: string;
|
|
48
|
+
certificate_pem: string;
|
|
49
|
+
private_key_pem: string;
|
|
50
|
+
payment_page: {
|
|
51
|
+
auth_key: string;
|
|
52
|
+
merchant_name: string;
|
|
53
|
+
merchant_type: string;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
interface CardnetConfig {
|
|
57
|
+
environment: "certificacion" | "produccion";
|
|
58
|
+
merchant_number: string;
|
|
59
|
+
merchant_terminal: string;
|
|
60
|
+
merchant_terminal_amex?: string;
|
|
61
|
+
merchant_type: string;
|
|
62
|
+
merchant_name: string;
|
|
63
|
+
acquiring_institution_code?: string;
|
|
64
|
+
}
|
|
65
|
+
interface PaymentLink {
|
|
66
|
+
id: string;
|
|
67
|
+
object: "payment_link";
|
|
68
|
+
livemode: Livemode;
|
|
69
|
+
url: string;
|
|
70
|
+
merchant_id: string;
|
|
71
|
+
amount: number;
|
|
72
|
+
itbis: number;
|
|
73
|
+
currency: "DOP" | "USD";
|
|
74
|
+
description: string;
|
|
75
|
+
reference: string | null;
|
|
76
|
+
customer: {
|
|
77
|
+
name: string | null;
|
|
78
|
+
email: string | null;
|
|
79
|
+
phone: string | null;
|
|
80
|
+
reference: string | null;
|
|
81
|
+
};
|
|
82
|
+
/** true si la tarjeta con la que se pague queda guardada. */
|
|
83
|
+
save_payment_method: boolean;
|
|
84
|
+
locale: "es" | "en";
|
|
85
|
+
success_url: string | null;
|
|
86
|
+
status: "open" | "paid" | "expired" | "canceled";
|
|
87
|
+
expires_at: string | null;
|
|
88
|
+
paid_at: string | null;
|
|
89
|
+
payment_id: string | null;
|
|
90
|
+
metadata: Record<string, string>;
|
|
91
|
+
created_at: string;
|
|
92
|
+
}
|
|
93
|
+
type PaymentStatus = "pending" | "processing" | "succeeded" | "failed" | "canceled";
|
|
94
|
+
interface Payment {
|
|
95
|
+
id: string;
|
|
96
|
+
object: "payment";
|
|
97
|
+
livemode: Livemode;
|
|
98
|
+
merchant_id: string;
|
|
99
|
+
payment_link_id: string | null;
|
|
100
|
+
/** Tarjeta guardada con la que se cobró (cobros por API). */
|
|
101
|
+
payment_method_id: string | null;
|
|
102
|
+
/** Concepto del cobro por API; en los pagos de un link está en el link. */
|
|
103
|
+
description: string | null;
|
|
104
|
+
reference: string | null;
|
|
105
|
+
/** Serie recurrente del cobro con tarjeta guardada; null en links y compras puntuales. */
|
|
106
|
+
recurring: RecurringType | null;
|
|
107
|
+
/** customer = lo inició el cliente (CIT); merchant = lo inició el comercio sobre una serie ya autorizada (MIT). */
|
|
108
|
+
initiated_by: "customer" | "merchant" | null;
|
|
109
|
+
/** Suscripción que generó este cobro. */
|
|
110
|
+
subscription_id: string | null;
|
|
111
|
+
/** Periodo de la suscripción que cobra (1 = el primero). */
|
|
112
|
+
subscription_period: number | null;
|
|
113
|
+
amount: number;
|
|
114
|
+
itbis: number;
|
|
115
|
+
amount_refunded: number;
|
|
116
|
+
itbis_refunded: number;
|
|
117
|
+
currency: "DOP" | "USD";
|
|
118
|
+
status: PaymentStatus;
|
|
119
|
+
requires_review: boolean;
|
|
120
|
+
processor: "simulador" | "azul" | "cardnet";
|
|
121
|
+
order_number: string;
|
|
122
|
+
processor_order_id: string | null;
|
|
123
|
+
authorization_code: string | null;
|
|
124
|
+
card: {
|
|
125
|
+
brand: string | null;
|
|
126
|
+
last4: string;
|
|
127
|
+
} | null;
|
|
128
|
+
failure_code: string | null;
|
|
129
|
+
failure_message: string | null;
|
|
130
|
+
metadata: Record<string, string>;
|
|
131
|
+
paid_at: string | null;
|
|
132
|
+
created_at: string;
|
|
133
|
+
}
|
|
134
|
+
/** Tarjeta guardada (DataVault de AZUL o el simulador). El token nunca sale de PagosRD. */
|
|
135
|
+
interface PaymentMethod {
|
|
136
|
+
id: string;
|
|
137
|
+
object: "payment_method";
|
|
138
|
+
livemode: Livemode;
|
|
139
|
+
merchant_id: string;
|
|
140
|
+
/** Id del cliente en tu sistema. */
|
|
141
|
+
customer_reference: string;
|
|
142
|
+
processor: "simulador" | "azul" | "cardnet";
|
|
143
|
+
card: {
|
|
144
|
+
brand: string | null;
|
|
145
|
+
last4: string | null;
|
|
146
|
+
exp_month: number | null;
|
|
147
|
+
exp_year: number | null;
|
|
148
|
+
};
|
|
149
|
+
status: "active" | "deleted";
|
|
150
|
+
source_payment_id: string | null;
|
|
151
|
+
created_at: string;
|
|
152
|
+
deleted_at: string | null;
|
|
153
|
+
}
|
|
154
|
+
type SubscriptionStatus = "active" | "past_due" | "unpaid" | "canceled" | "completed";
|
|
155
|
+
/**
|
|
156
|
+
* Cobro automático y periódico con una tarjeta guardada. PagosRD crea cada cobro en
|
|
157
|
+
* su fecha; cada uno llega como `payment.succeeded` o `payment.failed` con `subscription_id`.
|
|
158
|
+
*/
|
|
159
|
+
interface Subscription {
|
|
160
|
+
id: string;
|
|
161
|
+
object: "subscription";
|
|
162
|
+
livemode: Livemode;
|
|
163
|
+
merchant_id: string;
|
|
164
|
+
payment_method_id: string;
|
|
165
|
+
customer_reference: string;
|
|
166
|
+
kind: RecurringType;
|
|
167
|
+
description: string;
|
|
168
|
+
reference: string | null;
|
|
169
|
+
metadata: Record<string, string>;
|
|
170
|
+
amount: number;
|
|
171
|
+
itbis: number;
|
|
172
|
+
currency: "DOP" | "USD";
|
|
173
|
+
interval: "week" | "month";
|
|
174
|
+
interval_count: number;
|
|
175
|
+
start_at: string;
|
|
176
|
+
total_charges: number | null;
|
|
177
|
+
charges_count: number;
|
|
178
|
+
/** active al día; past_due reintentando; unpaid sin más reintentos (reactívala con retry o cambiando la tarjeta); canceled; completed. */
|
|
179
|
+
status: SubscriptionStatus;
|
|
180
|
+
next_charge_at: string | null;
|
|
181
|
+
failed_attempts: number;
|
|
182
|
+
/** Periodo que se está cobrando o el próximo (1 = el primero). */
|
|
183
|
+
current_period: number;
|
|
184
|
+
/** Cobro en curso esperando la confirmación del procesador. */
|
|
185
|
+
pending_payment_id: string | null;
|
|
186
|
+
last_payment_id: string | null;
|
|
187
|
+
last_failure: {
|
|
188
|
+
code: string;
|
|
189
|
+
message: string | null;
|
|
190
|
+
} | null;
|
|
191
|
+
canceled_at: string | null;
|
|
192
|
+
created_at: string;
|
|
193
|
+
}
|
|
194
|
+
interface CreateSubscriptionParams {
|
|
195
|
+
payment_method_id: string;
|
|
196
|
+
/** Monto de cada cobro en centavos, ITBIS incluido. */
|
|
197
|
+
amount: number;
|
|
198
|
+
itbis?: number;
|
|
199
|
+
description: string;
|
|
200
|
+
reference?: string | null;
|
|
201
|
+
metadata?: Record<string, string>;
|
|
202
|
+
interval: "week" | "month";
|
|
203
|
+
/** Cada cuántos intervalos (por defecto 1). */
|
|
204
|
+
interval_count?: number;
|
|
205
|
+
/** Por defecto subscription (monto fijo). installment exige total_charges. */
|
|
206
|
+
kind?: RecurringType;
|
|
207
|
+
total_charges?: number | null;
|
|
208
|
+
/** ISO 8601. Fecha del primer cobro; por defecto, ahora. */
|
|
209
|
+
start_at?: string | null;
|
|
210
|
+
}
|
|
211
|
+
interface UpdateSubscriptionParams {
|
|
212
|
+
/** Otra tarjeta del mismo cliente. Reactiva una suscripción past_due o unpaid. */
|
|
213
|
+
payment_method_id?: string;
|
|
214
|
+
amount?: number;
|
|
215
|
+
itbis?: number;
|
|
216
|
+
description?: string;
|
|
217
|
+
reference?: string | null;
|
|
218
|
+
metadata?: Record<string, string>;
|
|
219
|
+
}
|
|
220
|
+
interface Refund {
|
|
221
|
+
id: string;
|
|
222
|
+
object: "refund";
|
|
223
|
+
livemode: Livemode;
|
|
224
|
+
payment_id: string;
|
|
225
|
+
amount: number;
|
|
226
|
+
itbis: number;
|
|
227
|
+
reason: string | null;
|
|
228
|
+
status: "pending" | "succeeded" | "failed";
|
|
229
|
+
failure_message: string | null;
|
|
230
|
+
created_at: string;
|
|
231
|
+
}
|
|
232
|
+
type EventType = "payment.succeeded" | "payment.failed" | "payment.requires_review" | "payment_link.paid" | "payment_link.expired" | "payment_link.canceled" | "refund.succeeded" | "refund.failed" | "payment_method.created" | "payment_method.deleted" | "subscription.created" | "subscription.updated" | "subscription.past_due" | "subscription.period_unpaid" | "subscription.unpaid" | "subscription.canceled" | "subscription.completed";
|
|
233
|
+
interface EventBase<T extends EventType, D> {
|
|
234
|
+
id: string;
|
|
235
|
+
object: "event";
|
|
236
|
+
livemode: Livemode;
|
|
237
|
+
type: T;
|
|
238
|
+
data: D;
|
|
239
|
+
created_at: string;
|
|
240
|
+
}
|
|
241
|
+
/** Evento de webhook. `type` discrimina el contenido de `data`. */
|
|
242
|
+
type Event = EventBase<"payment.succeeded", {
|
|
243
|
+
object: Payment;
|
|
244
|
+
payment_link_reference: string | null;
|
|
245
|
+
saved_payment_method: PaymentMethod | null;
|
|
246
|
+
}> | EventBase<"payment.failed" | "payment.requires_review", {
|
|
247
|
+
object: Payment;
|
|
248
|
+
}> | EventBase<"payment_link.paid" | "payment_link.expired" | "payment_link.canceled", {
|
|
249
|
+
object: PaymentLink;
|
|
250
|
+
}> | EventBase<"refund.succeeded", {
|
|
251
|
+
object: Refund;
|
|
252
|
+
payment: Payment;
|
|
253
|
+
}> | EventBase<"refund.failed", {
|
|
254
|
+
object: Refund;
|
|
255
|
+
}> | EventBase<"payment_method.created", {
|
|
256
|
+
object: PaymentMethod;
|
|
257
|
+
payment_id: string;
|
|
258
|
+
}> | EventBase<"payment_method.deleted", {
|
|
259
|
+
object: PaymentMethod;
|
|
260
|
+
}> | EventBase<"subscription.created" | "subscription.updated" | "subscription.past_due" | "subscription.unpaid" | "subscription.canceled" | "subscription.completed", {
|
|
261
|
+
object: Subscription;
|
|
262
|
+
}>
|
|
263
|
+
/** Un periodo venció sin cobrarse (se agotó su tiempo o sus reintentos). Cóbralo por otra vía si corresponde. */
|
|
264
|
+
| EventBase<"subscription.period_unpaid", {
|
|
265
|
+
object: Subscription;
|
|
266
|
+
periods: Array<{
|
|
267
|
+
period: number;
|
|
268
|
+
due_at: string;
|
|
269
|
+
amount: number;
|
|
270
|
+
}>;
|
|
271
|
+
}>;
|
|
272
|
+
interface WebhookEndpoint {
|
|
273
|
+
id: string;
|
|
274
|
+
object: "webhook_endpoint";
|
|
275
|
+
livemode: Livemode;
|
|
276
|
+
url: string;
|
|
277
|
+
description: string | null;
|
|
278
|
+
events: string[];
|
|
279
|
+
enabled: boolean;
|
|
280
|
+
created_at: string;
|
|
281
|
+
}
|
|
282
|
+
interface WebhookDelivery {
|
|
283
|
+
id: string;
|
|
284
|
+
object: "webhook_delivery";
|
|
285
|
+
event_id: string;
|
|
286
|
+
event_type: string | null;
|
|
287
|
+
endpoint_id: string;
|
|
288
|
+
status: "pending" | "succeeded" | "failed";
|
|
289
|
+
attempts: number;
|
|
290
|
+
last_response_status: number | null;
|
|
291
|
+
last_response_body: string | null;
|
|
292
|
+
last_error: string | null;
|
|
293
|
+
next_attempt_at: string | null;
|
|
294
|
+
delivered_at: string | null;
|
|
295
|
+
created_at: string;
|
|
296
|
+
}
|
|
297
|
+
interface Summary {
|
|
298
|
+
object: "summary";
|
|
299
|
+
from: string;
|
|
300
|
+
to: string;
|
|
301
|
+
succeeded_count: number;
|
|
302
|
+
succeeded_amount: number;
|
|
303
|
+
refunded_amount: number;
|
|
304
|
+
failed_count: number;
|
|
305
|
+
review_count: number;
|
|
306
|
+
daily: {
|
|
307
|
+
day: string;
|
|
308
|
+
amount: number;
|
|
309
|
+
count: number;
|
|
310
|
+
}[];
|
|
311
|
+
}
|
|
312
|
+
interface PageParams {
|
|
313
|
+
limit?: number;
|
|
314
|
+
starting_after?: string;
|
|
315
|
+
}
|
|
316
|
+
interface CreatePaymentLinkParams {
|
|
317
|
+
merchant_id: string;
|
|
318
|
+
/** Total en centavos, ITBIS incluido. 450000 = RD$4,500.00 */
|
|
319
|
+
amount: number;
|
|
320
|
+
itbis?: number;
|
|
321
|
+
description: string;
|
|
322
|
+
reference?: string | null;
|
|
323
|
+
/** `reference` = id del cliente en tu sistema; obligatorio con save_payment_method. */
|
|
324
|
+
customer?: {
|
|
325
|
+
name?: string | null;
|
|
326
|
+
email?: string | null;
|
|
327
|
+
phone?: string | null;
|
|
328
|
+
reference?: string | null;
|
|
329
|
+
};
|
|
330
|
+
/** Guardar la tarjeta con la que se pague para cobrar después con payments.create. */
|
|
331
|
+
save_payment_method?: boolean;
|
|
332
|
+
locale?: "es" | "en";
|
|
333
|
+
success_url?: string | null;
|
|
334
|
+
expires_at?: string | null;
|
|
335
|
+
metadata?: Record<string, string>;
|
|
336
|
+
}
|
|
337
|
+
interface CreateMerchantParams {
|
|
338
|
+
name: string;
|
|
339
|
+
rnc?: string | null;
|
|
340
|
+
external_id?: string | null;
|
|
341
|
+
processor: "simulador" | "azul" | "cardnet";
|
|
342
|
+
processor_config?: AzulConfig | CardnetConfig;
|
|
343
|
+
customer_info?: CustomerInfoParams;
|
|
344
|
+
metadata?: Record<string, string>;
|
|
345
|
+
}
|
|
346
|
+
interface CreatePaymentParams {
|
|
347
|
+
payment_method_id: string;
|
|
348
|
+
/** Total en centavos, ITBIS incluido. */
|
|
349
|
+
amount: number;
|
|
350
|
+
itbis?: number;
|
|
351
|
+
description: string;
|
|
352
|
+
reference?: string | null;
|
|
353
|
+
metadata?: Record<string, string>;
|
|
354
|
+
/**
|
|
355
|
+
* Serie recurrente del cobro. Sin él es una compra puntual con el cliente presente,
|
|
356
|
+
* que con AZUL todavía no está disponible (necesita 3D Secure).
|
|
357
|
+
*/
|
|
358
|
+
recurring?: RecurringType;
|
|
359
|
+
}
|
|
360
|
+
/** subscription = monto y frecuencia fijos; standing_order = monto variable, frecuencia fija; installment = cuotas. */
|
|
361
|
+
type RecurringType = "subscription" | "standing_order" | "installment";
|
|
362
|
+
interface CreateRefundParams {
|
|
363
|
+
amount?: number;
|
|
364
|
+
itbis?: number;
|
|
365
|
+
reason?: string | null;
|
|
366
|
+
}
|
|
367
|
+
interface RequestOptions {
|
|
368
|
+
/** Llave de idempotencia propia. Si no la pasas, el SDK genera una por solicitud. */
|
|
369
|
+
idempotencyKey?: string;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
declare const DEFAULT_BASE_URL = "https://api.pagosrd.com";
|
|
373
|
+
/** Error devuelto por la API (Problem Details). */
|
|
374
|
+
declare class PagosRDError extends Error {
|
|
375
|
+
readonly status: number;
|
|
376
|
+
readonly code: string;
|
|
377
|
+
readonly field: string | undefined;
|
|
378
|
+
readonly requestId: string | undefined;
|
|
379
|
+
readonly raw: unknown;
|
|
380
|
+
readonly name = "PagosRDError";
|
|
381
|
+
constructor(message: string, status: number, code: string, field: string | undefined, requestId: string | undefined, raw: unknown);
|
|
382
|
+
}
|
|
383
|
+
/** No se pudo hablar con la API (red caída, timeout). */
|
|
384
|
+
declare class PagosRDConnectionError extends Error {
|
|
385
|
+
readonly name = "PagosRDConnectionError";
|
|
386
|
+
}
|
|
387
|
+
interface PagosRDOptions {
|
|
388
|
+
/** Por defecto https://api.pagosrd.com */
|
|
389
|
+
baseUrl?: string;
|
|
390
|
+
/** Reintentos ante fallas de red, 429 y 5xx. Por defecto 2. Los POST llevan llave de idempotencia, así que reintentar es seguro. */
|
|
391
|
+
maxRetries?: number;
|
|
392
|
+
/** Tiempo máximo por solicitud en ms. Por defecto 30000. */
|
|
393
|
+
timeoutMs?: number;
|
|
394
|
+
fetch?: typeof fetch;
|
|
395
|
+
}
|
|
396
|
+
declare class PagosRD {
|
|
397
|
+
private readonly apiKey;
|
|
398
|
+
private readonly baseUrl;
|
|
399
|
+
private readonly maxRetries;
|
|
400
|
+
private readonly timeoutMs;
|
|
401
|
+
private readonly fetchImpl;
|
|
402
|
+
constructor(apiKey: string, options?: PagosRDOptions);
|
|
403
|
+
/** true si la llave es de modo de prueba. */
|
|
404
|
+
get testMode(): boolean;
|
|
405
|
+
readonly paymentLinks: {
|
|
406
|
+
create: (params: CreatePaymentLinkParams, opts?: RequestOptions) => Promise<PaymentLink>;
|
|
407
|
+
retrieve: (id: string) => Promise<PaymentLink>;
|
|
408
|
+
list: (params?: PageParams & {
|
|
409
|
+
status?: PaymentLink["status"];
|
|
410
|
+
merchant_id?: string;
|
|
411
|
+
reference?: string;
|
|
412
|
+
}) => Promise<List<PaymentLink>>;
|
|
413
|
+
cancel: (id: string) => Promise<PaymentLink>;
|
|
414
|
+
};
|
|
415
|
+
readonly payments: {
|
|
416
|
+
/**
|
|
417
|
+
* Cobra con una tarjeta guardada, sin que el cliente vea ninguna página. La llave de
|
|
418
|
+
* idempotencia es obligatoria: usa algo propio de la operación (el id del pedido) para
|
|
419
|
+
* que reintentar nunca cobre dos veces. El pago vuelve succeeded, failed o processing.
|
|
420
|
+
*/
|
|
421
|
+
create: (params: CreatePaymentParams, opts: RequestOptions & {
|
|
422
|
+
idempotencyKey: string;
|
|
423
|
+
}) => Promise<Payment>;
|
|
424
|
+
retrieve: (id: string) => Promise<Payment>;
|
|
425
|
+
list: (params?: PageParams & {
|
|
426
|
+
status?: PaymentStatus;
|
|
427
|
+
merchant_id?: string;
|
|
428
|
+
payment_link_id?: string;
|
|
429
|
+
payment_method_id?: string;
|
|
430
|
+
subscription_id?: string;
|
|
431
|
+
created_gte?: string;
|
|
432
|
+
created_lte?: string;
|
|
433
|
+
}) => Promise<List<Payment>>;
|
|
434
|
+
};
|
|
435
|
+
readonly paymentMethods: {
|
|
436
|
+
retrieve: (id: string) => Promise<PaymentMethod>;
|
|
437
|
+
list: (params?: PageParams & {
|
|
438
|
+
merchant_id?: string;
|
|
439
|
+
customer_reference?: string;
|
|
440
|
+
status?: PaymentMethod["status"];
|
|
441
|
+
}) => Promise<List<PaymentMethod>>;
|
|
442
|
+
/** Deja de poder usarse de inmediato y se borra el token en el procesador. */
|
|
443
|
+
del: (id: string) => Promise<PaymentMethod>;
|
|
444
|
+
};
|
|
445
|
+
readonly subscriptions: {
|
|
446
|
+
/**
|
|
447
|
+
* PagosRD cobra solo en cada fecha con la tarjeta guardada; reintenta los rechazos a 1, 3 y 5 días.
|
|
448
|
+
* La llave de idempotencia es obligatoria: usa el id del contrato para que reintentar no cree otra.
|
|
449
|
+
*/
|
|
450
|
+
create: (params: CreateSubscriptionParams, opts: RequestOptions & {
|
|
451
|
+
idempotencyKey: string;
|
|
452
|
+
}) => Promise<Subscription>;
|
|
453
|
+
retrieve: (id: string) => Promise<Subscription>;
|
|
454
|
+
list: (params?: PageParams & {
|
|
455
|
+
status?: SubscriptionStatus;
|
|
456
|
+
merchant_id?: string;
|
|
457
|
+
customer_reference?: string;
|
|
458
|
+
payment_method_id?: string;
|
|
459
|
+
}) => Promise<List<Subscription>>;
|
|
460
|
+
update: (id: string, params: UpdateSubscriptionParams) => Promise<Subscription>;
|
|
461
|
+
/** Reintenta ya el cobro de una suscripción past_due o unpaid con la misma tarjeta. */
|
|
462
|
+
retry: (id: string) => Promise<Subscription>;
|
|
463
|
+
cancel: (id: string) => Promise<Subscription>;
|
|
464
|
+
};
|
|
465
|
+
readonly refunds: {
|
|
466
|
+
create: (paymentId: string, params?: CreateRefundParams, opts?: RequestOptions) => Promise<Refund>;
|
|
467
|
+
list: (params?: PageParams & {
|
|
468
|
+
payment_id?: string;
|
|
469
|
+
}) => Promise<List<Refund>>;
|
|
470
|
+
};
|
|
471
|
+
readonly merchants: {
|
|
472
|
+
create: (params: CreateMerchantParams) => Promise<Merchant>;
|
|
473
|
+
retrieve: (id: string) => Promise<Merchant>;
|
|
474
|
+
list: (params?: PageParams) => Promise<List<Merchant>>;
|
|
475
|
+
update: (id: string, params: {
|
|
476
|
+
name?: string;
|
|
477
|
+
rnc?: string | null;
|
|
478
|
+
status?: "active" | "disabled";
|
|
479
|
+
metadata?: Record<string, string>;
|
|
480
|
+
customer_info?: CustomerInfoParams;
|
|
481
|
+
}) => Promise<Merchant>;
|
|
482
|
+
setProcessorConfig: (id: string, config: AzulConfig | CardnetConfig) => Promise<Merchant>;
|
|
483
|
+
balance: (id: string) => Promise<{
|
|
484
|
+
object: "balance";
|
|
485
|
+
merchant_id: string;
|
|
486
|
+
processor_receivable: number;
|
|
487
|
+
}>;
|
|
488
|
+
};
|
|
489
|
+
readonly webhookEndpoints: {
|
|
490
|
+
create: (params: {
|
|
491
|
+
url: string;
|
|
492
|
+
events?: string[];
|
|
493
|
+
description?: string | null;
|
|
494
|
+
}) => Promise<WebhookEndpoint & {
|
|
495
|
+
secret: string;
|
|
496
|
+
}>;
|
|
497
|
+
list: () => Promise<List<WebhookEndpoint>>;
|
|
498
|
+
retrieve: (id: string) => Promise<WebhookEndpoint>;
|
|
499
|
+
update: (id: string, params: {
|
|
500
|
+
url?: string;
|
|
501
|
+
events?: string[];
|
|
502
|
+
description?: string | null;
|
|
503
|
+
enabled?: boolean;
|
|
504
|
+
}) => Promise<WebhookEndpoint>;
|
|
505
|
+
del: (id: string) => Promise<{
|
|
506
|
+
id: string;
|
|
507
|
+
deleted: true;
|
|
508
|
+
}>;
|
|
509
|
+
rollSecret: (id: string) => Promise<{
|
|
510
|
+
secret: string;
|
|
511
|
+
}>;
|
|
512
|
+
deliveries: (params?: PageParams & {
|
|
513
|
+
endpoint_id?: string;
|
|
514
|
+
event_id?: string;
|
|
515
|
+
status?: WebhookDelivery["status"];
|
|
516
|
+
}) => Promise<List<WebhookDelivery>>;
|
|
517
|
+
};
|
|
518
|
+
readonly events: {
|
|
519
|
+
retrieve: (id: string) => Promise<Event>;
|
|
520
|
+
list: (params?: PageParams & {
|
|
521
|
+
type?: string;
|
|
522
|
+
}) => Promise<List<Event>>;
|
|
523
|
+
resend: (id: string, endpointId?: string) => Promise<List<WebhookDelivery>>;
|
|
524
|
+
};
|
|
525
|
+
summary(params?: {
|
|
526
|
+
from?: string;
|
|
527
|
+
to?: string;
|
|
528
|
+
}): Promise<Summary>;
|
|
529
|
+
/**
|
|
530
|
+
* Recorre todas las páginas de una lista.
|
|
531
|
+
*
|
|
532
|
+
* for await (const pago of client.autoPaginate((p) => client.payments.list({ ...p, status: "succeeded" }))) { … }
|
|
533
|
+
*/
|
|
534
|
+
autoPaginate<T extends {
|
|
535
|
+
id: string;
|
|
536
|
+
}>(fetchPage: (page: PageParams) => Promise<List<T>>, pageSize?: number): AsyncGenerator<T>;
|
|
537
|
+
private get;
|
|
538
|
+
private post;
|
|
539
|
+
private request;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Verifica la firma de un webhook y devuelve el evento tipado.
|
|
544
|
+
*
|
|
545
|
+
* IMPORTANTE: pasa el cuerpo CRUDO (string o Buffer), tal como llegó. Si tu
|
|
546
|
+
* framework ya lo convirtió a JSON, la firma no va a coincidir.
|
|
547
|
+
*
|
|
548
|
+
* ```ts
|
|
549
|
+
* app.post("/webhooks/pagosrd", express.raw({ type: "application/json" }), (req, res) => {
|
|
550
|
+
* const event = constructEvent(req.body, req.header("PagosRD-Signature"), process.env.PAGOSRD_WEBHOOK_SECRET!);
|
|
551
|
+
* if (event.type === "payment.succeeded") marcarCuotaPagada(event.data.payment_link_reference);
|
|
552
|
+
* res.sendStatus(200);
|
|
553
|
+
* });
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
declare function constructEvent(rawBody: string | Uint8Array, signatureHeader: string | null | undefined, secret: string, toleranceSeconds?: number): Event;
|
|
557
|
+
|
|
558
|
+
export { type AzulConfig, type CardnetConfig, type CreateMerchantParams, type CreatePaymentLinkParams, type CreatePaymentParams, type CreateRefundParams, type CreateSubscriptionParams, type CustomerInfo, type CustomerInfoParams, DEFAULT_BASE_URL, type Event, type EventType, type List, type Livemode, type Merchant, type PageParams, PagosRD, PagosRDConnectionError, PagosRDError, type PagosRDOptions, type Payment, type PaymentLink, type PaymentMethod, type PaymentStatus, type RecurringType, type Refund, type RequestOptions, type Subscription, type SubscriptionStatus, type Summary, type UpdateSubscriptionParams, type WebhookDelivery, type WebhookEndpoint, constructEvent };
|