@momorail/paydunya 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.js +483 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Momorail contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { IdempotencyStore, PaymentProvider, ProviderCapabilities, CollectionInput, ProviderCallOptions, Transaction, DisbursementInput, TransactionRef, RawWebhook, WebhookEvent } from '@momorail/core';
|
|
2
|
+
|
|
3
|
+
type PaydunyaMode = 'live' | 'test';
|
|
4
|
+
interface PaydunyaOptions {
|
|
5
|
+
/** PAYDUNYA-MASTER-KEY — also the value hashed to verify the IPN. */
|
|
6
|
+
masterKey: string;
|
|
7
|
+
/** PAYDUNYA-PRIVATE-KEY. */
|
|
8
|
+
privateKey: string;
|
|
9
|
+
/** PAYDUNYA-TOKEN. */
|
|
10
|
+
token: string;
|
|
11
|
+
/** Store name PayDunya shows on the hosted invoice. */
|
|
12
|
+
storeName: string;
|
|
13
|
+
/** `'live'` (default) or `'test'` — selects the sandbox base URL and PAYDUNYA-MODE. */
|
|
14
|
+
mode?: PaydunyaMode;
|
|
15
|
+
/** Fallback IPN URL when a collection doesn't set `callbackUrl`. */
|
|
16
|
+
callbackUrl?: string;
|
|
17
|
+
/** Fallback success redirect. */
|
|
18
|
+
returnUrl?: string;
|
|
19
|
+
/** Fallback cancel redirect. */
|
|
20
|
+
cancelUrl?: string;
|
|
21
|
+
/** Override the API base URL (e.g. a mock in tests). */
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
/** Per-request timeout in ms. Default 15000. */
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
/** Injectable fetch implementation. Default the global `fetch`. */
|
|
26
|
+
fetch?: typeof fetch;
|
|
27
|
+
/** Where the adapter remembers created transactions. Default: in-memory, per process. */
|
|
28
|
+
idempotencyStore?: IdempotencyStore;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* PayDunya adapter (HTTP/JSON checkout). Implements collection via a hosted
|
|
32
|
+
* checkout invoice, status via `confirm/{token}`, and IPN verification.
|
|
33
|
+
* Disbursement uses PayDunya's separate PUSH API and is a later milestone.
|
|
34
|
+
*
|
|
35
|
+
* PayDunya can only look a transaction up by its **invoice token**, so the
|
|
36
|
+
* adapter keeps a per-instance cache from `reference` to the created
|
|
37
|
+
* `Transaction`, and also stashes the caller's `reference` in the invoice's
|
|
38
|
+
* `custom_data` so `confirm` and the IPN echo it back even across processes.
|
|
39
|
+
*/
|
|
40
|
+
declare class PaydunyaProvider implements PaymentProvider {
|
|
41
|
+
#private;
|
|
42
|
+
readonly id = "paydunya";
|
|
43
|
+
constructor(options: PaydunyaOptions);
|
|
44
|
+
capabilities(): ProviderCapabilities;
|
|
45
|
+
collection(input: CollectionInput, options?: ProviderCallOptions): Promise<Transaction>;
|
|
46
|
+
disbursement(input: DisbursementInput, options?: ProviderCallOptions): Promise<Transaction>;
|
|
47
|
+
getTransaction(ref: TransactionRef, options?: ProviderCallOptions): Promise<Transaction>;
|
|
48
|
+
parseWebhook(raw: RawWebhook): Promise<WebhookEvent>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Raw PayDunya HTTP/JSON API shapes. Only the fields Momorail reads are modelled;
|
|
53
|
+
* the untouched payload is always returned on `Transaction.providerRaw`.
|
|
54
|
+
*
|
|
55
|
+
* @see https://developers.paydunya.com/doc/EN/http_json
|
|
56
|
+
*/
|
|
57
|
+
/** `POST /checkout-invoice/create` */
|
|
58
|
+
interface PaydunyaCreateResponse {
|
|
59
|
+
/** `"00"` on success. */
|
|
60
|
+
response_code: string;
|
|
61
|
+
/** On success, the checkout URL; on failure, a message (often in French). */
|
|
62
|
+
response_text: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
token?: string;
|
|
65
|
+
invoice_url?: string;
|
|
66
|
+
}
|
|
67
|
+
interface PaydunyaCustomer {
|
|
68
|
+
name?: string;
|
|
69
|
+
phone?: string;
|
|
70
|
+
email?: string;
|
|
71
|
+
}
|
|
72
|
+
/** `GET /checkout-invoice/confirm/{token}` */
|
|
73
|
+
interface PaydunyaConfirmResponse {
|
|
74
|
+
response_code: string;
|
|
75
|
+
response_text?: string;
|
|
76
|
+
/** `completed` | `pending` | `cancelled` | `failed` (also seen `canceled` / `fail`). */
|
|
77
|
+
status?: string;
|
|
78
|
+
invoice?: {
|
|
79
|
+
token?: string;
|
|
80
|
+
total_amount?: number | string;
|
|
81
|
+
description?: string;
|
|
82
|
+
};
|
|
83
|
+
customer?: PaydunyaCustomer;
|
|
84
|
+
custom_data?: Record<string, unknown>;
|
|
85
|
+
receipt_url?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* IPN body fields, flattened. PayDunya POSTs `application/x-www-form-urlencoded`
|
|
89
|
+
* with bracketed keys, e.g. `data[invoice][token]`, `data[status]`, `data[hash]`.
|
|
90
|
+
*/
|
|
91
|
+
type PaydunyaIpnFields = Record<string, string | undefined>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Parse a PayDunya IPN body. PayDunya POSTs `application/x-www-form-urlencoded`
|
|
95
|
+
* with bracketed keys (`data[invoice][token]`, `data[status]`, `data[hash]`, …).
|
|
96
|
+
* The keys are kept flat and verbatim.
|
|
97
|
+
*/
|
|
98
|
+
declare function parseIpnBody(body: string | Uint8Array | Record<string, unknown>): PaydunyaIpnFields;
|
|
99
|
+
/** PayDunya's IPN hash is `sha512(masterKey)` — a static digest of your Master Key. */
|
|
100
|
+
declare function paydunyaIpnHash(masterKey: string): string;
|
|
101
|
+
/** Read a bracketed IPN field regardless of surrounding whitespace. */
|
|
102
|
+
declare function ipnField(fields: PaydunyaIpnFields, key: string): string | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Verify a PayDunya IPN. Returns the parsed fields on success; throws
|
|
105
|
+
* {@link WebhookVerificationError} when `data[hash]` is missing or does not equal
|
|
106
|
+
* `sha512(masterKey)`.
|
|
107
|
+
*
|
|
108
|
+
* NOTE: this proves the notification came from an actor holding your Master Key —
|
|
109
|
+
* it does not sign the payload. Momorail therefore re-queries the invoice for the
|
|
110
|
+
* authoritative status rather than trusting `data[status]`.
|
|
111
|
+
*/
|
|
112
|
+
declare function verifyPaydunyaIpn(body: string | Uint8Array | Record<string, unknown>, masterKey: string): PaydunyaIpnFields;
|
|
113
|
+
|
|
114
|
+
export { type PaydunyaConfirmResponse, type PaydunyaCreateResponse, type PaydunyaIpnFields, type PaydunyaMode, type PaydunyaOptions, PaydunyaProvider, ipnField, parseIpnBody, paydunyaIpnHash, verifyPaydunyaIpn };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
// src/provider.ts
|
|
2
|
+
import {
|
|
3
|
+
IdempotencyCache,
|
|
4
|
+
MemoryIdempotencyStore,
|
|
5
|
+
ValidationError,
|
|
6
|
+
isOperator,
|
|
7
|
+
webhookEventTypeForStatus
|
|
8
|
+
} from "@momorail/core";
|
|
9
|
+
|
|
10
|
+
// src/http.ts
|
|
11
|
+
import { ProviderUnavailableError, RateLimitError } from "@momorail/core";
|
|
12
|
+
|
|
13
|
+
// src/mapping.ts
|
|
14
|
+
import {
|
|
15
|
+
AuthError,
|
|
16
|
+
MomorailError,
|
|
17
|
+
TransactionNotFoundError
|
|
18
|
+
} from "@momorail/core";
|
|
19
|
+
var PROVIDER_ID = "paydunya";
|
|
20
|
+
var OK = "00";
|
|
21
|
+
var AUTH_HINT = /cl[eé]s?|api[\s-]?key|authenticat|non autoris|unauthor/i;
|
|
22
|
+
var NOT_FOUND_HINT = /introuvable|invalide|not[\s_]*found|no such|inexistant/i;
|
|
23
|
+
function mapConfirmStatus(res) {
|
|
24
|
+
switch (res.status?.toLowerCase()) {
|
|
25
|
+
case "completed":
|
|
26
|
+
return "succeeded";
|
|
27
|
+
case "pending":
|
|
28
|
+
return "processing";
|
|
29
|
+
case "cancelled":
|
|
30
|
+
case "canceled":
|
|
31
|
+
return "cancelled";
|
|
32
|
+
case "failed":
|
|
33
|
+
case "fail":
|
|
34
|
+
return "failed";
|
|
35
|
+
default:
|
|
36
|
+
return res.response_code === OK ? "processing" : "unknown";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function mapDisburseStatus(status, responseCode) {
|
|
40
|
+
switch (status?.toLowerCase()) {
|
|
41
|
+
case "completed":
|
|
42
|
+
case "success":
|
|
43
|
+
case "successful":
|
|
44
|
+
return "succeeded";
|
|
45
|
+
case "pending":
|
|
46
|
+
case "processing":
|
|
47
|
+
case "sent":
|
|
48
|
+
return "processing";
|
|
49
|
+
case "failed":
|
|
50
|
+
case "cancelled":
|
|
51
|
+
case "rejected":
|
|
52
|
+
return "failed";
|
|
53
|
+
default:
|
|
54
|
+
return responseCode === OK ? "processing" : "unknown";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function mapFailureReason(res) {
|
|
58
|
+
const text = `${res.response_text ?? ""}`.toLowerCase();
|
|
59
|
+
if (/solde|insufficient|fund/.test(text)) return "insufficient_funds";
|
|
60
|
+
if (/annul|cancel/.test(text)) return "user_declined";
|
|
61
|
+
if (/expir/.test(text)) return "timeout";
|
|
62
|
+
return "other";
|
|
63
|
+
}
|
|
64
|
+
function paydunyaError(responseCode, message, providerRaw) {
|
|
65
|
+
const opts = { provider: PROVIDER_ID, providerRaw };
|
|
66
|
+
if (AUTH_HINT.test(message)) {
|
|
67
|
+
return new AuthError(`PayDunya rejected the credentials (${responseCode}: ${message})`, opts);
|
|
68
|
+
}
|
|
69
|
+
if (NOT_FOUND_HINT.test(message)) {
|
|
70
|
+
return new TransactionNotFoundError(
|
|
71
|
+
`PayDunya has no such invoice (${responseCode}: ${message})`,
|
|
72
|
+
opts
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return new MomorailError(`PayDunya error (${responseCode}: ${message})`, "provider_error", opts);
|
|
76
|
+
}
|
|
77
|
+
function isOk(responseCode) {
|
|
78
|
+
return responseCode === OK;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/http.ts
|
|
82
|
+
var HttpClient = class {
|
|
83
|
+
#baseUrl;
|
|
84
|
+
#timeoutMs;
|
|
85
|
+
#fetch;
|
|
86
|
+
#authHeaders;
|
|
87
|
+
constructor(options) {
|
|
88
|
+
this.#baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
89
|
+
this.#timeoutMs = options.timeoutMs;
|
|
90
|
+
this.#fetch = options.fetch;
|
|
91
|
+
this.#authHeaders = options.authHeaders;
|
|
92
|
+
}
|
|
93
|
+
postJson(path, body, signal) {
|
|
94
|
+
return this.#request("POST", path, body, signal);
|
|
95
|
+
}
|
|
96
|
+
getJson(path, signal) {
|
|
97
|
+
return this.#request("GET", path, void 0, signal);
|
|
98
|
+
}
|
|
99
|
+
async #request(method, path, body, signal) {
|
|
100
|
+
const timeout = AbortSignal.timeout(this.#timeoutMs);
|
|
101
|
+
const composite = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
102
|
+
const headers = { accept: "application/json", ...this.#authHeaders };
|
|
103
|
+
if (method === "POST") headers["content-type"] = "application/json";
|
|
104
|
+
let response;
|
|
105
|
+
try {
|
|
106
|
+
response = await this.#fetch(`${this.#baseUrl}${path}`, {
|
|
107
|
+
method,
|
|
108
|
+
headers,
|
|
109
|
+
body: method === "POST" ? JSON.stringify(body) : void 0,
|
|
110
|
+
signal: composite
|
|
111
|
+
});
|
|
112
|
+
} catch (cause) {
|
|
113
|
+
if (signal?.aborted) throw cause;
|
|
114
|
+
throw new ProviderUnavailableError("PayDunya request failed to complete", {
|
|
115
|
+
provider: PROVIDER_ID,
|
|
116
|
+
cause
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (response.status === 429) {
|
|
120
|
+
throw new RateLimitError("PayDunya throttled the request", { provider: PROVIDER_ID });
|
|
121
|
+
}
|
|
122
|
+
const raw = await response.text();
|
|
123
|
+
let parsed;
|
|
124
|
+
try {
|
|
125
|
+
parsed = raw ? JSON.parse(raw) : {};
|
|
126
|
+
} catch (cause) {
|
|
127
|
+
throw new ProviderUnavailableError("PayDunya returned a non-JSON response", {
|
|
128
|
+
provider: PROVIDER_ID,
|
|
129
|
+
providerRaw: raw,
|
|
130
|
+
cause
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (response.status >= 500) {
|
|
134
|
+
throw new ProviderUnavailableError(`PayDunya responded ${response.status}`, {
|
|
135
|
+
provider: PROVIDER_ID,
|
|
136
|
+
providerRaw: parsed
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return parsed;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/webhook.ts
|
|
144
|
+
import { createHash, timingSafeEqual } from "crypto";
|
|
145
|
+
import { WebhookVerificationError } from "@momorail/core";
|
|
146
|
+
function parseIpnBody(body) {
|
|
147
|
+
if (typeof body === "string" || body instanceof Uint8Array) {
|
|
148
|
+
const raw = typeof body === "string" ? body : new TextDecoder().decode(body);
|
|
149
|
+
return Object.fromEntries(new URLSearchParams(raw).entries());
|
|
150
|
+
}
|
|
151
|
+
const out = {};
|
|
152
|
+
for (const [key, value] of Object.entries(body)) {
|
|
153
|
+
if (value != null) out[key] = String(value);
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
function paydunyaIpnHash(masterKey) {
|
|
158
|
+
return createHash("sha512").update(masterKey, "utf8").digest("hex");
|
|
159
|
+
}
|
|
160
|
+
function safeEqualHex(a, b) {
|
|
161
|
+
if (a.length !== b.length || a.length === 0) return false;
|
|
162
|
+
try {
|
|
163
|
+
return timingSafeEqual(Buffer.from(a, "hex"), Buffer.from(b, "hex"));
|
|
164
|
+
} catch {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function ipnField(fields, key) {
|
|
169
|
+
return fields[key] ?? fields[key.replace(/\s+/g, "")];
|
|
170
|
+
}
|
|
171
|
+
function verifyPaydunyaIpn(body, masterKey) {
|
|
172
|
+
const fields = parseIpnBody(body);
|
|
173
|
+
const received = ipnField(fields, "data[hash]");
|
|
174
|
+
if (!received) {
|
|
175
|
+
throw new WebhookVerificationError("PayDunya IPN is missing data[hash]", {
|
|
176
|
+
provider: PROVIDER_ID
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (!safeEqualHex(received.toLowerCase(), paydunyaIpnHash(masterKey))) {
|
|
180
|
+
throw new WebhookVerificationError("PayDunya IPN hash does not match the Master Key", {
|
|
181
|
+
provider: PROVIDER_ID
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return fields;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/provider.ts
|
|
188
|
+
var BASE_URL = {
|
|
189
|
+
live: "https://app.paydunya.com/api/v1",
|
|
190
|
+
test: "https://app.paydunya.com/sandbox-api/v1"
|
|
191
|
+
};
|
|
192
|
+
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
193
|
+
var REFERENCE_KEY = "momorail_reference";
|
|
194
|
+
var CALLING_CODES = [
|
|
195
|
+
"221",
|
|
196
|
+
"225",
|
|
197
|
+
"223",
|
|
198
|
+
"226",
|
|
199
|
+
"229",
|
|
200
|
+
"228",
|
|
201
|
+
"227",
|
|
202
|
+
"237",
|
|
203
|
+
"242",
|
|
204
|
+
"243",
|
|
205
|
+
"235",
|
|
206
|
+
"241",
|
|
207
|
+
"245"
|
|
208
|
+
];
|
|
209
|
+
var WITHDRAW_MODE = {
|
|
210
|
+
orange_sn: "orange-money-senegal",
|
|
211
|
+
free_sn: "free-money-senegal",
|
|
212
|
+
wave_sn: "wave-senegal",
|
|
213
|
+
expresso_sn: "expresso-senegal",
|
|
214
|
+
orange_ci: "orange-money-ci",
|
|
215
|
+
mtn_ci: "mtn-ci",
|
|
216
|
+
moov_ci: "moov-ci",
|
|
217
|
+
wave_ci: "wave-ci",
|
|
218
|
+
orange_ml: "orange-money-mali",
|
|
219
|
+
moov_ml: "moov-mali",
|
|
220
|
+
orange_bf: "orange-money-burkina",
|
|
221
|
+
moov_bf: "moov-burkina",
|
|
222
|
+
mtn_bj: "mtn-benin",
|
|
223
|
+
moov_bj: "moov-benin"
|
|
224
|
+
};
|
|
225
|
+
var CAPABILITIES = {
|
|
226
|
+
collection: true,
|
|
227
|
+
disbursement: true,
|
|
228
|
+
// PayDunya confirms an invoice by its token only — there is no lookup by our reference.
|
|
229
|
+
lookupByReference: false,
|
|
230
|
+
hostedCheckout: true,
|
|
231
|
+
operators: [
|
|
232
|
+
"orange_sn",
|
|
233
|
+
"free_sn",
|
|
234
|
+
"wave_sn",
|
|
235
|
+
"expresso_sn",
|
|
236
|
+
"orange_ci",
|
|
237
|
+
"mtn_ci",
|
|
238
|
+
"moov_ci",
|
|
239
|
+
"wave_ci",
|
|
240
|
+
"orange_ml",
|
|
241
|
+
"moov_ml",
|
|
242
|
+
"orange_bf",
|
|
243
|
+
"moov_bf",
|
|
244
|
+
"mtn_bj",
|
|
245
|
+
"moov_bj"
|
|
246
|
+
],
|
|
247
|
+
currencies: ["XOF"]
|
|
248
|
+
};
|
|
249
|
+
var PaydunyaProvider = class {
|
|
250
|
+
id = PROVIDER_ID;
|
|
251
|
+
#masterKey;
|
|
252
|
+
#storeName;
|
|
253
|
+
#callbackUrl;
|
|
254
|
+
#returnUrl;
|
|
255
|
+
#cancelUrl;
|
|
256
|
+
#http;
|
|
257
|
+
#cache;
|
|
258
|
+
constructor(options) {
|
|
259
|
+
for (const key of ["masterKey", "privateKey", "token", "storeName"]) {
|
|
260
|
+
if (!options[key]?.trim()) {
|
|
261
|
+
throw new ValidationError(`PaydunyaProvider requires a non-empty "${key}"`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const mode = options.mode ?? "live";
|
|
265
|
+
this.#masterKey = options.masterKey;
|
|
266
|
+
this.#storeName = options.storeName;
|
|
267
|
+
this.#callbackUrl = options.callbackUrl;
|
|
268
|
+
this.#returnUrl = options.returnUrl;
|
|
269
|
+
this.#cancelUrl = options.cancelUrl;
|
|
270
|
+
this.#cache = new IdempotencyCache(
|
|
271
|
+
options.idempotencyStore ?? new MemoryIdempotencyStore(),
|
|
272
|
+
this.id
|
|
273
|
+
);
|
|
274
|
+
this.#http = new HttpClient({
|
|
275
|
+
baseUrl: options.baseUrl ?? BASE_URL[mode],
|
|
276
|
+
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
277
|
+
fetch: options.fetch ?? globalThis.fetch,
|
|
278
|
+
authHeaders: {
|
|
279
|
+
"PAYDUNYA-MASTER-KEY": options.masterKey,
|
|
280
|
+
"PAYDUNYA-PRIVATE-KEY": options.privateKey,
|
|
281
|
+
"PAYDUNYA-TOKEN": options.token,
|
|
282
|
+
"PAYDUNYA-MODE": mode
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
capabilities() {
|
|
287
|
+
return CAPABILITIES;
|
|
288
|
+
}
|
|
289
|
+
async collection(input, options) {
|
|
290
|
+
if (input.customer.operator !== void 0 && !isOperator(input.customer.operator)) {
|
|
291
|
+
throw new ValidationError(`Unknown operator: ${input.customer.operator}`, {
|
|
292
|
+
provider: this.id
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
const cached = await this.#cache.byReference(input.reference);
|
|
296
|
+
if (cached) return structuredClone(cached);
|
|
297
|
+
const callbackUrl = input.callbackUrl ?? this.#callbackUrl;
|
|
298
|
+
if (!callbackUrl) {
|
|
299
|
+
throw new ValidationError(
|
|
300
|
+
"PayDunya needs an IPN URL: pass collection input.callbackUrl or set PaydunyaOptions.callbackUrl",
|
|
301
|
+
{ provider: this.id }
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
const body = {
|
|
305
|
+
invoice: {
|
|
306
|
+
total_amount: input.amount.amount,
|
|
307
|
+
description: input.description ?? `Payment ${input.reference}`
|
|
308
|
+
},
|
|
309
|
+
store: { name: this.#storeName },
|
|
310
|
+
actions: pruneUndefined({
|
|
311
|
+
callback_url: callbackUrl,
|
|
312
|
+
return_url: input.returnUrl ?? this.#returnUrl,
|
|
313
|
+
cancel_url: input.cancelUrl ?? this.#cancelUrl
|
|
314
|
+
}),
|
|
315
|
+
custom_data: { [REFERENCE_KEY]: input.reference, ...input.metadata }
|
|
316
|
+
};
|
|
317
|
+
const res = await this.#http.postJson(
|
|
318
|
+
"/checkout-invoice/create",
|
|
319
|
+
body,
|
|
320
|
+
options?.signal
|
|
321
|
+
);
|
|
322
|
+
if (!isOk(res.response_code) || !res.token) {
|
|
323
|
+
throw paydunyaError(res.response_code, res.response_text, res);
|
|
324
|
+
}
|
|
325
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
326
|
+
const txn = {
|
|
327
|
+
provider: this.id,
|
|
328
|
+
id: res.token,
|
|
329
|
+
reference: input.reference,
|
|
330
|
+
type: "collection",
|
|
331
|
+
status: "pending",
|
|
332
|
+
amount: input.amount,
|
|
333
|
+
operator: input.customer.operator,
|
|
334
|
+
customer: input.customer,
|
|
335
|
+
checkoutUrl: res.invoice_url ?? (isUrl(res.response_text) ? res.response_text : void 0),
|
|
336
|
+
providerRaw: res,
|
|
337
|
+
createdAt: now,
|
|
338
|
+
updatedAt: now
|
|
339
|
+
};
|
|
340
|
+
await this.#cache.remember(txn);
|
|
341
|
+
return structuredClone(txn);
|
|
342
|
+
}
|
|
343
|
+
async disbursement(input, options) {
|
|
344
|
+
const operator = input.recipient.operator;
|
|
345
|
+
if (!operator || !isOperator(operator)) {
|
|
346
|
+
throw new ValidationError("PayDunya disbursement needs recipient.operator", {
|
|
347
|
+
provider: this.id
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
const mode = WITHDRAW_MODE[operator];
|
|
351
|
+
if (!mode) {
|
|
352
|
+
throw new ValidationError(`PayDunya has no withdraw mode for operator "${operator}"`, {
|
|
353
|
+
provider: this.id
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
const cached = await this.#cache.byReference(input.reference);
|
|
357
|
+
if (cached) return structuredClone(cached);
|
|
358
|
+
const alias = localNumber(input.recipient.phone);
|
|
359
|
+
const get = await this.#http.postJson(
|
|
360
|
+
"/disburse/get-invoice",
|
|
361
|
+
{ account_alias: alias, amount: input.amount.amount, withdraw_mode: mode },
|
|
362
|
+
options?.signal
|
|
363
|
+
);
|
|
364
|
+
if (!isOk(get.response_code) || !get.disburse_token) {
|
|
365
|
+
throw paydunyaError(get.response_code, get.response_text ?? "get-invoice failed", get);
|
|
366
|
+
}
|
|
367
|
+
const submit = await this.#http.postJson(
|
|
368
|
+
"/disburse/submit-invoice",
|
|
369
|
+
{ disburse_invoice: get.disburse_token, disburse_id: input.reference },
|
|
370
|
+
options?.signal
|
|
371
|
+
);
|
|
372
|
+
const desc = typeof submit.description === "object" ? submit.description : void 0;
|
|
373
|
+
const status = mapDisburseStatus(desc?.status, submit.response_code);
|
|
374
|
+
if (status === "unknown") {
|
|
375
|
+
throw paydunyaError(
|
|
376
|
+
submit.response_code,
|
|
377
|
+
submit.response_text ?? "submit-invoice failed",
|
|
378
|
+
submit
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
382
|
+
const txn = {
|
|
383
|
+
provider: this.id,
|
|
384
|
+
id: desc?.provider_ref ?? input.reference,
|
|
385
|
+
reference: input.reference,
|
|
386
|
+
type: "disbursement",
|
|
387
|
+
status,
|
|
388
|
+
amount: input.amount,
|
|
389
|
+
operator,
|
|
390
|
+
customer: input.recipient,
|
|
391
|
+
failureReason: status === "failed" ? "other" : void 0,
|
|
392
|
+
providerRaw: { get, submit },
|
|
393
|
+
createdAt: now,
|
|
394
|
+
updatedAt: now
|
|
395
|
+
};
|
|
396
|
+
await this.#cache.remember(txn);
|
|
397
|
+
return structuredClone(txn);
|
|
398
|
+
}
|
|
399
|
+
async getTransaction(ref, options) {
|
|
400
|
+
const known = (ref.id ? await this.#cache.byId(ref.id) : void 0) ?? (ref.reference ? await this.#cache.byReference(ref.reference) : void 0);
|
|
401
|
+
if (known?.type === "disbursement") {
|
|
402
|
+
return structuredClone(known);
|
|
403
|
+
}
|
|
404
|
+
const token = ref.id ?? known?.id;
|
|
405
|
+
if (!token) {
|
|
406
|
+
throw new ValidationError(
|
|
407
|
+
"PayDunya looks a transaction up by its invoice token (the provider id); this reference is not known to this instance",
|
|
408
|
+
{ provider: this.id }
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
const res = await this.#http.getJson(
|
|
412
|
+
`/checkout-invoice/confirm/${encodeURIComponent(token)}`,
|
|
413
|
+
options?.signal
|
|
414
|
+
);
|
|
415
|
+
const status = mapConfirmStatus(res);
|
|
416
|
+
if (!isOk(res.response_code) && status === "unknown") {
|
|
417
|
+
throw paydunyaError(res.response_code, res.response_text ?? "unknown invoice", res);
|
|
418
|
+
}
|
|
419
|
+
const echoed = res.custom_data?.[REFERENCE_KEY];
|
|
420
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
421
|
+
const txn = {
|
|
422
|
+
provider: this.id,
|
|
423
|
+
id: token,
|
|
424
|
+
reference: (typeof echoed === "string" ? echoed : void 0) ?? known?.reference ?? ref.reference ?? token,
|
|
425
|
+
type: "collection",
|
|
426
|
+
status,
|
|
427
|
+
amount: known?.amount ?? coerceAmount(res.invoice?.total_amount),
|
|
428
|
+
operator: known?.operator,
|
|
429
|
+
customer: known?.customer,
|
|
430
|
+
checkoutUrl: known?.checkoutUrl,
|
|
431
|
+
failureReason: status === "failed" ? mapFailureReason(res) : void 0,
|
|
432
|
+
providerRaw: res,
|
|
433
|
+
createdAt: known?.createdAt ?? now,
|
|
434
|
+
updatedAt: now
|
|
435
|
+
};
|
|
436
|
+
await this.#cache.remember(txn);
|
|
437
|
+
return structuredClone(txn);
|
|
438
|
+
}
|
|
439
|
+
async parseWebhook(raw) {
|
|
440
|
+
const fields = verifyPaydunyaIpn(raw.body, this.#masterKey);
|
|
441
|
+
const token = ipnField(fields, "data[invoice][token]");
|
|
442
|
+
if (!token) {
|
|
443
|
+
throw new ValidationError("PayDunya IPN is missing data[invoice][token]", {
|
|
444
|
+
provider: this.id
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
const transaction = await this.getTransaction({ id: token });
|
|
448
|
+
return {
|
|
449
|
+
type: webhookEventTypeForStatus(transaction.status),
|
|
450
|
+
transaction,
|
|
451
|
+
providerRaw: fields
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
function isUrl(value) {
|
|
456
|
+
return typeof value === "string" && /^https?:\/\//i.test(value);
|
|
457
|
+
}
|
|
458
|
+
function localNumber(phone) {
|
|
459
|
+
const digits = phone.replace(/[^\d]/g, "");
|
|
460
|
+
for (const code of CALLING_CODES) {
|
|
461
|
+
if (digits.startsWith(code)) return digits.slice(code.length);
|
|
462
|
+
}
|
|
463
|
+
return digits;
|
|
464
|
+
}
|
|
465
|
+
function coerceAmount(raw) {
|
|
466
|
+
const amount = typeof raw === "string" ? Number.parseInt(raw, 10) : raw ?? 0;
|
|
467
|
+
return { amount: Number.isFinite(amount) ? Math.trunc(amount) : 0, currency: "XOF" };
|
|
468
|
+
}
|
|
469
|
+
function pruneUndefined(obj) {
|
|
470
|
+
const out = {};
|
|
471
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
472
|
+
if (value !== void 0) out[key] = value;
|
|
473
|
+
}
|
|
474
|
+
return out;
|
|
475
|
+
}
|
|
476
|
+
export {
|
|
477
|
+
PaydunyaProvider,
|
|
478
|
+
ipnField,
|
|
479
|
+
parseIpnBody,
|
|
480
|
+
paydunyaIpnHash,
|
|
481
|
+
verifyPaydunyaIpn
|
|
482
|
+
};
|
|
483
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.ts","../src/http.ts","../src/mapping.ts","../src/webhook.ts"],"sourcesContent":["import {\n type CollectionInput,\n type DisbursementInput,\n IdempotencyCache,\n type IdempotencyStore,\n MemoryIdempotencyStore,\n MomorailError,\n type Money,\n type Operator,\n type PaymentProvider,\n type ProviderCallOptions,\n type ProviderCapabilities,\n type RawWebhook,\n type Transaction,\n type TransactionRef,\n ValidationError,\n type WebhookEvent,\n isOperator,\n webhookEventTypeForStatus,\n} from '@momorail/core';\nimport { HttpClient } from './http.js';\nimport {\n PROVIDER_ID,\n isOk,\n mapConfirmStatus,\n mapDisburseStatus,\n mapFailureReason,\n paydunyaError,\n} from './mapping.js';\nimport type {\n PaydunyaConfirmResponse,\n PaydunyaCreateResponse,\n PaydunyaDisburseGetResponse,\n PaydunyaDisburseSubmitResponse,\n} from './types.js';\nimport { ipnField, verifyPaydunyaIpn } from './webhook.js';\n\nconst BASE_URL: Record<PaydunyaMode, string> = {\n live: 'https://app.paydunya.com/api/v1',\n test: 'https://app.paydunya.com/sandbox-api/v1',\n};\nconst DEFAULT_TIMEOUT_MS = 15_000;\nconst REFERENCE_KEY = 'momorail_reference';\n\n/** West/Central African calling codes, longest first, for stripping an E.164 number. */\nconst CALLING_CODES = [\n '221',\n '225',\n '223',\n '226',\n '229',\n '228',\n '227',\n '237',\n '242',\n '243',\n '235',\n '241',\n '245',\n];\n\n/** Momorail operator → PayDunya `withdraw_mode`. */\nconst WITHDRAW_MODE: Partial<Record<Operator, string>> = {\n orange_sn: 'orange-money-senegal',\n free_sn: 'free-money-senegal',\n wave_sn: 'wave-senegal',\n expresso_sn: 'expresso-senegal',\n orange_ci: 'orange-money-ci',\n mtn_ci: 'mtn-ci',\n moov_ci: 'moov-ci',\n wave_ci: 'wave-ci',\n orange_ml: 'orange-money-mali',\n moov_ml: 'moov-mali',\n orange_bf: 'orange-money-burkina',\n moov_bf: 'moov-burkina',\n mtn_bj: 'mtn-benin',\n moov_bj: 'moov-benin',\n};\n\nexport type PaydunyaMode = 'live' | 'test';\n\nexport interface PaydunyaOptions {\n /** PAYDUNYA-MASTER-KEY — also the value hashed to verify the IPN. */\n masterKey: string;\n /** PAYDUNYA-PRIVATE-KEY. */\n privateKey: string;\n /** PAYDUNYA-TOKEN. */\n token: string;\n /** Store name PayDunya shows on the hosted invoice. */\n storeName: string;\n /** `'live'` (default) or `'test'` — selects the sandbox base URL and PAYDUNYA-MODE. */\n mode?: PaydunyaMode;\n /** Fallback IPN URL when a collection doesn't set `callbackUrl`. */\n callbackUrl?: string;\n /** Fallback success redirect. */\n returnUrl?: string;\n /** Fallback cancel redirect. */\n cancelUrl?: string;\n /** Override the API base URL (e.g. a mock in tests). */\n baseUrl?: string;\n /** Per-request timeout in ms. Default 15000. */\n timeoutMs?: number;\n /** Injectable fetch implementation. Default the global `fetch`. */\n fetch?: typeof fetch;\n /** Where the adapter remembers created transactions. Default: in-memory, per process. */\n idempotencyStore?: IdempotencyStore;\n}\n\nconst CAPABILITIES: ProviderCapabilities = {\n collection: true,\n disbursement: true,\n // PayDunya confirms an invoice by its token only — there is no lookup by our reference.\n lookupByReference: false,\n hostedCheckout: true,\n operators: [\n 'orange_sn',\n 'free_sn',\n 'wave_sn',\n 'expresso_sn',\n 'orange_ci',\n 'mtn_ci',\n 'moov_ci',\n 'wave_ci',\n 'orange_ml',\n 'moov_ml',\n 'orange_bf',\n 'moov_bf',\n 'mtn_bj',\n 'moov_bj',\n ],\n currencies: ['XOF'],\n};\n\n/**\n * PayDunya adapter (HTTP/JSON checkout). Implements collection via a hosted\n * checkout invoice, status via `confirm/{token}`, and IPN verification.\n * Disbursement uses PayDunya's separate PUSH API and is a later milestone.\n *\n * PayDunya can only look a transaction up by its **invoice token**, so the\n * adapter keeps a per-instance cache from `reference` to the created\n * `Transaction`, and also stashes the caller's `reference` in the invoice's\n * `custom_data` so `confirm` and the IPN echo it back even across processes.\n */\nexport class PaydunyaProvider implements PaymentProvider {\n readonly id = PROVIDER_ID;\n\n readonly #masterKey: string;\n readonly #storeName: string;\n readonly #callbackUrl: string | undefined;\n readonly #returnUrl: string | undefined;\n readonly #cancelUrl: string | undefined;\n readonly #http: HttpClient;\n readonly #cache: IdempotencyCache;\n\n constructor(options: PaydunyaOptions) {\n for (const key of ['masterKey', 'privateKey', 'token', 'storeName'] as const) {\n if (!options[key]?.trim()) {\n throw new ValidationError(`PaydunyaProvider requires a non-empty \"${key}\"`);\n }\n }\n const mode: PaydunyaMode = options.mode ?? 'live';\n this.#masterKey = options.masterKey;\n this.#storeName = options.storeName;\n this.#callbackUrl = options.callbackUrl;\n this.#returnUrl = options.returnUrl;\n this.#cancelUrl = options.cancelUrl;\n this.#cache = new IdempotencyCache(\n options.idempotencyStore ?? new MemoryIdempotencyStore(),\n this.id,\n );\n this.#http = new HttpClient({\n baseUrl: options.baseUrl ?? BASE_URL[mode],\n timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n fetch: options.fetch ?? globalThis.fetch,\n authHeaders: {\n 'PAYDUNYA-MASTER-KEY': options.masterKey,\n 'PAYDUNYA-PRIVATE-KEY': options.privateKey,\n 'PAYDUNYA-TOKEN': options.token,\n 'PAYDUNYA-MODE': mode,\n },\n });\n }\n\n capabilities(): ProviderCapabilities {\n return CAPABILITIES;\n }\n\n async collection(input: CollectionInput, options?: ProviderCallOptions): Promise<Transaction> {\n if (input.customer.operator !== undefined && !isOperator(input.customer.operator)) {\n throw new ValidationError(`Unknown operator: ${input.customer.operator}`, {\n provider: this.id,\n });\n }\n\n const cached = await this.#cache.byReference(input.reference);\n if (cached) return structuredClone(cached);\n\n const callbackUrl = input.callbackUrl ?? this.#callbackUrl;\n if (!callbackUrl) {\n throw new ValidationError(\n 'PayDunya needs an IPN URL: pass collection input.callbackUrl or set PaydunyaOptions.callbackUrl',\n { provider: this.id },\n );\n }\n\n const body = {\n invoice: {\n total_amount: input.amount.amount,\n description: input.description ?? `Payment ${input.reference}`,\n },\n store: { name: this.#storeName },\n actions: pruneUndefined({\n callback_url: callbackUrl,\n return_url: input.returnUrl ?? this.#returnUrl,\n cancel_url: input.cancelUrl ?? this.#cancelUrl,\n }),\n custom_data: { [REFERENCE_KEY]: input.reference, ...input.metadata },\n };\n\n const res = await this.#http.postJson<PaydunyaCreateResponse>(\n '/checkout-invoice/create',\n body,\n options?.signal,\n );\n if (!isOk(res.response_code) || !res.token) {\n throw paydunyaError(res.response_code, res.response_text, res);\n }\n\n const now = new Date().toISOString();\n const txn: Transaction = {\n provider: this.id,\n id: res.token,\n reference: input.reference,\n type: 'collection',\n status: 'pending',\n amount: input.amount,\n operator: input.customer.operator,\n customer: input.customer,\n checkoutUrl: res.invoice_url ?? (isUrl(res.response_text) ? res.response_text : undefined),\n providerRaw: res,\n createdAt: now,\n updatedAt: now,\n };\n\n await this.#cache.remember(txn);\n return structuredClone(txn);\n }\n\n async disbursement(\n input: DisbursementInput,\n options?: ProviderCallOptions,\n ): Promise<Transaction> {\n const operator = input.recipient.operator;\n if (!operator || !isOperator(operator)) {\n throw new ValidationError('PayDunya disbursement needs recipient.operator', {\n provider: this.id,\n });\n }\n const mode = WITHDRAW_MODE[operator];\n if (!mode) {\n throw new ValidationError(`PayDunya has no withdraw mode for operator \"${operator}\"`, {\n provider: this.id,\n });\n }\n\n const cached = await this.#cache.byReference(input.reference);\n if (cached) return structuredClone(cached);\n\n const alias = localNumber(input.recipient.phone);\n const get = await this.#http.postJson<PaydunyaDisburseGetResponse>(\n '/disburse/get-invoice',\n { account_alias: alias, amount: input.amount.amount, withdraw_mode: mode },\n options?.signal,\n );\n if (!isOk(get.response_code) || !get.disburse_token) {\n throw paydunyaError(get.response_code, get.response_text ?? 'get-invoice failed', get);\n }\n\n const submit = await this.#http.postJson<PaydunyaDisburseSubmitResponse>(\n '/disburse/submit-invoice',\n { disburse_invoice: get.disburse_token, disburse_id: input.reference },\n options?.signal,\n );\n const desc = typeof submit.description === 'object' ? submit.description : undefined;\n const status = mapDisburseStatus(desc?.status, submit.response_code);\n if (status === 'unknown') {\n throw paydunyaError(\n submit.response_code,\n submit.response_text ?? 'submit-invoice failed',\n submit,\n );\n }\n\n const now = new Date().toISOString();\n const txn: Transaction = {\n provider: this.id,\n id: desc?.provider_ref ?? input.reference,\n reference: input.reference,\n type: 'disbursement',\n status,\n amount: input.amount,\n operator,\n customer: input.recipient,\n failureReason: status === 'failed' ? 'other' : undefined,\n providerRaw: { get, submit },\n createdAt: now,\n updatedAt: now,\n };\n\n await this.#cache.remember(txn);\n return structuredClone(txn);\n }\n\n async getTransaction(ref: TransactionRef, options?: ProviderCallOptions): Promise<Transaction> {\n const known =\n (ref.id ? await this.#cache.byId(ref.id) : undefined) ??\n (ref.reference ? await this.#cache.byReference(ref.reference) : undefined);\n\n if (known?.type === 'disbursement') {\n // PayDunya exposes no public disburse status endpoint; the submit response\n // is the last authoritative state. Callers poll it via reconcile().\n return structuredClone(known);\n }\n\n const token = ref.id ?? known?.id;\n if (!token) {\n throw new ValidationError(\n 'PayDunya looks a transaction up by its invoice token (the provider id); this reference is not known to this instance',\n { provider: this.id },\n );\n }\n\n const res = await this.#http.getJson<PaydunyaConfirmResponse>(\n `/checkout-invoice/confirm/${encodeURIComponent(token)}`,\n options?.signal,\n );\n\n const status = mapConfirmStatus(res);\n if (!isOk(res.response_code) && status === 'unknown') {\n throw paydunyaError(res.response_code, res.response_text ?? 'unknown invoice', res);\n }\n\n const echoed = res.custom_data?.[REFERENCE_KEY];\n const now = new Date().toISOString();\n const txn: Transaction = {\n provider: this.id,\n id: token,\n reference:\n (typeof echoed === 'string' ? echoed : undefined) ??\n known?.reference ??\n ref.reference ??\n token,\n type: 'collection',\n status,\n amount: known?.amount ?? coerceAmount(res.invoice?.total_amount),\n operator: known?.operator,\n customer: known?.customer,\n checkoutUrl: known?.checkoutUrl,\n failureReason: status === 'failed' ? mapFailureReason(res) : undefined,\n providerRaw: res,\n createdAt: known?.createdAt ?? now,\n updatedAt: now,\n };\n\n await this.#cache.remember(txn);\n return structuredClone(txn);\n }\n\n async parseWebhook(raw: RawWebhook): Promise<WebhookEvent> {\n const fields = verifyPaydunyaIpn(raw.body, this.#masterKey);\n const token = ipnField(fields, 'data[invoice][token]');\n if (!token) {\n throw new ValidationError('PayDunya IPN is missing data[invoice][token]', {\n provider: this.id,\n });\n }\n\n const transaction = await this.getTransaction({ id: token });\n return {\n type: webhookEventTypeForStatus(transaction.status),\n transaction,\n providerRaw: fields,\n };\n }\n}\n\nfunction isUrl(value: string | undefined): value is string {\n return typeof value === 'string' && /^https?:\\/\\//i.test(value);\n}\n\n/** Strip a leading `+` and a known country calling code from an E.164 number. */\nfunction localNumber(phone: string): string {\n const digits = phone.replace(/[^\\d]/g, '');\n for (const code of CALLING_CODES) {\n if (digits.startsWith(code)) return digits.slice(code.length);\n }\n return digits;\n}\n\nfunction coerceAmount(raw: number | string | undefined): Money {\n const amount = typeof raw === 'string' ? Number.parseInt(raw, 10) : (raw ?? 0);\n return { amount: Number.isFinite(amount) ? Math.trunc(amount) : 0, currency: 'XOF' };\n}\n\nfunction pruneUndefined<T extends Record<string, unknown>>(obj: T): { [K in keyof T]: T[K] } {\n const out = {} as { [K in keyof T]: T[K] };\n for (const [key, value] of Object.entries(obj)) {\n if (value !== undefined) out[key as keyof T] = value as T[keyof T];\n }\n return out;\n}\n","import { ProviderUnavailableError, RateLimitError } from '@momorail/core';\nimport { PROVIDER_ID } from './mapping.js';\n\nexport type FetchLike = typeof fetch;\n\nexport interface HttpClientOptions {\n baseUrl: string;\n timeoutMs: number;\n fetch: FetchLike;\n /** Sent on every request: PAYDUNYA-MASTER-KEY / -PRIVATE-KEY / -TOKEN, and PAYDUNYA-MODE. */\n authHeaders: Record<string, string>;\n}\n\n/**\n * Minimal JSON helper for PayDunya's HTTP/JSON API: attaches the PAYDUNYA-* auth\n * headers, merges abort signals, enforces a timeout, and maps transport-level\n * failures onto `MomorailError`s.\n */\nexport class HttpClient {\n readonly #baseUrl: string;\n readonly #timeoutMs: number;\n readonly #fetch: FetchLike;\n readonly #authHeaders: Record<string, string>;\n\n constructor(options: HttpClientOptions) {\n this.#baseUrl = options.baseUrl.replace(/\\/$/, '');\n this.#timeoutMs = options.timeoutMs;\n this.#fetch = options.fetch;\n this.#authHeaders = options.authHeaders;\n }\n\n postJson<T>(path: string, body: unknown, signal?: AbortSignal): Promise<T> {\n return this.#request<T>('POST', path, body, signal);\n }\n\n getJson<T>(path: string, signal?: AbortSignal): Promise<T> {\n return this.#request<T>('GET', path, undefined, signal);\n }\n\n async #request<T>(\n method: 'GET' | 'POST',\n path: string,\n body: unknown,\n signal?: AbortSignal,\n ): Promise<T> {\n const timeout = AbortSignal.timeout(this.#timeoutMs);\n const composite = signal ? AbortSignal.any([signal, timeout]) : timeout;\n\n const headers: Record<string, string> = { accept: 'application/json', ...this.#authHeaders };\n if (method === 'POST') headers['content-type'] = 'application/json';\n\n let response: Response;\n try {\n response = await this.#fetch(`${this.#baseUrl}${path}`, {\n method,\n headers,\n body: method === 'POST' ? JSON.stringify(body) : undefined,\n signal: composite,\n });\n } catch (cause) {\n if (signal?.aborted) throw cause;\n throw new ProviderUnavailableError('PayDunya request failed to complete', {\n provider: PROVIDER_ID,\n cause,\n });\n }\n\n if (response.status === 429) {\n throw new RateLimitError('PayDunya throttled the request', { provider: PROVIDER_ID });\n }\n\n const raw = await response.text();\n let parsed: unknown;\n try {\n parsed = raw ? JSON.parse(raw) : {};\n } catch (cause) {\n throw new ProviderUnavailableError('PayDunya returned a non-JSON response', {\n provider: PROVIDER_ID,\n providerRaw: raw,\n cause,\n });\n }\n\n if (response.status >= 500) {\n throw new ProviderUnavailableError(`PayDunya responded ${response.status}`, {\n provider: PROVIDER_ID,\n providerRaw: parsed,\n });\n }\n\n return parsed as T;\n }\n}\n","import {\n AuthError,\n type FailureReason,\n MomorailError,\n TransactionNotFoundError,\n type TransactionStatus,\n} from '@momorail/core';\nimport type { PaydunyaConfirmResponse } from './types.js';\n\nexport const PROVIDER_ID = 'paydunya';\n\nconst OK = '00';\nconst AUTH_HINT = /cl[eé]s?|api[\\s-]?key|authenticat|non autoris|unauthor/i;\nconst NOT_FOUND_HINT = /introuvable|invalide|not[\\s_]*found|no such|inexistant/i;\n\n/** Map a PayDunya `status` string onto a Momorail status. */\nexport function mapConfirmStatus(res: PaydunyaConfirmResponse): TransactionStatus {\n switch (res.status?.toLowerCase()) {\n case 'completed':\n return 'succeeded';\n case 'pending':\n return 'processing';\n case 'cancelled':\n case 'canceled':\n return 'cancelled';\n case 'failed':\n case 'fail':\n return 'failed';\n default:\n return res.response_code === OK ? 'processing' : 'unknown';\n }\n}\n\n/** Map a PayDunya disburse status onto a Momorail status. */\nexport function mapDisburseStatus(\n status: string | undefined,\n responseCode: string,\n): TransactionStatus {\n switch (status?.toLowerCase()) {\n case 'completed':\n case 'success':\n case 'successful':\n return 'succeeded';\n case 'pending':\n case 'processing':\n case 'sent':\n return 'processing';\n case 'failed':\n case 'cancelled':\n case 'rejected':\n return 'failed';\n default:\n return responseCode === OK ? 'processing' : 'unknown';\n }\n}\n\nexport function mapFailureReason(res: PaydunyaConfirmResponse): FailureReason {\n const text = `${res.response_text ?? ''}`.toLowerCase();\n if (/solde|insufficient|fund/.test(text)) return 'insufficient_funds';\n if (/annul|cancel/.test(text)) return 'user_declined';\n if (/expir/.test(text)) return 'timeout';\n return 'other';\n}\n\n/**\n * PayDunya usually returns HTTP 200 with `response_code !== \"00\"` and a message\n * in `response_text`. Translate that (or an HTTP status) into a `MomorailError`.\n */\nexport function paydunyaError(\n responseCode: string,\n message: string,\n providerRaw: unknown,\n): MomorailError {\n const opts = { provider: PROVIDER_ID, providerRaw } as const;\n\n if (AUTH_HINT.test(message)) {\n return new AuthError(`PayDunya rejected the credentials (${responseCode}: ${message})`, opts);\n }\n if (NOT_FOUND_HINT.test(message)) {\n return new TransactionNotFoundError(\n `PayDunya has no such invoice (${responseCode}: ${message})`,\n opts,\n );\n }\n return new MomorailError(`PayDunya error (${responseCode}: ${message})`, 'provider_error', opts);\n}\n\nexport function isOk(responseCode: string): boolean {\n return responseCode === OK;\n}\n","import { createHash, timingSafeEqual } from 'node:crypto';\nimport { WebhookVerificationError } from '@momorail/core';\nimport { PROVIDER_ID } from './mapping.js';\nimport type { PaydunyaIpnFields } from './types.js';\n\n/**\n * Parse a PayDunya IPN body. PayDunya POSTs `application/x-www-form-urlencoded`\n * with bracketed keys (`data[invoice][token]`, `data[status]`, `data[hash]`, …).\n * The keys are kept flat and verbatim.\n */\nexport function parseIpnBody(\n body: string | Uint8Array | Record<string, unknown>,\n): PaydunyaIpnFields {\n if (typeof body === 'string' || body instanceof Uint8Array) {\n const raw = typeof body === 'string' ? body : new TextDecoder().decode(body);\n return Object.fromEntries(new URLSearchParams(raw).entries());\n }\n const out: PaydunyaIpnFields = {};\n for (const [key, value] of Object.entries(body)) {\n if (value != null) out[key] = String(value);\n }\n return out;\n}\n\n/** PayDunya's IPN hash is `sha512(masterKey)` — a static digest of your Master Key. */\nexport function paydunyaIpnHash(masterKey: string): string {\n return createHash('sha512').update(masterKey, 'utf8').digest('hex');\n}\n\nfunction safeEqualHex(a: string, b: string): boolean {\n if (a.length !== b.length || a.length === 0) return false;\n try {\n return timingSafeEqual(Buffer.from(a, 'hex'), Buffer.from(b, 'hex'));\n } catch {\n return false;\n }\n}\n\n/** Read a bracketed IPN field regardless of surrounding whitespace. */\nexport function ipnField(fields: PaydunyaIpnFields, key: string): string | undefined {\n return fields[key] ?? fields[key.replace(/\\s+/g, '')];\n}\n\n/**\n * Verify a PayDunya IPN. Returns the parsed fields on success; throws\n * {@link WebhookVerificationError} when `data[hash]` is missing or does not equal\n * `sha512(masterKey)`.\n *\n * NOTE: this proves the notification came from an actor holding your Master Key —\n * it does not sign the payload. Momorail therefore re-queries the invoice for the\n * authoritative status rather than trusting `data[status]`.\n */\nexport function verifyPaydunyaIpn(\n body: string | Uint8Array | Record<string, unknown>,\n masterKey: string,\n): PaydunyaIpnFields {\n const fields = parseIpnBody(body);\n const received = ipnField(fields, 'data[hash]');\n if (!received) {\n throw new WebhookVerificationError('PayDunya IPN is missing data[hash]', {\n provider: PROVIDER_ID,\n });\n }\n if (!safeEqualHex(received.toLowerCase(), paydunyaIpnHash(masterKey))) {\n throw new WebhookVerificationError('PayDunya IPN hash does not match the Master Key', {\n provider: PROVIDER_ID,\n });\n }\n return fields;\n}\n"],"mappings":";AAAA;AAAA,EAGE;AAAA,EAEA;AAAA,EAUA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;;;ACnBP,SAAS,0BAA0B,sBAAsB;;;ACAzD;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OAEK;AAGA,IAAM,cAAc;AAE3B,IAAM,KAAK;AACX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C3F,QAAM,MAAM,CAAC;AACb,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,UAAU,OAAW,KAAI,GAAc,IAAI;AAAA,EACjD;AACA,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@momorail/paydunya",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "PayDunya adapter for Momorail (checkout invoice, status, IPN verification)",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"mobile-money",
|
|
8
|
+
"payments",
|
|
9
|
+
"west-africa",
|
|
10
|
+
"africa",
|
|
11
|
+
"orange-money",
|
|
12
|
+
"mtn-momo",
|
|
13
|
+
"wave",
|
|
14
|
+
"xof",
|
|
15
|
+
"byo-keys",
|
|
16
|
+
"typescript",
|
|
17
|
+
"paydunya",
|
|
18
|
+
"adapter"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Boukymen <boukymen@gmail.com>",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/Boukymen/momorail.git",
|
|
25
|
+
"directory": "packages/paydunya"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/Boukymen/momorail/tree/main/packages/paydunya#readme",
|
|
28
|
+
"bugs": "https://github.com/Boukymen/momorail/issues",
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@momorail/core": "0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"msw": "^2.7.0",
|
|
48
|
+
"tsup": "^8.3.5",
|
|
49
|
+
"typescript": "^5.7.2",
|
|
50
|
+
"vitest": "^2.1.8",
|
|
51
|
+
"@momorail/conformance": "0.1.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"test": "vitest run"
|
|
57
|
+
}
|
|
58
|
+
}
|