@ngandu-dev/flexpay 2.0.5 → 3.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.
- package/README.md +175 -125
- package/UPGRADE_3.0.0.md +345 -0
- package/dist/index.d.mts +186 -118
- package/dist/index.d.ts +186 -118
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,163 +1,231 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
getCheckStatusUrl(orderNumber: string): string;
|
|
17
|
-
getCardPaymentUrl(): string;
|
|
18
|
-
private getBaseUrl;
|
|
19
|
-
}
|
|
3
|
+
declare const BaseUrlSchema: z.ZodReadonly<z.ZodObject<{
|
|
4
|
+
payment: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
5
|
+
check: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
6
|
+
payout: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
7
|
+
}, z.core.$strict>>;
|
|
8
|
+
/** Three explicit versioned endpoint prefixes, without the service path. */
|
|
9
|
+
type BaseUrl = z.infer<typeof BaseUrlSchema>;
|
|
10
|
+
declare const productionBaseUrl: BaseUrl;
|
|
11
|
+
declare const CredentialSchema: z.ZodReadonly<z.ZodObject<{
|
|
12
|
+
merchant: z.ZodString;
|
|
13
|
+
token: z.ZodString;
|
|
14
|
+
}, z.core.$strict>>;
|
|
15
|
+
type Credential = z.infer<typeof CredentialSchema>;
|
|
20
16
|
|
|
21
|
-
declare enum Status {
|
|
22
|
-
SUCCESS = 0,// When the request is successfully processed
|
|
23
|
-
FAILURE = 1
|
|
24
|
-
}
|
|
25
17
|
declare const CurrencySchema: z.ZodEnum<{
|
|
26
18
|
USD: "USD";
|
|
27
19
|
CDF: "CDF";
|
|
28
20
|
}>;
|
|
29
21
|
type Currency = z.infer<typeof CurrencySchema>;
|
|
30
|
-
declare const
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
declare const MobileRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
23
|
+
amount: z.ZodNumber;
|
|
24
|
+
currency: z.ZodEnum<{
|
|
25
|
+
USD: "USD";
|
|
26
|
+
CDF: "CDF";
|
|
27
|
+
}>;
|
|
28
|
+
reference: z.ZodString;
|
|
29
|
+
callbackUrl: z.ZodString;
|
|
30
|
+
phone: z.ZodString;
|
|
31
|
+
}, z.core.$strict>>;
|
|
32
|
+
declare const CardRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
33
|
+
amount: z.ZodNumber;
|
|
34
|
+
currency: z.ZodEnum<{
|
|
35
|
+
USD: "USD";
|
|
36
|
+
CDF: "CDF";
|
|
37
|
+
}>;
|
|
38
|
+
reference: z.ZodString;
|
|
39
|
+
callbackUrl: z.ZodString;
|
|
40
|
+
approveUrl: z.ZodString;
|
|
41
|
+
cancelUrl: z.ZodString;
|
|
42
|
+
declineUrl: z.ZodString;
|
|
43
|
+
}, z.core.$strict>>;
|
|
44
|
+
declare const PayoutRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
45
|
+
amount: z.ZodNumber;
|
|
46
|
+
currency: z.ZodEnum<{
|
|
47
|
+
USD: "USD";
|
|
48
|
+
CDF: "CDF";
|
|
49
|
+
}>;
|
|
50
|
+
reference: z.ZodString;
|
|
51
|
+
callbackUrl: z.ZodString;
|
|
52
|
+
phone: z.ZodString;
|
|
53
|
+
}, z.core.$strict>>;
|
|
54
|
+
type MobileRequest = z.infer<typeof MobileRequestSchema>;
|
|
55
|
+
type CardRequest = z.infer<typeof CardRequestSchema>;
|
|
56
|
+
type PayoutRequest = z.infer<typeof PayoutRequestSchema>;
|
|
57
|
+
|
|
58
|
+
/** A provider result code. Unknown integer codes retain their value without an inferred state. */
|
|
59
|
+
declare class Status {
|
|
60
|
+
readonly value: number;
|
|
61
|
+
constructor(value: number);
|
|
62
|
+
isSuccessful(): boolean;
|
|
63
|
+
isFailure(): boolean;
|
|
64
|
+
}
|
|
65
|
+
declare const StatusSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodInt, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodInt>]>, z.ZodTransform<Status, number>>;
|
|
66
|
+
|
|
67
|
+
declare const MobileResponseSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
68
|
+
code: z.ZodPipe<z.ZodUnion<readonly [z.ZodInt, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodInt>]>, z.ZodTransform<Status, number>>;
|
|
33
69
|
message: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
34
|
-
orderNumber: z.ZodOptional<z.
|
|
35
|
-
provider_reference: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
36
|
-
providerReference: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
37
|
-
reference: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
38
|
-
url: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
70
|
+
orderNumber: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
39
71
|
}, z.core.$strip>, z.ZodTransform<{
|
|
72
|
+
accepted: boolean;
|
|
73
|
+
code: Status;
|
|
74
|
+
message: string;
|
|
75
|
+
orderNumber: string | null;
|
|
76
|
+
}, {
|
|
77
|
+
code: Status;
|
|
78
|
+
message: string;
|
|
79
|
+
orderNumber: string | null;
|
|
80
|
+
}>>>;
|
|
81
|
+
declare const CardResponseSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
82
|
+
code: z.ZodPipe<z.ZodUnion<readonly [z.ZodInt, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodInt>]>, z.ZodTransform<Status, number>>;
|
|
83
|
+
message: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
84
|
+
orderNumber: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
85
|
+
url: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
86
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
87
|
+
accepted: boolean;
|
|
40
88
|
code: Status;
|
|
41
89
|
message: string;
|
|
42
90
|
orderNumber: string | null;
|
|
43
|
-
providerReference: string | null;
|
|
44
|
-
reference: string | null;
|
|
45
91
|
url: string | null;
|
|
46
92
|
}, {
|
|
47
93
|
code: Status;
|
|
48
94
|
message: string;
|
|
49
|
-
orderNumber
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
95
|
+
orderNumber: string | null;
|
|
96
|
+
url: string | null;
|
|
97
|
+
}>>>;
|
|
98
|
+
declare const PayoutResponseSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
99
|
+
code: z.ZodPipe<z.ZodUnion<readonly [z.ZodInt, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodInt>]>, z.ZodTransform<Status, number>>;
|
|
100
|
+
message: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
101
|
+
orderNumber: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
102
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
103
|
+
accepted: boolean;
|
|
104
|
+
code: Status;
|
|
105
|
+
message: string;
|
|
106
|
+
orderNumber: string | null;
|
|
107
|
+
}, {
|
|
108
|
+
code: Status;
|
|
109
|
+
message: string;
|
|
110
|
+
orderNumber: string | null;
|
|
111
|
+
}>>>;
|
|
112
|
+
declare const CallbackResponseSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
113
|
+
code: z.ZodPipe<z.ZodUnion<readonly [z.ZodInt, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodInt>]>, z.ZodTransform<Status, number>>;
|
|
57
114
|
message: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
58
|
-
orderNumber: z.ZodOptional<z.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
115
|
+
orderNumber: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
116
|
+
reference: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
117
|
+
provider_reference: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
118
|
+
amount: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>]>>>>;
|
|
119
|
+
amountCustomer: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>]>>>>;
|
|
120
|
+
phone: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
121
|
+
currency: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
122
|
+
USD: "USD";
|
|
123
|
+
CDF: "CDF";
|
|
124
|
+
}>>>>;
|
|
125
|
+
createdAt: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
126
|
+
channel: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
127
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
128
|
+
code: Status;
|
|
129
|
+
successful: boolean;
|
|
130
|
+
message: string;
|
|
131
|
+
orderNumber: string | null;
|
|
132
|
+
reference: string | null;
|
|
133
|
+
providerReference: string | null;
|
|
134
|
+
amount: number | null;
|
|
135
|
+
amountCustomer: number | null;
|
|
136
|
+
phone: string | null;
|
|
137
|
+
currency: "USD" | "CDF" | null;
|
|
138
|
+
createdAt: string | null;
|
|
139
|
+
channel: string | null;
|
|
140
|
+
}, {
|
|
141
|
+
code: Status;
|
|
142
|
+
message: string;
|
|
143
|
+
orderNumber: string | null;
|
|
144
|
+
reference: string | null;
|
|
145
|
+
provider_reference: string | null;
|
|
146
|
+
amount: number | null;
|
|
147
|
+
amountCustomer: number | null;
|
|
148
|
+
phone: string | null;
|
|
149
|
+
currency: "USD" | "CDF" | null;
|
|
150
|
+
createdAt: string | null;
|
|
151
|
+
channel: string | null;
|
|
152
|
+
}>>>;
|
|
153
|
+
declare const TransactionSchema: z.ZodReadonly<z.ZodObject<{
|
|
62
154
|
amount: z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>]>;
|
|
63
155
|
amountCustomer: z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>]>;
|
|
64
|
-
channel: z.ZodOptional<z.
|
|
156
|
+
channel: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
65
157
|
createdAt: z.ZodString;
|
|
66
158
|
currency: z.ZodEnum<{
|
|
67
159
|
USD: "USD";
|
|
68
160
|
CDF: "CDF";
|
|
69
161
|
}>;
|
|
70
|
-
orderNumber: z.ZodOptional<z.
|
|
162
|
+
orderNumber: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
71
163
|
reference: z.ZodString;
|
|
72
|
-
status: z.ZodPipe<z.ZodUnion<readonly [z.
|
|
73
|
-
}, z.core.$strip
|
|
74
|
-
declare const CheckResponseSchema: z.ZodObject<{
|
|
75
|
-
code: z.ZodPipe<z.ZodUnion<readonly [z.
|
|
164
|
+
status: z.ZodPipe<z.ZodUnion<readonly [z.ZodInt, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodInt>]>, z.ZodTransform<Status, number>>;
|
|
165
|
+
}, z.core.$strip>>;
|
|
166
|
+
declare const CheckResponseSchema: z.ZodReadonly<z.ZodPipe<z.ZodObject<{
|
|
167
|
+
code: z.ZodPipe<z.ZodUnion<readonly [z.ZodInt, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodInt>]>, z.ZodTransform<Status, number>>;
|
|
76
168
|
message: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
77
|
-
transaction: z.ZodDefault<z.ZodOptional<z.
|
|
169
|
+
transaction: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
78
170
|
amount: z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>]>;
|
|
79
171
|
amountCustomer: z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>]>;
|
|
80
|
-
channel: z.ZodOptional<z.
|
|
172
|
+
channel: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
81
173
|
createdAt: z.ZodString;
|
|
82
174
|
currency: z.ZodEnum<{
|
|
83
175
|
USD: "USD";
|
|
84
176
|
CDF: "CDF";
|
|
85
177
|
}>;
|
|
86
|
-
orderNumber: z.ZodOptional<z.
|
|
178
|
+
orderNumber: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
87
179
|
reference: z.ZodString;
|
|
88
|
-
status: z.ZodPipe<z.ZodUnion<readonly [z.
|
|
89
|
-
}, z.core.$strip
|
|
90
|
-
}, z.core.$strip
|
|
91
|
-
|
|
92
|
-
code:
|
|
93
|
-
message:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}>;
|
|
119
|
-
declineUrl: z.ZodString;
|
|
120
|
-
description: z.ZodString;
|
|
121
|
-
homeUrl: z.ZodString;
|
|
122
|
-
reference: z.ZodString;
|
|
123
|
-
}, z.core.$strip>;
|
|
124
|
-
declare const PayoutRequestSchema: z.ZodObject<{
|
|
125
|
-
amount: z.ZodNumber;
|
|
126
|
-
callbackUrl: z.ZodString;
|
|
127
|
-
currency: z.ZodEnum<{
|
|
128
|
-
USD: "USD";
|
|
129
|
-
CDF: "CDF";
|
|
130
|
-
}>;
|
|
131
|
-
phone: z.ZodString;
|
|
132
|
-
reference: z.ZodString;
|
|
133
|
-
}, z.core.$strip>;
|
|
180
|
+
status: z.ZodPipe<z.ZodUnion<readonly [z.ZodInt, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodInt>]>, z.ZodTransform<Status, number>>;
|
|
181
|
+
}, z.core.$strip>>>>>;
|
|
182
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
183
|
+
successful: boolean;
|
|
184
|
+
code: Status;
|
|
185
|
+
message: string;
|
|
186
|
+
transaction: Readonly<{
|
|
187
|
+
amount: number;
|
|
188
|
+
amountCustomer: number;
|
|
189
|
+
channel: string | null;
|
|
190
|
+
createdAt: string;
|
|
191
|
+
currency: "USD" | "CDF";
|
|
192
|
+
orderNumber: string | null;
|
|
193
|
+
reference: string;
|
|
194
|
+
status: Status;
|
|
195
|
+
}> | null;
|
|
196
|
+
}, {
|
|
197
|
+
code: Status;
|
|
198
|
+
message: string;
|
|
199
|
+
transaction: Readonly<{
|
|
200
|
+
amount: number;
|
|
201
|
+
amountCustomer: number;
|
|
202
|
+
channel: string | null;
|
|
203
|
+
createdAt: string;
|
|
204
|
+
currency: "USD" | "CDF";
|
|
205
|
+
orderNumber: string | null;
|
|
206
|
+
reference: string;
|
|
207
|
+
status: Status;
|
|
208
|
+
}> | null;
|
|
209
|
+
}>>>;
|
|
134
210
|
type MobileResponse = z.infer<typeof MobileResponseSchema>;
|
|
135
211
|
type CardResponse = z.infer<typeof CardResponseSchema>;
|
|
212
|
+
type PayoutResponse = z.infer<typeof PayoutResponseSchema>;
|
|
213
|
+
type CallbackResponse = z.infer<typeof CallbackResponseSchema>;
|
|
136
214
|
type Transaction = z.infer<typeof TransactionSchema>;
|
|
137
215
|
type CheckResponse = z.infer<typeof CheckResponseSchema>;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
type CardRequest = z.infer<typeof CardRequestSchema>;
|
|
141
|
-
type PayoutRequest = z.infer<typeof PayoutRequestSchema>;
|
|
216
|
+
/** Parses a provider callback; it does not authenticate its sender. */
|
|
217
|
+
declare function parseCallback(data: unknown): CallbackResponse;
|
|
142
218
|
|
|
219
|
+
/** Coordinates explicit payment operations using validated configuration and the HTTP transport. */
|
|
143
220
|
declare class Client {
|
|
144
|
-
private readonly
|
|
145
|
-
private readonly
|
|
146
|
-
|
|
221
|
+
private readonly merchant;
|
|
222
|
+
private readonly baseUrl;
|
|
223
|
+
private readonly transport;
|
|
224
|
+
constructor(credential: Credential, baseUrl: BaseUrl, fetch?: typeof globalThis.fetch);
|
|
147
225
|
mobile(request: MobileRequest): Promise<MobileResponse>;
|
|
148
226
|
card(request: CardRequest): Promise<CardResponse>;
|
|
149
|
-
pay(request: MobileRequest): Promise<MobileResponse>;
|
|
150
|
-
pay(request: CardRequest): Promise<CardResponse>;
|
|
151
|
-
check(orderNumber: string): Promise<CheckResponse>;
|
|
152
227
|
payout(request: PayoutRequest): Promise<PayoutResponse>;
|
|
153
|
-
|
|
154
|
-
isSuccessful<T extends {
|
|
155
|
-
code: Status;
|
|
156
|
-
}>(response: T): response is T & {
|
|
157
|
-
code: Status.SUCCESS;
|
|
158
|
-
};
|
|
159
|
-
private requestJson;
|
|
160
|
-
private parseWith;
|
|
228
|
+
check(orderNumber: string): Promise<CheckResponse>;
|
|
161
229
|
}
|
|
162
230
|
|
|
163
231
|
declare class NetworkException extends Error {
|
|
@@ -173,4 +241,4 @@ declare class ClientException extends NetworkException {
|
|
|
173
241
|
declare class ServerException extends NetworkException {
|
|
174
242
|
}
|
|
175
243
|
|
|
176
|
-
export { AccountException, type
|
|
244
|
+
export { AccountException, type BaseUrl, BaseUrlSchema, type CallbackResponse, CallbackResponseSchema, type CardRequest, CardRequestSchema, type CardResponse, CardResponseSchema, type CheckResponse, CheckResponseSchema, Client, ClientException, type Credential, CredentialSchema, type Currency, CurrencySchema, type MobileRequest, MobileRequestSchema, type MobileResponse, MobileResponseSchema, NetworkException, type PayoutRequest, PayoutRequestSchema, type PayoutResponse, PayoutResponseSchema, ServerException, Status, StatusSchema, type Transaction, TransactionSchema, parseCallback, productionBaseUrl };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var j=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(e,t)=>{for(var r in t)j(e,r,{get:t[r],enumerable:!0})},X=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Q(t))!V.call(e,o)&&o!==r&&j(e,o,{get:()=>t[o],enumerable:!(n=K(t,o))||n.enumerable});return e};var Y=e=>X(j({},"__esModule",{value:!0}),e);var ne={};W(ne,{AccountException:()=>S,BaseUrlSchema:()=>C,CallbackResponseSchema:()=>A,CardRequestSchema:()=>T,CardResponseSchema:()=>q,CheckResponseSchema:()=>B,Client:()=>$,ClientException:()=>x,CredentialSchema:()=>k,CurrencySchema:()=>y,MobileRequestSchema:()=>P,MobileResponseSchema:()=>z,NetworkException:()=>c,PayoutRequestSchema:()=>w,PayoutResponseSchema:()=>M,ServerException:()=>g,Status:()=>R,StatusSchema:()=>u,TransactionSchema:()=>v,parseCallback:()=>Z,productionBaseUrl:()=>D});module.exports=Y(ne);var d=require("zod"),E=d.z.string().transform(e=>e.trim().replace(/\/+$/,"")).refine(ee,"Base URLs must be absolute HTTP(S) URLs without credentials, query, or fragment"),C=d.z.strictObject({payment:E,check:E,payout:E}).readonly(),D=Object.freeze({payment:"https://corporateapi.flexpay.cd/api/rest/v1",check:"https://apicheck.flexpaie.com/api/rest/v1",payout:"https://backend.flexpay.cd/api/rest/v1"}),k=d.z.strictObject({merchant:d.z.string().refine(e=>e.trim()!=="","Merchant cannot be empty"),token:d.z.string().refine(e=>e.trim()!=="","The authorization token cannot be empty")}).readonly();function ee(e){try{let t=new URL(e);return/^https?:\/\//i.test(e)&&!!t.hostname&&!t.username&&!t.password&&!e.includes("?")&&!e.includes("#")&&!/[\s\p{Cc}]/u.test(e)&&!e.includes("\\")}catch{return!1}}var i=require("zod"),y=i.z.enum(["USD","CDF"]),N=i.z.strictObject({amount:i.z.number().finite().gt(0,"The transaction amount should be greater than 0"),currency:y,reference:i.z.string().refine(e=>e.trim()!=="","The transaction reference is mandatory"),callbackUrl:i.z.string().refine(e=>e.trim()!=="","The callback URL must be provided")}),P=N.extend({phone:i.z.string().regex(/^\d{12}$/,"The phone number must contain 12 digits, eg: 243123456789")}).readonly(),T=N.extend({approveUrl:i.z.string().refine(e=>e.trim()!=="","The redirect URL must be provided"),cancelUrl:i.z.string().refine(e=>e.trim()!=="","The redirect URL must be provided"),declineUrl:i.z.string().refine(e=>e.trim()!=="","The redirect URL must be provided")}).readonly(),w=N.extend({phone:i.z.string().regex(/^\d{12}$/,"The phone number must contain 12 digits, eg: 243123456789")}).readonly();function G(e,t){return{merchant:t,type:"1",amount:e.amount,currency:e.currency,phone:e.phone,reference:e.reference,callback_url:e.callbackUrl}}function H(e,t){return{merchant:t,type:"2",amount:e.amount,currency:e.currency,reference:e.reference,callback_url:e.callbackUrl,approve_url:e.approveUrl,cancel_url:e.cancelUrl,decline_url:e.declineUrl}}function I(e,t){return{merchant:t,type:1,amount:e.amount,currency:e.currency,phone:e.phone,reference:e.reference,callbackUrl:e.callbackUrl}}var a=require("zod");var b=require("zod"),R=class{value;constructor(t){if(!Number.isSafeInteger(t))throw new RangeError("Status must be a safe integer");this.value=t,Object.freeze(this)}isSuccessful(){return this.value===0}isFailure(){return this.value===1}},u=b.z.union([b.z.int(),b.z.string().regex(/^(0|-?[1-9]\d*)$/).transform(Number).pipe(b.z.int())]).transform(e=>new R(e));var U=a.z.union([a.z.number().finite(),a.z.string().trim().min(1).transform(Number).pipe(a.z.number().finite())]),l=a.z.string().nullable().optional().default(null),_=a.z.object({code:u,message:a.z.string().optional().default(""),orderNumber:l}),z=_.transform(e=>({...e,accepted:e.code.isSuccessful()})).readonly(),q=_.extend({url:l}).transform(e=>({...e,accepted:e.code.isSuccessful()})).readonly(),M=_.transform(e=>({...e,accepted:e.code.isSuccessful()})).readonly(),A=a.z.object({code:u,message:a.z.string().optional().default(""),orderNumber:l,reference:l,provider_reference:l,amount:U.nullable().optional().default(null),amountCustomer:U.nullable().optional().default(null),phone:l,currency:y.nullable().optional().default(null),createdAt:l,channel:l}).transform(e=>({code:e.code,successful:e.code.isSuccessful(),message:e.message,orderNumber:e.orderNumber,reference:e.reference,providerReference:e.provider_reference,amount:e.amount,amountCustomer:e.amountCustomer,phone:e.phone,currency:e.currency,createdAt:e.createdAt,channel:e.channel})).readonly(),v=a.z.object({amount:U,amountCustomer:U,channel:l,createdAt:a.z.string(),currency:y,orderNumber:l,reference:a.z.string(),status:u}).readonly(),B=a.z.object({code:u,message:a.z.string().optional().default(""),transaction:v.nullable().optional().default(null)}).transform(e=>({...e,successful:e.code.isSuccessful()&&e.transaction?.status.isSuccessful()===!0})).readonly();function Z(e){return A.parse(e)}var c=class e extends Error{status;type;constructor(t,r,n){let o=n!=null?`${t} (HTTP ${n}/${r??"unknown"})`:t;super(o),this.name=this.constructor.name,this.status=n??void 0,this.type=r??void 0,Object.setPrototypeOf(this,new.target.prototype)}static create(t,r,n){let o=t.trim()===""?"No message was provided":t;return n===401||n===429?new S(o,r,n):n>=400&&n<=499?new x(o,r,n):n>=500&&n<=599?new g(o,r,n):new e(o,r,n)}},S=class extends c{},x=class extends c{},g=class extends c{};var O=class{constructor(t,r){this.token=t;this.fetch=r}token;fetch;async request(t,r,n,o){let m=t==="GET"?3:0;for(let h=0;;h++){let p=await this.attempt(t,r,n,o);if(p.kind==="response")return p.response;if(h>=m||!te(p.error)||p.minimumRetryDelay===null)throw p.error;let s=Math.max(500*2**h,p.minimumRetryDelay);await new Promise(f=>setTimeout(f,s))}}async attempt(t,r,n,o){let m=new AbortController,h=setTimeout(()=>m.abort(),3e4),p=0;try{let s=await this.fetch(r,{method:t,redirect:"manual",signal:m.signal,headers:{Accept:"application/json",Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:t==="POST"?JSON.stringify(o):void 0});if(s.status>=500&&s.status<=599?p=re(s.headers.get("retry-after")):s.status>=300&&s.status<500&&(p=null),s.status>=300&&s.status<400)throw c.create("FlexPay returned an unexpected redirect","unexpected_redirect",s.status);let f=s.headers.get("content-type")??"unknown",F;try{F=await s.json()}catch{throw J(s.status,f)}if(!s.ok)throw c.create("FlexPay rejected the HTTP request","http_error",s.status);let L=n.safeParse(F);if(!L.success)throw J(s.status,f);return{kind:"response",response:L.data}}catch(s){return{kind:"failure",error:m.signal.aborted?new c("FlexPay request exceeded the 30-second deadline","timeout"):s instanceof c?s:new c("FlexPay request failed","network_error"),minimumRetryDelay:p}}finally{clearTimeout(h),m.abort()}}};function J(e,t){return c.create(`FlexPay returned an invalid response (Content-Type: ${t})`,"invalid_response",e)}function te(e){return e.status===void 0||e.status>=500&&e.status<=599}function re(e){if(e===null)return 0;if(!/^\d+$/.test(e))return null;let t=Number(e);return t<=2?t*1e3:null}var $=class{merchant;baseUrl;transport;constructor(t,r,n=globalThis.fetch){let o=k.parse(t);this.merchant=o.merchant,this.baseUrl=C.parse(r),this.transport=new O(o.token,n)}async mobile(t){let r=G(P.parse(t),this.merchant);return this.transport.request("POST",`${this.baseUrl.payment}/paymentService`,z,r)}async card(t){let r=H(T.parse(t),this.merchant);return this.transport.request("POST",`${this.baseUrl.payment}/paymentService`,q,r)}async payout(t){let r=I(w.parse(t),this.merchant);return this.transport.request("POST",`${this.baseUrl.payout}/merchantPayOutService`,M,r)}async check(t){if(typeof t!="string"||t.trim()===""||t==="."||t==="..")throw new Error("The order number must be nonempty and cannot be a dot segment");return this.transport.request("GET",`${this.baseUrl.check}/check/${encodeURIComponent(t)}`,B)}};0&&(module.exports={AccountException,BaseUrlSchema,CallbackResponseSchema,CardRequestSchema,CardResponseSchema,CheckResponseSchema,Client,ClientException,CredentialSchema,CurrencySchema,MobileRequestSchema,MobileResponseSchema,NetworkException,PayoutRequestSchema,PayoutResponseSchema,ServerException,Status,StatusSchema,TransactionSchema,parseCallback,productionBaseUrl});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
import{z as h}from"zod";var P=h.string().transform(e=>e.trim().replace(/\/+$/,"")).refine(Z,"Base URLs must be absolute HTTP(S) URLs without credentials, query, or fragment"),T=h.strictObject({payment:P,check:P,payout:P}).readonly(),I=Object.freeze({payment:"https://corporateapi.flexpay.cd/api/rest/v1",check:"https://apicheck.flexpaie.com/api/rest/v1",payout:"https://backend.flexpay.cd/api/rest/v1"}),w=h.strictObject({merchant:h.string().refine(e=>e.trim()!=="","Merchant cannot be empty"),token:h.string().refine(e=>e.trim()!=="","The authorization token cannot be empty")}).readonly();function Z(e){try{let t=new URL(e);return/^https?:\/\//i.test(e)&&!!t.hostname&&!t.username&&!t.password&&!e.includes("?")&&!e.includes("#")&&!/[\s\p{Cc}]/u.test(e)&&!e.includes("\\")}catch{return!1}}import{z as p}from"zod";var f=p.enum(["USD","CDF"]),U=p.strictObject({amount:p.number().finite().gt(0,"The transaction amount should be greater than 0"),currency:f,reference:p.string().refine(e=>e.trim()!=="","The transaction reference is mandatory"),callbackUrl:p.string().refine(e=>e.trim()!=="","The callback URL must be provided")}),z=U.extend({phone:p.string().regex(/^\d{12}$/,"The phone number must contain 12 digits, eg: 243123456789")}).readonly(),q=U.extend({approveUrl:p.string().refine(e=>e.trim()!=="","The redirect URL must be provided"),cancelUrl:p.string().refine(e=>e.trim()!=="","The redirect URL must be provided"),declineUrl:p.string().refine(e=>e.trim()!=="","The redirect URL must be provided")}).readonly(),M=U.extend({phone:p.string().regex(/^\d{12}$/,"The phone number must contain 12 digits, eg: 243123456789")}).readonly();function v(e,t){return{merchant:t,type:"1",amount:e.amount,currency:e.currency,phone:e.phone,reference:e.reference,callback_url:e.callbackUrl}}function F(e,t){return{merchant:t,type:"2",amount:e.amount,currency:e.currency,reference:e.reference,callback_url:e.callbackUrl,approve_url:e.approveUrl,cancel_url:e.cancelUrl,decline_url:e.declineUrl}}function L(e,t){return{merchant:t,type:1,amount:e.amount,currency:e.currency,phone:e.phone,reference:e.reference,callbackUrl:e.callbackUrl}}import{z as s}from"zod";import{z as b}from"zod";var R=class{value;constructor(t){if(!Number.isSafeInteger(t))throw new RangeError("Status must be a safe integer");this.value=t,Object.freeze(this)}isSuccessful(){return this.value===0}isFailure(){return this.value===1}},m=b.union([b.int(),b.string().regex(/^(0|-?[1-9]\d*)$/).transform(Number).pipe(b.int())]).transform(e=>new R(e));var S=s.union([s.number().finite(),s.string().trim().min(1).transform(Number).pipe(s.number().finite())]),l=s.string().nullable().optional().default(null),B=s.object({code:m,message:s.string().optional().default(""),orderNumber:l}),O=B.transform(e=>({...e,accepted:e.code.isSuccessful()})).readonly(),$=B.extend({url:l}).transform(e=>({...e,accepted:e.code.isSuccessful()})).readonly(),j=B.transform(e=>({...e,accepted:e.code.isSuccessful()})).readonly(),D=s.object({code:m,message:s.string().optional().default(""),orderNumber:l,reference:l,provider_reference:l,amount:S.nullable().optional().default(null),amountCustomer:S.nullable().optional().default(null),phone:l,currency:f.nullable().optional().default(null),createdAt:l,channel:l}).transform(e=>({code:e.code,successful:e.code.isSuccessful(),message:e.message,orderNumber:e.orderNumber,reference:e.reference,providerReference:e.provider_reference,amount:e.amount,amountCustomer:e.amountCustomer,phone:e.phone,currency:e.currency,createdAt:e.createdAt,channel:e.channel})).readonly(),G=s.object({amount:S,amountCustomer:S,channel:l,createdAt:s.string(),currency:f,orderNumber:l,reference:s.string(),status:m}).readonly(),E=s.object({code:m,message:s.string().optional().default(""),transaction:G.nullable().optional().default(null)}).transform(e=>({...e,successful:e.code.isSuccessful()&&e.transaction?.status.isSuccessful()===!0})).readonly();function J(e){return D.parse(e)}var c=class e extends Error{status;type;constructor(t,n,r){let a=r!=null?`${t} (HTTP ${r}/${n??"unknown"})`:t;super(a),this.name=this.constructor.name,this.status=r??void 0,this.type=n??void 0,Object.setPrototypeOf(this,new.target.prototype)}static create(t,n,r){let a=t.trim()===""?"No message was provided":t;return r===401||r===429?new x(a,n,r):r>=400&&r<=499?new g(a,n,r):r>=500&&r<=599?new C(a,n,r):new e(a,n,r)}},x=class extends c{},g=class extends c{},C=class extends c{};var k=class{constructor(t,n){this.token=t;this.fetch=n}token;fetch;async request(t,n,r,a){let u=t==="GET"?3:0;for(let d=0;;d++){let i=await this.attempt(t,n,r,a);if(i.kind==="response")return i.response;if(d>=u||!K(i.error)||i.minimumRetryDelay===null)throw i.error;let o=Math.max(500*2**d,i.minimumRetryDelay);await new Promise(y=>setTimeout(y,o))}}async attempt(t,n,r,a){let u=new AbortController,d=setTimeout(()=>u.abort(),3e4),i=0;try{let o=await this.fetch(n,{method:t,redirect:"manual",signal:u.signal,headers:{Accept:"application/json",Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:t==="POST"?JSON.stringify(a):void 0});if(o.status>=500&&o.status<=599?i=Q(o.headers.get("retry-after")):o.status>=300&&o.status<500&&(i=null),o.status>=300&&o.status<400)throw c.create("FlexPay returned an unexpected redirect","unexpected_redirect",o.status);let y=o.headers.get("content-type")??"unknown",_;try{_=await o.json()}catch{throw H(o.status,y)}if(!o.ok)throw c.create("FlexPay rejected the HTTP request","http_error",o.status);let A=r.safeParse(_);if(!A.success)throw H(o.status,y);return{kind:"response",response:A.data}}catch(o){return{kind:"failure",error:u.signal.aborted?new c("FlexPay request exceeded the 30-second deadline","timeout"):o instanceof c?o:new c("FlexPay request failed","network_error"),minimumRetryDelay:i}}finally{clearTimeout(d),u.abort()}}};function H(e,t){return c.create(`FlexPay returned an invalid response (Content-Type: ${t})`,"invalid_response",e)}function K(e){return e.status===void 0||e.status>=500&&e.status<=599}function Q(e){if(e===null)return 0;if(!/^\d+$/.test(e))return null;let t=Number(e);return t<=2?t*1e3:null}var N=class{merchant;baseUrl;transport;constructor(t,n,r=globalThis.fetch){let a=w.parse(t);this.merchant=a.merchant,this.baseUrl=T.parse(n),this.transport=new k(a.token,r)}async mobile(t){let n=v(z.parse(t),this.merchant);return this.transport.request("POST",`${this.baseUrl.payment}/paymentService`,O,n)}async card(t){let n=F(q.parse(t),this.merchant);return this.transport.request("POST",`${this.baseUrl.payment}/paymentService`,$,n)}async payout(t){let n=L(M.parse(t),this.merchant);return this.transport.request("POST",`${this.baseUrl.payout}/merchantPayOutService`,j,n)}async check(t){if(typeof t!="string"||t.trim()===""||t==="."||t==="..")throw new Error("The order number must be nonempty and cannot be a dot segment");return this.transport.request("GET",`${this.baseUrl.check}/check/${encodeURIComponent(t)}`,E)}};export{x as AccountException,T as BaseUrlSchema,D as CallbackResponseSchema,q as CardRequestSchema,$ as CardResponseSchema,E as CheckResponseSchema,N as Client,g as ClientException,w as CredentialSchema,f as CurrencySchema,z as MobileRequestSchema,O as MobileResponseSchema,c as NetworkException,M as PayoutRequestSchema,j as PayoutResponseSchema,C as ServerException,R as Status,m as StatusSchema,G as TransactionSchema,J as parseCallback,I as productionBaseUrl};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngandu-dev/flexpay",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"dist",
|
|
24
|
-
"README.md"
|
|
24
|
+
"README.md",
|
|
25
|
+
"UPGRADE_3.0.0.md"
|
|
25
26
|
],
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "tsup --minify",
|
|
@@ -56,19 +57,19 @@
|
|
|
56
57
|
"homepage": "https://github.com/ngandu-dev/flexpay-ts#readme",
|
|
57
58
|
"description": "FlexPay API TypeScript client",
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"zod": "^4.
|
|
60
|
+
"zod": "^4.6.7"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
63
64
|
"@biomejs/biome": "^2.5.12",
|
|
64
65
|
"@changesets/cli": "^3.0.2",
|
|
65
66
|
"@types/node": "^26.5.0",
|
|
66
|
-
"@vitest/coverage-v8": "^5.0.
|
|
67
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
67
68
|
"husky": "^9.1.7",
|
|
68
69
|
"publint": "^0.3.24",
|
|
69
70
|
"tsup": "^8.5.1",
|
|
70
71
|
"typescript": "^6.0.3",
|
|
71
|
-
"vitest": "^5.0.
|
|
72
|
+
"vitest": "^5.0.5",
|
|
72
73
|
"vite": "8.2.4"
|
|
73
74
|
},
|
|
74
75
|
"overrides": {
|