payweave 0.0.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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +272 -0
  3. package/dist/_tsup-dts-rollup.d.ts +19470 -0
  4. package/dist/chunk-4R5OGOCC.js +94 -0
  5. package/dist/chunk-4R5OGOCC.js.map +1 -0
  6. package/dist/chunk-535Q3GUN.js +175 -0
  7. package/dist/chunk-535Q3GUN.js.map +1 -0
  8. package/dist/chunk-67NRYGRC.js +192 -0
  9. package/dist/chunk-67NRYGRC.js.map +1 -0
  10. package/dist/chunk-CGQ73I4I.js +568 -0
  11. package/dist/chunk-CGQ73I4I.js.map +1 -0
  12. package/dist/chunk-CJEYDHY6.js +18 -0
  13. package/dist/chunk-CJEYDHY6.js.map +1 -0
  14. package/dist/chunk-CR63JAAS.js +3 -0
  15. package/dist/chunk-CR63JAAS.js.map +1 -0
  16. package/dist/chunk-E633MKVX.js +1507 -0
  17. package/dist/chunk-E633MKVX.js.map +1 -0
  18. package/dist/chunk-FBPOCXRZ.js +1135 -0
  19. package/dist/chunk-FBPOCXRZ.js.map +1 -0
  20. package/dist/chunk-HTRGMZFH.js +267 -0
  21. package/dist/chunk-HTRGMZFH.js.map +1 -0
  22. package/dist/chunk-IUVGM3K7.js +765 -0
  23. package/dist/chunk-IUVGM3K7.js.map +1 -0
  24. package/dist/chunk-JD4OZHRI.js +326 -0
  25. package/dist/chunk-JD4OZHRI.js.map +1 -0
  26. package/dist/chunk-NV3MZF7L.js +139 -0
  27. package/dist/chunk-NV3MZF7L.js.map +1 -0
  28. package/dist/chunk-NXQBP35U.js +13 -0
  29. package/dist/chunk-NXQBP35U.js.map +1 -0
  30. package/dist/chunk-QJHXDZYC.js +412 -0
  31. package/dist/chunk-QJHXDZYC.js.map +1 -0
  32. package/dist/chunk-TWZK62TZ.js +83 -0
  33. package/dist/chunk-TWZK62TZ.js.map +1 -0
  34. package/dist/cli/index.js +35381 -0
  35. package/dist/core/index.d.ts +85 -0
  36. package/dist/core/index.js +6 -0
  37. package/dist/core/index.js.map +1 -0
  38. package/dist/db/drizzle/index.d.ts +6 -0
  39. package/dist/db/drizzle/index.js +1532 -0
  40. package/dist/db/drizzle/index.js.map +1 -0
  41. package/dist/db/index.d.ts +43 -0
  42. package/dist/db/index.js +3 -0
  43. package/dist/db/index.js.map +1 -0
  44. package/dist/db/mongodb/index.d.ts +3 -0
  45. package/dist/db/mongodb/index.js +934 -0
  46. package/dist/db/mongodb/index.js.map +1 -0
  47. package/dist/db/mysql/index.d.ts +1 -0
  48. package/dist/db/mysql/index.js +12 -0
  49. package/dist/db/mysql/index.js.map +1 -0
  50. package/dist/db/postgres/index.d.ts +5 -0
  51. package/dist/db/postgres/index.js +791 -0
  52. package/dist/db/postgres/index.js.map +1 -0
  53. package/dist/db/prisma/index.d.ts +1 -0
  54. package/dist/db/prisma/index.js +12 -0
  55. package/dist/db/prisma/index.js.map +1 -0
  56. package/dist/db/sqlite/index.d.ts +5 -0
  57. package/dist/db/sqlite/index.js +750 -0
  58. package/dist/db/sqlite/index.js.map +1 -0
  59. package/dist/express/index.d.ts +1 -0
  60. package/dist/express/index.js +3 -0
  61. package/dist/express/index.js.map +1 -0
  62. package/dist/fastify/index.d.ts +1 -0
  63. package/dist/fastify/index.js +3 -0
  64. package/dist/fastify/index.js.map +1 -0
  65. package/dist/flutterwave/index.d.ts +27 -0
  66. package/dist/flutterwave/index.js +9 -0
  67. package/dist/flutterwave/index.js.map +1 -0
  68. package/dist/index.d.ts +85 -0
  69. package/dist/index.js +3677 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/next/index.d.ts +1 -0
  72. package/dist/next/index.js +3 -0
  73. package/dist/next/index.js.map +1 -0
  74. package/dist/paystack/index.d.ts +33 -0
  75. package/dist/paystack/index.js +9 -0
  76. package/dist/paystack/index.js.map +1 -0
  77. package/dist/products/index.d.ts +22 -0
  78. package/dist/products/index.js +7 -0
  79. package/dist/products/index.js.map +1 -0
  80. package/dist/testing/index.d.ts +11 -0
  81. package/dist/testing/index.js +69 -0
  82. package/dist/testing/index.js.map +1 -0
  83. package/dist/unified/index.d.ts +41 -0
  84. package/dist/unified/index.js +6 -0
  85. package/dist/unified/index.js.map +1 -0
  86. package/dist/webhooks/index.d.ts +8 -0
  87. package/dist/webhooks/index.js +8 -0
  88. package/dist/webhooks/index.js.map +1 -0
  89. package/package.json +164 -0
