@vexpay/node 0.12.0 → 0.14.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 CHANGED
@@ -109,6 +109,9 @@ const session = await vexpay.checkout.sessions.create({
109
109
  // Or a static deposit address per customer — every deposit fires payment.completed with this customerRef.
110
110
  const address = await vexpay.crypto.depositAddresses.create({ customerRef: 'user_123', network: 'BEP20' });
111
111
 
112
+ // Test key only: make a deposit "arrive" at that address (same payment, fee and webhook, livemode: false).
113
+ await vexpay.crypto.simulateDeposit({ customerRef: 'user_123', network: 'BEP20', amount: '40.00' });
114
+
112
115
  const balance = await vexpay.crypto.balance.retrieve();
113
116
  const networks = await vexpay.crypto.networks.list({ amountUsdt: '50.00' });
114
117
 
@@ -177,13 +180,28 @@ await vexpay.conversions.settings.update({ autoConvert: { COP: { percent: 50 } }
177
180
 
178
181
  ## Colombian pesos (COP)
179
182
 
180
- Collect pesos from buyers in Colombia through Bre-B, Nequi or Daviplata. Amounts are whole pesos, payments complete asynchronously (`payment.completed` / `payment.failed`), and completed payments go to your COP balance net of the COP fee. COP must be enabled on your account — otherwise the calls fail with `method_not_allowed` (403).
183
+ Collect pesos from buyers in Colombia through PSE, Bancolombia (transfer or QR), Bre-B, Nequi or Daviplata — and cards on the hosted checkout. Amounts are whole pesos, payments complete asynchronously (`payment.completed` / `payment.failed`), and completed payments go to your COP balance net of the COP fee. COP must be enabled on your account — otherwise the calls fail with `method_not_allowed` (403).
181
184
 
182
185
  ```ts
183
186
  import VexPay from '@vexpay/node';
184
187
 
185
188
  const vexpay = new VexPay(process.env.VEXPAY_API_KEY!);
186
189
 
190
+ // What your account can use now, the PSE banks, and the terms links some channels need.
191
+ const { channels, pseBanks, terms } = await vexpay.cop.channels();
192
+
193
+ // PSE: send the buyer to their bank (next.url). On redirect_pending, retrieve again in a few seconds.
194
+ const pse = await vexpay.cop.payments.create({
195
+ amountCop: 80000,
196
+ channel: 'pse',
197
+ pse: { bankCode: pseBanks![0]!.code },
198
+ buyer: {
199
+ firstName: 'Juan', lastName: 'Pérez', personType: 'natural', email: 'juan@example.com', phone: '3001234567',
200
+ documentType: 'CC', documentNumber: '1234567890', termsAccepted: true, // the buyer accepted `terms`
201
+ },
202
+ });
203
+ if (pse.next?.type === 'redirect') console.log('Send the buyer to', pse.next.url);
204
+
187
205
  // Bre-B: no buyer data. Show next.qrPngBase64 as an image and next.transferKey as text.
188
206
  const breb = await vexpay.cop.payments.create(
189
207
  { amountCop: 100000, channel: 'breb', reference: 'order-1042' },
@@ -194,10 +212,10 @@ const breb = await vexpay.cop.payments.create(
194
212
  await vexpay.cop.payments.create({
195
213
  amountCop: 50000,
196
214
  channel: 'nequi',
197
- buyer: { email: 'juan@example.com', phone: '3001234567', documentType: 'CC', documentNumber: '1234567890' },
215
+ buyer: { email: 'juan@example.com', phone: '3001234567', documentType: 'CC', documentNumber: '1234567890', termsAccepted: true },
198
216
  });
199
217
 
200
- // Daviplata: the buyer reads you the SMS code; submit it.
218
+ // Daviplata: with next.type 'submit_otp' the buyer reads you the SMS code; submit it (otherwise follow next.url).
201
219
  const davi = await vexpay.cop.payments.create({
202
220
  amountCop: 50000,
203
221
  channel: 'daviplata',
@@ -209,15 +227,17 @@ const status = (await vexpay.cop.payments.retrieve(breb.id)).status; // pending
209
227
  const { availableCop } = await vexpay.cop.balance.retrieve();
210
228
  ```
211
229
 
212
- `cancel(id)` cancels a pending payment and `refund(id)` refunds a completed one in full within 96 hours. A webhook for a COP payment has `data.method === 'COP'`; read it as `CopPaymentWebhookData`.
230
+ `cancel(id)` cancels a pending payment and `refund(id)` refunds a completed one in full (cards within 24 hours, Bre-B within 96 hours; channels without API refunds fail with `refund_not_supported`). Send `buyer.termsAccepted: true` for channels whose catalog entry has `needsTermsAcceptance`. A webhook for a COP payment has `data.method === 'COP'`; read it as `CopPaymentWebhookData`.
213
231
 
214
232
  **Test mode** (test API keys use a sandbox):
215
233
 
216
234
  | Channel | What to use | Result |
217
235
  |---|---|---|
218
236
  | Bre-B | No buyer data | QR and key from the sandbox. **Never send real money to them** — sandbox keys are reachable from real banks and the money is not credited. |
219
- | Nequi | Any valid data, e.g. phone `3001234567`, `CC` `1234567890`, any email | Completes on its own within about a minute |
220
- | Daviplata | Same buyer data (`CC`, `CE` or `TI` only) | OTP `123456`, `000000` or `111111` completes it; any other code fails with `invalid_otp` |
237
+ | Nequi | Phone `3991111111`, any valid document and email | Completes on its own within about a minute; `3992222222` is declined |
238
+ | Daviplata | Same buyer data (`CC`, `CE` or `TI` only) | With `submit_otp`, OTP `123456`, `000000` or `111111` completes it; any other code fails with `invalid_otp`. With `redirect`, follow the test page |
239
+ | PSE | Any valid buyer data | Bank code `1` approves, `2` declines |
240
+ | Card (hosted checkout) | `4242 4242 4242 4242`, any future expiry and CVC | Approved; `4111 1111 1111 1111` is declined |
221
241
 
222
242
  ## Subscriptions
223
243
 
@@ -315,6 +335,32 @@ const page = await vexpay.balance.transactions.list({ paymentId: 'pay_…', type
315
335
  console.log(page.items.map((m) => [m.type, m.amountVes]));
316
336
  ```
317
337
 
338
+ ## Top up your balance
339
+
340
+ Load your own Bs balance by Pago Móvil — for money that is not a sale (for example advertising income). Send the exact `amountVes` from `payerPhone` to the returned `receiver` before `expiresAt` (15 minutes); the top-up completes on its own when the transfer arrives, and its fee is charged then. The credit is held like any other credit unless you release it early with `instant` (for `instantFeeVes`). Each top-up needs a `sourceNote` and counts against your monthly limit (`topup_cap_exceeded`, 422, with `remainingUsd`/`remainingVes` in the error body). Top-ups are enabled per account (`topups_not_enabled`, 403). In balance movements they appear as `topup`, `topup_fee`, `topup_instant_release` and `topup_instant_fee`.
341
+
342
+ ```ts
343
+ import VexPay from '@vexpay/node';
344
+
345
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!);
346
+
347
+ const topup = await vexpay.balance.topups.create({
348
+ amountVes: '100000.00',
349
+ payerPhone: '04121234567',
350
+ payerCedula: 'V12345678',
351
+ sourceNote: 'Ingresos publicidad quincena 2',
352
+ });
353
+ console.log(topup.receiver, topup.expiresAt); // where and until when to send the Pago Móvil
354
+
355
+ const { data, monthRemainingUsd } = await vexpay.balance.topups.list({ limit: 20 });
356
+ console.log(data.length, monthRemainingUsd); // newest first, plus what is left of this month's limit (USD)
357
+ const latest = await vexpay.balance.topups.retrieve(topup.id);
358
+ if (latest.status === 'completed' && latest.heldVes !== '0.00') {
359
+ await vexpay.balance.topups.instant(topup.id); // idempotent; `not_held` (409) when nothing is held
360
+ }
361
+ // Test mode only: await vexpay.balance.topups.simulate(topup.id);
362
+ ```
363
+
318
364
  ## Errors
319
365
 
320
366
  Every error extends `VexPayError` and carries `status`, the API `code` (e.g. `insufficient_balance`), and the response `body`.
@@ -377,6 +423,32 @@ await vexpay.payments.c2p.execute(
377
423
  );
378
424
  ```
379
425
 
426
+ ## Seller balances
427
+
428
+ Credit a seller from your platform balance in bolívares, or in dollars converted at the official BCV rate, then read their movements and monthly statement:
429
+
430
+ ```ts
431
+ import VexPay from '@vexpay/node';
432
+
433
+ const vexpay = new VexPay(process.env.VEXPAY_API_KEY!);
434
+ const merchantId = '00000000-0000-4000-8000-000000000002';
435
+
436
+ const balance = await vexpay.merchants.transfer(merchantId, { amountUsd: '100.00', transferKey: 'payroll-2026-11-u1' });
437
+ console.log(balance.pendingVes, balance.transfer.amountVes, balance.transfer.rate);
438
+
439
+ for await (const movement of vexpay.merchants.listTransactions(merchantId, { from: '2026-11-01T00:00:00Z' })) {
440
+ console.log(movement.type, movement.amountVes);
441
+ }
442
+
443
+ const statement = await vexpay.merchants.retrieveStatement(merchantId, { month: '2026-11' });
444
+ console.log(statement.openingVes, statement.closingVes, statement.movements.length);
445
+
446
+ const csv = await vexpay.merchants.retrieveStatementCsv(merchantId, { month: '2026-11' });
447
+ console.log(csv.split('\n')[0]);
448
+ ```
449
+
450
+ A transfer with `amountUsd` fails with `rate_unavailable` (503) when no BCV rate can be read; nothing is recorded.
451
+
380
452
  ## Pagination
381
453
 
382
454
  `list()` methods on payouts, merchants, products, customers, prices, subscriptions and invoices return the first page when awaited, and every item when iterated:
@@ -434,12 +506,14 @@ console.log(describe, {} as NewPayout, {} as Session);
434
506
  | `quotes` | `retrieve` |
435
507
  | `balance` | `retrieve` |
436
508
  | `balance.transactions` | `list` |
509
+ | `balance.topups` | `create`, `list`, `retrieve`, `instant`, `simulate` |
437
510
  | `payments` | `retrieve`, `retrieveByRef`, `reverse` |
438
511
  | `payments.c2p` | `request`, `execute` |
439
512
  | `payments.vpos` | `create` |
440
513
  | `payments.pagoMovil` | `verify` |
441
514
  | `payments.debit` · `credit` · `operations` · `dispersals` · `change` | débito/crédito inmediato and disbursements (advanced payments) |
442
515
  | `checkout.sessions` | `create`, `retrieve` |
516
+ | `crypto` | `simulateDeposit` (Test mode only) |
443
517
  | `crypto.balance` | `retrieve` |
444
518
  | `crypto.balances` | `list` |
445
519
  | `crypto.depositAddresses` | `create` |
@@ -449,8 +523,9 @@ console.log(describe, {} as NewPayout, {} as Session);
449
523
  | `conversions.quotes` | `create` |
450
524
  | `conversions.settings` | `retrieve`, `update` |
451
525
  | `cop.payments` | `create`, `retrieve`, `submitOtp`, `cancel`, `refund` |
526
+ | `cop` | `channels` |
452
527
  | `cop.balance` | `retrieve` |
453
- | `merchants` | `create`, `list`, `retrieve`, `retrieveByRef`, `update`, `delete`, `retrieveBalance`, `transfer`, `listAuditEvents`, `startVerification`, `confirmVerification` |
528
+ | `merchants` | `create`, `list`, `retrieve`, `retrieveByRef`, `update`, `delete`, `retrieveBalance`, `transfer`, `listTransactions`, `retrieveStatement`, `retrieveStatementCsv`, `listAuditEvents`, `startVerification`, `confirmVerification` |
454
529
  | `merchants.payoutMethods` | `list`, `create`, `setDefault`, `delete`, `startVerification`, `confirmVerification` |
455
530
  | `payouts` | `create`, `createInstant`, `createBatch`, `list`, `retrieve`, `retrieveByRef` |
456
531
  | `products` | `create`, `list`, `retrieve`, `update`, `delete`, `createLink`, `listLinks` |
package/dist/index.cjs CHANGED
@@ -107,7 +107,7 @@ function errorFromResponse(status, body, requestId) {
107
107
  }
108
108
 
109
109
  // src/version.ts
110
- var VERSION = "0.12.0";
110
+ var VERSION = "0.14.0";
111
111
 
112
112
  // src/core.ts
113
113
  var INITIAL_RETRY_DELAY_MS = 500;
@@ -270,6 +270,7 @@ var ROUTES = {
270
270
  ConversionSettings_update: { method: "PATCH", path: "/v1/conversions/settings" },
271
271
  CopPayments_balance: { method: "GET", path: "/v1/cop/balance" },
272
272
  CopPayments_cancel: { method: "POST", path: "/v1/cop/payments/{id}/cancel" },
273
+ CopPayments_channels: { method: "GET", path: "/v1/cop/channels" },
273
274
  CopPayments_create: { method: "POST", path: "/v1/cop/payments" },
274
275
  CopPayments_get: { method: "GET", path: "/v1/cop/payments/{id}" },
275
276
  CopPayments_refund: { method: "POST", path: "/v1/cop/payments/{id}/refund" },
@@ -280,6 +281,7 @@ var ROUTES = {
280
281
  Crypto_getBalances: { method: "GET", path: "/v1/crypto/balances" },
281
282
  Crypto_getPayout: { method: "GET", path: "/v1/crypto/payouts/{id}" },
282
283
  Crypto_listNetworks: { method: "GET", path: "/v1/crypto/networks" },
284
+ Crypto_simulateDeposit: { method: "POST", path: "/v1/crypto/deposit-addresses/simulate" },
283
285
  Customers_create: { method: "POST", path: "/v1/customers" },
284
286
  Customers_list: { method: "GET", path: "/v1/customers" },
285
287
  Customers_remove: { method: "DELETE", path: "/v1/customers/{id}" },
@@ -300,10 +302,12 @@ var ROUTES = {
300
302
  Merchants_listAuditEvents: { method: "GET", path: "/v1/merchants/{id}/audit-events" },
301
303
  Merchants_listOrGetByRef: { method: "GET", path: "/v1/merchants" },
302
304
  Merchants_listPayoutMethods: { method: "GET", path: "/v1/merchants/{id}/payout-methods" },
305
+ Merchants_listTransactions: { method: "GET", path: "/v1/merchants/{id}/transactions" },
303
306
  Merchants_remove: { method: "DELETE", path: "/v1/merchants/{id}" },
304
307
  Merchants_setDefaultPayoutMethod: { method: "POST", path: "/v1/merchants/{id}/payout-methods/{methodId}/default" },
305
308
  Merchants_startVerify: { method: "POST", path: "/v1/merchants/{id}/verify/start" },
306
309
  Merchants_startVerifyMethod: { method: "POST", path: "/v1/merchants/{id}/payout-methods/{methodId}/verify/start" },
310
+ Merchants_statement: { method: "GET", path: "/v1/merchants/{id}/statement" },
307
311
  Merchants_transfer: { method: "POST", path: "/v1/merchants/{id}/transfers" },
308
312
  Merchants_update: { method: "PATCH", path: "/v1/merchants/{id}" },
309
313
  Notifications_sendTest: { method: "POST", path: "/v1/notifications/test" },
@@ -362,6 +366,11 @@ var ROUTES = {
362
366
  TenantPayoutAccount_startVerify: { method: "POST", path: "/v1/tenant/payout-account/verify/start" },
363
367
  TenantPayoutAccount_upsert: { method: "PUT", path: "/v1/tenant/payout-account" },
364
368
  TenantPayoutAccount_upsertPost: { method: "POST", path: "/v1/tenant/payout-account" },
369
+ Topups_create: { method: "POST", path: "/v1/balance/topups" },
370
+ Topups_get: { method: "GET", path: "/v1/balance/topups/{id}" },
371
+ Topups_instant: { method: "POST", path: "/v1/balance/topups/{id}/instant" },
372
+ Topups_list: { method: "GET", path: "/v1/balance/topups" },
373
+ Topups_simulate: { method: "POST", path: "/v1/balance/topups/{id}/simulate" },
365
374
  Webhooks_createWebhook: { method: "POST", path: "/v1/webhooks" },
366
375
  Webhooks_deleteWebhook: { method: "DELETE", path: "/v1/webhooks/{id}" },
367
376
  Webhooks_listWebhooks: { method: "GET", path: "/v1/webhooks" },
@@ -412,8 +421,30 @@ var BalanceTransactions = class extends APIResource {
412
421
  );
413
422
  }
414
423
  };
424
+ var BalanceTopups = class extends APIResource {
425
+ /** Start a top-up. Over the monthly limit fails with `topup_cap_exceeded` (422). */
426
+ create(params, options) {
427
+ return this.call("Topups_create", { body: params }, options);
428
+ }
429
+ /** Your latest top-ups (newest first, `limit` 1–100) plus this month's limit usage. */
430
+ list(params = {}, options) {
431
+ return this.call("Topups_list", { query: params }, options);
432
+ }
433
+ retrieve(id, options) {
434
+ return this.call("Topups_get", { path: { id } }, options);
435
+ }
436
+ /** Release the still-held part of a completed top-up now, for `instantFeeVes`. Idempotent; `not_held` (409) if nothing is held. */
437
+ instant(id, options) {
438
+ return this.call("Topups_instant", { path: { id } }, options);
439
+ }
440
+ /** Test mode only: complete the top-up as if the Pago Móvil arrived. */
441
+ simulate(id, options) {
442
+ return this.call("Topups_simulate", { path: { id } }, options);
443
+ }
444
+ };
415
445
  var Balance = class extends APIResource {
416
446
  transactions = new BalanceTransactions(this.http);
447
+ topups = new BalanceTopups(this.http);
417
448
  retrieve(options) {
418
449
  return this.call("Balance_getBalance", {}, options);
419
450
  }
@@ -701,8 +732,10 @@ var Conversions = class extends APIResource {
701
732
  // src/resources/cop.ts
702
733
  var CopPayments = class extends APIResource {
703
734
  /**
704
- * Create a payment in whole pesos. `buyer` is required for `nequi` and `daviplata`. The response
705
- * `next` says what the buyer does: `show_qr`, `approve_in_app` or `submit_otp`.
735
+ * Create a payment in whole pesos. `buyer` is required for every channel except `breb`, with
736
+ * `termsAccepted: true` when {@link Cop.channels} says `needsTermsAcceptance`; `pse` also needs
737
+ * `pse.bankCode`. The response `next` says what the buyer does: `show_qr`, `approve_in_app`,
738
+ * `submit_otp`, `redirect` (send them to `next.url`) or `redirect_pending` (retrieve again shortly).
706
739
  * Pass `idempotencyKey` in options to retry safely.
707
740
  */
708
741
  create(params, options) {
@@ -711,7 +744,7 @@ var CopPayments = class extends APIResource {
711
744
  retrieve(id, options) {
712
745
  return this.call("CopPayments_get", { path: { id } }, options);
713
746
  }
714
- /** Daviplata: submit the code the buyer received by SMS. A wrong code fails with `invalid_otp`. */
747
+ /** Daviplata with `next.type: "submit_otp"`: submit the code the buyer received by SMS. A wrong code fails with `invalid_otp`. */
715
748
  submitOtp(id, params, options) {
716
749
  return this.call("CopPayments_submitOtp", { path: { id }, body: params }, options);
717
750
  }
@@ -719,7 +752,10 @@ var CopPayments = class extends APIResource {
719
752
  cancel(id, options) {
720
753
  return this.call("CopPayments_cancel", { path: { id } }, options);
721
754
  }
722
- /** Full refund of a completed payment, within 96 hours. */
755
+ /**
756
+ * Full refund of a completed payment, within the channel's window (card 24 h, Bre-B 96 h).
757
+ * Channels that cannot be refunded through the API fail with `refund_not_supported`.
758
+ */
723
759
  refund(id, options) {
724
760
  return this.call("CopPayments_refund", { path: { id } }, options);
725
761
  }
@@ -732,6 +768,10 @@ var CopBalance = class extends APIResource {
732
768
  var Cop = class extends APIResource {
733
769
  payments = new CopPayments(this.http);
734
770
  balance = new CopBalance(this.http);
771
+ /** Channels you can use right now, with what each needs, plus the PSE banks and terms links. */
772
+ channels(options) {
773
+ return this.call("CopPayments_channels", {}, options);
774
+ }
735
775
  };
736
776
 
737
777
  // src/resources/crypto.ts
@@ -770,6 +810,14 @@ var Crypto = class extends APIResource {
770
810
  depositAddresses = new DepositAddresses(this.http);
771
811
  networks = new CryptoNetworks(this.http);
772
812
  payouts = new CryptoPayouts(this.http);
813
+ /**
814
+ * Test mode only: credit a deposit to one of your deposit addresses (`customerRef` + `currency` +
815
+ * `network`, requested before) as if it had arrived on chain. Sends `payment.completed` with
816
+ * `livemode: false`. A Live key gets 403 `test_mode_only`; an unknown address 404.
817
+ */
818
+ simulateDeposit(params, options) {
819
+ return this.call("Crypto_simulateDeposit", { body: params }, options);
820
+ }
773
821
  };
774
822
 
775
823
  // src/resources/merchants.ts
@@ -828,10 +876,34 @@ var Merchants = class extends APIResource {
828
876
  retrieveBalance(id, options) {
829
877
  return this.call("Merchants_getBalance", { path: { id } }, options);
830
878
  }
831
- /** Move VES between this merchant's balance and another. */
879
+ /**
880
+ * Credit this seller's pending balance from your platform balance. Send `amountVes`, or
881
+ * `amountUsd` to convert at the official BCV rate; `transferKey` makes it idempotent.
882
+ * The response is the seller balance plus `transfer` (amounts and rate used).
883
+ */
832
884
  transfer(id, params, options) {
833
885
  return this.call("Merchants_transfer", { path: { id }, body: params }, options);
834
886
  }
887
+ /** Seller balance movements, newest first. Await for one page, or `for await` over every movement. */
888
+ listTransactions(id, params = {}, options) {
889
+ return new PagePromise(
890
+ (cursor) => this.call("Merchants_listTransactions", { path: { id }, query: { ...params, cursor } }, options),
891
+ params.cursor
892
+ );
893
+ }
894
+ /** Monthly statement (`month: 'YYYY-MM'`, America/Caracas): opening, movements, closing. */
895
+ retrieveStatement(id, params, options) {
896
+ return this.call("Merchants_statement", { path: { id }, query: { ...params, format: "json" } }, options);
897
+ }
898
+ /** The same monthly statement as CSV (with a running balance column), returned as a string. */
899
+ async retrieveStatementCsv(id, params, options) {
900
+ const body = await this.call(
901
+ "Merchants_statement",
902
+ { path: { id }, query: { ...params, format: "csv" } },
903
+ options
904
+ );
905
+ return typeof body === "string" ? body : "";
906
+ }
835
907
  listAuditEvents(id, options) {
836
908
  return this.call("Merchants_listAuditEvents", { path: { id } }, options);
837
909
  }