spaark-payapi-sdk 1.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.
@@ -0,0 +1,505 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { D as DepositRequest, a as DepositResponse, P as PayoutRequest, b as PayoutResponse, c as PaymentPageRequest, d as PaymentPageResponse, R as RefundRequest, e as RefundResponse, T as TransactionStatusResponse, f as PollOptions, g as TransactionFilters, A as ActionResponse, C as Currency, h as Correspondent, i as TransactionLimits, j as CorrespondentInfo, F as FailureReason } from './react-pjDvSSJA.mjs';
3
+ export { k as CORRESPONDENTS, l as CORRESPONDENT_INFO, m as CorrespondentFeature, n as DEFAULT_LIMITS, o as DepositFailureCode, p as FinancialAddress, M as MMOAccount, q as PawapayTestDashboard, r as PawapayTestDashboardProps, s as PayoutFailureCode, t as TransactionStatus } from './react-pjDvSSJA.mjs';
4
+ import 'react/jsx-runtime';
5
+
6
+ type Environment = 'sandbox' | 'production';
7
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
8
+ interface SpaarkPayApiSdkConfig {
9
+ apiKey: string;
10
+ environment: Environment;
11
+ baseUrl?: string;
12
+ callbackUrl?: string;
13
+ timeout?: number;
14
+ retries?: number;
15
+ retryDelay?: number;
16
+ logLevel?: LogLevel;
17
+ }
18
+ interface ResolvedConfig {
19
+ apiKey: string;
20
+ environment: Environment;
21
+ baseUrl: string;
22
+ callbackUrl?: string;
23
+ timeout: number;
24
+ retries: number;
25
+ retryDelay: number;
26
+ logLevel: LogLevel;
27
+ }
28
+
29
+ declare class Logger {
30
+ private readonly prefix;
31
+ private level;
32
+ constructor(prefix: string, level?: LogLevel);
33
+ setLevel(level: LogLevel): void;
34
+ private shouldLog;
35
+ private formatMessage;
36
+ private sanitize;
37
+ debug(message: string, data?: unknown): void;
38
+ info(message: string, data?: unknown): void;
39
+ warn(message: string, data?: unknown): void;
40
+ error(message: string, error?: Error | unknown): void;
41
+ }
42
+
43
+ interface HttpClientConfig {
44
+ baseUrl: string;
45
+ apiKey: string;
46
+ timeout: number;
47
+ retries: number;
48
+ retryDelay: number;
49
+ logger: Logger;
50
+ }
51
+ declare class HttpClient {
52
+ private readonly client;
53
+ private readonly logger;
54
+ private readonly retries;
55
+ private readonly retryDelay;
56
+ constructor(config: HttpClientConfig);
57
+ private setupInterceptors;
58
+ private handleError;
59
+ get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
60
+ post<T, D = unknown>(url: string, data?: D, config?: AxiosRequestConfig): Promise<T>;
61
+ put<T, D = unknown>(url: string, data?: D, config?: AxiosRequestConfig): Promise<T>;
62
+ delete<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
63
+ static fromConfig(config: ResolvedConfig, logger: Logger): HttpClient;
64
+ }
65
+
66
+ declare class TransactionsModule {
67
+ private readonly httpClient;
68
+ private readonly logger;
69
+ constructor(httpClient: HttpClient, logger: Logger);
70
+ /**
71
+ * Initiate a deposit (collect payment from mobile money user) - V2 API
72
+ */
73
+ initiateDeposit(request: DepositRequest): Promise<DepositResponse>;
74
+ /**
75
+ * Initiate a payout (send money to mobile money user) - V2 API
76
+ */
77
+ initiatePayout(request: PayoutRequest): Promise<PayoutResponse>;
78
+ /**
79
+ * Create a hosted payment page - V2 API
80
+ */
81
+ createPaymentPage(request: PaymentPageRequest): Promise<PaymentPageResponse>;
82
+ /**
83
+ * Refund a deposit
84
+ */
85
+ refund(request: RefundRequest): Promise<RefundResponse>;
86
+ /**
87
+ * Check deposit status - V2 API
88
+ */
89
+ checkDepositStatus(depositId: string): Promise<TransactionStatusResponse>;
90
+ /**
91
+ * Check payout status - V2 API
92
+ */
93
+ checkPayoutStatus(payoutId: string): Promise<TransactionStatusResponse>;
94
+ /**
95
+ * Check transaction status (tries deposit first, then payout) - V2 API
96
+ */
97
+ checkStatus(transactionId: string): Promise<TransactionStatusResponse>;
98
+ /**
99
+ * Poll until transaction reaches final status
100
+ */
101
+ pollUntilComplete(transactionId: string, options?: PollOptions): Promise<TransactionStatusResponse>;
102
+ /**
103
+ * List deposits with filters
104
+ */
105
+ listDeposits(filters?: TransactionFilters): Promise<DepositResponse[]>;
106
+ /**
107
+ * List payouts with filters
108
+ */
109
+ listPayouts(filters?: TransactionFilters): Promise<PayoutResponse[]>;
110
+ /**
111
+ * Resend deposit callback - V2 API
112
+ * Triggers a new callback for a deposit transaction
113
+ */
114
+ resendDepositCallback(depositId: string): Promise<ActionResponse>;
115
+ /**
116
+ * Resend payout callback - V2 API
117
+ * Triggers a new callback for a payout transaction
118
+ */
119
+ resendPayoutCallback(payoutId: string): Promise<ActionResponse>;
120
+ /**
121
+ * Cancel enqueued payout - V2 API
122
+ * Cancels a payout that is still in ENQUEUED status
123
+ */
124
+ cancelEnqueuedPayout(payoutId: string): Promise<ActionResponse>;
125
+ }
126
+
127
+ interface ProductCreateRequest {
128
+ name: string;
129
+ description?: string;
130
+ price: number;
131
+ currency: Currency;
132
+ metadata?: Record<string, unknown>;
133
+ }
134
+ interface Product {
135
+ id: string;
136
+ name: string;
137
+ description?: string;
138
+ price: number;
139
+ currency: string;
140
+ domains: string[];
141
+ created: string;
142
+ updated: string;
143
+ }
144
+ interface DomainAddRequest {
145
+ productId: string;
146
+ domain: string;
147
+ }
148
+
149
+ declare class ProductsModule {
150
+ private readonly logger;
151
+ private products;
152
+ constructor(logger: Logger);
153
+ create(request: ProductCreateRequest): Promise<Product>;
154
+ get(productId: string): Promise<Product>;
155
+ list(): Promise<Product[]>;
156
+ update(productId: string, updates: Partial<ProductCreateRequest>): Promise<Product>;
157
+ delete(productId: string): Promise<void>;
158
+ addDomain(request: DomainAddRequest): Promise<Product>;
159
+ removeDomain(productId: string, domain: string): Promise<Product>;
160
+ private toProduct;
161
+ }
162
+
163
+ type WebhookEventType = 'deposit.accepted' | 'deposit.completed' | 'deposit.failed' | 'payout.accepted' | 'payout.completed' | 'payout.failed' | 'refund.completed' | 'refund.failed';
164
+ interface PawapayWebhookEvent<T = unknown> {
165
+ eventId: string;
166
+ eventType: WebhookEventType;
167
+ timestamp: string;
168
+ data: T;
169
+ }
170
+ interface DepositCallbackData {
171
+ depositId: string;
172
+ status: 'COMPLETED' | 'FAILED';
173
+ amount: string;
174
+ currency: string;
175
+ correspondent: string;
176
+ payer: {
177
+ type: string;
178
+ address: {
179
+ value: string;
180
+ };
181
+ };
182
+ customerTimestamp: string;
183
+ created: string;
184
+ receivedByPayer?: string;
185
+ failureReason?: {
186
+ failureCode: string;
187
+ failureMessage: string;
188
+ };
189
+ metadata?: Record<string, unknown>;
190
+ }
191
+ interface PayoutCallbackData {
192
+ payoutId: string;
193
+ status: 'COMPLETED' | 'FAILED';
194
+ amount: string;
195
+ currency: string;
196
+ correspondent: string;
197
+ recipient: {
198
+ type: string;
199
+ address: {
200
+ value: string;
201
+ };
202
+ };
203
+ customerTimestamp: string;
204
+ created: string;
205
+ receivedByRecipient?: string;
206
+ failureReason?: {
207
+ failureCode: string;
208
+ failureMessage: string;
209
+ };
210
+ metadata?: Record<string, unknown>;
211
+ }
212
+
213
+ interface WebhooksConfig {
214
+ webhookSecret?: string;
215
+ }
216
+ declare class WebhooksModule {
217
+ private readonly httpClient;
218
+ private readonly logger;
219
+ private webhookSecret?;
220
+ constructor(httpClient: HttpClient, logger: Logger, config?: WebhooksConfig);
221
+ setWebhookSecret(secret: string): void;
222
+ verifySignature(payload: string, signature: string): boolean;
223
+ parseEvent<T = unknown>(payload: string): PawapayWebhookEvent<T>;
224
+ constructEvent<T = unknown>(payload: string, signature: string): PawapayWebhookEvent<T>;
225
+ registerCallback(url: string): Promise<void>;
226
+ unregisterCallback(): Promise<void>;
227
+ isDepositEvent(eventType: WebhookEventType): boolean;
228
+ isPayoutEvent(eventType: WebhookEventType): boolean;
229
+ isRefundEvent(eventType: WebhookEventType): boolean;
230
+ isSuccessEvent(eventType: WebhookEventType): boolean;
231
+ isFailureEvent(eventType: WebhookEventType): boolean;
232
+ }
233
+
234
+ type OperationType = 'DEPOSIT' | 'PAYOUT' | 'REFUND' | 'REMITTANCE';
235
+ type OperationStatus = 'OPERATIONAL' | 'DELAYED' | 'CLOSED';
236
+ interface ProviderOperationStatus {
237
+ operationType: OperationType;
238
+ status: OperationStatus;
239
+ }
240
+ interface ProviderAvailability {
241
+ provider: string;
242
+ operationTypes: ProviderOperationStatus[];
243
+ }
244
+ interface CountryAvailability {
245
+ country: string;
246
+ providers: ProviderAvailability[];
247
+ }
248
+ interface PredictProviderRequest {
249
+ phoneNumber: string;
250
+ }
251
+ interface PredictProviderResponse {
252
+ country: string;
253
+ provider: string;
254
+ phoneNumber: string;
255
+ }
256
+ interface ActiveConfigResponse {
257
+ companyName: string;
258
+ signatureConfiguration: {
259
+ signedRequestsOnly?: boolean;
260
+ signedCallbacks?: boolean;
261
+ };
262
+ countries: CountryConfig[];
263
+ }
264
+ interface CountryConfig {
265
+ country: string;
266
+ displayName: Record<string, string>;
267
+ prefix: string;
268
+ flag: string;
269
+ providers: ProviderConfig[];
270
+ }
271
+ interface ProviderConfig {
272
+ provider: string;
273
+ displayName: string;
274
+ nameDisplayedToCustomer: string;
275
+ currencies: CurrencyConfig[];
276
+ }
277
+ interface CurrencyConfig {
278
+ currency: string;
279
+ displayName: string;
280
+ operationTypes: {
281
+ DEPOSIT?: OperationTypeConfig;
282
+ PAYOUT?: OperationTypeConfig;
283
+ REFUND?: OperationTypeConfig;
284
+ REMITTANCE?: OperationTypeConfig;
285
+ USSD_DEPOSIT?: {
286
+ callbackUrl?: string;
287
+ };
288
+ };
289
+ }
290
+ interface OperationTypeConfig {
291
+ minAmount?: string;
292
+ maxAmount?: string;
293
+ decimalsInAmount?: 'TWO_PLACES' | 'NONE';
294
+ status?: OperationStatus;
295
+ callbackUrl?: string;
296
+ authorisationType?: string;
297
+ authorisationInstructions?: Record<string, string>;
298
+ }
299
+ interface PublicKeyResponse {
300
+ id: string;
301
+ key: string;
302
+ }
303
+
304
+ interface MMOAvailability {
305
+ correspondent: Correspondent;
306
+ available: boolean;
307
+ degraded: boolean;
308
+ estimatedRecovery?: string;
309
+ message?: string;
310
+ }
311
+ declare class UtilsModule {
312
+ private readonly httpClient;
313
+ private readonly logger;
314
+ constructor(httpClient: HttpClient, logger: Logger);
315
+ generateTransactionId(): string;
316
+ validateTransactionId(id: string): boolean;
317
+ /**
318
+ * Get active configuration - V2 API
319
+ * Returns your account configuration including countries, providers, and limits
320
+ */
321
+ getActiveConfiguration(options?: {
322
+ country?: string;
323
+ operationType?: OperationType;
324
+ }): Promise<ActiveConfigResponse>;
325
+ /**
326
+ * Get provider availability - V2 API
327
+ * Returns current processing status for all providers
328
+ */
329
+ getProviderAvailability(options?: {
330
+ country?: string;
331
+ operationType?: OperationType;
332
+ }): Promise<CountryAvailability[]>;
333
+ /**
334
+ * Predict provider from phone number - V2 API
335
+ * Returns the predicted provider and sanitized phone number
336
+ */
337
+ predictProvider(phoneNumber: string): Promise<PredictProviderResponse>;
338
+ /**
339
+ * Get public keys for callback verification - V2 API
340
+ */
341
+ getPublicKeys(): Promise<PublicKeyResponse[]>;
342
+ getTransactionLimits(correspondent: Correspondent): Promise<TransactionLimits>;
343
+ checkMMOAvailability(correspondent: Correspondent): Promise<MMOAvailability>;
344
+ formatPhoneNumber(phone: string, countryCode: string): string;
345
+ validatePhoneNumber(phone: string, correspondent: Correspondent): boolean;
346
+ getSupportedCorrespondents(): readonly Correspondent[];
347
+ getCorrespondentInfo(correspondent: Correspondent): CorrespondentInfo;
348
+ getAllCorrespondentsInfo(): CorrespondentInfo[];
349
+ detectCorrespondent(phone: string): Correspondent | null;
350
+ }
351
+
352
+ interface WalletBalance {
353
+ country: string;
354
+ balance: string;
355
+ currency: string;
356
+ provider?: string;
357
+ }
358
+ interface WalletBalancesResponse {
359
+ balances: WalletBalance[];
360
+ }
361
+ interface StatementWallet {
362
+ country: string;
363
+ currency: string;
364
+ provider?: string;
365
+ }
366
+ interface StatementRequest {
367
+ wallet: StatementWallet;
368
+ callbackUrl: string;
369
+ startDate: string;
370
+ endDate: string;
371
+ compressed?: boolean;
372
+ }
373
+ type StatementStatus = 'PROCESSING' | 'COMPLETED' | 'FAILED';
374
+ interface StatementResponse {
375
+ status: 'ACCEPTED' | 'REJECTED';
376
+ statementId?: string;
377
+ created?: string;
378
+ failureReason?: {
379
+ failureCode: StatementFailureCode;
380
+ failureMessage?: string;
381
+ };
382
+ }
383
+ type StatementFailureCode = 'NO_AUTHENTICATION' | 'AUTHENTICATION_ERROR' | 'AUTHORISATION_ERROR' | 'INVALID_INPUT' | 'MISSING_PARAMETER' | 'UNSUPPORTED_PARAMETER' | 'INVALID_PARAMETER' | 'INVALID_CALLBACK_URL' | 'INVALID_DATE_RANGE' | 'WALLET_NOT_FOUND' | 'UNKNOWN_ERROR';
384
+ interface StatementStatusResponse {
385
+ status: 'FOUND' | 'NOT_FOUND';
386
+ data?: StatementData;
387
+ }
388
+ interface StatementData {
389
+ statementId: string;
390
+ status: StatementStatus;
391
+ wallet: StatementWallet;
392
+ created: string;
393
+ startDate: string;
394
+ endDate: string;
395
+ fileSize?: number;
396
+ downloadUrl?: string;
397
+ downloadUrlExpiresAt?: string;
398
+ completedAt?: string;
399
+ failedAt?: string;
400
+ failureReason?: {
401
+ failureCode: 'UNKNOWN_ERROR';
402
+ failureMessage?: string;
403
+ };
404
+ }
405
+ interface StatementCallbackData {
406
+ statementId: string;
407
+ status: StatementStatus;
408
+ wallet: StatementWallet;
409
+ created: string;
410
+ startDate: string;
411
+ endDate: string;
412
+ fileSize?: number;
413
+ downloadUrl?: string;
414
+ downloadUrlExpiresAt?: string;
415
+ completedAt?: string;
416
+ failedAt?: string;
417
+ failureReason?: {
418
+ failureCode: 'UNKNOWN_ERROR';
419
+ failureMessage?: string;
420
+ };
421
+ }
422
+
423
+ declare class FinancesModule {
424
+ private readonly httpClient;
425
+ private readonly logger;
426
+ constructor(httpClient: HttpClient, logger: Logger);
427
+ /**
428
+ * Get wallet balances - V2 API
429
+ * Returns balances for all wallets configured on your account
430
+ */
431
+ getWalletBalances(): Promise<WalletBalance[]>;
432
+ /**
433
+ * Generate a statement for a wallet - V2 API
434
+ * The statement can be downloaded from the callback URL or checked via status endpoint
435
+ */
436
+ generateStatement(request: StatementRequest): Promise<StatementResponse>;
437
+ /**
438
+ * Check statement status - V2 API
439
+ */
440
+ checkStatementStatus(statementId: string): Promise<StatementData>;
441
+ /**
442
+ * Poll until statement is ready
443
+ */
444
+ pollStatementUntilComplete(statementId: string, options?: {
445
+ interval?: number;
446
+ maxAttempts?: number;
447
+ }): Promise<StatementData>;
448
+ }
449
+
450
+ declare class SpaarkPayApiSdk {
451
+ private readonly config;
452
+ private readonly logger;
453
+ private readonly httpClient;
454
+ readonly transactions: TransactionsModule;
455
+ readonly products: ProductsModule;
456
+ readonly webhooks: WebhooksModule;
457
+ readonly utils: UtilsModule;
458
+ readonly finances: FinancesModule;
459
+ constructor(config: SpaarkPayApiSdkConfig);
460
+ private getWebhookSecretFromEnv;
461
+ getConfig(): Readonly<ResolvedConfig>;
462
+ setLogLevel(level: LogLevel): void;
463
+ setWebhookSecret(secret: string): void;
464
+ }
465
+
466
+ declare const ERROR_CODES: {
467
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
468
+ readonly INVALID_PHONE: "INVALID_PHONE";
469
+ readonly INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS";
470
+ readonly AMOUNT_TOO_LOW: "AMOUNT_TOO_LOW";
471
+ readonly AMOUNT_TOO_HIGH: "AMOUNT_TOO_HIGH";
472
+ readonly LIMIT_EXCEEDED: "LIMIT_EXCEEDED";
473
+ readonly DUPLICATE: "DUPLICATE";
474
+ readonly MMO_UNAVAILABLE: "MMO_UNAVAILABLE";
475
+ readonly TIMEOUT: "TIMEOUT";
476
+ readonly UNAUTHORIZED: "UNAUTHORIZED";
477
+ readonly RATE_LIMITED: "RATE_LIMITED";
478
+ readonly SERVER_ERROR: "SERVER_ERROR";
479
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
480
+ readonly NOT_FOUND: "NOT_FOUND";
481
+ readonly REFUND_NOT_ALLOWED: "REFUND_NOT_ALLOWED";
482
+ };
483
+ type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
484
+
485
+ declare class PawapayError extends Error {
486
+ readonly code: ErrorCode;
487
+ readonly statusCode: number;
488
+ readonly failureReason?: FailureReason;
489
+ readonly retryable: boolean;
490
+ readonly originalError?: Error;
491
+ constructor(message: string, code: ErrorCode, statusCode: number, options?: {
492
+ failureReason?: FailureReason;
493
+ retryable?: boolean;
494
+ originalError?: Error;
495
+ });
496
+ static fromPawapayResponse(pawapayCode: string, message?: string, originalError?: Error): PawapayError;
497
+ static validation(message: string): PawapayError;
498
+ static network(message: string, originalError?: Error): PawapayError;
499
+ static timeout(message?: string): PawapayError;
500
+ static unauthorized(message?: string): PawapayError;
501
+ static notFound(message?: string): PawapayError;
502
+ toJSON(): Record<string, unknown>;
503
+ }
504
+
505
+ export { ActionResponse, type ActiveConfigResponse, Correspondent, CorrespondentInfo, type CountryAvailability, type CountryConfig, Currency, type CurrencyConfig, type DepositCallbackData, DepositRequest, DepositResponse, type DomainAddRequest, ERROR_CODES, type Environment, type ErrorCode, FailureReason, type LogLevel, Logger, type MMOAvailability, type OperationStatus, type OperationType, type OperationTypeConfig, PawapayError, type PawapayWebhookEvent, PaymentPageRequest, PaymentPageResponse, type PayoutCallbackData, PayoutRequest, PayoutResponse, PollOptions, type PredictProviderRequest, type PredictProviderResponse, type Product, type ProductCreateRequest, type ProviderAvailability, type ProviderConfig, type ProviderOperationStatus, type PublicKeyResponse, RefundRequest, RefundResponse, type ResolvedConfig, SpaarkPayApiSdk, type SpaarkPayApiSdkConfig, type StatementCallbackData, type StatementData, type StatementFailureCode, type StatementRequest, type StatementResponse, type StatementStatus, type StatementStatusResponse, type StatementWallet, TransactionFilters, TransactionLimits, TransactionStatusResponse, type WalletBalance, type WalletBalancesResponse, type WebhookEventType };