@vitrindigital/node 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/index.cjs +51 -0
- package/dist/index.d.cts +122 -2
- package/dist/index.d.ts +122 -2
- package/dist/index.js +51 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,16 @@ const vitrin = new Vitrin({
|
|
|
24
24
|
|
|
25
25
|
Use a chave `vd_test_*` em desenvolvimento e `vd_live_*` em produção.
|
|
26
26
|
|
|
27
|
+
## Organizações LLC (US)
|
|
28
|
+
|
|
29
|
+
Se a org é uma **US LLC** (`entity_type: "llc"`), os valores são em **USD**
|
|
30
|
+
(campo `currency` nas transações); os métodos default são **cartão** e **Pix
|
|
31
|
+
cross-border** (o cliente paga em BRL, a LLC recebe em USD). A liquidação é
|
|
32
|
+
**automática**: os endpoints de saldo/recebíveis/transferências retornam
|
|
33
|
+
`{ auto_payout: true }` em vez de saldo retido (não há saque/antecipação
|
|
34
|
+
manual). O onboarding inclui verificação de identidade (KYC), hospedada ou
|
|
35
|
+
embedded. Veja `docs/api/onboarding-llc.md` e `docs/api/differences-cnpj-llc.md`.
|
|
36
|
+
|
|
27
37
|
## Recursos
|
|
28
38
|
|
|
29
39
|
### Clientes
|
package/dist/index.cjs
CHANGED
|
@@ -214,6 +214,19 @@ var Charges = class {
|
|
|
214
214
|
idempotencyKey
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* One-click buy: cobra usando o cartão preferido salvo do cliente.
|
|
219
|
+
* O cliente precisa ter um saved card (vide `customers.savedCard.create`).
|
|
220
|
+
* Retorna 422 `no_saved_card` se não houver cartão; 422 `card_expired` se vencido.
|
|
221
|
+
*/
|
|
222
|
+
createWithSavedCard(params) {
|
|
223
|
+
const { idempotencyKey, ...body } = params;
|
|
224
|
+
return this.client.request("/charges/charge-saved/", {
|
|
225
|
+
method: "POST",
|
|
226
|
+
body,
|
|
227
|
+
idempotencyKey
|
|
228
|
+
});
|
|
229
|
+
}
|
|
217
230
|
retrieve(id) {
|
|
218
231
|
return this.client.request(`/transactions/${id}/`);
|
|
219
232
|
}
|
|
@@ -243,11 +256,42 @@ var Charges = class {
|
|
|
243
256
|
};
|
|
244
257
|
|
|
245
258
|
// src/resources/customers.ts
|
|
259
|
+
var SavedCardResource = class {
|
|
260
|
+
constructor(client) {
|
|
261
|
+
this.client = client;
|
|
262
|
+
}
|
|
263
|
+
client;
|
|
264
|
+
/** Tokeniza + persiste o cartão preferido do cliente (substitui o anterior). */
|
|
265
|
+
create(customerId, params) {
|
|
266
|
+
return this.client.request(`/customers/${customerId}/saved-card/`, {
|
|
267
|
+
method: "POST",
|
|
268
|
+
body: params
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/** Retorna brand/last4/exp/holder — nunca o token. */
|
|
272
|
+
retrieve(customerId) {
|
|
273
|
+
return this.client.request(`/customers/${customerId}/saved-card/`);
|
|
274
|
+
}
|
|
275
|
+
delete(customerId) {
|
|
276
|
+
return this.client.request(`/customers/${customerId}/saved-card/`, {
|
|
277
|
+
method: "DELETE"
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/** Gera URL assinada (JWT 24h) pro cliente final ver/remover o próprio cartão. */
|
|
281
|
+
createManagementLink(customerId) {
|
|
282
|
+
return this.client.request(
|
|
283
|
+
`/customers/${customerId}/saved-card/management-link/`,
|
|
284
|
+
{ method: "POST" }
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
246
288
|
var Customers = class {
|
|
247
289
|
constructor(client) {
|
|
248
290
|
this.client = client;
|
|
291
|
+
this.savedCard = new SavedCardResource(client);
|
|
249
292
|
}
|
|
250
293
|
client;
|
|
294
|
+
savedCard;
|
|
251
295
|
create(params) {
|
|
252
296
|
return this.client.request("/customers/", {
|
|
253
297
|
method: "POST",
|
|
@@ -271,6 +315,13 @@ var Customers = class {
|
|
|
271
315
|
delete(id) {
|
|
272
316
|
return this.client.request(`/customers/${id}/`, { method: "DELETE" });
|
|
273
317
|
}
|
|
318
|
+
/** Gera link assinado de recompra one-click (JWT 15min, uso único). */
|
|
319
|
+
oneClickLink(customerId, params) {
|
|
320
|
+
return this.client.request(
|
|
321
|
+
`/customers/${customerId}/one-click-link/`,
|
|
322
|
+
{ method: "POST", body: params }
|
|
323
|
+
);
|
|
324
|
+
}
|
|
274
325
|
};
|
|
275
326
|
|
|
276
327
|
// src/resources/plans.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -43,8 +43,42 @@ declare class VitrinClient {
|
|
|
43
43
|
* Mantidos como interfaces genéricas (em vez de unions super-precisas) pra
|
|
44
44
|
* que mudanças não-quebra-API no backend não exijam major bump no SDK.
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
/** ISO 4217. BRL é o default histórico; USD/EUR/GBP habilitados com orgs LLC. */
|
|
47
|
+
type Currency = 'BRL' | 'USD' | 'EUR' | 'GBP';
|
|
48
|
+
/** Tipo jurídico da organização. CNPJ = subconta Safe2Pay (Brasil),
|
|
49
|
+
* LLC = Stripe Connect (US/internacional). */
|
|
50
|
+
type EntityType = 'cnpj' | 'llc';
|
|
51
|
+
/**
|
|
52
|
+
* Métodos de pagamento suportados pela plataforma.
|
|
53
|
+
*
|
|
54
|
+
* A disponibilidade por org é dinâmica — sempre cheque
|
|
55
|
+
* `Organization.enabled_payment_methods`. Por tipo de entidade:
|
|
56
|
+
*
|
|
57
|
+
* - CNPJ (BR): PIX, PIX_AUTOMATIC, BOLETO, CREDIT_CARD (default).
|
|
58
|
+
* - LLC (US): CREDIT_CARD por default. PIX está disponível cross-border
|
|
59
|
+
* (o cliente paga em BRL, a liquidação é em USD) como opt-in habilitado
|
|
60
|
+
* pela Vitrin. BOLETO NÃO se aplica a LLC (é Brasil-only). Os demais
|
|
61
|
+
* métodos abaixo (cartão internacional / ACH / wallets / Klarna /
|
|
62
|
+
* Afterpay) são reservados para evolução e podem não estar habilitados.
|
|
63
|
+
*/
|
|
64
|
+
type PaymentMethod = 'PIX' | 'PIX_AUTOMATIC' | 'BOLETO' | 'CREDIT_CARD' | 'CARD_INTERNATIONAL' | 'ACH_DEBIT' | 'SEPA_DEBIT' | 'APPLE_PAY' | 'GOOGLE_PAY' | 'KLARNA' | 'AFTERPAY';
|
|
47
65
|
type TransactionStatus = 'pending' | 'confirmed' | 'received' | 'overdue' | 'refunded' | 'chargeback' | 'failed' | 'canceled';
|
|
66
|
+
/**
|
|
67
|
+
* Representa a organização (subconta) dona da API key em uso.
|
|
68
|
+
*
|
|
69
|
+
* Nota: `default_currency` é derivado de `entity_type` no backend e pode
|
|
70
|
+
* ainda não estar exposto pelo serializer — a declaração aqui é
|
|
71
|
+
* forward-compatible para quando o backend passar a emiti-lo.
|
|
72
|
+
*/
|
|
73
|
+
interface Organization {
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
entity_type: EntityType;
|
|
77
|
+
default_currency: Currency;
|
|
78
|
+
enabled_payment_methods?: PaymentMethod[];
|
|
79
|
+
created_at: string;
|
|
80
|
+
updated_at: string;
|
|
81
|
+
}
|
|
48
82
|
interface Customer {
|
|
49
83
|
id: string;
|
|
50
84
|
name: string;
|
|
@@ -94,6 +128,11 @@ interface Subscription {
|
|
|
94
128
|
canceled_at: string | null;
|
|
95
129
|
created_at: string;
|
|
96
130
|
updated_at: string;
|
|
131
|
+
/** LLC: moeda da assinatura (USD). Ausente/BRL para CNPJ. */
|
|
132
|
+
currency?: Currency;
|
|
133
|
+
/** LLC: secret de confirmação da 1ª cobrança — quando presente, confirme
|
|
134
|
+
* com Stripe.js (cartão/SCA) antes da assinatura ficar ativa. */
|
|
135
|
+
client_secret?: string | null;
|
|
97
136
|
}
|
|
98
137
|
interface Transaction {
|
|
99
138
|
id: string;
|
|
@@ -106,6 +145,16 @@ interface Transaction {
|
|
|
106
145
|
platform_fee: string;
|
|
107
146
|
provider_fee: string;
|
|
108
147
|
billing_type: PaymentMethod;
|
|
148
|
+
/** ISO 4217. Default herdado de `Organization.default_currency` na criação. */
|
|
149
|
+
currency: Currency;
|
|
150
|
+
/** LLC: secret de confirmação — cartão (SCA/3DS) ou PIX (QR); confirme com
|
|
151
|
+
* Stripe.js quando presente. Ausente para cobranças síncronas/CNPJ. */
|
|
152
|
+
client_secret?: string | null;
|
|
153
|
+
/** PIX-LLC cross-currency: o cliente vê BRL (`presentment_*`) e a LLC escritura
|
|
154
|
+
* em USD (`currency`/`amount`); `exchange_rate` é o câmbio aplicado. */
|
|
155
|
+
presentment_currency?: Currency | null;
|
|
156
|
+
presentment_amount?: string | null;
|
|
157
|
+
exchange_rate?: string | null;
|
|
109
158
|
installments: number;
|
|
110
159
|
status: TransactionStatus;
|
|
111
160
|
pix_qr_code?: string;
|
|
@@ -126,6 +175,27 @@ interface PaginatedList<T> {
|
|
|
126
175
|
previous: string | null;
|
|
127
176
|
results: T[];
|
|
128
177
|
}
|
|
178
|
+
/** Metadados do cartão salvo de um Customer (one-click buy). Nunca inclui o token. */
|
|
179
|
+
interface SavedCard {
|
|
180
|
+
brand: string;
|
|
181
|
+
last4: string;
|
|
182
|
+
exp_month: number | null;
|
|
183
|
+
exp_year: number | null;
|
|
184
|
+
holder_name: string;
|
|
185
|
+
consent_at: string | null;
|
|
186
|
+
}
|
|
187
|
+
/** Resposta de POST /customers/{id}/saved-card/management-link/. */
|
|
188
|
+
interface SavedCardManagementLink {
|
|
189
|
+
url: string;
|
|
190
|
+
token: string;
|
|
191
|
+
expires_at: string;
|
|
192
|
+
}
|
|
193
|
+
/** Resposta de POST /customers/{id}/one-click-link/. */
|
|
194
|
+
interface OneClickLink {
|
|
195
|
+
url: string;
|
|
196
|
+
token: string;
|
|
197
|
+
expires_at: string;
|
|
198
|
+
}
|
|
129
199
|
/** Response do GET /balance/. */
|
|
130
200
|
interface Balance {
|
|
131
201
|
available: number;
|
|
@@ -168,6 +238,15 @@ interface CreateChargeParams {
|
|
|
168
238
|
/** Idempotency-Key (header) — recomendado pra evitar duplo-débito em retry. */
|
|
169
239
|
idempotencyKey?: string;
|
|
170
240
|
}
|
|
241
|
+
interface CreateChargeWithSavedCardParams {
|
|
242
|
+
customer_id: string;
|
|
243
|
+
amount: number | string;
|
|
244
|
+
description?: string;
|
|
245
|
+
installments?: number;
|
|
246
|
+
external_reference?: string;
|
|
247
|
+
/** Idempotency-Key (header) — recomendado pra evitar duplo-débito em retry. */
|
|
248
|
+
idempotencyKey?: string;
|
|
249
|
+
}
|
|
171
250
|
interface RefundParams {
|
|
172
251
|
/** Valor parcial em reais. Omitir = reembolso total. */
|
|
173
252
|
amount?: number | string;
|
|
@@ -188,6 +267,12 @@ declare class Charges {
|
|
|
188
267
|
constructor(client: VitrinClient);
|
|
189
268
|
/** Cria uma cobrança avulsa (PIX/Boleto/Cartão). */
|
|
190
269
|
create(params: CreateChargeParams): Promise<Transaction>;
|
|
270
|
+
/**
|
|
271
|
+
* One-click buy: cobra usando o cartão preferido salvo do cliente.
|
|
272
|
+
* O cliente precisa ter um saved card (vide `customers.savedCard.create`).
|
|
273
|
+
* Retorna 422 `no_saved_card` se não houver cartão; 422 `card_expired` se vencido.
|
|
274
|
+
*/
|
|
275
|
+
createWithSavedCard(params: CreateChargeWithSavedCardParams): Promise<Transaction>;
|
|
191
276
|
retrieve(id: string): Promise<Transaction>;
|
|
192
277
|
list(params?: ListChargesParams): Promise<PaginatedList<Transaction>>;
|
|
193
278
|
refund(id: string, params: RefundParams): Promise<Transaction>;
|
|
@@ -214,8 +299,33 @@ interface CreateCustomerParams {
|
|
|
214
299
|
state?: string;
|
|
215
300
|
}
|
|
216
301
|
type UpdateCustomerParams = Partial<CreateCustomerParams>;
|
|
302
|
+
interface SaveCardParams {
|
|
303
|
+
credit_card: {
|
|
304
|
+
holder_name: string;
|
|
305
|
+
number: string;
|
|
306
|
+
expiry_month: string;
|
|
307
|
+
expiry_year: string;
|
|
308
|
+
cvv: string;
|
|
309
|
+
};
|
|
310
|
+
consent: {
|
|
311
|
+
accepted_at: string;
|
|
312
|
+
ip: string;
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
declare class SavedCardResource {
|
|
316
|
+
private client;
|
|
317
|
+
constructor(client: VitrinClient);
|
|
318
|
+
/** Tokeniza + persiste o cartão preferido do cliente (substitui o anterior). */
|
|
319
|
+
create(customerId: string, params: SaveCardParams): Promise<SavedCard>;
|
|
320
|
+
/** Retorna brand/last4/exp/holder — nunca o token. */
|
|
321
|
+
retrieve(customerId: string): Promise<SavedCard>;
|
|
322
|
+
delete(customerId: string): Promise<void>;
|
|
323
|
+
/** Gera URL assinada (JWT 24h) pro cliente final ver/remover o próprio cartão. */
|
|
324
|
+
createManagementLink(customerId: string): Promise<SavedCardManagementLink>;
|
|
325
|
+
}
|
|
217
326
|
declare class Customers {
|
|
218
327
|
private client;
|
|
328
|
+
readonly savedCard: SavedCardResource;
|
|
219
329
|
constructor(client: VitrinClient);
|
|
220
330
|
create(params: CreateCustomerParams): Promise<Customer>;
|
|
221
331
|
retrieve(id: string): Promise<Customer>;
|
|
@@ -225,6 +335,16 @@ declare class Customers {
|
|
|
225
335
|
}): Promise<PaginatedList<Customer>>;
|
|
226
336
|
update(id: string, params: UpdateCustomerParams): Promise<Customer>;
|
|
227
337
|
delete(id: string): Promise<void>;
|
|
338
|
+
/** Gera link assinado de recompra one-click (JWT 15min, uso único). */
|
|
339
|
+
oneClickLink(customerId: string, params: {
|
|
340
|
+
product_id?: string;
|
|
341
|
+
plan_id?: string;
|
|
342
|
+
amount?: string;
|
|
343
|
+
installments?: number;
|
|
344
|
+
coupon_code?: string;
|
|
345
|
+
bump_ids?: string[];
|
|
346
|
+
expires_in?: number;
|
|
347
|
+
}): Promise<OneClickLink>;
|
|
228
348
|
}
|
|
229
349
|
|
|
230
350
|
interface CreatePlanParams {
|
|
@@ -425,4 +545,4 @@ declare class Vitrin {
|
|
|
425
545
|
request<T = unknown>(path: string, options?: Parameters<VitrinClient['request']>[1]): Promise<T>;
|
|
426
546
|
}
|
|
427
547
|
|
|
428
|
-
export { type Balance, type ConstructEventOptions, type Customer, type PaginatedList, type PaymentMethod, type Plan, type Product, type RequestOptions, type ScheduledReceivable, type ScheduledReceivablesResponse, type Subscription, type Transaction, type TransactionStatus, Vitrin, VitrinAuthError, type VitrinClientOptions, VitrinError, VitrinNetworkError, VitrinNotFoundError, VitrinRateLimitError, VitrinServerError, VitrinValidationError, type WebhookEvent, Webhooks };
|
|
548
|
+
export { type Balance, type ConstructEventOptions, type Currency, type Customer, type EntityType, type Organization, type PaginatedList, type PaymentMethod, type Plan, type Product, type RequestOptions, type ScheduledReceivable, type ScheduledReceivablesResponse, type Subscription, type Transaction, type TransactionStatus, Vitrin, VitrinAuthError, type VitrinClientOptions, VitrinError, VitrinNetworkError, VitrinNotFoundError, VitrinRateLimitError, VitrinServerError, VitrinValidationError, type WebhookEvent, Webhooks };
|
package/dist/index.d.ts
CHANGED
|
@@ -43,8 +43,42 @@ declare class VitrinClient {
|
|
|
43
43
|
* Mantidos como interfaces genéricas (em vez de unions super-precisas) pra
|
|
44
44
|
* que mudanças não-quebra-API no backend não exijam major bump no SDK.
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
/** ISO 4217. BRL é o default histórico; USD/EUR/GBP habilitados com orgs LLC. */
|
|
47
|
+
type Currency = 'BRL' | 'USD' | 'EUR' | 'GBP';
|
|
48
|
+
/** Tipo jurídico da organização. CNPJ = subconta Safe2Pay (Brasil),
|
|
49
|
+
* LLC = Stripe Connect (US/internacional). */
|
|
50
|
+
type EntityType = 'cnpj' | 'llc';
|
|
51
|
+
/**
|
|
52
|
+
* Métodos de pagamento suportados pela plataforma.
|
|
53
|
+
*
|
|
54
|
+
* A disponibilidade por org é dinâmica — sempre cheque
|
|
55
|
+
* `Organization.enabled_payment_methods`. Por tipo de entidade:
|
|
56
|
+
*
|
|
57
|
+
* - CNPJ (BR): PIX, PIX_AUTOMATIC, BOLETO, CREDIT_CARD (default).
|
|
58
|
+
* - LLC (US): CREDIT_CARD por default. PIX está disponível cross-border
|
|
59
|
+
* (o cliente paga em BRL, a liquidação é em USD) como opt-in habilitado
|
|
60
|
+
* pela Vitrin. BOLETO NÃO se aplica a LLC (é Brasil-only). Os demais
|
|
61
|
+
* métodos abaixo (cartão internacional / ACH / wallets / Klarna /
|
|
62
|
+
* Afterpay) são reservados para evolução e podem não estar habilitados.
|
|
63
|
+
*/
|
|
64
|
+
type PaymentMethod = 'PIX' | 'PIX_AUTOMATIC' | 'BOLETO' | 'CREDIT_CARD' | 'CARD_INTERNATIONAL' | 'ACH_DEBIT' | 'SEPA_DEBIT' | 'APPLE_PAY' | 'GOOGLE_PAY' | 'KLARNA' | 'AFTERPAY';
|
|
47
65
|
type TransactionStatus = 'pending' | 'confirmed' | 'received' | 'overdue' | 'refunded' | 'chargeback' | 'failed' | 'canceled';
|
|
66
|
+
/**
|
|
67
|
+
* Representa a organização (subconta) dona da API key em uso.
|
|
68
|
+
*
|
|
69
|
+
* Nota: `default_currency` é derivado de `entity_type` no backend e pode
|
|
70
|
+
* ainda não estar exposto pelo serializer — a declaração aqui é
|
|
71
|
+
* forward-compatible para quando o backend passar a emiti-lo.
|
|
72
|
+
*/
|
|
73
|
+
interface Organization {
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
entity_type: EntityType;
|
|
77
|
+
default_currency: Currency;
|
|
78
|
+
enabled_payment_methods?: PaymentMethod[];
|
|
79
|
+
created_at: string;
|
|
80
|
+
updated_at: string;
|
|
81
|
+
}
|
|
48
82
|
interface Customer {
|
|
49
83
|
id: string;
|
|
50
84
|
name: string;
|
|
@@ -94,6 +128,11 @@ interface Subscription {
|
|
|
94
128
|
canceled_at: string | null;
|
|
95
129
|
created_at: string;
|
|
96
130
|
updated_at: string;
|
|
131
|
+
/** LLC: moeda da assinatura (USD). Ausente/BRL para CNPJ. */
|
|
132
|
+
currency?: Currency;
|
|
133
|
+
/** LLC: secret de confirmação da 1ª cobrança — quando presente, confirme
|
|
134
|
+
* com Stripe.js (cartão/SCA) antes da assinatura ficar ativa. */
|
|
135
|
+
client_secret?: string | null;
|
|
97
136
|
}
|
|
98
137
|
interface Transaction {
|
|
99
138
|
id: string;
|
|
@@ -106,6 +145,16 @@ interface Transaction {
|
|
|
106
145
|
platform_fee: string;
|
|
107
146
|
provider_fee: string;
|
|
108
147
|
billing_type: PaymentMethod;
|
|
148
|
+
/** ISO 4217. Default herdado de `Organization.default_currency` na criação. */
|
|
149
|
+
currency: Currency;
|
|
150
|
+
/** LLC: secret de confirmação — cartão (SCA/3DS) ou PIX (QR); confirme com
|
|
151
|
+
* Stripe.js quando presente. Ausente para cobranças síncronas/CNPJ. */
|
|
152
|
+
client_secret?: string | null;
|
|
153
|
+
/** PIX-LLC cross-currency: o cliente vê BRL (`presentment_*`) e a LLC escritura
|
|
154
|
+
* em USD (`currency`/`amount`); `exchange_rate` é o câmbio aplicado. */
|
|
155
|
+
presentment_currency?: Currency | null;
|
|
156
|
+
presentment_amount?: string | null;
|
|
157
|
+
exchange_rate?: string | null;
|
|
109
158
|
installments: number;
|
|
110
159
|
status: TransactionStatus;
|
|
111
160
|
pix_qr_code?: string;
|
|
@@ -126,6 +175,27 @@ interface PaginatedList<T> {
|
|
|
126
175
|
previous: string | null;
|
|
127
176
|
results: T[];
|
|
128
177
|
}
|
|
178
|
+
/** Metadados do cartão salvo de um Customer (one-click buy). Nunca inclui o token. */
|
|
179
|
+
interface SavedCard {
|
|
180
|
+
brand: string;
|
|
181
|
+
last4: string;
|
|
182
|
+
exp_month: number | null;
|
|
183
|
+
exp_year: number | null;
|
|
184
|
+
holder_name: string;
|
|
185
|
+
consent_at: string | null;
|
|
186
|
+
}
|
|
187
|
+
/** Resposta de POST /customers/{id}/saved-card/management-link/. */
|
|
188
|
+
interface SavedCardManagementLink {
|
|
189
|
+
url: string;
|
|
190
|
+
token: string;
|
|
191
|
+
expires_at: string;
|
|
192
|
+
}
|
|
193
|
+
/** Resposta de POST /customers/{id}/one-click-link/. */
|
|
194
|
+
interface OneClickLink {
|
|
195
|
+
url: string;
|
|
196
|
+
token: string;
|
|
197
|
+
expires_at: string;
|
|
198
|
+
}
|
|
129
199
|
/** Response do GET /balance/. */
|
|
130
200
|
interface Balance {
|
|
131
201
|
available: number;
|
|
@@ -168,6 +238,15 @@ interface CreateChargeParams {
|
|
|
168
238
|
/** Idempotency-Key (header) — recomendado pra evitar duplo-débito em retry. */
|
|
169
239
|
idempotencyKey?: string;
|
|
170
240
|
}
|
|
241
|
+
interface CreateChargeWithSavedCardParams {
|
|
242
|
+
customer_id: string;
|
|
243
|
+
amount: number | string;
|
|
244
|
+
description?: string;
|
|
245
|
+
installments?: number;
|
|
246
|
+
external_reference?: string;
|
|
247
|
+
/** Idempotency-Key (header) — recomendado pra evitar duplo-débito em retry. */
|
|
248
|
+
idempotencyKey?: string;
|
|
249
|
+
}
|
|
171
250
|
interface RefundParams {
|
|
172
251
|
/** Valor parcial em reais. Omitir = reembolso total. */
|
|
173
252
|
amount?: number | string;
|
|
@@ -188,6 +267,12 @@ declare class Charges {
|
|
|
188
267
|
constructor(client: VitrinClient);
|
|
189
268
|
/** Cria uma cobrança avulsa (PIX/Boleto/Cartão). */
|
|
190
269
|
create(params: CreateChargeParams): Promise<Transaction>;
|
|
270
|
+
/**
|
|
271
|
+
* One-click buy: cobra usando o cartão preferido salvo do cliente.
|
|
272
|
+
* O cliente precisa ter um saved card (vide `customers.savedCard.create`).
|
|
273
|
+
* Retorna 422 `no_saved_card` se não houver cartão; 422 `card_expired` se vencido.
|
|
274
|
+
*/
|
|
275
|
+
createWithSavedCard(params: CreateChargeWithSavedCardParams): Promise<Transaction>;
|
|
191
276
|
retrieve(id: string): Promise<Transaction>;
|
|
192
277
|
list(params?: ListChargesParams): Promise<PaginatedList<Transaction>>;
|
|
193
278
|
refund(id: string, params: RefundParams): Promise<Transaction>;
|
|
@@ -214,8 +299,33 @@ interface CreateCustomerParams {
|
|
|
214
299
|
state?: string;
|
|
215
300
|
}
|
|
216
301
|
type UpdateCustomerParams = Partial<CreateCustomerParams>;
|
|
302
|
+
interface SaveCardParams {
|
|
303
|
+
credit_card: {
|
|
304
|
+
holder_name: string;
|
|
305
|
+
number: string;
|
|
306
|
+
expiry_month: string;
|
|
307
|
+
expiry_year: string;
|
|
308
|
+
cvv: string;
|
|
309
|
+
};
|
|
310
|
+
consent: {
|
|
311
|
+
accepted_at: string;
|
|
312
|
+
ip: string;
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
declare class SavedCardResource {
|
|
316
|
+
private client;
|
|
317
|
+
constructor(client: VitrinClient);
|
|
318
|
+
/** Tokeniza + persiste o cartão preferido do cliente (substitui o anterior). */
|
|
319
|
+
create(customerId: string, params: SaveCardParams): Promise<SavedCard>;
|
|
320
|
+
/** Retorna brand/last4/exp/holder — nunca o token. */
|
|
321
|
+
retrieve(customerId: string): Promise<SavedCard>;
|
|
322
|
+
delete(customerId: string): Promise<void>;
|
|
323
|
+
/** Gera URL assinada (JWT 24h) pro cliente final ver/remover o próprio cartão. */
|
|
324
|
+
createManagementLink(customerId: string): Promise<SavedCardManagementLink>;
|
|
325
|
+
}
|
|
217
326
|
declare class Customers {
|
|
218
327
|
private client;
|
|
328
|
+
readonly savedCard: SavedCardResource;
|
|
219
329
|
constructor(client: VitrinClient);
|
|
220
330
|
create(params: CreateCustomerParams): Promise<Customer>;
|
|
221
331
|
retrieve(id: string): Promise<Customer>;
|
|
@@ -225,6 +335,16 @@ declare class Customers {
|
|
|
225
335
|
}): Promise<PaginatedList<Customer>>;
|
|
226
336
|
update(id: string, params: UpdateCustomerParams): Promise<Customer>;
|
|
227
337
|
delete(id: string): Promise<void>;
|
|
338
|
+
/** Gera link assinado de recompra one-click (JWT 15min, uso único). */
|
|
339
|
+
oneClickLink(customerId: string, params: {
|
|
340
|
+
product_id?: string;
|
|
341
|
+
plan_id?: string;
|
|
342
|
+
amount?: string;
|
|
343
|
+
installments?: number;
|
|
344
|
+
coupon_code?: string;
|
|
345
|
+
bump_ids?: string[];
|
|
346
|
+
expires_in?: number;
|
|
347
|
+
}): Promise<OneClickLink>;
|
|
228
348
|
}
|
|
229
349
|
|
|
230
350
|
interface CreatePlanParams {
|
|
@@ -425,4 +545,4 @@ declare class Vitrin {
|
|
|
425
545
|
request<T = unknown>(path: string, options?: Parameters<VitrinClient['request']>[1]): Promise<T>;
|
|
426
546
|
}
|
|
427
547
|
|
|
428
|
-
export { type Balance, type ConstructEventOptions, type Customer, type PaginatedList, type PaymentMethod, type Plan, type Product, type RequestOptions, type ScheduledReceivable, type ScheduledReceivablesResponse, type Subscription, type Transaction, type TransactionStatus, Vitrin, VitrinAuthError, type VitrinClientOptions, VitrinError, VitrinNetworkError, VitrinNotFoundError, VitrinRateLimitError, VitrinServerError, VitrinValidationError, type WebhookEvent, Webhooks };
|
|
548
|
+
export { type Balance, type ConstructEventOptions, type Currency, type Customer, type EntityType, type Organization, type PaginatedList, type PaymentMethod, type Plan, type Product, type RequestOptions, type ScheduledReceivable, type ScheduledReceivablesResponse, type Subscription, type Transaction, type TransactionStatus, Vitrin, VitrinAuthError, type VitrinClientOptions, VitrinError, VitrinNetworkError, VitrinNotFoundError, VitrinRateLimitError, VitrinServerError, VitrinValidationError, type WebhookEvent, Webhooks };
|
package/dist/index.js
CHANGED
|
@@ -180,6 +180,19 @@ var Charges = class {
|
|
|
180
180
|
idempotencyKey
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* One-click buy: cobra usando o cartão preferido salvo do cliente.
|
|
185
|
+
* O cliente precisa ter um saved card (vide `customers.savedCard.create`).
|
|
186
|
+
* Retorna 422 `no_saved_card` se não houver cartão; 422 `card_expired` se vencido.
|
|
187
|
+
*/
|
|
188
|
+
createWithSavedCard(params) {
|
|
189
|
+
const { idempotencyKey, ...body } = params;
|
|
190
|
+
return this.client.request("/charges/charge-saved/", {
|
|
191
|
+
method: "POST",
|
|
192
|
+
body,
|
|
193
|
+
idempotencyKey
|
|
194
|
+
});
|
|
195
|
+
}
|
|
183
196
|
retrieve(id) {
|
|
184
197
|
return this.client.request(`/transactions/${id}/`);
|
|
185
198
|
}
|
|
@@ -209,11 +222,42 @@ var Charges = class {
|
|
|
209
222
|
};
|
|
210
223
|
|
|
211
224
|
// src/resources/customers.ts
|
|
225
|
+
var SavedCardResource = class {
|
|
226
|
+
constructor(client) {
|
|
227
|
+
this.client = client;
|
|
228
|
+
}
|
|
229
|
+
client;
|
|
230
|
+
/** Tokeniza + persiste o cartão preferido do cliente (substitui o anterior). */
|
|
231
|
+
create(customerId, params) {
|
|
232
|
+
return this.client.request(`/customers/${customerId}/saved-card/`, {
|
|
233
|
+
method: "POST",
|
|
234
|
+
body: params
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/** Retorna brand/last4/exp/holder — nunca o token. */
|
|
238
|
+
retrieve(customerId) {
|
|
239
|
+
return this.client.request(`/customers/${customerId}/saved-card/`);
|
|
240
|
+
}
|
|
241
|
+
delete(customerId) {
|
|
242
|
+
return this.client.request(`/customers/${customerId}/saved-card/`, {
|
|
243
|
+
method: "DELETE"
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/** Gera URL assinada (JWT 24h) pro cliente final ver/remover o próprio cartão. */
|
|
247
|
+
createManagementLink(customerId) {
|
|
248
|
+
return this.client.request(
|
|
249
|
+
`/customers/${customerId}/saved-card/management-link/`,
|
|
250
|
+
{ method: "POST" }
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
212
254
|
var Customers = class {
|
|
213
255
|
constructor(client) {
|
|
214
256
|
this.client = client;
|
|
257
|
+
this.savedCard = new SavedCardResource(client);
|
|
215
258
|
}
|
|
216
259
|
client;
|
|
260
|
+
savedCard;
|
|
217
261
|
create(params) {
|
|
218
262
|
return this.client.request("/customers/", {
|
|
219
263
|
method: "POST",
|
|
@@ -237,6 +281,13 @@ var Customers = class {
|
|
|
237
281
|
delete(id) {
|
|
238
282
|
return this.client.request(`/customers/${id}/`, { method: "DELETE" });
|
|
239
283
|
}
|
|
284
|
+
/** Gera link assinado de recompra one-click (JWT 15min, uso único). */
|
|
285
|
+
oneClickLink(customerId, params) {
|
|
286
|
+
return this.client.request(
|
|
287
|
+
`/customers/${customerId}/one-click-link/`,
|
|
288
|
+
{ method: "POST", body: params }
|
|
289
|
+
);
|
|
290
|
+
}
|
|
240
291
|
};
|
|
241
292
|
|
|
242
293
|
// src/resources/plans.ts
|