@mopay/node-sdk 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/README.md +246 -0
- package/dist/base.d.ts +13 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +122 -0
- package/dist/checkout.d.ts +6 -0
- package/dist/checkout.d.ts.map +1 -0
- package/dist/checkout.js +402 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +15 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/payments/index.d.ts +7 -0
- package/dist/payments/index.d.ts.map +1 -0
- package/dist/payments/index.js +14 -0
- package/dist/redirects/index.d.ts +7 -0
- package/dist/redirects/index.d.ts.map +1 -0
- package/dist/redirects/index.js +11 -0
- package/dist/sessions/index.d.ts +11 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/sessions/index.js +58 -0
- package/dist/types.d.ts +132 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +125 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MoPay
|
|
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/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# MoPay Node SDK
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for creating and verifying MoPay hosted payment sessions from Node.js.
|
|
4
|
+
|
|
5
|
+
MoPay's flow is:
|
|
6
|
+
|
|
7
|
+
1. Create a payment session from your backend.
|
|
8
|
+
2. Redirect the customer to the returned `paymentUrl`.
|
|
9
|
+
3. When MoPay redirects the customer back, verify the final state with the session API.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add @mopay/node-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { MoPay } from "@mopay/node-sdk";
|
|
21
|
+
|
|
22
|
+
const mopay = new MoPay({
|
|
23
|
+
apiKey: process.env.MOPAY_API_KEY!,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const session = await mopay.createPaymentSession({
|
|
27
|
+
amount: "100.00",
|
|
28
|
+
reference: "ORDER12345",
|
|
29
|
+
redirectUrl: "https://yourwebsite.com/payment-complete",
|
|
30
|
+
description: "Order #12345",
|
|
31
|
+
customerEmail: "customer@example.com",
|
|
32
|
+
customerName: "John Doe",
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.log(session.paymentUrl);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Browser Checkout
|
|
39
|
+
|
|
40
|
+
Use the secret-key SDK only on the merchant backend. The frontend should receive a checkout URL or token from the merchant backend, then call `MoPayCheckout.open({ checkoutUrl })`.
|
|
41
|
+
|
|
42
|
+
Merchant backend:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { MoPay } from "@mopay/node-sdk";
|
|
46
|
+
|
|
47
|
+
const mopay = new MoPay({
|
|
48
|
+
apiKey: process.env.MOPAY_API_KEY!,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const session = await mopay.createPaymentSession({
|
|
52
|
+
amount: "100.00",
|
|
53
|
+
reference: "ORDER12345",
|
|
54
|
+
redirectUrl: "https://yourwebsite.com/payment-complete",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
sessionId: session.sessionId,
|
|
59
|
+
checkoutUrl: session.paymentUrl,
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Merchant frontend:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
import { MoPayCheckout } from "@mopay/node-sdk";
|
|
67
|
+
|
|
68
|
+
const session = await fetch("/api/create-mopay-checkout", {
|
|
69
|
+
method: "POST",
|
|
70
|
+
headers: { "Content-Type": "application/json" },
|
|
71
|
+
body: JSON.stringify({ amount: "100.00", reference: "ORDER12345" }),
|
|
72
|
+
}).then((response) => response.json());
|
|
73
|
+
|
|
74
|
+
MoPayCheckout.open({
|
|
75
|
+
checkoutUrl: session.checkoutUrl,
|
|
76
|
+
allowedOrigins: [window.location.origin],
|
|
77
|
+
width: 520,
|
|
78
|
+
height: 760,
|
|
79
|
+
resizable: true,
|
|
80
|
+
onSuccess: () => {
|
|
81
|
+
// UI feedback only. Do not deliver value here.
|
|
82
|
+
},
|
|
83
|
+
onClose: async () => {
|
|
84
|
+
await fetch(`/api/verify-mopay-session/${session.sessionId}`);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Supported modes:
|
|
90
|
+
|
|
91
|
+
- `dialog`: opens an iframe dialog inside your UI. This is the default.
|
|
92
|
+
- `popup`: opens the hosted MoPay page in a centered browser popup.
|
|
93
|
+
- `redirect`: sends the current page to `paymentUrl`.
|
|
94
|
+
|
|
95
|
+
For dialog mode, `width`, `height`, `minWidth`, `minHeight`, `maxWidth`, and `maxHeight` control the SDK-owned frame around the hosted MoPay page. Set `resizable: true` if customers should be able to drag-resize the checkout frame.
|
|
96
|
+
|
|
97
|
+
For iframe checkout, MoPay's hosted page must allow embedding from approved merchant sites. The MoPay checkout server should set `Content-Security-Policy: frame-ancestors ...` dynamically from the merchant's registered allowed origins and avoid `X-Frame-Options: DENY` or `SAMEORIGIN` for embeddable checkout pages.
|
|
98
|
+
|
|
99
|
+
The SDK only accepts `postMessage` events from the checkout URL origin, and only from the opened iframe or popup window. Frontend callbacks are for UI feedback only; merchants must confirm payment through signed webhooks or `mopay.getTransaction(sessionId)` before delivering value.
|
|
100
|
+
|
|
101
|
+
If your checkout iframe can redirect back to a merchant-owned completion page, pass that exact origin in `allowedOrigins`. The checkout URL origin is always trusted automatically.
|
|
102
|
+
|
|
103
|
+
## Verify A Redirect
|
|
104
|
+
|
|
105
|
+
Redirect parameters are useful for routing your user, but they should not be treated as the final source of truth. Always verify with MoPay from your backend.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { MoPay, parseRedirect } from "@mopay/node-sdk";
|
|
109
|
+
|
|
110
|
+
const redirect = parseRedirect(
|
|
111
|
+
"https://yourwebsite.com/payment-complete?status=success&reference=ORDER12345&transactionId=TXN123&sessionId=MOP_abc123_ORDER12345&amount=100.00&paymentMethod=mpesa",
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const mopay = new MoPay({ apiKey: process.env.MOPAY_API_KEY! });
|
|
115
|
+
const verified = await mopay.retrieveSession(redirect.sessionId);
|
|
116
|
+
|
|
117
|
+
if (verified.session.status === "COMPLETED") {
|
|
118
|
+
// Fulfil the order.
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## API
|
|
123
|
+
|
|
124
|
+
### `new MoPay(options)`
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
const mopay = new MoPay({
|
|
128
|
+
apiKey: "YOUR_API_KEY",
|
|
129
|
+
baseUrl: "https://mopay.co.ls",
|
|
130
|
+
timeoutMs: 30000,
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`apiKey` is required. `baseUrl` is optional and defaults to `https://mopay.co.ls`.
|
|
135
|
+
|
|
136
|
+
### `mopay.createPaymentSession(params)`
|
|
137
|
+
|
|
138
|
+
Creates a hosted payment session with `POST /api/external/payment`.
|
|
139
|
+
|
|
140
|
+
Required fields:
|
|
141
|
+
|
|
142
|
+
- `amount`: string or number, for example `"100.00"`.
|
|
143
|
+
- `reference`: unique alphanumeric order reference, for example `"ORDER12345"`.
|
|
144
|
+
- `redirectUrl`: absolute URL where MoPay should send the customer after payment.
|
|
145
|
+
|
|
146
|
+
Optional fields:
|
|
147
|
+
|
|
148
|
+
- `description`
|
|
149
|
+
- `customerEmail`
|
|
150
|
+
- `customerName`
|
|
151
|
+
- `paymentFrequency`: `ONCE`, `MONTHLY`, or `ANNUALLY`
|
|
152
|
+
- `productName`
|
|
153
|
+
- `productDetails`
|
|
154
|
+
- `productImage`
|
|
155
|
+
- `payWhatYouWant`
|
|
156
|
+
- `minimumAmount`
|
|
157
|
+
|
|
158
|
+
### `mopay.retrieveSession(sessionId)`
|
|
159
|
+
|
|
160
|
+
Retrieves session details with `GET /api/external/session/v1/{sessionId}`.
|
|
161
|
+
|
|
162
|
+
### `mopay.parseRedirect(input)` or `parseRedirect(input)`
|
|
163
|
+
|
|
164
|
+
Parses MoPay redirect query parameters from a URL, `URLSearchParams`, or plain object.
|
|
165
|
+
|
|
166
|
+
### `MoPayCheckout.open({ checkoutUrl, ...options })`
|
|
167
|
+
|
|
168
|
+
Opens the hosted checkout page in `popup`, `dialog`, or `redirect` mode.
|
|
169
|
+
|
|
170
|
+
Accepts `checkoutUrl`, `checkout_url`, `checkoutToken`, or `checkout_token`. `checkoutUrl` is the same value as the documented `paymentUrl` returned by `createPaymentSession`.
|
|
171
|
+
|
|
172
|
+
### `mopay.checkout(params, options)`
|
|
173
|
+
|
|
174
|
+
Convenience method that creates a session and opens the checkout dialog. Use this only from a trusted environment because it requires the secret API key.
|
|
175
|
+
|
|
176
|
+
### `mopay.getSession(sessionId)` / `mopay.getTransaction(sessionId)`
|
|
177
|
+
|
|
178
|
+
Retrieves the latest MoPay session and transaction data for any session ID.
|
|
179
|
+
|
|
180
|
+
### `mopay.isSuccessful(session)`
|
|
181
|
+
|
|
182
|
+
Returns `true` when a retrieved session is completed or has `transactionStatus: "success"`.
|
|
183
|
+
|
|
184
|
+
### `mopay.isPaymentSuccessful(sessionId)`
|
|
185
|
+
|
|
186
|
+
Retrieves the session by ID and returns `true` when the payment is successful.
|
|
187
|
+
|
|
188
|
+
### `mopay.waitForSession(sessionId, options)`
|
|
189
|
+
|
|
190
|
+
Polls MoPay until a session reaches a terminal state such as `COMPLETED`, `FAILED`, `CANCELLED`, or `EXPIRED`.
|
|
191
|
+
|
|
192
|
+
## Sandbox Mobile Money Numbers
|
|
193
|
+
|
|
194
|
+
Use these only while your MoPay project is in sandbox mode.
|
|
195
|
+
|
|
196
|
+
| Method | Number | Expected result |
|
|
197
|
+
| --- | --- | --- |
|
|
198
|
+
| M-Pesa | `52211111` | Immediate success |
|
|
199
|
+
| M-Pesa | `52222222` | Pending first, then success |
|
|
200
|
+
| M-Pesa | `52233333` | Failed |
|
|
201
|
+
| M-Pesa | `52244444` | Cancelled |
|
|
202
|
+
| M-Pesa | `52255555` | Expired |
|
|
203
|
+
| EcoCash | `63211111` | Immediate success |
|
|
204
|
+
| EcoCash | `63222222` | Pending first, then success |
|
|
205
|
+
| EcoCash | `63233333` | Failed |
|
|
206
|
+
| EcoCash | `63244444` | Cancelled |
|
|
207
|
+
| EcoCash | `63255555` | Expired |
|
|
208
|
+
|
|
209
|
+
## Development
|
|
210
|
+
|
|
211
|
+
```sh
|
|
212
|
+
pnpm install
|
|
213
|
+
pnpm test
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Simple HTML Example
|
|
217
|
+
|
|
218
|
+
This repository includes an Express-backed checkout example outside the publishable SDK package.
|
|
219
|
+
From the repository root:
|
|
220
|
+
|
|
221
|
+
```sh
|
|
222
|
+
cp examples/simple-checkout/.env.example examples/simple-checkout/.env
|
|
223
|
+
pnpm example:simple-checkout
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Open `http://127.0.0.1:4173/`.
|
|
227
|
+
|
|
228
|
+
Put your real MoPay secret key in `examples/simple-checkout/.env`:
|
|
229
|
+
|
|
230
|
+
```env
|
|
231
|
+
MOPAY_API_KEY=sk_live_or_test_xxx
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Optional environment variables:
|
|
235
|
+
|
|
236
|
+
- `MOPAY_BASE_URL`: defaults to `https://mopay.co.ls`.
|
|
237
|
+
- `MERCHANT_PUBLIC_URL`: public URL for the merchant demo, used to build the MoPay `redirectUrl`.
|
|
238
|
+
- `MOPAY_REDIRECT_URL`: full redirect URL override.
|
|
239
|
+
- `PORT`: defaults to `4173`.
|
|
240
|
+
- `HOST`: defaults to `127.0.0.1`.
|
|
241
|
+
|
|
242
|
+
The example serves a tiny merchant backend with Express:
|
|
243
|
+
|
|
244
|
+
- `POST /api/create-mopay-checkout` creates a MoPay checkout session through `mopay.createPaymentSession`.
|
|
245
|
+
- `GET /api/mopay-session/:sessionId` retrieves transaction data through `mopay.getTransaction`.
|
|
246
|
+
- `GET /api/mopay-session/:sessionId/success` verifies whether the session is paid through `mopay.isSuccessful`.
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CheckoutOptions, MoPayConfig, RequestOptions } from "./types.js";
|
|
2
|
+
export declare abstract class Base {
|
|
3
|
+
private readonly apiKey;
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly timeoutMs;
|
|
6
|
+
private readonly fetchImpl?;
|
|
7
|
+
private readonly userAgent;
|
|
8
|
+
private readonly checkoutOptions;
|
|
9
|
+
constructor(config: MoPayConfig);
|
|
10
|
+
protected getDefaultCheckoutOptions(): CheckoutOptions;
|
|
11
|
+
protected request<T>(endpoint: string, options?: RequestInit, requestOptions?: RequestOptions): Promise<T>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EAGf,WAAW,EACX,cAAc,EACf,MAAM,YAAY,CAAC;AAKpB,8BAAsB,IAAI;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;gBAEtC,MAAM,EAAE,WAAW;IAa/B,SAAS,CAAC,yBAAyB,IAAI,eAAe;cAItC,OAAO,CAAC,CAAC,EACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,WAAgB,EACzB,cAAc,GAAE,cAAmB,GAClC,OAAO,CAAC,CAAC,CAAC;CAuDd"}
|
package/dist/base.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { MoPayAPIError } from "./errors.js";
|
|
2
|
+
const DEFAULT_BASE_URL = "https://mopay.co.ls";
|
|
3
|
+
const DEFAULT_TIMEOUT_MS = 30000;
|
|
4
|
+
export class Base {
|
|
5
|
+
apiKey;
|
|
6
|
+
baseUrl;
|
|
7
|
+
timeoutMs;
|
|
8
|
+
fetchImpl;
|
|
9
|
+
userAgent;
|
|
10
|
+
checkoutOptions;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
if (!config.apiKey) {
|
|
13
|
+
throw new MoPayAPIError("apiKey is required");
|
|
14
|
+
}
|
|
15
|
+
this.apiKey = config.apiKey;
|
|
16
|
+
this.baseUrl = normalizeBaseUrl(config.baseUrl || DEFAULT_BASE_URL);
|
|
17
|
+
this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
18
|
+
this.fetchImpl = config.fetch || getNativeFetch();
|
|
19
|
+
this.userAgent = config.userAgent || "@mopay/node-sdk/0.1.0";
|
|
20
|
+
this.checkoutOptions = config.checkout || {};
|
|
21
|
+
}
|
|
22
|
+
getDefaultCheckoutOptions() {
|
|
23
|
+
return this.checkoutOptions;
|
|
24
|
+
}
|
|
25
|
+
async request(endpoint, options = {}, requestOptions = {}) {
|
|
26
|
+
if (!this.fetchImpl) {
|
|
27
|
+
throw new MoPayAPIError("fetch is not available in this runtime. Use Node.js 18+ or pass a fetch implementation.");
|
|
28
|
+
}
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
const timeout = this.timeoutMs > 0
|
|
31
|
+
? setTimeout(() => controller.abort(new Error("MoPay request timed out")), this.timeoutMs)
|
|
32
|
+
: undefined;
|
|
33
|
+
const signal = anySignal([controller.signal, requestOptions.signal].filter(Boolean));
|
|
34
|
+
const url = new URL(endpoint, this.baseUrl);
|
|
35
|
+
const requestInit = {
|
|
36
|
+
...options,
|
|
37
|
+
headers: {
|
|
38
|
+
Accept: "application/json",
|
|
39
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
"User-Agent": this.userAgent,
|
|
42
|
+
...options.headers,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
if (signal) {
|
|
46
|
+
requestInit.signal = signal;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const response = await this.fetchImpl(url, requestInit);
|
|
50
|
+
const data = await parseResponse(response);
|
|
51
|
+
const apiError = data;
|
|
52
|
+
if (!response.ok || apiError.success === false) {
|
|
53
|
+
throw new MoPayAPIError(apiError.error || apiError.message || "MoPay API request failed", {
|
|
54
|
+
statusCode: response.status,
|
|
55
|
+
code: apiError.code,
|
|
56
|
+
response: data,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error instanceof MoPayAPIError) {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
throw new MoPayAPIError(error instanceof Error ? error.message : "MoPay API request failed");
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
if (timeout !== undefined) {
|
|
69
|
+
clearTimeout(timeout);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function getNativeFetch() {
|
|
75
|
+
if (typeof globalThis.fetch !== "function") {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
return globalThis.fetch.bind(globalThis);
|
|
79
|
+
}
|
|
80
|
+
async function parseResponse(response) {
|
|
81
|
+
const text = await response.text();
|
|
82
|
+
if (!text) {
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(text);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return { success: false, error: text };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function normalizeBaseUrl(baseUrl) {
|
|
93
|
+
const normalized = /^https?:\/\//i.test(baseUrl) ? baseUrl : `https://${baseUrl}`;
|
|
94
|
+
try {
|
|
95
|
+
const url = new URL(normalized);
|
|
96
|
+
return url.href.endsWith("/") ? url.href : `${url.href}/`;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
throw new MoPayAPIError(`baseUrl must be a valid URL. Received: ${baseUrl}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function anySignal(signals) {
|
|
103
|
+
if (signals.length === 0) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
if (signals.length === 1) {
|
|
107
|
+
return signals[0];
|
|
108
|
+
}
|
|
109
|
+
const controller = new AbortController();
|
|
110
|
+
const abort = (event) => {
|
|
111
|
+
const signal = event.target;
|
|
112
|
+
controller.abort(signal.reason);
|
|
113
|
+
};
|
|
114
|
+
signals.forEach((signal) => {
|
|
115
|
+
if (signal.aborted) {
|
|
116
|
+
controller.abort(signal.reason);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
120
|
+
});
|
|
121
|
+
return controller.signal;
|
|
122
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CheckoutHandle, CheckoutOptions, MoPayCheckoutOpenOptions } from "./types.js";
|
|
2
|
+
export declare function checkout(paymentUrl: string, options?: CheckoutOptions): CheckoutHandle;
|
|
3
|
+
export declare class MoPayCheckout {
|
|
4
|
+
static open(options: MoPayCheckoutOpenOptions): CheckoutHandle;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../src/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,eAAe,EACf,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAUpB,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,cAAc,CAE1F;AAED,qBAAa,aAAa;IACxB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,wBAAwB,GAAG,cAAc;CA6B/D"}
|