mariapay 0.0.0-stage → 1.5.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 +37 -2
- package/dist/index.d.ts +502 -0
- package/dist/index.js +164 -0
- package/package.json +50 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Laercio Borges
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mariapay
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SDK da [Maria Pay](https://sniperpay-api-production.up.railway.app/docs) para Node 18+, Deno e Bun. Sem dependências.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install mariapay
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import MariaPay from 'mariapay';
|
|
11
|
+
|
|
12
|
+
const mp = new MariaPay(process.env.MARIAPAY_API_KEY!);
|
|
13
|
+
const pix = await mp.pix.create({ amount: 1990, description: 'Plano Pro' }); // R$ 19,90
|
|
14
|
+
// pix.brCode: Pix copia e cola · pix.brCodeBase64: QR Code em PNG
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Valores sempre em centavos. Chaves `sp_test_` para desenvolver e `sp_live_` em produção.
|
|
18
|
+
|
|
19
|
+
## Webhooks
|
|
20
|
+
|
|
21
|
+
Confira o secret e a assinatura com o corpo cru, antes do `JSON.parse`:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const ok = MariaPay.verifyWebhook(rawBody, {
|
|
25
|
+
secret: req.get('X-Webhook-Secret') ?? req.query.webhookSecret,
|
|
26
|
+
signature: req.get('X-Webhook-Signature'),
|
|
27
|
+
}, process.env.MARIAPAY_WEBHOOK_SECRET!);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API v2
|
|
31
|
+
|
|
32
|
+
`mp.v2` cobre produtos, clientes, cupons, checkout, links de pagamento, checkout transparente (Pix e boleto), reembolso e webhooks. Guia completo em [/docs](https://sniperpay-api-production.up.railway.app/docs).
|
|
33
|
+
|
|
34
|
+
Quem já usava os nomes `SniperPay`, `SniperPayError` e `SNIPERPAY_WEBHOOK_PUBLIC_KEY` pode continuar: eles são exportados como apelidos.
|
|
35
|
+
|
|
36
|
+
## Licença
|
|
37
|
+
|
|
38
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chave pública de assinatura dos webhooks da Maria Pay. Igual para todas as contas:
|
|
3
|
+
* X-Webhook-Signature = base64(HMAC-SHA256(corpo cru, esta chave)).
|
|
4
|
+
*/
|
|
5
|
+
export declare const MARIAPAY_WEBHOOK_PUBLIC_KEY = "5I3sRLuE2aSbSx3PtKzAiWgfK39zN2hp8B7Jhi2xn3QUmpT14ZIaWGNXsm6upvRFoiszscwi9CntL1k3reX0DM6PPam89xz0may1j6cccdmAsd59lsec334CMusPBNcQMGajPLSnMbJO8vm7ERYauGYRB1aJjZkQLwUsYoXl72uRhApzI1l10lYR2QbH33ldJEJfCZfBsYa9KacCigrqIKMh1pUk5oU7362svTjneZskovToAXpx4RuShiBlrEfn";
|
|
6
|
+
export type ChargeStatus = 'PENDING' | 'PAID' | 'EXPIRED' | 'CANCELLED' | 'REFUNDED';
|
|
7
|
+
export interface BoletoInfo {
|
|
8
|
+
providerChargeId: string;
|
|
9
|
+
barcode: string;
|
|
10
|
+
digitableLine: string;
|
|
11
|
+
dueDate: string;
|
|
12
|
+
pdfUrl: string | null;
|
|
13
|
+
installment: number | null;
|
|
14
|
+
installments: number | null;
|
|
15
|
+
carnetId: string | null;
|
|
16
|
+
}
|
|
17
|
+
export interface PixCharge {
|
|
18
|
+
id: string;
|
|
19
|
+
kind: 'pix' | 'boleto';
|
|
20
|
+
amount: number;
|
|
21
|
+
fee: number;
|
|
22
|
+
netAmount: number;
|
|
23
|
+
boleto: BoletoInfo | null;
|
|
24
|
+
paymentUrl: string;
|
|
25
|
+
status: ChargeStatus;
|
|
26
|
+
devMode: boolean;
|
|
27
|
+
description: string | null;
|
|
28
|
+
brCode: string | null;
|
|
29
|
+
brCodeBase64: string | null;
|
|
30
|
+
customer: Record<string, string> | null;
|
|
31
|
+
metadata: Record<string, unknown> | null;
|
|
32
|
+
endToEndId: string | null;
|
|
33
|
+
expiresAt: string;
|
|
34
|
+
paidAt: string | null;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
}
|
|
37
|
+
export interface CreatePixCharge {
|
|
38
|
+
/** valor em centavos (R$ 10,00 = 1000) */
|
|
39
|
+
amount: number;
|
|
40
|
+
/** segundos até expirar (padrão 3600) */
|
|
41
|
+
expiresIn?: number;
|
|
42
|
+
description?: string;
|
|
43
|
+
customer?: {
|
|
44
|
+
name?: string;
|
|
45
|
+
email?: string;
|
|
46
|
+
taxId?: string;
|
|
47
|
+
cellphone?: string;
|
|
48
|
+
};
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
export type Charge = PixCharge;
|
|
52
|
+
/** address: obrigatório para boleto quando o provedor é o Inter */
|
|
53
|
+
export interface BoletoCustomer {
|
|
54
|
+
name: string;
|
|
55
|
+
taxId: string;
|
|
56
|
+
email?: string;
|
|
57
|
+
cellphone?: string;
|
|
58
|
+
address?: Partial<Address> & Pick<Address, 'zipCode' | 'street' | 'city' | 'state'>;
|
|
59
|
+
}
|
|
60
|
+
export interface CreateBoleto {
|
|
61
|
+
/** centavos (mínimo R$ 5,00) */
|
|
62
|
+
amount: number;
|
|
63
|
+
/** YYYY-MM-DD */
|
|
64
|
+
dueDate: string;
|
|
65
|
+
description: string;
|
|
66
|
+
customer: BoletoCustomer;
|
|
67
|
+
/** multa após vencimento, % (máx. 2) */
|
|
68
|
+
finePercent?: number;
|
|
69
|
+
/** juros ao mês, % */
|
|
70
|
+
interestMonthly?: number;
|
|
71
|
+
metadata?: Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
export interface CreateCarne extends Omit<CreateBoleto, 'amount' | 'dueDate'> {
|
|
74
|
+
/** valor total em centavos, dividido nas parcelas */
|
|
75
|
+
totalAmount: number;
|
|
76
|
+
/** 2 a 24 */
|
|
77
|
+
installments: number;
|
|
78
|
+
/** vencimento da 1ª parcela; as demais vencem mês a mês */
|
|
79
|
+
firstDueDate: string;
|
|
80
|
+
}
|
|
81
|
+
export interface Carne {
|
|
82
|
+
carnetId: string;
|
|
83
|
+
totalAmount: number;
|
|
84
|
+
installments: number;
|
|
85
|
+
pdfUrl?: string | null;
|
|
86
|
+
paidInstallments?: number;
|
|
87
|
+
parcels: Charge[];
|
|
88
|
+
}
|
|
89
|
+
export interface ListParams {
|
|
90
|
+
limit?: number;
|
|
91
|
+
after?: string;
|
|
92
|
+
before?: string;
|
|
93
|
+
startDate?: string;
|
|
94
|
+
endDate?: string;
|
|
95
|
+
[filter: string]: string | number | undefined;
|
|
96
|
+
}
|
|
97
|
+
export interface Pagination {
|
|
98
|
+
hasMore: boolean;
|
|
99
|
+
next: string | null;
|
|
100
|
+
before: string | null;
|
|
101
|
+
}
|
|
102
|
+
export interface Page<T> {
|
|
103
|
+
data: T[];
|
|
104
|
+
pagination: Pagination;
|
|
105
|
+
}
|
|
106
|
+
export type ProductCycle = 'WEEKLY' | 'MONTHLY' | 'QUARTERLY' | 'SEMIANNUALLY' | 'ANNUALLY';
|
|
107
|
+
export interface V2Product {
|
|
108
|
+
id: string;
|
|
109
|
+
externalId: string;
|
|
110
|
+
name: string;
|
|
111
|
+
description: string;
|
|
112
|
+
imageUrl: string | null;
|
|
113
|
+
price: number;
|
|
114
|
+
currency: 'BRL';
|
|
115
|
+
cycle: ProductCycle | null;
|
|
116
|
+
trialDays: number | null;
|
|
117
|
+
hasFile: boolean;
|
|
118
|
+
status: 'ACTIVE' | 'ARCHIVED';
|
|
119
|
+
devMode: boolean;
|
|
120
|
+
createdAt: string;
|
|
121
|
+
updatedAt: string;
|
|
122
|
+
}
|
|
123
|
+
export interface CreateProduct {
|
|
124
|
+
externalId: string;
|
|
125
|
+
name: string;
|
|
126
|
+
price: number;
|
|
127
|
+
currency?: 'BRL';
|
|
128
|
+
description?: string;
|
|
129
|
+
imageUrl?: string | null;
|
|
130
|
+
fileUrl?: string;
|
|
131
|
+
cycle?: ProductCycle | null;
|
|
132
|
+
trialDays?: number;
|
|
133
|
+
}
|
|
134
|
+
export interface Address {
|
|
135
|
+
zipCode: string;
|
|
136
|
+
street: string;
|
|
137
|
+
number: string;
|
|
138
|
+
neighborhood: string;
|
|
139
|
+
city: string;
|
|
140
|
+
state: string;
|
|
141
|
+
complement?: string;
|
|
142
|
+
}
|
|
143
|
+
export interface V2Customer {
|
|
144
|
+
id: string;
|
|
145
|
+
devMode: boolean;
|
|
146
|
+
name: string | null;
|
|
147
|
+
email: string | null;
|
|
148
|
+
taxId: string | null;
|
|
149
|
+
cellphone: string | null;
|
|
150
|
+
country: 'BR';
|
|
151
|
+
zipCode: string | null;
|
|
152
|
+
address: Address | null;
|
|
153
|
+
metadata: Record<string, string>;
|
|
154
|
+
createdAt: string;
|
|
155
|
+
updatedAt: string;
|
|
156
|
+
}
|
|
157
|
+
export interface CreateCustomer {
|
|
158
|
+
email: string;
|
|
159
|
+
name?: string;
|
|
160
|
+
taxId?: string;
|
|
161
|
+
cellphone?: string;
|
|
162
|
+
zipCode?: string;
|
|
163
|
+
address?: Address;
|
|
164
|
+
metadata?: Record<string, string>;
|
|
165
|
+
}
|
|
166
|
+
export interface V2Coupon {
|
|
167
|
+
id: string;
|
|
168
|
+
notes: string | null;
|
|
169
|
+
maxRedeems: number;
|
|
170
|
+
redeemsCount: number;
|
|
171
|
+
discountKind: 'PERCENTAGE' | 'FIXED';
|
|
172
|
+
discount: number;
|
|
173
|
+
devMode: boolean;
|
|
174
|
+
status: 'ACTIVE' | 'DISABLED' | 'EXPIRED';
|
|
175
|
+
startsAt: string | null;
|
|
176
|
+
expiresAt: string | null;
|
|
177
|
+
createdAt: string;
|
|
178
|
+
updatedAt: string;
|
|
179
|
+
}
|
|
180
|
+
export interface CreateCoupon {
|
|
181
|
+
code: string;
|
|
182
|
+
discountKind: 'PERCENTAGE' | 'FIXED';
|
|
183
|
+
/** PERCENTAGE: centésimos de % (1000 = 10%). FIXED: centavos */
|
|
184
|
+
discount: number;
|
|
185
|
+
/** -1 = ilimitado */
|
|
186
|
+
maxRedeems: number;
|
|
187
|
+
notes?: string;
|
|
188
|
+
startsAt?: string;
|
|
189
|
+
expiresAt?: string;
|
|
190
|
+
}
|
|
191
|
+
export type PayMethod = 'PIX' | 'BOLETO';
|
|
192
|
+
export interface Interest {
|
|
193
|
+
value: number;
|
|
194
|
+
}
|
|
195
|
+
export interface Fine {
|
|
196
|
+
value: number;
|
|
197
|
+
type: 'PERCENTAGE' | 'FIXED';
|
|
198
|
+
}
|
|
199
|
+
export interface CreateCheckout {
|
|
200
|
+
items: {
|
|
201
|
+
id: string;
|
|
202
|
+
quantity?: number;
|
|
203
|
+
}[];
|
|
204
|
+
methods?: PayMethod[];
|
|
205
|
+
returnUrl?: string;
|
|
206
|
+
completionUrl?: string;
|
|
207
|
+
customerId?: string;
|
|
208
|
+
coupons?: string[];
|
|
209
|
+
externalId?: string;
|
|
210
|
+
dueDate?: string;
|
|
211
|
+
interest?: Interest;
|
|
212
|
+
fine?: Fine;
|
|
213
|
+
metadata?: Record<string, unknown>;
|
|
214
|
+
}
|
|
215
|
+
export interface V2Checkout {
|
|
216
|
+
id: string;
|
|
217
|
+
externalId: string | null;
|
|
218
|
+
url: string;
|
|
219
|
+
amount: number;
|
|
220
|
+
paidAmount: number | null;
|
|
221
|
+
items: {
|
|
222
|
+
id: string;
|
|
223
|
+
quantity: number;
|
|
224
|
+
}[];
|
|
225
|
+
status: 'PENDING' | 'PAID' | 'REFUNDED' | 'REDEEMED' | 'ACTIVE' | 'CANCELLED';
|
|
226
|
+
methods: PayMethod[];
|
|
227
|
+
frequency: 'ONE_TIME' | 'MULTIPLE_PAYMENTS';
|
|
228
|
+
coupons: string[];
|
|
229
|
+
devMode: boolean;
|
|
230
|
+
customerId: string | null;
|
|
231
|
+
returnUrl: string | null;
|
|
232
|
+
completionUrl: string | null;
|
|
233
|
+
dueDate: string | null;
|
|
234
|
+
interest: Interest | null;
|
|
235
|
+
fine: Fine | null;
|
|
236
|
+
metadata: Record<string, unknown>;
|
|
237
|
+
createdAt: string;
|
|
238
|
+
updatedAt: string;
|
|
239
|
+
}
|
|
240
|
+
export interface Utm {
|
|
241
|
+
source?: string;
|
|
242
|
+
medium?: string;
|
|
243
|
+
campaign?: string;
|
|
244
|
+
term?: string;
|
|
245
|
+
content?: string;
|
|
246
|
+
src?: string;
|
|
247
|
+
sck?: string;
|
|
248
|
+
}
|
|
249
|
+
export interface CreateTransparent {
|
|
250
|
+
method: PayMethod;
|
|
251
|
+
data: {
|
|
252
|
+
amount: number;
|
|
253
|
+
expiresIn?: number;
|
|
254
|
+
dueDate?: string;
|
|
255
|
+
description?: string;
|
|
256
|
+
customer?: {
|
|
257
|
+
name: string;
|
|
258
|
+
taxId: string;
|
|
259
|
+
email?: string;
|
|
260
|
+
cellphone?: string;
|
|
261
|
+
address?: Address;
|
|
262
|
+
};
|
|
263
|
+
externalId?: string;
|
|
264
|
+
interest?: Interest;
|
|
265
|
+
fine?: Fine;
|
|
266
|
+
coupon?: string;
|
|
267
|
+
metadata?: Record<string, unknown>;
|
|
268
|
+
utm?: Utm;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
export interface V2Transparent {
|
|
272
|
+
id: string;
|
|
273
|
+
externalId: string | null;
|
|
274
|
+
amount: number;
|
|
275
|
+
status: ChargeStatus;
|
|
276
|
+
devMode: boolean;
|
|
277
|
+
method: PayMethod;
|
|
278
|
+
brCode: string | null;
|
|
279
|
+
brCodeBase64: string | null;
|
|
280
|
+
platformFee: number;
|
|
281
|
+
url: string;
|
|
282
|
+
customerId: string | null;
|
|
283
|
+
barCode?: string;
|
|
284
|
+
identificationNumber?: string;
|
|
285
|
+
dueDate?: string;
|
|
286
|
+
interest?: Interest | null;
|
|
287
|
+
fine?: Fine | null;
|
|
288
|
+
expiresAt: string;
|
|
289
|
+
createdAt: string;
|
|
290
|
+
updatedAt: string;
|
|
291
|
+
paidAt: string | null;
|
|
292
|
+
metadata: Record<string, unknown>;
|
|
293
|
+
}
|
|
294
|
+
export type WebhookEvent = 'checkout.completed' | 'checkout.refunded' | 'checkout.disputed' | 'checkout.lost' | 'transparent.completed' | 'transparent.refunded' | 'transparent.disputed' | 'transparent.lost' | 'subscription.completed' | 'subscription.trial_started' | 'subscription.cancelled' | 'subscription.renewed' | 'payout.completed' | 'payout.failed' | 'transfer.completed' | 'transfer.failed' | 'pix_key.received' | 'pix_key.refunded';
|
|
295
|
+
export interface CreateWebhook {
|
|
296
|
+
name: string;
|
|
297
|
+
/** URL HTTPS pública */
|
|
298
|
+
endpoint: string;
|
|
299
|
+
/** 32+ caracteres; sem ele, a Maria Pay gera um e devolve em `secret` só nesta resposta */
|
|
300
|
+
secret?: string;
|
|
301
|
+
events: WebhookEvent[];
|
|
302
|
+
}
|
|
303
|
+
export interface V2Webhook {
|
|
304
|
+
id: string;
|
|
305
|
+
name: string;
|
|
306
|
+
endpoint: string;
|
|
307
|
+
events: WebhookEvent[];
|
|
308
|
+
devMode: boolean;
|
|
309
|
+
v2: true;
|
|
310
|
+
createdAt: string;
|
|
311
|
+
updatedAt: string;
|
|
312
|
+
secret?: string;
|
|
313
|
+
}
|
|
314
|
+
export interface V2Refund {
|
|
315
|
+
id: string;
|
|
316
|
+
status: 'COMPLETE' | 'PROCESSING';
|
|
317
|
+
amount: number;
|
|
318
|
+
reason: string | null;
|
|
319
|
+
originalId: string;
|
|
320
|
+
createdAt: string;
|
|
321
|
+
}
|
|
322
|
+
export declare class MariaPayError extends Error {
|
|
323
|
+
status: number;
|
|
324
|
+
constructor(message: string, status: number);
|
|
325
|
+
}
|
|
326
|
+
export declare class MariaPay {
|
|
327
|
+
private apiKey;
|
|
328
|
+
private baseUrl;
|
|
329
|
+
constructor(apiKey: string, opts?: {
|
|
330
|
+
baseUrl?: string;
|
|
331
|
+
});
|
|
332
|
+
private raw;
|
|
333
|
+
private req;
|
|
334
|
+
private qs;
|
|
335
|
+
private page;
|
|
336
|
+
pix: {
|
|
337
|
+
keys: {
|
|
338
|
+
/** sem argumento: gera chave aleatória; com key: cadastra uma chave existente */
|
|
339
|
+
create: (key?: string) => Promise<{
|
|
340
|
+
id: string;
|
|
341
|
+
key: string;
|
|
342
|
+
type: string;
|
|
343
|
+
}>;
|
|
344
|
+
list: () => Promise<{
|
|
345
|
+
id: string;
|
|
346
|
+
key: string;
|
|
347
|
+
type: string;
|
|
348
|
+
default: boolean;
|
|
349
|
+
}[]>;
|
|
350
|
+
};
|
|
351
|
+
/** QR Pix com valor fixo (estático, reutilizável, sem confirmação) */
|
|
352
|
+
staticQr: (input?: {
|
|
353
|
+
amount?: number;
|
|
354
|
+
description?: string;
|
|
355
|
+
}) => Promise<{
|
|
356
|
+
brCode: string;
|
|
357
|
+
brCodeBase64: string;
|
|
358
|
+
pixKey: string;
|
|
359
|
+
amount: number | null;
|
|
360
|
+
}>;
|
|
361
|
+
create: (input: CreatePixCharge) => Promise<PixCharge>;
|
|
362
|
+
get: (id: string) => Promise<PixCharge>;
|
|
363
|
+
list: (limit?: number) => Promise<PixCharge[]>;
|
|
364
|
+
cancel: (id: string) => Promise<PixCharge>;
|
|
365
|
+
/** só com chave sp_test_ */
|
|
366
|
+
simulatePayment: (id: string) => Promise<PixCharge>;
|
|
367
|
+
};
|
|
368
|
+
boletos: {
|
|
369
|
+
create: (input: CreateBoleto) => Promise<PixCharge>;
|
|
370
|
+
/** boleto parcelado (carnê) */
|
|
371
|
+
createCarne: (input: CreateCarne) => Promise<Carne>;
|
|
372
|
+
getCarne: (carnetId: string) => Promise<Carne>;
|
|
373
|
+
get: (id: string) => Promise<PixCharge>;
|
|
374
|
+
list: (limit?: number) => Promise<PixCharge[]>;
|
|
375
|
+
cancel: (id: string) => Promise<PixCharge>;
|
|
376
|
+
simulatePayment: (id: string) => Promise<PixCharge>;
|
|
377
|
+
};
|
|
378
|
+
fees: () => Promise<{
|
|
379
|
+
method: string;
|
|
380
|
+
fee: number;
|
|
381
|
+
feeFormatted: string;
|
|
382
|
+
chargedWhen: string;
|
|
383
|
+
}[]>;
|
|
384
|
+
/** saldo: net = gross - fees - refunded (a taxa da venda reembolsada não volta) */
|
|
385
|
+
balance: () => Promise<{
|
|
386
|
+
paidCount: number;
|
|
387
|
+
gross: number;
|
|
388
|
+
fees: number;
|
|
389
|
+
refundedCount: number;
|
|
390
|
+
refunded: number;
|
|
391
|
+
net: number;
|
|
392
|
+
pendingCount: number;
|
|
393
|
+
pendingAmount: number;
|
|
394
|
+
}>;
|
|
395
|
+
/** API v2: produtos, clientes, cupons, checkout, links de pagamento e checkout transparente */
|
|
396
|
+
v2: {
|
|
397
|
+
products: {
|
|
398
|
+
create: (input: CreateProduct) => Promise<V2Product>;
|
|
399
|
+
list: (p?: ListParams) => Promise<Page<V2Product>>;
|
|
400
|
+
get: (by: {
|
|
401
|
+
id?: string;
|
|
402
|
+
externalId?: string;
|
|
403
|
+
name?: string;
|
|
404
|
+
}) => Promise<V2Product>;
|
|
405
|
+
/** arquiva o produto */
|
|
406
|
+
delete: (id: string) => Promise<V2Product>;
|
|
407
|
+
};
|
|
408
|
+
customers: {
|
|
409
|
+
/** cria ou atualiza (procura por CPF/CNPJ, depois e-mail, depois celular) */
|
|
410
|
+
create: (input: CreateCustomer) => Promise<V2Customer>;
|
|
411
|
+
list: (p?: ListParams) => Promise<Page<V2Customer>>;
|
|
412
|
+
get: (by: {
|
|
413
|
+
id?: string;
|
|
414
|
+
email?: string;
|
|
415
|
+
taxId?: string;
|
|
416
|
+
}) => Promise<V2Customer>;
|
|
417
|
+
delete: (id: string) => Promise<V2Customer>;
|
|
418
|
+
};
|
|
419
|
+
coupons: {
|
|
420
|
+
/** mesmo código: devolve o cupom existente */
|
|
421
|
+
create: (input: CreateCoupon) => Promise<V2Coupon>;
|
|
422
|
+
list: (p?: ListParams) => Promise<Page<V2Coupon>>;
|
|
423
|
+
get: (code: string) => Promise<V2Coupon>;
|
|
424
|
+
delete: (code: string) => Promise<V2Coupon>;
|
|
425
|
+
toggle: (code: string) => Promise<V2Coupon>;
|
|
426
|
+
};
|
|
427
|
+
checkouts: {
|
|
428
|
+
create: (input: CreateCheckout) => Promise<V2Checkout>;
|
|
429
|
+
list: (p?: ListParams) => Promise<Page<V2Checkout>>;
|
|
430
|
+
get: (by: {
|
|
431
|
+
id?: string;
|
|
432
|
+
externalId?: string;
|
|
433
|
+
customerId?: string;
|
|
434
|
+
}) => Promise<V2Checkout>;
|
|
435
|
+
refund: (id: string, reason?: string) => Promise<V2Refund>;
|
|
436
|
+
};
|
|
437
|
+
paymentLinks: {
|
|
438
|
+
create: (input: Omit<CreateCheckout, "customerId">) => Promise<V2Checkout>;
|
|
439
|
+
list: (p?: ListParams) => Promise<Page<V2Checkout>>;
|
|
440
|
+
get: (by: {
|
|
441
|
+
id?: string;
|
|
442
|
+
externalId?: string;
|
|
443
|
+
}) => Promise<V2Checkout>;
|
|
444
|
+
/** id do pagamento (pix_char_...), não do link */
|
|
445
|
+
refund: (id: string, reason?: string) => Promise<V2Refund>;
|
|
446
|
+
};
|
|
447
|
+
transparents: {
|
|
448
|
+
create: (input: CreateTransparent) => Promise<V2Transparent>;
|
|
449
|
+
list: (p?: ListParams) => Promise<Page<V2Transparent>>;
|
|
450
|
+
get: (id: string) => Promise<V2Transparent>;
|
|
451
|
+
check: (id: string) => Promise<{
|
|
452
|
+
id: string;
|
|
453
|
+
status: ChargeStatus;
|
|
454
|
+
expiresAt: string;
|
|
455
|
+
}>;
|
|
456
|
+
/** só com chave sp_test_ */
|
|
457
|
+
simulatePayment: (id: string) => Promise<V2Transparent>;
|
|
458
|
+
refund: (id: string, reason?: string) => Promise<V2Refund>;
|
|
459
|
+
};
|
|
460
|
+
webhooks: {
|
|
461
|
+
create: (input: CreateWebhook) => Promise<V2Webhook>;
|
|
462
|
+
list: (p?: ListParams & {
|
|
463
|
+
search?: string;
|
|
464
|
+
}) => Promise<Page<V2Webhook>>;
|
|
465
|
+
get: (id: string) => Promise<V2Webhook>;
|
|
466
|
+
delete: (id: string) => Promise<void>;
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
webhooks: {
|
|
470
|
+
setUrl: (url: string | null) => Promise<{
|
|
471
|
+
url: string | null;
|
|
472
|
+
secret: string;
|
|
473
|
+
}>;
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Confere um webhook recebido: o secret (header X-Webhook-Secret ou ?webhookSecret=) em tempo constante
|
|
477
|
+
* e a assinatura X-Webhook-Signature sobre o corpo CRU (antes do JSON.parse).
|
|
478
|
+
*
|
|
479
|
+
* MariaPay.verifyWebhook(rawBody, {
|
|
480
|
+
* secret: req.get('X-Webhook-Secret') ?? req.query.webhookSecret,
|
|
481
|
+
* signature: req.get('X-Webhook-Signature'),
|
|
482
|
+
* }, process.env.MARIAPAY_WEBHOOK_SECRET!)
|
|
483
|
+
*
|
|
484
|
+
* Compatível com o formato antigo da v1: passe { timestamp, signature } com X-MariaPay-Timestamp/Signature (ou os nomes antigos X-SniperPay-*, com os mesmos valores).
|
|
485
|
+
*/
|
|
486
|
+
static verifyWebhook(rawBody: string | Uint8Array, received: {
|
|
487
|
+
secret?: string | null;
|
|
488
|
+
signature?: string | null;
|
|
489
|
+
} | {
|
|
490
|
+
timestamp: string;
|
|
491
|
+
signature: string;
|
|
492
|
+
}, expectedSecret: string, opts?: {
|
|
493
|
+
publicKey?: string;
|
|
494
|
+
toleranceSec?: number;
|
|
495
|
+
}): boolean;
|
|
496
|
+
/** Só a assinatura: base64(HMAC-SHA256(corpo cru, chave pública da Maria Pay)) === X-Webhook-Signature */
|
|
497
|
+
static verifyWebhookSignature(rawBody: string | Uint8Array, signature: string, publicKey?: string): boolean;
|
|
498
|
+
}
|
|
499
|
+
/** Nomes antigos (antes da troca de marca), mantidos por compatibilidade. */
|
|
500
|
+
export { MariaPay as SniperPay, MariaPayError as SniperPayError };
|
|
501
|
+
export declare const SNIPERPAY_WEBHOOK_PUBLIC_KEY = "5I3sRLuE2aSbSx3PtKzAiWgfK39zN2hp8B7Jhi2xn3QUmpT14ZIaWGNXsm6upvRFoiszscwi9CntL1k3reX0DM6PPam89xz0may1j6cccdmAsd59lsec334CMusPBNcQMGajPLSnMbJO8vm7ERYauGYRB1aJjZkQLwUsYoXl72uRhApzI1l10lYR2QbH33ldJEJfCZfBsYa9KacCigrqIKMh1pUk5oU7362svTjneZskovToAXpx4RuShiBlrEfn";
|
|
502
|
+
export default MariaPay;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// SDK oficial Maria Pay — zero dependências (Node 18+, Deno, Bun, Edge)
|
|
2
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
/**
|
|
4
|
+
* Chave pública de assinatura dos webhooks da Maria Pay. Igual para todas as contas:
|
|
5
|
+
* X-Webhook-Signature = base64(HMAC-SHA256(corpo cru, esta chave)).
|
|
6
|
+
*/
|
|
7
|
+
export const MARIAPAY_WEBHOOK_PUBLIC_KEY = '5I3sRLuE2aSbSx3PtKzAiWgfK39zN2hp8B7Jhi2xn3QUmpT14ZIaWGNXsm6upvRFoiszscwi9CntL1k3reX0DM6PPam89xz0may1j6cccdmAsd59lsec334CMusPBNcQMGajPLSnMbJO8vm7ERYauGYRB1aJjZkQLwUsYoXl72uRhApzI1l10lYR2QbH33ldJEJfCZfBsYa9KacCigrqIKMh1pUk5oU7362svTjneZskovToAXpx4RuShiBlrEfn';
|
|
8
|
+
export class MariaPayError extends Error {
|
|
9
|
+
status;
|
|
10
|
+
constructor(message, status) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.status = status;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class MariaPay {
|
|
16
|
+
apiKey;
|
|
17
|
+
baseUrl;
|
|
18
|
+
constructor(apiKey, opts = {}) {
|
|
19
|
+
this.apiKey = apiKey;
|
|
20
|
+
this.baseUrl = (opts.baseUrl ?? 'https://sniperpay-api-production.up.railway.app').replace(/\/$/, '');
|
|
21
|
+
}
|
|
22
|
+
async raw(method, path, body) {
|
|
23
|
+
const res = await fetch(this.baseUrl + path, {
|
|
24
|
+
method,
|
|
25
|
+
headers: { Authorization: `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' },
|
|
26
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
27
|
+
});
|
|
28
|
+
const json = (await res.json());
|
|
29
|
+
if (json.error)
|
|
30
|
+
throw new MariaPayError(json.error, res.status);
|
|
31
|
+
return json;
|
|
32
|
+
}
|
|
33
|
+
async req(method, path, body) {
|
|
34
|
+
return (await this.raw(method, path, body)).data;
|
|
35
|
+
}
|
|
36
|
+
qs(p = {}) {
|
|
37
|
+
const e = Object.entries(p).filter(([, v]) => v !== undefined && v !== '');
|
|
38
|
+
return e.length ? '?' + new URLSearchParams(e.map(([k, v]) => [k, String(v)])).toString() : '';
|
|
39
|
+
}
|
|
40
|
+
async page(path, p) {
|
|
41
|
+
const r = await this.raw('GET', path + this.qs(p));
|
|
42
|
+
return { data: r.data, pagination: r.pagination ?? { hasMore: false, next: null, before: null } };
|
|
43
|
+
}
|
|
44
|
+
pix = {
|
|
45
|
+
keys: {
|
|
46
|
+
/** sem argumento: gera chave aleatória; com key: cadastra uma chave existente */
|
|
47
|
+
create: (key) => this.req('POST', '/v1/pix/keys', key ? { key } : {}),
|
|
48
|
+
list: () => this.req('GET', '/v1/pix/keys'),
|
|
49
|
+
},
|
|
50
|
+
/** QR Pix com valor fixo (estático, reutilizável, sem confirmação) */
|
|
51
|
+
staticQr: (input = {}) => this.req('POST', '/v1/pix/static', input),
|
|
52
|
+
create: (input) => this.req('POST', '/v1/pix/charges', input),
|
|
53
|
+
get: (id) => this.req('GET', `/v1/pix/charges/${id}`),
|
|
54
|
+
list: (limit = 20) => this.req('GET', `/v1/pix/charges?limit=${limit}`),
|
|
55
|
+
cancel: (id) => this.req('POST', `/v1/pix/charges/${id}/cancel`),
|
|
56
|
+
/** só com chave sp_test_ */
|
|
57
|
+
simulatePayment: (id) => this.req('POST', `/v1/pix/charges/${id}/simulate-payment`),
|
|
58
|
+
};
|
|
59
|
+
boletos = {
|
|
60
|
+
create: (input) => this.req('POST', '/v1/boletos', input),
|
|
61
|
+
/** boleto parcelado (carnê) */
|
|
62
|
+
createCarne: (input) => this.req('POST', '/v1/boletos/carne', input),
|
|
63
|
+
getCarne: (carnetId) => this.req('GET', `/v1/boletos/carne/${carnetId}`),
|
|
64
|
+
get: (id) => this.req('GET', `/v1/boletos/${id}`),
|
|
65
|
+
list: (limit = 20) => this.req('GET', `/v1/boletos?limit=${limit}`),
|
|
66
|
+
cancel: (id) => this.req('POST', `/v1/boletos/${id}/cancel`),
|
|
67
|
+
simulatePayment: (id) => this.req('POST', `/v1/boletos/${id}/simulate-payment`),
|
|
68
|
+
};
|
|
69
|
+
fees = () => this.req('GET', '/v1/fees');
|
|
70
|
+
/** saldo: net = gross - fees - refunded (a taxa da venda reembolsada não volta) */
|
|
71
|
+
balance = () => this.req('GET', '/v1/merchant/balance');
|
|
72
|
+
/** API v2: produtos, clientes, cupons, checkout, links de pagamento e checkout transparente */
|
|
73
|
+
v2 = {
|
|
74
|
+
products: {
|
|
75
|
+
create: (input) => this.req('POST', '/v2/products/create', input),
|
|
76
|
+
list: (p) => this.page('/v2/products/list', p),
|
|
77
|
+
get: (by) => this.req('GET', '/v2/products/get' + this.qs(by)),
|
|
78
|
+
/** arquiva o produto */
|
|
79
|
+
delete: (id) => this.req('POST', '/v2/products/delete' + this.qs({ id })),
|
|
80
|
+
},
|
|
81
|
+
customers: {
|
|
82
|
+
/** cria ou atualiza (procura por CPF/CNPJ, depois e-mail, depois celular) */
|
|
83
|
+
create: (input) => this.req('POST', '/v2/customers/create', input),
|
|
84
|
+
list: (p) => this.page('/v2/customers/list', p),
|
|
85
|
+
get: (by) => this.req('GET', '/v2/customers/get' + this.qs(by)),
|
|
86
|
+
delete: (id) => this.req('POST', '/v2/customers/delete' + this.qs({ id })),
|
|
87
|
+
},
|
|
88
|
+
coupons: {
|
|
89
|
+
/** mesmo código: devolve o cupom existente */
|
|
90
|
+
create: (input) => this.req('POST', '/v2/coupons/create', input),
|
|
91
|
+
list: (p) => this.page('/v2/coupons/list', p),
|
|
92
|
+
get: (code) => this.req('GET', '/v2/coupons/get' + this.qs({ id: code })),
|
|
93
|
+
delete: (code) => this.req('POST', '/v2/coupons/delete' + this.qs({ id: code })),
|
|
94
|
+
toggle: (code) => this.req('POST', '/v2/coupons/toggle', { id: code }),
|
|
95
|
+
},
|
|
96
|
+
checkouts: {
|
|
97
|
+
create: (input) => this.req('POST', '/v2/checkouts/create', input),
|
|
98
|
+
list: (p) => this.page('/v2/checkouts/list', p),
|
|
99
|
+
get: (by) => this.req('GET', '/v2/checkouts/get' + this.qs(by)),
|
|
100
|
+
refund: (id, reason) => this.req('POST', '/v2/checkouts/refund', { id, reason }),
|
|
101
|
+
},
|
|
102
|
+
paymentLinks: {
|
|
103
|
+
create: (input) => this.req('POST', '/v2/payment-links/create', input),
|
|
104
|
+
list: (p) => this.page('/v2/payment-links/list', p),
|
|
105
|
+
get: (by) => this.req('GET', '/v2/payment-links/get' + this.qs(by)),
|
|
106
|
+
/** id do pagamento (pix_char_...), não do link */
|
|
107
|
+
refund: (id, reason) => this.req('POST', '/v2/payment-links/refund', { id, reason }),
|
|
108
|
+
},
|
|
109
|
+
transparents: {
|
|
110
|
+
create: (input) => this.req('POST', '/v2/transparents/create', input),
|
|
111
|
+
list: (p) => this.page('/v2/transparents/list', p),
|
|
112
|
+
get: (id) => this.req('GET', '/v2/transparents/get' + this.qs({ id })),
|
|
113
|
+
check: (id) => this.req('GET', '/v2/transparents/check' + this.qs({ id })),
|
|
114
|
+
/** só com chave sp_test_ */
|
|
115
|
+
simulatePayment: (id) => this.req('POST', '/v2/transparents/simulate-payment' + this.qs({ id })),
|
|
116
|
+
refund: (id, reason) => this.req('POST', '/v2/transparents/refund', { id, reason }),
|
|
117
|
+
},
|
|
118
|
+
webhooks: {
|
|
119
|
+
create: (input) => this.req('POST', '/v2/webhooks/create', input),
|
|
120
|
+
list: (p) => this.page('/v2/webhooks/list', p),
|
|
121
|
+
get: (id) => this.req('GET', '/v2/webhooks/get' + this.qs({ id })),
|
|
122
|
+
delete: async (id) => { await this.raw('POST', '/v2/webhooks/delete' + this.qs({ id })); },
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
webhooks = {
|
|
126
|
+
setUrl: (url) => this.req('PUT', '/v1/merchant/webhook', { url }),
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Confere um webhook recebido: o secret (header X-Webhook-Secret ou ?webhookSecret=) em tempo constante
|
|
130
|
+
* e a assinatura X-Webhook-Signature sobre o corpo CRU (antes do JSON.parse).
|
|
131
|
+
*
|
|
132
|
+
* MariaPay.verifyWebhook(rawBody, {
|
|
133
|
+
* secret: req.get('X-Webhook-Secret') ?? req.query.webhookSecret,
|
|
134
|
+
* signature: req.get('X-Webhook-Signature'),
|
|
135
|
+
* }, process.env.MARIAPAY_WEBHOOK_SECRET!)
|
|
136
|
+
*
|
|
137
|
+
* Compatível com o formato antigo da v1: passe { timestamp, signature } com X-MariaPay-Timestamp/Signature (ou os nomes antigos X-SniperPay-*, com os mesmos valores).
|
|
138
|
+
*/
|
|
139
|
+
static verifyWebhook(rawBody, received, expectedSecret, opts = {}) {
|
|
140
|
+
if ('timestamp' in received) {
|
|
141
|
+
const tol = opts.toleranceSec ?? 300;
|
|
142
|
+
if (Math.abs(Date.now() / 1000 - Number(received.timestamp)) > tol)
|
|
143
|
+
return false;
|
|
144
|
+
const body = typeof rawBody === 'string' ? rawBody : Buffer.from(rawBody).toString('utf8');
|
|
145
|
+
return safeEqual('sha256=' + createHmac('sha256', expectedSecret).update(`${received.timestamp}.${body}`).digest('hex'), received.signature);
|
|
146
|
+
}
|
|
147
|
+
if (!received.secret || !received.signature || !expectedSecret)
|
|
148
|
+
return false;
|
|
149
|
+
return safeEqual(received.secret, expectedSecret) && MariaPay.verifyWebhookSignature(rawBody, received.signature, opts.publicKey);
|
|
150
|
+
}
|
|
151
|
+
/** Só a assinatura: base64(HMAC-SHA256(corpo cru, chave pública da Maria Pay)) === X-Webhook-Signature */
|
|
152
|
+
static verifyWebhookSignature(rawBody, signature, publicKey = MARIAPAY_WEBHOOK_PUBLIC_KEY) {
|
|
153
|
+
const expected = createHmac('sha256', publicKey).update(rawBody).digest('base64');
|
|
154
|
+
return safeEqual(expected, signature ?? '');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function safeEqual(a, b) {
|
|
158
|
+
const A = Buffer.from(a, 'utf8'), B = Buffer.from(b, 'utf8');
|
|
159
|
+
return A.length === B.length && timingSafeEqual(A, B);
|
|
160
|
+
}
|
|
161
|
+
/** Nomes antigos (antes da troca de marca), mantidos por compatibilidade. */
|
|
162
|
+
export { MariaPay as SniperPay, MariaPayError as SniperPayError };
|
|
163
|
+
export const SNIPERPAY_WEBHOOK_PUBLIC_KEY = MARIAPAY_WEBHOOK_PUBLIC_KEY;
|
|
164
|
+
export default MariaPay;
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mariapay",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "SDK da Maria Pay para Node, Deno e Bun: Pix, boleto, carnê, checkout, links de pagamento, reembolso e webhooks",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.json",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"pix",
|
|
28
|
+
"boleto",
|
|
29
|
+
"carne",
|
|
30
|
+
"pagamentos",
|
|
31
|
+
"checkout",
|
|
32
|
+
"webhooks",
|
|
33
|
+
"mariapay",
|
|
34
|
+
"maria-pay",
|
|
35
|
+
"brasil"
|
|
36
|
+
],
|
|
37
|
+
"author": "Laercio Borges (VERTAL COMPANY)",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"homepage": "https://sniperpay-api-production.up.railway.app/docs",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/kuboprotocol/SniperPay.git",
|
|
43
|
+
"directory": "packages/sdk"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^22.10.2",
|
|
47
|
+
"typescript": "^5.7.2"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|