@undernouzen/ay-payments-sdk 1.0.1
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 +409 -0
- package/dist/client.d.ts +346 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +237 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +622 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Under Nouzen
|
|
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
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
# AY Payments SDK
|
|
2
|
+
|
|
3
|
+
SDK TypeScript/JavaScript para consumir a API do AY Payments.
|
|
4
|
+
|
|
5
|
+
O pacote não lê `.env`. A autenticação é passada na inicialização. Se você criar o client sem `apiKey`, ele continua funcionando como instância HTTP, mas as rotas protegidas vão depender de sessão/cookie ou retornar erro de autenticação da API.
|
|
6
|
+
|
|
7
|
+
## Instalação
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @ay-payments/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Se o escopo `@ay-payments` não estiver disponível no npm, publique como `@undernouzen/ay-payments-sdk` ou outro escopo seu e mantenha os imports equivalentes.
|
|
14
|
+
|
|
15
|
+
## Criar o client
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createAYPaymentsClient } from "@ay-payments/sdk";
|
|
19
|
+
|
|
20
|
+
const ay = createAYPaymentsClient({
|
|
21
|
+
baseUrl: "https://aypayments.undernouzen.com.br",
|
|
22
|
+
apiKey: process.env.AYP_API_KEY,
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Por padrão, o client usa:
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
https://aypayments.undernouzen.com.br/api/v1
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Você também pode passar a URL exata da API:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const ay = createAYPaymentsClient({
|
|
36
|
+
apiUrl: "http://localhost:3489/api/v1",
|
|
37
|
+
apiKey: "ayp_secret",
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Autenticação
|
|
42
|
+
|
|
43
|
+
Authorization Bearer é o padrão:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const ay = createAYPaymentsClient({
|
|
47
|
+
baseUrl: "https://aypayments.undernouzen.com.br",
|
|
48
|
+
apiKey: "ayp_secret",
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Usando `x-api-key`:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
const ay = createAYPaymentsClient({
|
|
56
|
+
baseUrl: "https://aypayments.undernouzen.com.br",
|
|
57
|
+
apiKey: "ayp_secret",
|
|
58
|
+
authHeader: "x-api-key",
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Usando Authorization sem `Bearer`:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const ay = createAYPaymentsClient({
|
|
66
|
+
apiKey: "ayp_secret",
|
|
67
|
+
authorizationPrefix: false,
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Sem autenticação:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const ay = createAYPaymentsClient();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Versionamento
|
|
78
|
+
|
|
79
|
+
A versão padrão é `v1`.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const ay = createAYPaymentsClient({
|
|
83
|
+
baseUrl: "https://aypayments.undernouzen.com.br",
|
|
84
|
+
apiVersion: "v1",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await ay.v1.projects.list();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Os atalhos abaixo apontam para `v1`:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
await ay.projects.list();
|
|
94
|
+
await ay.products.list();
|
|
95
|
+
await ay.checkouts.create(payload);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Raw Axios
|
|
99
|
+
|
|
100
|
+
Para rotas novas que ainda não foram mapeadas:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
const response = await ay.raw<{ ok: boolean }>({
|
|
104
|
+
method: "GET",
|
|
105
|
+
url: "/minha-rota",
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Você também pode usar a instância diretamente:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
const response = await ay.api.get("/projects");
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Projects
|
|
116
|
+
|
|
117
|
+
Criar ou atualizar por `externalId`:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const { project, created } = await ay.projects.create({
|
|
121
|
+
externalId: "832320430277918720",
|
|
122
|
+
name: "Vagalumes",
|
|
123
|
+
webhookUrl: "https://guildbuilders.example.com/webhooks/aypayments",
|
|
124
|
+
metadata: {
|
|
125
|
+
guildId: "832320430277918720",
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Listar:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
const { projects, pagination } = await ay.projects.list({
|
|
134
|
+
page: 1,
|
|
135
|
+
limit: 50,
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Buscar com query parcial, incluindo metadata:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
const result = await ay.projects.query({
|
|
143
|
+
metadata: {
|
|
144
|
+
guildId: "832320430277918720",
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
O identificador do projeto aceita `id` interno ou `externalId` nas rotas que usam `projectIdOrExternalId`.
|
|
150
|
+
|
|
151
|
+
## Contas conectadas
|
|
152
|
+
|
|
153
|
+
Gerar URL OAuth:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
const oauth = await ay.projects.accounts.oauth({
|
|
157
|
+
projectId: "832320430277918720",
|
|
158
|
+
provider: "mercadopago",
|
|
159
|
+
name: "Conta principal",
|
|
160
|
+
redirectUrl: "https://guildbuilders.example.com/connect/result",
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
console.log(oauth.authorizationUrl);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Listar contas:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
const { accounts } = await ay.projects.accounts.list("832320430277918720");
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Editar nome/status:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
await ay.projects.accounts.update("832320430277918720", "connection-id", {
|
|
176
|
+
name: "Conta Pix principal",
|
|
177
|
+
status: "active",
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Remover:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
await ay.projects.accounts.delete("832320430277918720", "connection-id");
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Products
|
|
188
|
+
|
|
189
|
+
Produtos usam `value`. Comissão não é calculada no produto; ela é calculada no checkout.
|
|
190
|
+
|
|
191
|
+
Criar produto:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
const { product } = await ay.products.create("832320430277918720", {
|
|
195
|
+
connectedAccountId: "330692399",
|
|
196
|
+
name: "Cargo VIP",
|
|
197
|
+
icon: "https://cdn.example.com/vip.png",
|
|
198
|
+
description: "Acesso VIP no Discord",
|
|
199
|
+
value: 19.9,
|
|
200
|
+
fees: [
|
|
201
|
+
{
|
|
202
|
+
name: "Taxa operacional",
|
|
203
|
+
kind: "fixed",
|
|
204
|
+
value: 1.5,
|
|
205
|
+
payer: "customer",
|
|
206
|
+
active: true,
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
metadata: {
|
|
210
|
+
discordRoleId: "123",
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Listar por projeto:
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
const { products } = await ay.products.listByProject("832320430277918720");
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Buscar produtos:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
const result = await ay.products.query({
|
|
225
|
+
metadata: {
|
|
226
|
+
discordRoleId: "123",
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Checkouts
|
|
232
|
+
|
|
233
|
+
### Calcular sem criar cobrança
|
|
234
|
+
|
|
235
|
+
Use `calculate` para exibir o resumo antes de gerar Pix, boleto ou Checkout Pro/Stripe Checkout.
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
const calculation = await ay.checkouts.calculate({
|
|
239
|
+
items: [
|
|
240
|
+
{
|
|
241
|
+
productId: "product-id",
|
|
242
|
+
quantity: 1,
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
customer: {
|
|
246
|
+
email: "cliente@example.com",
|
|
247
|
+
name: "Cliente Teste",
|
|
248
|
+
},
|
|
249
|
+
currency: "BRL",
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
console.log(calculation.summary.amount);
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Criar checkout com produto cadastrado
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
const checkout = await ay.checkouts.create({
|
|
259
|
+
paymentMethod: "pix",
|
|
260
|
+
items: [
|
|
261
|
+
{
|
|
262
|
+
productId: "product-id",
|
|
263
|
+
quantity: 1,
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
customer: {
|
|
267
|
+
email: "cliente@example.com",
|
|
268
|
+
name: "Cliente Teste",
|
|
269
|
+
documentType: "CPF",
|
|
270
|
+
document: "00000000000",
|
|
271
|
+
},
|
|
272
|
+
externalReference: "guild-832320430277918720-user-123",
|
|
273
|
+
webhookUrl: "https://guildbuilders.example.com/webhooks/orders",
|
|
274
|
+
redirectUrls: {
|
|
275
|
+
successUrl: "https://guildbuilders.example.com/payments/success",
|
|
276
|
+
pendingUrl: "https://guildbuilders.example.com/payments/pending",
|
|
277
|
+
failureUrl: "https://guildbuilders.example.com/payments/failure",
|
|
278
|
+
cancelUrl: "https://guildbuilders.example.com/payments/cancel",
|
|
279
|
+
},
|
|
280
|
+
metadata: {
|
|
281
|
+
guildId: "832320430277918720",
|
|
282
|
+
discordUserId: "123456789",
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
console.log(checkout.order.id);
|
|
287
|
+
console.log(checkout.payment?.qrCode);
|
|
288
|
+
console.log(checkout.checkout?.url);
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Criar checkout avulso
|
|
292
|
+
|
|
293
|
+
Para itens sem produto cadastrado, informe `projectId` e `accountId`. Todos os itens do mesmo checkout devem resolver para o mesmo projeto e a mesma conta conectada.
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
const checkout = await ay.checkouts.create({
|
|
297
|
+
projectId: "832320430277918720",
|
|
298
|
+
accountId: "330692399",
|
|
299
|
+
paymentMethod: "checkout",
|
|
300
|
+
items: [
|
|
301
|
+
{
|
|
302
|
+
name: "Cargo VIP",
|
|
303
|
+
amount: 19.9,
|
|
304
|
+
quantity: 1,
|
|
305
|
+
description: "Acesso VIP no Discord",
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
customer: {
|
|
309
|
+
email: "cliente@example.com",
|
|
310
|
+
name: "Cliente Teste",
|
|
311
|
+
},
|
|
312
|
+
externalReference: "guild-832320430277918720-custom-001",
|
|
313
|
+
});
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Orders
|
|
317
|
+
|
|
318
|
+
Listar orders:
|
|
319
|
+
|
|
320
|
+
```ts
|
|
321
|
+
const { orders } = await ay.orders.list({ page: 1, limit: 100 });
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Buscar por metadata:
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
const result = await ay.orders.query({
|
|
328
|
+
metadata: {
|
|
329
|
+
guildId: "832320430277918720",
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Listar por projeto:
|
|
335
|
+
|
|
336
|
+
```ts
|
|
337
|
+
const result = await ay.orders.listByProject("832320430277918720");
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## Customers
|
|
341
|
+
|
|
342
|
+
A API atual usa `/clients`, mas a SDK expõe `customers` e o alias `clients`.
|
|
343
|
+
|
|
344
|
+
```ts
|
|
345
|
+
const { client } = await ay.customers.create({
|
|
346
|
+
email: "cliente@example.com",
|
|
347
|
+
password: "123456",
|
|
348
|
+
fullName: "Cliente Teste",
|
|
349
|
+
document: "00000000000",
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
const { clients } = await ay.customers.list();
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Merchants, Admins, API Keys
|
|
356
|
+
|
|
357
|
+
Essas rotas dependem do escopo da sessão/API key.
|
|
358
|
+
|
|
359
|
+
```ts
|
|
360
|
+
await ay.merchants.create({
|
|
361
|
+
email: "merchant@example.com",
|
|
362
|
+
password: "123456",
|
|
363
|
+
name: "Minha Loja",
|
|
364
|
+
fullName: "Responsavel",
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
const key = await ay.apiKeys.create({
|
|
368
|
+
name: "Guild Builders",
|
|
369
|
+
permissions: {
|
|
370
|
+
projects: { list: true, create: true, edit: true, delete: false },
|
|
371
|
+
products: { list: true, create: true, edit: true, delete: true },
|
|
372
|
+
orders: { list: true, create: true },
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Revogar, habilitar/desabilitar ou deletar:
|
|
378
|
+
|
|
379
|
+
```ts
|
|
380
|
+
await ay.apiKeys.revoke("api-key-id");
|
|
381
|
+
await ay.apiKeys.setStatus("api-key-id", "active");
|
|
382
|
+
await ay.apiKeys.delete("api-key-id");
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## Tratamento de erro
|
|
386
|
+
|
|
387
|
+
Métodos da SDK retornam `data` em caso de sucesso e lançam `AyPaymentsApiError` em caso de erro.
|
|
388
|
+
|
|
389
|
+
```ts
|
|
390
|
+
import { AyPaymentsApiError } from "@ay-payments/sdk";
|
|
391
|
+
|
|
392
|
+
try {
|
|
393
|
+
await ay.projects.list();
|
|
394
|
+
} catch (error) {
|
|
395
|
+
if (error instanceof AyPaymentsApiError) {
|
|
396
|
+
console.log(error.status);
|
|
397
|
+
console.log(error.payload.error);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## Notas de contrato
|
|
403
|
+
|
|
404
|
+
- Produto usa `value`.
|
|
405
|
+
- Produto não calcula comissão.
|
|
406
|
+
- Comissão é calculada em `POST /checkouts/calculate` e `POST /checkouts`.
|
|
407
|
+
- `projectIdOrExternalId` aceita o `id` interno do AY Payments ou o `externalId` do projeto.
|
|
408
|
+
- `connectedAccountId` é o id da conta conectada no provedor, como `acct_...` na Stripe ou o user id do Mercado Pago.
|
|
409
|
+
- `connectionId` é o id interno da conexão dentro do projeto.
|