@vexpay/node 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VEXPay
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,261 @@
1
+ # VEXPay Node.js SDK
2
+
3
+ The official Node.js / TypeScript library for the [VEXPay](https://vexwallet.co/vexpay) API: accept Venezuelan payments (Pago Móvil C2P, cards, débito inmediato), pay out to merchants, create checkout sessions, and verify signed webhooks.
4
+
5
+ - Fully typed from the VEXPay OpenAPI contract
6
+ - Safe retries: every `POST` carries an `Idempotency-Key`, so a retried charge never charges twice
7
+ - Auto-pagination with `for await`
8
+ - Webhook signature verification with replay protection
9
+ - Zero runtime dependencies, Node.js 20+, ESM and CommonJS
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install @vexpay/node
15
+ ```
16
+
17
+ ## Quickstart
18
+
19
+ ```ts
20
+ import VexPay from '@vexpay/node';
21
+
22
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!);
23
+
24
+ const quote = await vexpay.quotes.retrieve({ usdAmount: 25 });
25
+ console.log(`$25 = Bs ${quote.vesAmount} at BCV ${quote.bcvRate}`);
26
+ ```
27
+
28
+ Keep your API key on the server. Use your test-mode key while you build; it runs against the sandbox provider.
29
+
30
+ ## Collect a Pago Móvil C2P payment
31
+
32
+ C2P is two steps: create an intent (the payer's bank sends them a token by SMS), then charge with the token your customer types in.
33
+
34
+ ```ts
35
+ import VexPay from '@vexpay/node';
36
+
37
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!);
38
+
39
+ const intent = await vexpay.payments.c2p.request({
40
+ usdAmount: 25,
41
+ debtorId: 'V12345678',
42
+ debtorCellPhone: '584141234567',
43
+ debtorBankCode: 102,
44
+ externalRef: 'order-1042',
45
+ });
46
+
47
+ // …the customer reads the token from their bank SMS…
48
+ const token = '123456';
49
+
50
+ const payment = await vexpay.payments.c2p.execute({
51
+ intentId: intent.intentId,
52
+ usdAmount: 25,
53
+ debtorId: 'V12345678',
54
+ debtorCellPhone: '584141234567',
55
+ debtorBankCode: 102,
56
+ token,
57
+ });
58
+
59
+ console.log(payment.status); // "COMPLETED" or "PENDING" — confirm with the payment.* webhook
60
+ ```
61
+
62
+ ## Checkout sessions (hosted or embedded)
63
+
64
+ Let VEXPay collect the payment details. Redirect the buyer to `url`, or embed the checkout on your own site with [`@vexpay/js`](https://www.npmjs.com/package/@vexpay/js) and the one-time `clientSecret`.
65
+
66
+ ```ts
67
+ import VexPay from '@vexpay/node';
68
+
69
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!);
70
+
71
+ const session = await vexpay.checkout.sessions.create({
72
+ amountUsd: 25,
73
+ reference: 'order-1042',
74
+ description: 'Pedido #1042',
75
+ allowedOrigins: ['https://shop.example'],
76
+ successUrl: 'https://shop.example/gracias',
77
+ metadata: { orderId: '1042' },
78
+ });
79
+
80
+ // Send session.clientSecret to the browser (never log or store it), or redirect:
81
+ console.log(session.url);
82
+
83
+ // Later — fulfil only after checking on the server:
84
+ const current = await vexpay.checkout.sessions.retrieve(session.id);
85
+ if (current.status === 'paid') {
86
+ // ship order 1042
87
+ }
88
+ ```
89
+
90
+ ## Webhooks
91
+
92
+ VEXPay signs every delivery with a `VexPay-Signature` header. Verify it with the **raw** request body — parsing and re-serializing JSON changes the bytes and breaks the signature.
93
+
94
+ ```ts
95
+ import VexPay from '@vexpay/node';
96
+
97
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!);
98
+
99
+ // Any Fetch-style handler (Next.js route handlers, Remix, Hono, Workers, …)
100
+ export async function POST(request: Request): Promise<Response> {
101
+ const rawBody = await request.text();
102
+ try {
103
+ const event = vexpay.webhooks.constructEvent(
104
+ rawBody,
105
+ request.headers.get('vexpay-signature'),
106
+ process.env.VEXPAY_WEBHOOK_SECRET!,
107
+ );
108
+
109
+ if (event.event === 'payment.completed') {
110
+ const { paymentId, externalRef, checkoutSession } = event.data;
111
+ console.log('paid', paymentId, externalRef ?? checkoutSession?.reference);
112
+ }
113
+ return new Response(null, { status: 204 });
114
+ } catch {
115
+ return new Response('invalid signature', { status: 400 });
116
+ }
117
+ }
118
+ ```
119
+
120
+ With Express, mount `express.raw({ type: 'application/json' })` on the webhook route and pass `req.body` (a Buffer) and `req.headers['vexpay-signature']`.
121
+
122
+ Deliveries older than 5 minutes are rejected as possible replays; pass `{ toleranceSeconds }` to change that. Each delivery also carries a `VexPay-Event-Id` header you can use to deduplicate. In your own tests, sign fixtures with `vexpay.webhooks.generateTestHeader({ payload, secret })`.
123
+
124
+ ## Errors
125
+
126
+ Every error extends `VexPayError` and carries `status`, the API `code` (e.g. `insufficient_balance`), and the response `body`.
127
+
128
+ ```ts
129
+ import VexPay, { VexPayConflictError, VexPayError, VexPayInvalidRequestError } from '@vexpay/node';
130
+
131
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!);
132
+
133
+ try {
134
+ await vexpay.payouts.create({
135
+ merchantId: '4f0c6f1e-2b7d-4c1a-9e3f-5a6b7c8d9e0f',
136
+ monto: '1523.40',
137
+ concepto: 'Liquidación semana 30',
138
+ externalRef: 'po_2026_30_maria',
139
+ });
140
+ } catch (error) {
141
+ if (error instanceof VexPayInvalidRequestError && error.code === 'insufficient_balance') {
142
+ // top up, then retry
143
+ } else if (error instanceof VexPayConflictError) {
144
+ console.error('externalRef reused with a different payload', error.body);
145
+ } else if (error instanceof VexPayError) {
146
+ console.error(error.status, error.code, error.message);
147
+ } else {
148
+ throw error;
149
+ }
150
+ }
151
+ ```
152
+
153
+ | Class | When |
154
+ |---|---|
155
+ | `VexPayAuthenticationError` | 401 — missing or invalid API key |
156
+ | `VexPayInvalidRequestError` | 400, 403, 410, 422 — fix the request |
157
+ | `VexPayNotFoundError` | 404 |
158
+ | `VexPayConflictError` | 409 — e.g. `external_ref_conflict`, `idempotency_key_reused` |
159
+ | `VexPayRateLimitError` | 429, after retries |
160
+ | `VexPayAPIError` | 5xx, after retries |
161
+ | `VexPayConnectionError` / `VexPayTimeoutError` | no HTTP answer, after retries |
162
+ | `VexPaySignatureVerificationError` | a webhook did not verify |
163
+
164
+ ## Retries and idempotency
165
+
166
+ The SDK retries connection errors, timeouts, `429`, `5xx`, and `409 idempotency_request_in_progress` up to `maxNetworkRetries` times (default 2) with exponential backoff, honouring `Retry-After`. Every `POST` gets a random `Idempotency-Key` that stays the same across its retries, so VEXPay executes it at most once. Supply your own key to make retries safe across process restarts too:
167
+
168
+ ```ts
169
+ import VexPay from '@vexpay/node';
170
+
171
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!, { maxNetworkRetries: 3, timeoutMs: 20_000 });
172
+
173
+ await vexpay.payments.c2p.execute(
174
+ {
175
+ intentId: '00000000-0000-4000-8000-000000000001',
176
+ usdAmount: 25,
177
+ debtorId: 'V12345678',
178
+ debtorCellPhone: '584141234567',
179
+ debtorBankCode: 102,
180
+ token: '123456',
181
+ },
182
+ { idempotencyKey: 'order-1042-charge' },
183
+ );
184
+ ```
185
+
186
+ ## Pagination
187
+
188
+ `list()` methods on payouts, merchants, and products return the first page when awaited, and every item when iterated:
189
+
190
+ ```ts
191
+ import VexPay from '@vexpay/node';
192
+
193
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!);
194
+
195
+ const firstPage = await vexpay.merchants.list({ limit: 100 });
196
+ console.log(firstPage.items.length, firstPage.nextCursor);
197
+
198
+ for await (const merchant of vexpay.merchants.list({ status: 'verified', isActive: 'true' })) {
199
+ console.log(merchant.merchantId, merchant.name);
200
+ }
201
+
202
+ const recentPayouts = await vexpay.payouts.list({ limit: 50 }).autoPagingToArray({ limit: 200 });
203
+ console.log(recentPayouts.length);
204
+ ```
205
+
206
+ ## Configuration
207
+
208
+ ```ts
209
+ import VexPay from '@vexpay/node';
210
+
211
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!, {
212
+ baseUrl: 'http://localhost:3010', // default: https://api.pay.vexwallet.co
213
+ timeoutMs: 30_000,
214
+ maxNetworkRetries: 2,
215
+ });
216
+
217
+ console.log(await vexpay.banks.list());
218
+ ```
219
+
220
+ ## TypeScript
221
+
222
+ Every request and response type is generated from the API contract:
223
+
224
+ ```ts
225
+ import type { RequestBody, ResponseBody, Schemas } from '@vexpay/node';
226
+
227
+ type Receipt = Schemas['PaymentReceiptDto'];
228
+ type NewPayout = RequestBody<'Payouts_create'>;
229
+ type Session = ResponseBody<'CheckoutSessions_retrieve'>;
230
+
231
+ const describe = (receipt: Receipt) => `${receipt.paymentId}: ${receipt.status}`;
232
+ console.log(describe, {} as NewPayout, {} as Session);
233
+ ```
234
+
235
+ ## Resources
236
+
237
+ | Namespace | Methods |
238
+ |---|---|
239
+ | `banks` | `list` |
240
+ | `quotes` | `retrieve` |
241
+ | `balance` | `retrieve` |
242
+ | `payments` | `retrieve`, `retrieveByRef`, `reverse` |
243
+ | `payments.c2p` | `request`, `execute` |
244
+ | `payments.vpos` | `create` |
245
+ | `payments.pagoMovil` | `verify` |
246
+ | `payments.debit` · `credit` · `operations` · `dispersals` · `change` | débito/crédito inmediato and disbursements (R4) |
247
+ | `checkout.sessions` | `create`, `retrieve` |
248
+ | `merchants` | `create`, `list`, `retrieve`, `retrieveByRef`, `update`, `delete`, `retrieveBalance`, `transfer`, `listAuditEvents`, `startVerification`, `confirmVerification` |
249
+ | `merchants.payoutMethods` | `list`, `create`, `setDefault`, `delete`, `startVerification`, `confirmVerification` |
250
+ | `payouts` | `create`, `createInstant`, `createBatch`, `list`, `retrieve`, `retrieveByRef` |
251
+ | `products` | `create`, `list`, `retrieve`, `update`, `delete`, `createLink`, `listLinks` |
252
+ | `paymentLinks` | `retrieve`, `update`, `delete` |
253
+ | `tenantPayoutAccount` | `retrieve`, `upsert`, `create`, `startVerification`, `confirmVerification` |
254
+ | `webhookEndpoints` | `create`, `list`, `update`, `delete`, `sendTest` |
255
+ | `webhooks` | `constructEvent`, `generateTestHeader` (offline) |
256
+
257
+ Full API reference: [docs](https://pay.vexwallet.co/docs) · OpenAPI: `/openapi.json`.
258
+
259
+ ## License
260
+
261
+ MIT