@undernouzen/ay-payments-sdk 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +82 -221
- package/dist/client.d.ts +199 -175
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -2
- package/dist/client.js.map +1 -1
- package/dist/core.d.ts +51 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +2 -0
- package/dist/core.js.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +31 -0
- package/dist/errors.js.map +1 -0
- package/dist/models.d.ts +277 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +2 -0
- package/dist/models.js.map +1 -0
- package/dist/modules/admin.types.d.ts +35 -0
- package/dist/modules/admin.types.d.ts.map +1 -0
- package/dist/modules/admin.types.js +2 -0
- package/dist/modules/admin.types.js.map +1 -0
- package/dist/modules/analytics.types.d.ts +21 -0
- package/dist/modules/analytics.types.d.ts.map +1 -0
- package/dist/modules/analytics.types.js +2 -0
- package/dist/modules/analytics.types.js.map +1 -0
- package/dist/modules/api-keys.types.d.ts +20 -0
- package/dist/modules/api-keys.types.d.ts.map +1 -0
- package/dist/modules/api-keys.types.js +2 -0
- package/dist/modules/api-keys.types.js.map +1 -0
- package/dist/modules/auth.types.d.ts +55 -0
- package/dist/modules/auth.types.d.ts.map +1 -0
- package/dist/modules/auth.types.js +2 -0
- package/dist/modules/auth.types.js.map +1 -0
- package/dist/modules/checkouts.types.d.ts +128 -0
- package/dist/modules/checkouts.types.d.ts.map +1 -0
- package/dist/modules/checkouts.types.js +2 -0
- package/dist/modules/checkouts.types.js.map +1 -0
- package/dist/modules/commissions.types.d.ts +17 -0
- package/dist/modules/commissions.types.d.ts.map +1 -0
- package/dist/modules/commissions.types.js +2 -0
- package/dist/modules/commissions.types.js.map +1 -0
- package/dist/modules/customers.types.d.ts +22 -0
- package/dist/modules/customers.types.d.ts.map +1 -0
- package/dist/modules/customers.types.js +2 -0
- package/dist/modules/customers.types.js.map +1 -0
- package/dist/modules/logs.types.d.ts +16 -0
- package/dist/modules/logs.types.d.ts.map +1 -0
- package/dist/modules/logs.types.js +2 -0
- package/dist/modules/logs.types.js.map +1 -0
- package/dist/modules/orders.types.d.ts +32 -0
- package/dist/modules/orders.types.d.ts.map +1 -0
- package/dist/modules/orders.types.js +2 -0
- package/dist/modules/orders.types.js.map +1 -0
- package/dist/modules/products.types.d.ts +28 -0
- package/dist/modules/products.types.d.ts.map +1 -0
- package/dist/modules/products.types.js +2 -0
- package/dist/modules/products.types.js.map +1 -0
- package/dist/modules/profile.types.d.ts +23 -0
- package/dist/modules/profile.types.d.ts.map +1 -0
- package/dist/modules/profile.types.js +2 -0
- package/dist/modules/profile.types.js.map +1 -0
- package/dist/modules/projects.types.d.ts +91 -0
- package/dist/modules/projects.types.d.ts.map +1 -0
- package/dist/modules/projects.types.js +2 -0
- package/dist/modules/projects.types.js.map +1 -0
- package/dist/types.d.ts +15 -621
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +15 -10
- package/dist/types.js.map +1 -1
- package/examples/calculate-checkout.ts +25 -0
- package/examples/create-pix-checkout.ts +30 -0
- package/examples/create-project.ts +21 -0
- package/examples/handle-error.ts +22 -0
- package/package.json +20 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.3
|
|
4
|
+
|
|
5
|
+
- Reorganized public SDK types by module.
|
|
6
|
+
- Added typed `ApiResult<T>` responses.
|
|
7
|
+
- Added `isApiError`, `isContextError` and `isExternalProviderError` helpers.
|
|
8
|
+
- Sanitized connected account types so public SDK responses do not expose `accessToken` or `refreshToken`.
|
|
9
|
+
- Added module-specific package exports.
|
|
10
|
+
|
|
11
|
+
## 1.0.2
|
|
12
|
+
|
|
13
|
+
- Updated package scope to `@undernouzen/ay-payments-sdk`.
|
|
14
|
+
- Added AY Payments docs homepage.
|
|
15
|
+
|
|
16
|
+
## 1.0.0
|
|
17
|
+
|
|
18
|
+
- Initial SDK client for AY Payments API v1.
|
package/README.md
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
# AY Payments SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript/JavaScript SDK for the AY Payments API.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Full docs: https://aypayments.undernouzen.com.br/docs/
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @ay-payments
|
|
10
|
+
npm install @undernouzen/ay-payments-sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @undernouzen/ay-payments-sdk
|
|
15
|
+
```
|
|
14
16
|
|
|
15
|
-
##
|
|
17
|
+
## Create a client
|
|
16
18
|
|
|
17
19
|
```ts
|
|
18
|
-
import { createAYPaymentsClient } from "@ay-payments
|
|
20
|
+
import { createAYPaymentsClient } from "@undernouzen/ay-payments-sdk";
|
|
19
21
|
|
|
20
22
|
const ay = createAYPaymentsClient({
|
|
21
23
|
baseUrl: "https://aypayments.undernouzen.com.br",
|
|
@@ -23,13 +25,13 @@ const ay = createAYPaymentsClient({
|
|
|
23
25
|
});
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
The default API base is:
|
|
27
29
|
|
|
28
|
-
```
|
|
30
|
+
```txt
|
|
29
31
|
https://aypayments.undernouzen.com.br/api/v1
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
You can also pass the exact API URL:
|
|
33
35
|
|
|
34
36
|
```ts
|
|
35
37
|
const ay = createAYPaymentsClient({
|
|
@@ -38,28 +40,24 @@ const ay = createAYPaymentsClient({
|
|
|
38
40
|
});
|
|
39
41
|
```
|
|
40
42
|
|
|
41
|
-
##
|
|
43
|
+
## Authentication
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
Default:
|
|
44
46
|
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
baseUrl: "https://aypayments.undernouzen.com.br",
|
|
48
|
-
apiKey: "ayp_secret",
|
|
49
|
-
});
|
|
47
|
+
```http
|
|
48
|
+
Authorization: Bearer ayp_secret
|
|
50
49
|
```
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
Use `x-api-key` instead:
|
|
53
52
|
|
|
54
53
|
```ts
|
|
55
54
|
const ay = createAYPaymentsClient({
|
|
56
|
-
baseUrl: "https://aypayments.undernouzen.com.br",
|
|
57
55
|
apiKey: "ayp_secret",
|
|
58
56
|
authHeader: "x-api-key",
|
|
59
57
|
});
|
|
60
58
|
```
|
|
61
59
|
|
|
62
|
-
|
|
60
|
+
Send the raw key in `Authorization`:
|
|
63
61
|
|
|
64
62
|
```ts
|
|
65
63
|
const ay = createAYPaymentsClient({
|
|
@@ -68,56 +66,68 @@ const ay = createAYPaymentsClient({
|
|
|
68
66
|
});
|
|
69
67
|
```
|
|
70
68
|
|
|
71
|
-
|
|
69
|
+
The client can be created without an API key. Protected routes will then depend on session cookies or return an API auth error.
|
|
70
|
+
|
|
71
|
+
## Error handling
|
|
72
|
+
|
|
73
|
+
Mapped SDK methods return `ApiResult<T>`, which is either the expected response or an `ErrorResponse`.
|
|
72
74
|
|
|
73
75
|
```ts
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
import { createAYPaymentsClient, isApiError } from "@undernouzen/ay-payments-sdk";
|
|
77
|
+
|
|
78
|
+
const ay = createAYPaymentsClient({ apiKey: "ayp_secret" });
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
const result = await ay.projects.accounts.list("project-id-or-external-id");
|
|
78
81
|
|
|
79
|
-
|
|
82
|
+
if (isApiError(result)) {
|
|
83
|
+
console.log(result.error);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log(result.accounts);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Error shapes:
|
|
80
91
|
|
|
81
92
|
```ts
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
type ErrorResponse = CommunError | ContextError | ExternalProviderError;
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Versioning
|
|
97
|
+
|
|
98
|
+
`v1` is the default.
|
|
86
99
|
|
|
100
|
+
```ts
|
|
87
101
|
await ay.v1.projects.list();
|
|
88
102
|
```
|
|
89
103
|
|
|
90
|
-
|
|
104
|
+
Convenience aliases point to `v1`:
|
|
91
105
|
|
|
92
106
|
```ts
|
|
93
107
|
await ay.projects.list();
|
|
94
|
-
await ay.products.
|
|
108
|
+
await ay.products.listByProject("project-id");
|
|
95
109
|
await ay.checkouts.create(payload);
|
|
96
110
|
```
|
|
97
111
|
|
|
98
|
-
## Raw
|
|
112
|
+
## Raw requests
|
|
99
113
|
|
|
100
|
-
|
|
114
|
+
Use `raw` or the exposed Axios instance for endpoints not mapped yet.
|
|
101
115
|
|
|
102
116
|
```ts
|
|
103
|
-
const
|
|
117
|
+
const result = await ay.raw<{ ok: boolean }>({
|
|
104
118
|
method: "GET",
|
|
105
|
-
url: "/
|
|
119
|
+
url: "/projects",
|
|
106
120
|
});
|
|
107
121
|
```
|
|
108
122
|
|
|
109
|
-
Você também pode usar a instância diretamente:
|
|
110
|
-
|
|
111
123
|
```ts
|
|
112
124
|
const response = await ay.api.get("/projects");
|
|
113
125
|
```
|
|
114
126
|
|
|
115
127
|
## Projects
|
|
116
128
|
|
|
117
|
-
Criar ou atualizar por `externalId`:
|
|
118
|
-
|
|
119
129
|
```ts
|
|
120
|
-
const
|
|
130
|
+
const result = await ay.projects.create({
|
|
121
131
|
externalId: "832320430277918720",
|
|
122
132
|
name: "Vagalumes",
|
|
123
133
|
webhookUrl: "https://guildbuilders.example.com/webhooks/aypayments",
|
|
@@ -125,32 +135,15 @@ const { project, created } = await ay.projects.create({
|
|
|
125
135
|
guildId: "832320430277918720",
|
|
126
136
|
},
|
|
127
137
|
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Listar:
|
|
131
|
-
|
|
132
|
-
```ts
|
|
133
|
-
const { projects, pagination } = await ay.projects.list({
|
|
134
|
-
page: 1,
|
|
135
|
-
limit: 50,
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const result = await ay.projects.query({
|
|
143
|
-
metadata: {
|
|
144
|
-
guildId: "832320430277918720",
|
|
145
|
-
},
|
|
146
|
-
});
|
|
139
|
+
if (!isApiError(result)) {
|
|
140
|
+
console.log(result.project.id, result.created);
|
|
141
|
+
}
|
|
147
142
|
```
|
|
148
143
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
## Contas conectadas
|
|
144
|
+
## Connected accounts
|
|
152
145
|
|
|
153
|
-
|
|
146
|
+
Generate an OAuth URL:
|
|
154
147
|
|
|
155
148
|
```ts
|
|
156
149
|
const oauth = await ay.projects.accounts.oauth({
|
|
@@ -160,43 +153,34 @@ const oauth = await ay.projects.accounts.oauth({
|
|
|
160
153
|
redirectUrl: "https://guildbuilders.example.com/connect/result",
|
|
161
154
|
});
|
|
162
155
|
|
|
163
|
-
|
|
156
|
+
if (!isApiError(oauth)) {
|
|
157
|
+
console.log(oauth.authorizationUrl);
|
|
158
|
+
}
|
|
164
159
|
```
|
|
165
160
|
|
|
166
|
-
|
|
161
|
+
List connected accounts:
|
|
167
162
|
|
|
168
163
|
```ts
|
|
169
|
-
const
|
|
170
|
-
```
|
|
164
|
+
const accounts = await ay.projects.accounts.list("832320430277918720");
|
|
171
165
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
await ay.projects.accounts.update("832320430277918720", "connection-id", {
|
|
176
|
-
name: "Conta Pix principal",
|
|
177
|
-
status: "active",
|
|
178
|
-
});
|
|
166
|
+
if (!isApiError(accounts)) {
|
|
167
|
+
console.log(accounts.accounts);
|
|
168
|
+
}
|
|
179
169
|
```
|
|
180
170
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
```ts
|
|
184
|
-
await ay.projects.accounts.delete("832320430277918720", "connection-id");
|
|
185
|
-
```
|
|
171
|
+
Public connected account responses never expose `accessToken` or `refreshToken`.
|
|
186
172
|
|
|
187
173
|
## Products
|
|
188
174
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
Criar produto:
|
|
175
|
+
Products use `value`. Product routes do not calculate platform commission; commission is calculated by checkout routes.
|
|
192
176
|
|
|
193
177
|
```ts
|
|
194
|
-
const
|
|
178
|
+
const product = await ay.products.create("832320430277918720", {
|
|
195
179
|
connectedAccountId: "330692399",
|
|
196
180
|
name: "Cargo VIP",
|
|
181
|
+
value: 19.9,
|
|
197
182
|
icon: "https://cdn.example.com/vip.png",
|
|
198
183
|
description: "Acesso VIP no Discord",
|
|
199
|
-
value: 19.9,
|
|
200
184
|
fees: [
|
|
201
185
|
{
|
|
202
186
|
name: "Taxa operacional",
|
|
@@ -206,63 +190,30 @@ const { product } = await ay.products.create("832320430277918720", {
|
|
|
206
190
|
active: true,
|
|
207
191
|
},
|
|
208
192
|
],
|
|
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
193
|
});
|
|
229
194
|
```
|
|
230
195
|
|
|
231
196
|
## Checkouts
|
|
232
197
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
Use `calculate` para exibir o resumo antes de gerar Pix, boleto ou Checkout Pro/Stripe Checkout.
|
|
198
|
+
Calculate totals without creating an order/payment:
|
|
236
199
|
|
|
237
200
|
```ts
|
|
238
201
|
const calculation = await ay.checkouts.calculate({
|
|
239
|
-
items: [
|
|
240
|
-
{
|
|
241
|
-
productId: "product-id",
|
|
242
|
-
quantity: 1,
|
|
243
|
-
},
|
|
244
|
-
],
|
|
202
|
+
items: [{ productId: "product-id", quantity: 1 }],
|
|
245
203
|
customer: {
|
|
246
204
|
email: "cliente@example.com",
|
|
247
205
|
name: "Cliente Teste",
|
|
248
206
|
},
|
|
249
207
|
currency: "BRL",
|
|
250
208
|
});
|
|
251
|
-
|
|
252
|
-
console.log(calculation.summary.amount);
|
|
253
209
|
```
|
|
254
210
|
|
|
255
|
-
|
|
211
|
+
Create a real checkout:
|
|
256
212
|
|
|
257
213
|
```ts
|
|
258
214
|
const checkout = await ay.checkouts.create({
|
|
259
215
|
paymentMethod: "pix",
|
|
260
|
-
items: [
|
|
261
|
-
{
|
|
262
|
-
productId: "product-id",
|
|
263
|
-
quantity: 1,
|
|
264
|
-
},
|
|
265
|
-
],
|
|
216
|
+
items: [{ productId: "product-id", quantity: 1 }],
|
|
266
217
|
customer: {
|
|
267
218
|
email: "cliente@example.com",
|
|
268
219
|
name: "Cliente Teste",
|
|
@@ -271,26 +222,14 @@ const checkout = await ay.checkouts.create({
|
|
|
271
222
|
},
|
|
272
223
|
externalReference: "guild-832320430277918720-user-123",
|
|
273
224
|
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
225
|
metadata: {
|
|
281
226
|
guildId: "832320430277918720",
|
|
282
227
|
discordUserId: "123456789",
|
|
283
228
|
},
|
|
284
229
|
});
|
|
285
|
-
|
|
286
|
-
console.log(checkout.order.id);
|
|
287
|
-
console.log(checkout.payment?.qrCode);
|
|
288
|
-
console.log(checkout.checkout?.url);
|
|
289
230
|
```
|
|
290
231
|
|
|
291
|
-
|
|
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.
|
|
232
|
+
Custom checkout without a registered product:
|
|
294
233
|
|
|
295
234
|
```ts
|
|
296
235
|
const checkout = await ay.checkouts.create({
|
|
@@ -302,108 +241,30 @@ const checkout = await ay.checkouts.create({
|
|
|
302
241
|
name: "Cargo VIP",
|
|
303
242
|
amount: 19.9,
|
|
304
243
|
quantity: 1,
|
|
305
|
-
description: "Acesso VIP no Discord",
|
|
306
244
|
},
|
|
307
245
|
],
|
|
308
246
|
customer: {
|
|
309
247
|
email: "cliente@example.com",
|
|
310
248
|
name: "Cliente Teste",
|
|
311
249
|
},
|
|
312
|
-
externalReference: "guild-832320430277918720-custom-001",
|
|
313
250
|
});
|
|
314
251
|
```
|
|
315
252
|
|
|
316
|
-
##
|
|
317
|
-
|
|
318
|
-
Listar orders:
|
|
253
|
+
## Typed imports
|
|
319
254
|
|
|
320
|
-
|
|
321
|
-
const { orders } = await ay.orders.list({ page: 1, limit: 100 });
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
Buscar por metadata:
|
|
255
|
+
Everything is also available from `types`:
|
|
325
256
|
|
|
326
257
|
```ts
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
258
|
+
import type {
|
|
259
|
+
AyPaymentsCreateProjectPayload,
|
|
260
|
+
AyPaymentsCreateCheckoutResponse,
|
|
261
|
+
ErrorResponse,
|
|
262
|
+
} from "@undernouzen/ay-payments-sdk/types";
|
|
332
263
|
```
|
|
333
264
|
|
|
334
|
-
|
|
265
|
+
Module-specific imports are supported:
|
|
335
266
|
|
|
336
267
|
```ts
|
|
337
|
-
|
|
268
|
+
import type { AyPaymentsCheckoutPayload } from "@undernouzen/ay-payments-sdk/modules/checkouts.types";
|
|
269
|
+
import { isApiError } from "@undernouzen/ay-payments-sdk/errors";
|
|
338
270
|
```
|
|
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.
|