@@ -0,0 +1,1507 @@
1
+ import { defineProvider, PAYSTACK_BASE_URL, paystackProviderConfigSchema, readHeader, inferEnvironment, HttpClient, bearer } from './chunk-IUVGM3K7.js';
2
+ import { verifyPaystack } from './chunk-NXQBP35U.js';
3
+ import { toUnifiedEventType } from './chunk-67NRYGRC.js';
4
+ import { PayweaveConfigError, PayweaveValidationError } from './chunk-HTRGMZFH.js';
5
+ import { z } from 'zod';
6
+
7
+ function parseRequest(schema, input) {
8
+ try {
9
+ return schema.parse(input);
10
+ } catch (err) {
11
+ if (err instanceof z.ZodError) {
12
+ const detail = err.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; ");
13
+ throw new PayweaveValidationError(`paystack request validation failed \u2014 ${detail}`, {
14
+ provider: "paystack",
15
+ cause: err
16
+ });
17
+ }
18
+ throw err;
19
+ }
20
+ }
21
+ var paystackEnvelope = (data) => z.looseObject({
22
+ status: z.boolean(),
23
+ message: z.string(),
24
+ data
25
+ });
26
+ var paginationMeta = z.looseObject({
27
+ total: z.union([z.number(), z.string()]).optional(),
28
+ perPage: z.union([z.number(), z.string()]).optional(),
29
+ page: z.union([z.number(), z.string()]).optional(),
30
+ pageCount: z.union([z.number(), z.string()]).optional(),
31
+ // Cursor pagination (e.g. `GET /bank`) uses next/previous instead of pageCount.
32
+ next: z.string().nullable().optional(),
33
+ previous: z.string().nullable().optional()
34
+ });
35
+ var paystackListEnvelope = (item) => z.looseObject({
36
+ status: z.boolean(),
37
+ message: z.string(),
38
+ data: z.array(item),
39
+ meta: paginationMeta.optional()
40
+ });
41
+ var metadataSchema = z.record(z.string(), z.unknown());
42
+ ({
43
+ perPage: z.number().int().positive().optional(),
44
+ page: z.number().int().positive().optional(),
45
+ from: z.string().optional(),
46
+ to: z.string().optional()
47
+ });
48
+ function metaNumber(value) {
49
+ if (typeof value === "number") return value;
50
+ if (typeof value === "string" && value.trim() !== "") {
51
+ const n = Number(value);
52
+ return Number.isFinite(n) ? n : void 0;
53
+ }
54
+ return void 0;
55
+ }
56
+ var channelEnum = z.enum([
57
+ "card",
58
+ "bank",
59
+ "ussd",
60
+ "qr",
61
+ "mobile_money",
62
+ "bank_transfer",
63
+ "eft"
64
+ ]);
65
+ var initializeReq = z.object({
66
+ /** Customer email. Required by Paystack. */
67
+ email: z.string(),
68
+ /** Amount in KOBO (minor units) — passed through unchanged (e.g. 500000 = ₦5,000). */
69
+ amount: z.number().int().nonnegative(),
70
+ currency: z.string().optional(),
71
+ /** Your unique transaction reference. If omitted, Paystack generates one. */
72
+ reference: z.string().optional(),
73
+ callback_url: z.string().optional(),
74
+ plan: z.string().optional(),
75
+ invoice_limit: z.number().int().optional(),
76
+ metadata: metadataSchema.optional(),
77
+ channels: z.array(channelEnum).optional(),
78
+ split_code: z.string().optional(),
79
+ subaccount: z.string().optional(),
80
+ transaction_charge: z.number().int().optional(),
81
+ bearer: z.enum(["account", "subaccount"]).optional()
82
+ });
83
+ var initializeData = z.looseObject({
84
+ authorization_url: z.string(),
85
+ access_code: z.string(),
86
+ reference: z.string()
87
+ });
88
+ var transaction = z.looseObject({
89
+ id: z.number(),
90
+ domain: z.string().optional(),
91
+ status: z.string().optional(),
92
+ reference: z.string().optional(),
93
+ amount: z.number().optional(),
94
+ message: z.string().nullable().optional(),
95
+ gateway_response: z.string().nullable().optional(),
96
+ paid_at: z.string().nullable().optional(),
97
+ created_at: z.string().optional(),
98
+ channel: z.string().nullable().optional(),
99
+ currency: z.string().optional(),
100
+ ip_address: z.string().nullable().optional(),
101
+ metadata: z.unknown().optional(),
102
+ customer: z.looseObject({}).optional(),
103
+ authorization: z.looseObject({}).optional(),
104
+ requested_amount: z.number().optional()
105
+ });
106
+ var listQuery = z.object({
107
+ perPage: z.number().int().positive().optional(),
108
+ page: z.number().int().positive().optional(),
109
+ customer: z.number().int().optional(),
110
+ terminalid: z.string().optional(),
111
+ status: z.enum(["failed", "success", "abandoned"]).optional(),
112
+ from: z.string().optional(),
113
+ to: z.string().optional(),
114
+ amount: z.number().int().optional()
115
+ });
116
+ var chargeAuthorizationReq = z.object({
117
+ email: z.string(),
118
+ amount: z.number().int().nonnegative(),
119
+ /** Reusable authorization code (`AUTH_...`) from a prior charge. Required. */
120
+ authorization_code: z.string(),
121
+ currency: z.string().optional(),
122
+ reference: z.string().optional(),
123
+ metadata: metadataSchema.optional(),
124
+ channels: z.array(channelEnum).optional(),
125
+ subaccount: z.string().optional(),
126
+ transaction_charge: z.number().int().optional(),
127
+ bearer: z.enum(["account", "subaccount"]).optional(),
128
+ queue: z.boolean().optional()
129
+ });
130
+ var partialDebitReq = z.object({
131
+ authorization_code: z.string(),
132
+ /** Currency to debit — required by Paystack for partial debit. */
133
+ currency: z.string(),
134
+ amount: z.number().int().nonnegative(),
135
+ email: z.string(),
136
+ reference: z.string().optional(),
137
+ at_least: z.number().int().optional()
138
+ });
139
+ var totalsQuery = z.object({
140
+ perPage: z.number().int().positive().optional(),
141
+ page: z.number().int().positive().optional(),
142
+ from: z.string().optional(),
143
+ to: z.string().optional()
144
+ });
145
+
146
+ // src/paystack/resources/transactions.ts
147
+ var initializeRes = paystackEnvelope(initializeData);
148
+ var transactionRes = paystackEnvelope(transaction);
149
+ var transactionListRes = paystackListEnvelope(transaction);
150
+ function refString(value) {
151
+ return parseRequest(z.string().min(1), value);
152
+ }
153
+ function looseData() {
154
+ return z.looseObject({});
155
+ }
156
+ var Transactions = class {
157
+ constructor(http) {
158
+ this.http = http;
159
+ }
160
+ http;
161
+ /**
162
+ * Initialize a transaction and get a hosted checkout URL. `amount` is in KOBO
163
+ * (minor units) and is sent to Paystack unchanged.
164
+ *
165
+ * Docs: https://paystack.com/docs/api/transaction/#initialize
166
+ *
167
+ * @example
168
+ * const res = await ps.paystack.transactions.initialize({
169
+ * email: "buyer@example.com",
170
+ * amount: 500000, // ₦5,000 in kobo
171
+ * });
172
+ * console.log(res.data.authorization_url);
173
+ */
174
+ async initialize(input) {
175
+ const body = parseRequest(initializeReq, input);
176
+ return this.http.request({
177
+ method: "POST",
178
+ path: "/transaction/initialize",
179
+ body,
180
+ schema: initializeRes
181
+ });
182
+ }
183
+ /**
184
+ * Verify a transaction by its `reference` (Paystack verifies by reference, not
185
+ * numeric id). A 404 for an unknown reference surfaces as
186
+ * {@link PayweaveNotFoundError}.
187
+ *
188
+ * Docs: https://paystack.com/docs/api/transaction/#verify
189
+ *
190
+ * @example
191
+ * const res = await ps.paystack.transactions.verify("pwv_ref_001");
192
+ * if (res.data.status === "success") { }
193
+ */
194
+ async verify(reference) {
195
+ const ref = refString(reference);
196
+ return this.http.request({
197
+ method: "GET",
198
+ path: `/transaction/verify/${encodeURIComponent(ref)}`,
199
+ schema: transactionRes
200
+ });
201
+ }
202
+ /**
203
+ * List transactions on the integration.
204
+ *
205
+ * Docs: https://paystack.com/docs/api/transaction/#list
206
+ *
207
+ * @example
208
+ * const page = await ps.paystack.transactions.list({ perPage: 50, status: "success" });
209
+ */
210
+ async list(query = {}) {
211
+ const q = parseRequest(listQuery, query);
212
+ return this.http.request({
213
+ method: "GET",
214
+ path: "/transaction",
215
+ query: q,
216
+ schema: transactionListRes
217
+ });
218
+ }
219
+ /**
220
+ * Async iterator over ALL transactions matching `query`, transparently walking
221
+ * every page (`meta.pageCount`).
222
+ *
223
+ * Docs: https://paystack.com/docs/api/transaction/#list
224
+ *
225
+ * @example
226
+ * for await (const tx of ps.paystack.transactions.iterate({ status: "success" })) {
227
+ * console.log(tx.id);
228
+ * }
229
+ */
230
+ async *iterate(query = {}) {
231
+ const base = parseRequest(listQuery, query);
232
+ const perPage = base.perPage ?? 50;
233
+ let page = base.page ?? 1;
234
+ for (; ; ) {
235
+ const res = await this.http.request({
236
+ method: "GET",
237
+ path: "/transaction",
238
+ query: { ...base, perPage, page },
239
+ schema: transactionListRes
240
+ });
241
+ for (const tx of res.data) yield tx;
242
+ const pageCount = metaNumber(res.meta?.pageCount);
243
+ if (pageCount !== void 0) {
244
+ if (page >= pageCount) return;
245
+ } else if (res.data.length < perPage) {
246
+ return;
247
+ }
248
+ page += 1;
249
+ }
250
+ }
251
+ /**
252
+ * Fetch a single transaction by its numeric Paystack id.
253
+ *
254
+ * Docs: https://paystack.com/docs/api/transaction/#fetch
255
+ *
256
+ * @example
257
+ * const res = await ps.paystack.transactions.fetch(123456789);
258
+ */
259
+ async fetch(id) {
260
+ return this.http.request({
261
+ method: "GET",
262
+ path: `/transaction/${encodeURIComponent(String(id))}`,
263
+ schema: transactionRes
264
+ });
265
+ }
266
+ /**
267
+ * Charge a previously-authorized card using its reusable `authorization_code`.
268
+ * `amount` is KOBO minor units, passed through unchanged.
269
+ *
270
+ * Docs: https://paystack.com/docs/api/transaction/#charge-authorization
271
+ *
272
+ * @example
273
+ * const res = await ps.paystack.transactions.chargeAuthorization({
274
+ * email: "buyer@example.com",
275
+ * amount: 500000,
276
+ * authorization_code: "AUTH_example",
277
+ * });
278
+ */
279
+ async chargeAuthorization(input) {
280
+ const body = parseRequest(chargeAuthorizationReq, input);
281
+ return this.http.request({
282
+ method: "POST",
283
+ path: "/transaction/charge_authorization",
284
+ body,
285
+ schema: transactionRes
286
+ });
287
+ }
288
+ /**
289
+ * Retrieve the timeline (event log) of a transaction by id or reference.
290
+ *
291
+ * Docs: https://paystack.com/docs/api/transaction/#view-timeline
292
+ *
293
+ * @example
294
+ * const res = await ps.paystack.transactions.timeline("pwv_ref_001");
295
+ */
296
+ async timeline(idOrReference) {
297
+ return this.http.request({
298
+ method: "GET",
299
+ path: `/transaction/timeline/${encodeURIComponent(String(idOrReference))}`,
300
+ schema: paystackEnvelope(looseData())
301
+ });
302
+ }
303
+ /**
304
+ * Total amount received on the integration over an optional date window.
305
+ *
306
+ * Docs: https://paystack.com/docs/api/transaction/#totals
307
+ *
308
+ * @example
309
+ * const res = await ps.paystack.transactions.totals({ from: "2024-01-01" });
310
+ */
311
+ async totals(query = {}) {
312
+ const q = parseRequest(totalsQuery, query);
313
+ return this.http.request({
314
+ method: "GET",
315
+ path: "/transaction/totals",
316
+ query: q,
317
+ schema: paystackEnvelope(looseData())
318
+ });
319
+ }
320
+ /**
321
+ * Deduct a partial amount from a customer's authorization. `amount` is KOBO.
322
+ *
323
+ * Docs: https://paystack.com/docs/api/transaction/#partial-debit
324
+ *
325
+ * @example
326
+ * const res = await ps.paystack.transactions.partialDebit({
327
+ * authorization_code: "AUTH_example",
328
+ * currency: "NGN",
329
+ * amount: 200000,
330
+ * email: "buyer@example.com",
331
+ * });
332
+ */
333
+ async partialDebit(input) {
334
+ const body = parseRequest(partialDebitReq, input);
335
+ return this.http.request({
336
+ method: "POST",
337
+ path: "/transaction/partial_debit",
338
+ body,
339
+ schema: transactionRes
340
+ });
341
+ }
342
+ };
343
+ var createRefundReq = z.object({
344
+ /** Transaction id or reference to refund. Required. */
345
+ transaction: z.union([z.string(), z.number().int()]),
346
+ /** Amount in KOBO (minor units). Omit to refund the full amount. */
347
+ amount: z.number().int().nonnegative().optional(),
348
+ currency: z.string().optional(),
349
+ customer_note: z.string().optional(),
350
+ merchant_note: z.string().optional()
351
+ });
352
+ var listRefundsQuery = z.object({
353
+ transaction: z.union([z.string(), z.number().int()]).optional(),
354
+ currency: z.string().optional(),
355
+ perPage: z.number().int().positive().optional(),
356
+ page: z.number().int().positive().optional(),
357
+ from: z.string().optional(),
358
+ to: z.string().optional()
359
+ });
360
+ var refund = z.looseObject({
361
+ id: z.number().optional(),
362
+ transaction: z.union([z.number(), z.looseObject({})]).optional(),
363
+ integration: z.number().optional(),
364
+ amount: z.number().optional(),
365
+ deducted_amount: z.number().nullable().optional(),
366
+ currency: z.string().optional(),
367
+ channel: z.string().nullable().optional(),
368
+ status: z.string().optional(),
369
+ refunded_by: z.string().nullable().optional(),
370
+ customer_note: z.string().nullable().optional(),
371
+ merchant_note: z.string().nullable().optional(),
372
+ expected_at: z.string().nullable().optional(),
373
+ created_at: z.string().optional(),
374
+ updated_at: z.string().optional()
375
+ });
376
+
377
+ // src/paystack/resources/refunds.ts
378
+ var refundRes = paystackEnvelope(refund);
379
+ var refundListRes = paystackListEnvelope(refund);
380
+ var Refunds = class {
381
+ constructor(http) {
382
+ this.http = http;
383
+ }
384
+ http;
385
+ /**
386
+ * Create a refund for a transaction. `amount` is KOBO minor units; omit to
387
+ * refund in full.
388
+ *
389
+ * Docs: https://paystack.com/docs/api/refund/#create
390
+ *
391
+ * @example
392
+ * const res = await ps.paystack.refunds.create({ transaction: "pwv_ref_001", amount: 100000 });
393
+ */
394
+ async create(input) {
395
+ const body = parseRequest(createRefundReq, input);
396
+ return this.http.request({
397
+ method: "POST",
398
+ path: "/refund",
399
+ body,
400
+ schema: refundRes
401
+ });
402
+ }
403
+ /**
404
+ * List refunds.
405
+ *
406
+ * Docs: https://paystack.com/docs/api/refund/#list
407
+ *
408
+ * @example
409
+ * const page = await ps.paystack.refunds.list({ perPage: 50 });
410
+ */
411
+ async list(query = {}) {
412
+ const q = parseRequest(listRefundsQuery, query);
413
+ return this.http.request({
414
+ method: "GET",
415
+ path: "/refund",
416
+ query: q,
417
+ schema: refundListRes
418
+ });
419
+ }
420
+ /**
421
+ * Async iterator over ALL refunds matching `query`.
422
+ *
423
+ * Docs: https://paystack.com/docs/api/refund/#list
424
+ *
425
+ * @example
426
+ * for await (const r of ps.paystack.refunds.iterate()) console.log(r.id);
427
+ */
428
+ async *iterate(query = {}) {
429
+ const base = parseRequest(listRefundsQuery, query);
430
+ const perPage = base.perPage ?? 50;
431
+ let page = base.page ?? 1;
432
+ for (; ; ) {
433
+ const res = await this.http.request({
434
+ method: "GET",
435
+ path: "/refund",
436
+ query: { ...base, perPage, page },
437
+ schema: refundListRes
438
+ });
439
+ for (const r of res.data) yield r;
440
+ const pageCount = metaNumber(res.meta?.pageCount);
441
+ if (pageCount !== void 0) {
442
+ if (page >= pageCount) return;
443
+ } else if (res.data.length < perPage) {
444
+ return;
445
+ }
446
+ page += 1;
447
+ }
448
+ }
449
+ /**
450
+ * Fetch a single refund by id.
451
+ *
452
+ * Docs: https://paystack.com/docs/api/refund/#fetch
453
+ *
454
+ * @example
455
+ * const res = await ps.paystack.refunds.fetch(1234);
456
+ */
457
+ async fetch(id) {
458
+ z.string().min(1).parse(String(id));
459
+ return this.http.request({
460
+ method: "GET",
461
+ path: `/refund/${encodeURIComponent(String(id))}`,
462
+ schema: refundRes
463
+ });
464
+ }
465
+ };
466
+ var createCustomerReq = z.object({
467
+ /** Customer email. Required. */
468
+ email: z.string(),
469
+ first_name: z.string().optional(),
470
+ last_name: z.string().optional(),
471
+ phone: z.string().optional(),
472
+ metadata: metadataSchema.optional()
473
+ });
474
+ var updateCustomerReq = z.object({
475
+ first_name: z.string().optional(),
476
+ last_name: z.string().optional(),
477
+ phone: z.string().optional(),
478
+ metadata: metadataSchema.optional()
479
+ });
480
+ var listCustomersQuery = z.object({
481
+ perPage: z.number().int().positive().optional(),
482
+ page: z.number().int().positive().optional(),
483
+ from: z.string().optional(),
484
+ to: z.string().optional()
485
+ });
486
+ var validateCustomerReq = z.object({
487
+ /** e.g. "NG". Required. */
488
+ country: z.string(),
489
+ /** Predefined type of identification, e.g. "bank_account". Required. */
490
+ type: z.string(),
491
+ account_number: z.string().optional(),
492
+ bvn: z.string().optional(),
493
+ bank_code: z.string().optional(),
494
+ first_name: z.string().optional(),
495
+ last_name: z.string().optional(),
496
+ middle_name: z.string().optional(),
497
+ value: z.string().optional()
498
+ });
499
+ var setRiskActionReq = z.object({
500
+ /** Customer code or email. Required. */
501
+ customer: z.string(),
502
+ /** allow (whitelist), deny (blacklist), or default. Required. */
503
+ risk_action: z.enum(["default", "allow", "deny"])
504
+ });
505
+ var customer = z.looseObject({
506
+ id: z.number().optional(),
507
+ integration: z.number().optional(),
508
+ first_name: z.string().nullable().optional(),
509
+ last_name: z.string().nullable().optional(),
510
+ email: z.string().optional(),
511
+ phone: z.string().nullable().optional(),
512
+ customer_code: z.string().optional(),
513
+ domain: z.string().optional(),
514
+ risk_action: z.string().optional(),
515
+ metadata: z.unknown().optional(),
516
+ created_at: z.string().optional(),
517
+ updated_at: z.string().optional()
518
+ });
519
+
520
+ // src/paystack/resources/customers.ts
521
+ var customerRes = paystackEnvelope(customer);
522
+ var customerListRes = paystackListEnvelope(customer);
523
+ var ackRes = paystackEnvelope(z.unknown());
524
+ var Customers = class {
525
+ constructor(http) {
526
+ this.http = http;
527
+ }
528
+ http;
529
+ /**
530
+ * Create a customer.
531
+ *
532
+ * Docs: https://paystack.com/docs/api/customer/#create
533
+ *
534
+ * @example
535
+ * const res = await ps.paystack.customers.create({ email: "buyer@example.com" });
536
+ */
537
+ async create(input) {
538
+ const body = parseRequest(createCustomerReq, input);
539
+ return this.http.request({
540
+ method: "POST",
541
+ path: "/customer",
542
+ body,
543
+ schema: customerRes
544
+ });
545
+ }
546
+ /**
547
+ * List customers.
548
+ *
549
+ * Docs: https://paystack.com/docs/api/customer/#list
550
+ *
551
+ * @example
552
+ * const page = await ps.paystack.customers.list({ perPage: 50 });
553
+ */
554
+ async list(query = {}) {
555
+ const q = parseRequest(listCustomersQuery, query);
556
+ return this.http.request({
557
+ method: "GET",
558
+ path: "/customer",
559
+ query: q,
560
+ schema: customerListRes
561
+ });
562
+ }
563
+ /**
564
+ * Async iterator over ALL customers.
565
+ *
566
+ * Docs: https://paystack.com/docs/api/customer/#list
567
+ *
568
+ * @example
569
+ * for await (const c of ps.paystack.customers.iterate()) console.log(c.customer_code);
570
+ */
571
+ async *iterate(query = {}) {
572
+ const base = parseRequest(listCustomersQuery, query);
573
+ const perPage = base.perPage ?? 50;
574
+ let page = base.page ?? 1;
575
+ for (; ; ) {
576
+ const res = await this.http.request({
577
+ method: "GET",
578
+ path: "/customer",
579
+ query: { ...base, perPage, page },
580
+ schema: customerListRes
581
+ });
582
+ for (const c of res.data) yield c;
583
+ const pageCount = metaNumber(res.meta?.pageCount);
584
+ if (pageCount !== void 0) {
585
+ if (page >= pageCount) return;
586
+ } else if (res.data.length < perPage) {
587
+ return;
588
+ }
589
+ page += 1;
590
+ }
591
+ }
592
+ /**
593
+ * Fetch a customer by email or customer code.
594
+ *
595
+ * Docs: https://paystack.com/docs/api/customer/#fetch
596
+ *
597
+ * @example
598
+ * const res = await ps.paystack.customers.fetch("CUS_example");
599
+ */
600
+ async fetch(emailOrCode) {
601
+ const key = parseRequest(z.string().min(1), emailOrCode);
602
+ return this.http.request({
603
+ method: "GET",
604
+ path: `/customer/${encodeURIComponent(key)}`,
605
+ schema: customerRes
606
+ });
607
+ }
608
+ /**
609
+ * Update a customer by customer code.
610
+ *
611
+ * Docs: https://paystack.com/docs/api/customer/#update
612
+ *
613
+ * @example
614
+ * const res = await ps.paystack.customers.update("CUS_example", { first_name: "Ada" });
615
+ */
616
+ async update(code, input) {
617
+ const key = parseRequest(z.string().min(1), code);
618
+ const body = parseRequest(updateCustomerReq, input);
619
+ return this.http.request({
620
+ method: "PUT",
621
+ path: `/customer/${encodeURIComponent(key)}`,
622
+ body,
623
+ schema: customerRes
624
+ });
625
+ }
626
+ /**
627
+ * Validate a customer's identity (e.g. bank account). Paystack processes this
628
+ * asynchronously and returns an acknowledgement envelope.
629
+ *
630
+ * Docs: https://paystack.com/docs/api/customer/#validate
631
+ *
632
+ * @example
633
+ * await ps.paystack.customers.validate("CUS_example", {
634
+ * country: "NG", type: "bank_account",
635
+ * account_number: "0000000000", bank_code: "011",
636
+ * first_name: "Ada", last_name: "Lovelace",
637
+ * });
638
+ */
639
+ async validate(code, input) {
640
+ const key = parseRequest(z.string().min(1), code);
641
+ const body = parseRequest(validateCustomerReq, input);
642
+ return this.http.request({
643
+ method: "POST",
644
+ path: `/customer/${encodeURIComponent(key)}/identification`,
645
+ body,
646
+ schema: ackRes
647
+ });
648
+ }
649
+ /**
650
+ * Whitelist or blacklist a customer (set risk action).
651
+ *
652
+ * Docs: https://paystack.com/docs/api/customer/#whitelist-blacklist
653
+ *
654
+ * @example
655
+ * await ps.paystack.customers.setRiskAction({ customer: "CUS_example", risk_action: "allow" });
656
+ */
657
+ async setRiskAction(input) {
658
+ const body = parseRequest(setRiskActionReq, input);
659
+ return this.http.request({
660
+ method: "POST",
661
+ path: "/customer/set_risk_action",
662
+ body,
663
+ schema: customerRes
664
+ });
665
+ }
666
+ /**
667
+ * Deactivate a reusable authorization on a customer.
668
+ *
669
+ * Docs: https://paystack.com/docs/api/customer/#deactivate-authorization
670
+ *
671
+ * @example
672
+ * await ps.paystack.customers.deactivateAuthorization("AUTH_example");
673
+ */
674
+ async deactivateAuthorization(authorizationCode) {
675
+ const code = parseRequest(z.string().min(1), authorizationCode);
676
+ return this.http.request({
677
+ method: "POST",
678
+ path: "/customer/deactivate_authorization",
679
+ body: { authorization_code: code },
680
+ schema: ackRes
681
+ });
682
+ }
683
+ };
684
+ var listBanksQuery = z.object({
685
+ /** Country name, e.g. "nigeria" (lowercase, as Paystack documents). */
686
+ country: z.string().optional(),
687
+ use_cursor: z.boolean().optional(),
688
+ perPage: z.number().int().positive().optional(),
689
+ pay_with_bank_transfer: z.boolean().optional(),
690
+ pay_with_bank: z.boolean().optional(),
691
+ gateway: z.string().optional(),
692
+ type: z.string().optional(),
693
+ currency: z.string().optional(),
694
+ next: z.string().optional(),
695
+ previous: z.string().optional()
696
+ });
697
+ var bank = z.looseObject({
698
+ id: z.number().optional(),
699
+ name: z.string().optional(),
700
+ slug: z.string().optional(),
701
+ code: z.string().optional(),
702
+ longcode: z.string().nullable().optional(),
703
+ gateway: z.string().nullable().optional(),
704
+ pay_with_bank: z.boolean().optional(),
705
+ active: z.boolean().optional(),
706
+ country: z.string().optional(),
707
+ currency: z.string().optional(),
708
+ type: z.string().optional()
709
+ });
710
+ var resolveAccountQuery = z.object({
711
+ account_number: z.string(),
712
+ bank_code: z.string()
713
+ });
714
+ var resolvedAccount = z.looseObject({
715
+ account_number: z.string(),
716
+ account_name: z.string(),
717
+ bank_id: z.number().optional()
718
+ });
719
+ var listStatesQuery = z.object({
720
+ /** Country code, e.g. "CA" or "NG". */
721
+ country: z.string()
722
+ });
723
+ var country = z.looseObject({
724
+ id: z.number().optional(),
725
+ name: z.string().optional(),
726
+ iso_code: z.string().optional(),
727
+ default_currency_code: z.string().optional()
728
+ });
729
+ var avsState = z.looseObject({
730
+ name: z.string().optional(),
731
+ slug: z.string().optional(),
732
+ abbreviation: z.string().optional()
733
+ });
734
+ var cardBin = z.looseObject({
735
+ bin: z.string().optional(),
736
+ brand: z.string().optional(),
737
+ sub_brand: z.string().optional(),
738
+ country_code: z.string().optional(),
739
+ country_name: z.string().optional(),
740
+ card_type: z.string().optional(),
741
+ bank: z.string().optional(),
742
+ linked_bank_id: z.number().optional()
743
+ });
744
+
745
+ // src/paystack/resources/misc.ts
746
+ var bankListRes = paystackListEnvelope(bank);
747
+ var resolveRes = paystackEnvelope(resolvedAccount);
748
+ var countryListRes = paystackListEnvelope(country);
749
+ var stateListRes = paystackListEnvelope(avsState);
750
+ var cardBinRes = paystackEnvelope(cardBin);
751
+ var Misc = class {
752
+ constructor(http) {
753
+ this.http = http;
754
+ }
755
+ http;
756
+ /**
757
+ * List banks (and other financial channels) for a country.
758
+ *
759
+ * Docs: https://paystack.com/docs/api/miscellaneous/#bank
760
+ *
761
+ * @example
762
+ * const res = await ps.paystack.misc.listBanks({ country: "nigeria" });
763
+ */
764
+ async listBanks(query = {}) {
765
+ const q = parseRequest(listBanksQuery, query);
766
+ return this.http.request({
767
+ method: "GET",
768
+ path: "/bank",
769
+ query: q,
770
+ schema: bankListRes
771
+ });
772
+ }
773
+ /**
774
+ * Resolve an account number to an account name at a bank.
775
+ *
776
+ * Docs: https://paystack.com/docs/api/verification/#resolve-account
777
+ *
778
+ * @example
779
+ * const res = await ps.paystack.misc.resolveAccountNumber({
780
+ * account_number: "0000000000", bank_code: "011",
781
+ * });
782
+ * console.log(res.data.account_name);
783
+ */
784
+ async resolveAccountNumber(query) {
785
+ const q = parseRequest(resolveAccountQuery, query);
786
+ return this.http.request({
787
+ method: "GET",
788
+ path: "/bank/resolve",
789
+ query: q,
790
+ schema: resolveRes
791
+ });
792
+ }
793
+ /**
794
+ * List countries Paystack currently supports.
795
+ *
796
+ * Docs: https://paystack.com/docs/api/miscellaneous/#country
797
+ *
798
+ * @example
799
+ * const res = await ps.paystack.misc.listCountries();
800
+ */
801
+ async listCountries() {
802
+ return this.http.request({
803
+ method: "GET",
804
+ path: "/country",
805
+ schema: countryListRes
806
+ });
807
+ }
808
+ /**
809
+ * List the states for a country's address verification.
810
+ *
811
+ * Docs: https://paystack.com/docs/api/miscellaneous/#avs-states
812
+ *
813
+ * @example
814
+ * const res = await ps.paystack.misc.listStates({ country: "CA" });
815
+ */
816
+ async listStates(query) {
817
+ const q = parseRequest(listStatesQuery, query);
818
+ return this.http.request({
819
+ method: "GET",
820
+ path: "/address_verification/states",
821
+ query: q,
822
+ schema: stateListRes
823
+ });
824
+ }
825
+ /**
826
+ * Resolve a card BIN (first 6 digits) to its issuer/brand.
827
+ *
828
+ * Docs: https://paystack.com/docs/api/verification/#resolve-card-bin
829
+ *
830
+ * @example
831
+ * const res = await ps.paystack.misc.resolveCardBin("539983");
832
+ */
833
+ async resolveCardBin(bin) {
834
+ const value = parseRequest(z.string().min(1), bin);
835
+ return this.http.request({
836
+ method: "GET",
837
+ path: `/decision/bin/${encodeURIComponent(value)}`,
838
+ schema: cardBinRes
839
+ });
840
+ }
841
+ };
842
+ var createRecipientReq = z.object({
843
+ /** Recipient type, e.g. "nuban", "mobile_money", "basa". Required. */
844
+ type: z.string(),
845
+ /** Recipient name. Required. */
846
+ name: z.string(),
847
+ account_number: z.string().optional(),
848
+ bank_code: z.string().optional(),
849
+ description: z.string().optional(),
850
+ currency: z.string().optional(),
851
+ authorization_code: z.string().optional(),
852
+ metadata: metadataSchema.optional()
853
+ });
854
+ var listRecipientsQuery = z.object({
855
+ perPage: z.number().int().positive().optional(),
856
+ page: z.number().int().positive().optional(),
857
+ from: z.string().optional(),
858
+ to: z.string().optional()
859
+ });
860
+ var recipient = z.looseObject({
861
+ id: z.number().optional(),
862
+ integration: z.number().optional(),
863
+ domain: z.string().optional(),
864
+ type: z.string().optional(),
865
+ currency: z.string().optional(),
866
+ name: z.string().optional(),
867
+ recipient_code: z.string().optional(),
868
+ active: z.boolean().optional(),
869
+ is_deleted: z.boolean().optional(),
870
+ details: z.looseObject({}).optional(),
871
+ created_at: z.string().optional(),
872
+ updated_at: z.string().optional()
873
+ });
874
+ var initiateTransferReq = z.object({
875
+ /** Where to debit, currently only "balance". Required. */
876
+ source: z.string(),
877
+ /** Amount in KOBO (minor units). Required. */
878
+ amount: z.number().int().nonnegative(),
879
+ /** Recipient code (`RCP_...`). Required. */
880
+ recipient: z.string(),
881
+ reason: z.string().optional(),
882
+ currency: z.string().optional(),
883
+ reference: z.string().optional()
884
+ });
885
+ var listTransfersQuery = z.object({
886
+ perPage: z.number().int().positive().optional(),
887
+ page: z.number().int().positive().optional(),
888
+ recipient: z.number().int().optional(),
889
+ from: z.string().optional(),
890
+ to: z.string().optional()
891
+ });
892
+ var transfer = z.looseObject({
893
+ id: z.number().optional(),
894
+ integration: z.number().optional(),
895
+ domain: z.string().optional(),
896
+ amount: z.number().optional(),
897
+ currency: z.string().optional(),
898
+ source: z.string().optional(),
899
+ reason: z.string().nullable().optional(),
900
+ recipient: z.union([z.number(), z.looseObject({})]).optional(),
901
+ status: z.string().optional(),
902
+ transfer_code: z.string().optional(),
903
+ reference: z.string().nullable().optional(),
904
+ created_at: z.string().optional(),
905
+ updated_at: z.string().optional()
906
+ });
907
+ var balanceEntry = z.looseObject({
908
+ currency: z.string().optional(),
909
+ balance: z.number().optional()
910
+ });
911
+
912
+ // src/paystack/resources/transfer-recipients.ts
913
+ var recipientRes = paystackEnvelope(recipient);
914
+ var recipientListRes = paystackListEnvelope(recipient);
915
+ var TransferRecipients = class {
916
+ constructor(http) {
917
+ this.http = http;
918
+ }
919
+ http;
920
+ /**
921
+ * Create a transfer recipient.
922
+ *
923
+ * Docs: https://paystack.com/docs/api/transfer-recipient/#create
924
+ *
925
+ * @example
926
+ * const res = await ps.paystack.transferRecipients.create({
927
+ * type: "nuban", name: "Ada Lovelace",
928
+ * account_number: "0000000000", bank_code: "011",
929
+ * });
930
+ */
931
+ async create(input) {
932
+ const body = parseRequest(createRecipientReq, input);
933
+ return this.http.request({
934
+ method: "POST",
935
+ path: "/transferrecipient",
936
+ body,
937
+ schema: recipientRes
938
+ });
939
+ }
940
+ /**
941
+ * List transfer recipients.
942
+ *
943
+ * Docs: https://paystack.com/docs/api/transfer-recipient/#list
944
+ *
945
+ * @example
946
+ * const page = await ps.paystack.transferRecipients.list({ perPage: 50 });
947
+ */
948
+ async list(query = {}) {
949
+ const q = parseRequest(listRecipientsQuery, query);
950
+ return this.http.request({
951
+ method: "GET",
952
+ path: "/transferrecipient",
953
+ query: q,
954
+ schema: recipientListRes
955
+ });
956
+ }
957
+ /**
958
+ * Async iterator over ALL transfer recipients.
959
+ *
960
+ * Docs: https://paystack.com/docs/api/transfer-recipient/#list
961
+ *
962
+ * @example
963
+ * for await (const r of ps.paystack.transferRecipients.iterate()) console.log(r.recipient_code);
964
+ */
965
+ async *iterate(query = {}) {
966
+ const base = parseRequest(listRecipientsQuery, query);
967
+ const perPage = base.perPage ?? 50;
968
+ let page = base.page ?? 1;
969
+ for (; ; ) {
970
+ const res = await this.http.request({
971
+ method: "GET",
972
+ path: "/transferrecipient",
973
+ query: { ...base, perPage, page },
974
+ schema: recipientListRes
975
+ });
976
+ for (const r of res.data) yield r;
977
+ const pageCount = metaNumber(res.meta?.pageCount);
978
+ if (pageCount !== void 0) {
979
+ if (page >= pageCount) return;
980
+ } else if (res.data.length < perPage) {
981
+ return;
982
+ }
983
+ page += 1;
984
+ }
985
+ }
986
+ /**
987
+ * Fetch a transfer recipient by id or recipient code.
988
+ *
989
+ * Docs: https://paystack.com/docs/api/transfer-recipient/#fetch
990
+ *
991
+ * @example
992
+ * const res = await ps.paystack.transferRecipients.fetch("RCP_example");
993
+ */
994
+ async fetch(idOrCode) {
995
+ const key = z.string().min(1).parse(String(idOrCode));
996
+ return this.http.request({
997
+ method: "GET",
998
+ path: `/transferrecipient/${encodeURIComponent(key)}`,
999
+ schema: recipientRes
1000
+ });
1001
+ }
1002
+ };
1003
+ var transferRes = paystackEnvelope(transfer);
1004
+ var transferListRes = paystackListEnvelope(transfer);
1005
+ var balanceRes = paystackEnvelope(z.array(balanceEntry));
1006
+ var Transfers = class {
1007
+ constructor(http) {
1008
+ this.http = http;
1009
+ }
1010
+ http;
1011
+ /**
1012
+ * Initiate a transfer to a recipient. `amount` is KOBO minor units.
1013
+ *
1014
+ * Docs: https://paystack.com/docs/api/transfer/#initiate
1015
+ *
1016
+ * @example
1017
+ * const res = await ps.paystack.transfers.initiate({
1018
+ * source: "balance", amount: 500000, recipient: "RCP_example",
1019
+ * });
1020
+ */
1021
+ async initiate(input) {
1022
+ const body = parseRequest(initiateTransferReq, input);
1023
+ return this.http.request({
1024
+ method: "POST",
1025
+ path: "/transfer",
1026
+ body,
1027
+ schema: transferRes
1028
+ });
1029
+ }
1030
+ /**
1031
+ * List transfers.
1032
+ *
1033
+ * Docs: https://paystack.com/docs/api/transfer/#list
1034
+ *
1035
+ * @example
1036
+ * const page = await ps.paystack.transfers.list({ perPage: 50 });
1037
+ */
1038
+ async list(query = {}) {
1039
+ const q = parseRequest(listTransfersQuery, query);
1040
+ return this.http.request({
1041
+ method: "GET",
1042
+ path: "/transfer",
1043
+ query: q,
1044
+ schema: transferListRes
1045
+ });
1046
+ }
1047
+ /**
1048
+ * Async iterator over ALL transfers.
1049
+ *
1050
+ * Docs: https://paystack.com/docs/api/transfer/#list
1051
+ *
1052
+ * @example
1053
+ * for await (const t of ps.paystack.transfers.iterate()) console.log(t.transfer_code);
1054
+ */
1055
+ async *iterate(query = {}) {
1056
+ const base = parseRequest(listTransfersQuery, query);
1057
+ const perPage = base.perPage ?? 50;
1058
+ let page = base.page ?? 1;
1059
+ for (; ; ) {
1060
+ const res = await this.http.request({
1061
+ method: "GET",
1062
+ path: "/transfer",
1063
+ query: { ...base, perPage, page },
1064
+ schema: transferListRes
1065
+ });
1066
+ for (const t of res.data) yield t;
1067
+ const pageCount = metaNumber(res.meta?.pageCount);
1068
+ if (pageCount !== void 0) {
1069
+ if (page >= pageCount) return;
1070
+ } else if (res.data.length < perPage) {
1071
+ return;
1072
+ }
1073
+ page += 1;
1074
+ }
1075
+ }
1076
+ /**
1077
+ * Fetch a transfer by id or transfer code.
1078
+ *
1079
+ * Docs: https://paystack.com/docs/api/transfer/#fetch
1080
+ *
1081
+ * @example
1082
+ * const res = await ps.paystack.transfers.fetch("TRF_example");
1083
+ */
1084
+ async fetch(idOrCode) {
1085
+ const key = z.string().min(1).parse(String(idOrCode));
1086
+ return this.http.request({
1087
+ method: "GET",
1088
+ path: `/transfer/${encodeURIComponent(key)}`,
1089
+ schema: transferRes
1090
+ });
1091
+ }
1092
+ /**
1093
+ * Verify a transfer by its reference.
1094
+ *
1095
+ * Docs: https://paystack.com/docs/api/transfer/#verify
1096
+ *
1097
+ * @example
1098
+ * const res = await ps.paystack.transfers.verify("pwv_transfer_ref");
1099
+ */
1100
+ async verify(reference) {
1101
+ const ref = parseRequest(z.string().min(1), reference);
1102
+ return this.http.request({
1103
+ method: "GET",
1104
+ path: `/transfer/verify/${encodeURIComponent(ref)}`,
1105
+ schema: transferRes
1106
+ });
1107
+ }
1108
+ /**
1109
+ * Fetch the balance(s) available on the integration.
1110
+ *
1111
+ * Docs: https://paystack.com/docs/api/transfer/#balance
1112
+ *
1113
+ * @example
1114
+ * const res = await ps.paystack.transfers.balance();
1115
+ * console.log(res.data[0]?.balance);
1116
+ */
1117
+ async balance() {
1118
+ return this.http.request({
1119
+ method: "GET",
1120
+ path: "/balance",
1121
+ schema: balanceRes
1122
+ });
1123
+ }
1124
+ };
1125
+ var planInterval = z.enum([
1126
+ "daily",
1127
+ "weekly",
1128
+ "monthly",
1129
+ "quarterly",
1130
+ "biannually",
1131
+ "annually"
1132
+ ]);
1133
+ var createPlanReq = z.object({
1134
+ /** Plan name. Required. */
1135
+ name: z.string(),
1136
+ /** Amount in KOBO (minor units). Required. */
1137
+ amount: z.number().int().nonnegative(),
1138
+ /** Billing interval. Required. */
1139
+ interval: planInterval,
1140
+ description: z.string().optional(),
1141
+ send_invoices: z.boolean().optional(),
1142
+ send_sms: z.boolean().optional(),
1143
+ currency: z.string().optional(),
1144
+ invoice_limit: z.number().int().optional()
1145
+ });
1146
+ var listPlansQuery = z.object({
1147
+ perPage: z.number().int().positive().optional(),
1148
+ page: z.number().int().positive().optional(),
1149
+ status: z.string().optional(),
1150
+ interval: planInterval.optional(),
1151
+ amount: z.number().int().optional()
1152
+ });
1153
+ var plan = z.looseObject({
1154
+ id: z.number().optional(),
1155
+ name: z.string().optional(),
1156
+ plan_code: z.string().optional(),
1157
+ description: z.string().nullable().optional(),
1158
+ amount: z.number().optional(),
1159
+ interval: z.string().optional(),
1160
+ currency: z.string().optional(),
1161
+ send_invoices: z.boolean().optional(),
1162
+ send_sms: z.boolean().optional(),
1163
+ hosted_page: z.boolean().optional(),
1164
+ integration: z.number().optional(),
1165
+ domain: z.string().optional(),
1166
+ created_at: z.string().optional(),
1167
+ updated_at: z.string().optional()
1168
+ });
1169
+ var createSubscriptionReq = z.object({
1170
+ /** Customer code or email. Required. */
1171
+ customer: z.string(),
1172
+ /** Plan code. Required. */
1173
+ plan: z.string(),
1174
+ /** Authorization code to charge (optional; defaults to the customer's). */
1175
+ authorization: z.string().optional(),
1176
+ start_date: z.string().optional()
1177
+ });
1178
+ var listSubscriptionsQuery = z.object({
1179
+ perPage: z.number().int().positive().optional(),
1180
+ page: z.number().int().positive().optional(),
1181
+ customer: z.number().int().optional(),
1182
+ plan: z.number().int().optional()
1183
+ });
1184
+ var toggleSubscriptionReq = z.object({
1185
+ /** Subscription code. Required. */
1186
+ code: z.string(),
1187
+ /** Email token from the subscription. Required. */
1188
+ token: z.string()
1189
+ });
1190
+ var subscription = z.looseObject({
1191
+ id: z.number().optional(),
1192
+ subscription_code: z.string().optional(),
1193
+ email_token: z.string().optional(),
1194
+ status: z.string().optional(),
1195
+ amount: z.number().optional(),
1196
+ quantity: z.number().optional(),
1197
+ customer: z.union([z.number(), z.looseObject({})]).optional(),
1198
+ plan: z.union([z.number(), z.looseObject({})]).optional(),
1199
+ authorization: z.looseObject({}).optional(),
1200
+ start: z.number().optional(),
1201
+ next_payment_date: z.string().nullable().optional(),
1202
+ created_at: z.string().optional(),
1203
+ updated_at: z.string().optional()
1204
+ });
1205
+
1206
+ // src/paystack/resources/plans.ts
1207
+ var planRes = paystackEnvelope(plan);
1208
+ var planListRes = paystackListEnvelope(plan);
1209
+ var Plans = class {
1210
+ constructor(http) {
1211
+ this.http = http;
1212
+ }
1213
+ http;
1214
+ /**
1215
+ * Create a plan. `amount` is KOBO minor units.
1216
+ *
1217
+ * Docs: https://paystack.com/docs/api/plan/#create
1218
+ *
1219
+ * @example
1220
+ * const res = await ps.paystack.plans.create({
1221
+ * name: "Monthly", amount: 500000, interval: "monthly",
1222
+ * });
1223
+ */
1224
+ async create(input) {
1225
+ const body = parseRequest(createPlanReq, input);
1226
+ return this.http.request({
1227
+ method: "POST",
1228
+ path: "/plan",
1229
+ body,
1230
+ schema: planRes
1231
+ });
1232
+ }
1233
+ /**
1234
+ * List plans.
1235
+ *
1236
+ * Docs: https://paystack.com/docs/api/plan/#list
1237
+ *
1238
+ * @example
1239
+ * const page = await ps.paystack.plans.list({ perPage: 50 });
1240
+ */
1241
+ async list(query = {}) {
1242
+ const q = parseRequest(listPlansQuery, query);
1243
+ return this.http.request({
1244
+ method: "GET",
1245
+ path: "/plan",
1246
+ query: q,
1247
+ schema: planListRes
1248
+ });
1249
+ }
1250
+ /**
1251
+ * Async iterator over ALL plans.
1252
+ *
1253
+ * Docs: https://paystack.com/docs/api/plan/#list
1254
+ *
1255
+ * @example
1256
+ * for await (const p of ps.paystack.plans.iterate()) console.log(p.plan_code);
1257
+ */
1258
+ async *iterate(query = {}) {
1259
+ const base = parseRequest(listPlansQuery, query);
1260
+ const perPage = base.perPage ?? 50;
1261
+ let page = base.page ?? 1;
1262
+ for (; ; ) {
1263
+ const res = await this.http.request({
1264
+ method: "GET",
1265
+ path: "/plan",
1266
+ query: { ...base, perPage, page },
1267
+ schema: planListRes
1268
+ });
1269
+ for (const p of res.data) yield p;
1270
+ const pageCount = metaNumber(res.meta?.pageCount);
1271
+ if (pageCount !== void 0) {
1272
+ if (page >= pageCount) return;
1273
+ } else if (res.data.length < perPage) {
1274
+ return;
1275
+ }
1276
+ page += 1;
1277
+ }
1278
+ }
1279
+ /**
1280
+ * Fetch a plan by id or plan code.
1281
+ *
1282
+ * Docs: https://paystack.com/docs/api/plan/#fetch
1283
+ *
1284
+ * @example
1285
+ * const res = await ps.paystack.plans.fetch("PLN_example");
1286
+ */
1287
+ async fetch(idOrCode) {
1288
+ const key = z.string().min(1).parse(String(idOrCode));
1289
+ return this.http.request({
1290
+ method: "GET",
1291
+ path: `/plan/${encodeURIComponent(key)}`,
1292
+ schema: planRes
1293
+ });
1294
+ }
1295
+ };
1296
+ var subscriptionRes = paystackEnvelope(subscription);
1297
+ var subscriptionListRes = paystackListEnvelope(subscription);
1298
+ var ackRes2 = paystackEnvelope(z.unknown());
1299
+ var Subscriptions = class {
1300
+ constructor(http) {
1301
+ this.http = http;
1302
+ }
1303
+ http;
1304
+ /**
1305
+ * Create a subscription binding a customer to a plan.
1306
+ *
1307
+ * Docs: https://paystack.com/docs/api/subscription/#create
1308
+ *
1309
+ * @example
1310
+ * const res = await ps.paystack.subscriptions.create({
1311
+ * customer: "CUS_example", plan: "PLN_example",
1312
+ * });
1313
+ */
1314
+ async create(input) {
1315
+ const body = parseRequest(createSubscriptionReq, input);
1316
+ return this.http.request({
1317
+ method: "POST",
1318
+ path: "/subscription",
1319
+ body,
1320
+ schema: subscriptionRes
1321
+ });
1322
+ }
1323
+ /**
1324
+ * List subscriptions.
1325
+ *
1326
+ * Docs: https://paystack.com/docs/api/subscription/#list
1327
+ *
1328
+ * @example
1329
+ * const page = await ps.paystack.subscriptions.list({ perPage: 50 });
1330
+ */
1331
+ async list(query = {}) {
1332
+ const q = parseRequest(listSubscriptionsQuery, query);
1333
+ return this.http.request({
1334
+ method: "GET",
1335
+ path: "/subscription",
1336
+ query: q,
1337
+ schema: subscriptionListRes
1338
+ });
1339
+ }
1340
+ /**
1341
+ * Async iterator over ALL subscriptions.
1342
+ *
1343
+ * Docs: https://paystack.com/docs/api/subscription/#list
1344
+ *
1345
+ * @example
1346
+ * for await (const s of ps.paystack.subscriptions.iterate()) console.log(s.subscription_code);
1347
+ */
1348
+ async *iterate(query = {}) {
1349
+ const base = parseRequest(listSubscriptionsQuery, query);
1350
+ const perPage = base.perPage ?? 50;
1351
+ let page = base.page ?? 1;
1352
+ for (; ; ) {
1353
+ const res = await this.http.request({
1354
+ method: "GET",
1355
+ path: "/subscription",
1356
+ query: { ...base, perPage, page },
1357
+ schema: subscriptionListRes
1358
+ });
1359
+ for (const s of res.data) yield s;
1360
+ const pageCount = metaNumber(res.meta?.pageCount);
1361
+ if (pageCount !== void 0) {
1362
+ if (page >= pageCount) return;
1363
+ } else if (res.data.length < perPage) {
1364
+ return;
1365
+ }
1366
+ page += 1;
1367
+ }
1368
+ }
1369
+ /**
1370
+ * Fetch a subscription by id or subscription code.
1371
+ *
1372
+ * Docs: https://paystack.com/docs/api/subscription/#fetch
1373
+ *
1374
+ * @example
1375
+ * const res = await ps.paystack.subscriptions.fetch("SUB_example");
1376
+ */
1377
+ async fetch(idOrCode) {
1378
+ const key = z.string().min(1).parse(String(idOrCode));
1379
+ return this.http.request({
1380
+ method: "GET",
1381
+ path: `/subscription/${encodeURIComponent(key)}`,
1382
+ schema: subscriptionRes
1383
+ });
1384
+ }
1385
+ /**
1386
+ * Enable a subscription (`code` + email `token`).
1387
+ *
1388
+ * Docs: https://paystack.com/docs/api/subscription/#enable
1389
+ *
1390
+ * @example
1391
+ * await ps.paystack.subscriptions.enable({ code: "SUB_example", token: "email_token" });
1392
+ */
1393
+ async enable(input) {
1394
+ const body = parseRequest(toggleSubscriptionReq, input);
1395
+ return this.http.request({
1396
+ method: "POST",
1397
+ path: "/subscription/enable",
1398
+ body,
1399
+ schema: ackRes2
1400
+ });
1401
+ }
1402
+ /**
1403
+ * Disable a subscription (`code` + email `token`).
1404
+ *
1405
+ * Docs: https://paystack.com/docs/api/subscription/#disable
1406
+ *
1407
+ * @example
1408
+ * await ps.paystack.subscriptions.disable({ code: "SUB_example", token: "email_token" });
1409
+ */
1410
+ async disable(input) {
1411
+ const body = parseRequest(toggleSubscriptionReq, input);
1412
+ return this.http.request({
1413
+ method: "POST",
1414
+ path: "/subscription/disable",
1415
+ body,
1416
+ schema: ackRes2
1417
+ });
1418
+ }
1419
+ };
1420
+
1421
+ // src/paystack/client.ts
1422
+ var PaystackClient = class {
1423
+ /** Shared HTTP client every resource is constructed with. */
1424
+ http;
1425
+ /** Transactions: initialize, verify, list/iterate, fetch, charge auth, etc. */
1426
+ transactions;
1427
+ /** Refunds: create, list, fetch. */
1428
+ refunds;
1429
+ /** Customers: create, list, fetch, update, validate, risk action. */
1430
+ customers;
1431
+ /** Verification / misc: banks, resolve account, countries, states, card BIN. */
1432
+ misc;
1433
+ /** Transfer recipients: create, list, fetch. */
1434
+ transferRecipients;
1435
+ /** Transfers: initiate, list, fetch, verify, balance. */
1436
+ transfers;
1437
+ /** Plans: create, list, fetch. */
1438
+ plans;
1439
+ /** Subscriptions: create, list, fetch, enable, disable. */
1440
+ subscriptions;
1441
+ constructor(http) {
1442
+ this.http = http;
1443
+ this.transactions = new Transactions(this.http);
1444
+ this.refunds = new Refunds(this.http);
1445
+ this.customers = new Customers(this.http);
1446
+ this.misc = new Misc(this.http);
1447
+ this.transferRecipients = new TransferRecipients(this.http);
1448
+ this.transfers = new Transfers(this.http);
1449
+ this.plans = new Plans(this.http);
1450
+ this.subscriptions = new Subscriptions(this.http);
1451
+ }
1452
+ };
1453
+ function paystackHttp(cfg) {
1454
+ if (!cfg.secretKey) {
1455
+ throw new PayweaveConfigError("Missing secret key for paystack.", { provider: "paystack" });
1456
+ }
1457
+ return new HttpClient({
1458
+ baseUrl: cfg.baseUrl,
1459
+ auth: bearer(cfg.secretKey),
1460
+ provider: "paystack",
1461
+ timeoutMs: cfg.timeoutMs,
1462
+ maxRetries: cfg.maxRetries,
1463
+ fetch: cfg.fetch,
1464
+ logger: cfg.logger
1465
+ });
1466
+ }
1467
+ defineProvider({
1468
+ id: "paystack",
1469
+ configKey: "paystack",
1470
+ configSchema: paystackProviderConfigSchema,
1471
+ environments: {
1472
+ // One host for both — Paystack's environment is key-derived, not host-derived.
1473
+ test: { baseUrl: PAYSTACK_BASE_URL },
1474
+ live: { baseUrl: PAYSTACK_BASE_URL }
1475
+ },
1476
+ inferEnvironment: (secretKey) => {
1477
+ try {
1478
+ return inferEnvironment("paystack", secretKey);
1479
+ } catch {
1480
+ return null;
1481
+ }
1482
+ },
1483
+ createHttp: paystackHttp,
1484
+ webhooks: {
1485
+ signatureHeader: "x-paystack-signature",
1486
+ verify: ({ rawBody, headers, secret }) => verifyPaystack(rawBody, readHeader(headers, "x-paystack-signature"), secret),
1487
+ parse: (rawBody) => {
1488
+ const root = JSON.parse(rawBody);
1489
+ return {
1490
+ type: typeof root.event === "string" ? root.event : "unknown",
1491
+ data: root.data,
1492
+ raw: root
1493
+ };
1494
+ },
1495
+ toUnified: (e) => ({
1496
+ provider: "paystack",
1497
+ type: e.type,
1498
+ unifiedType: toUnifiedEventType("paystack", void 0, e.type, e.data),
1499
+ data: e.data,
1500
+ raw: e.raw
1501
+ })
1502
+ }
1503
+ });
1504
+
1505
+ export { Customers, Misc, PaystackClient, Plans, Refunds, Subscriptions, Transactions, TransferRecipients, Transfers };
1506
+ //# sourceMappingURL=chunk-E633MKVX.js.map
1507
+ //# sourceMappingURL=chunk-E633MKVX.js.map