@laranex/myanmar-payments 4.0.0-dev.1 → 4.0.0-dev.10
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/CHANGELOG.md +19 -4
- package/README.md +3 -3
- package/dist/cjs/aya-pay/aya-pay.d.ts +13 -9
- package/dist/cjs/aya-pay/aya-pay.js +16 -12
- package/dist/cjs/core/amount.d.ts +4 -3
- package/dist/cjs/core/amount.js +13 -4
- package/dist/cjs/core/callback.d.ts +14 -8
- package/dist/cjs/core/callback.js +19 -11
- package/dist/cjs/core/crypto.d.ts +6 -1
- package/dist/cjs/core/crypto.js +17 -3
- package/dist/cjs/core/env.d.ts +14 -5
- package/dist/cjs/core/env.js +35 -11
- package/dist/cjs/core/errors.d.ts +9 -3
- package/dist/cjs/core/errors.js +12 -4
- package/dist/cjs/core/http.d.ts +10 -11
- package/dist/cjs/core/http.js +7 -9
- package/dist/cjs/core/index.d.ts +2 -2
- package/dist/cjs/core/index.js +3 -2
- package/dist/cjs/core/json.d.ts +2 -2
- package/dist/cjs/core/json.js +3 -3
- package/dist/cjs/core/status.d.ts +3 -3
- package/dist/cjs/core/status.js +2 -2
- package/dist/cjs/core/values.d.ts +2 -0
- package/dist/cjs/core/values.js +5 -0
- package/dist/cjs/cyber-source/cyber-source.d.ts +12 -14
- package/dist/cjs/cyber-source/cyber-source.js +39 -26
- package/dist/cjs/kbz-pay/kbz-pay.d.ts +27 -11
- package/dist/cjs/kbz-pay/kbz-pay.js +43 -20
- package/dist/cjs/kbz-pay/signer.d.ts +4 -1
- package/dist/cjs/kbz-pay/signer.js +7 -2
- package/dist/cjs/wave-money/wave-money.d.ts +26 -13
- package/dist/cjs/wave-money/wave-money.js +29 -29
- package/dist/cjs/yoma-mmqr/yoma-mmqr.d.ts +17 -13
- package/dist/cjs/yoma-mmqr/yoma-mmqr.js +21 -19
- package/dist/esm/aya-pay/aya-pay.d.ts +13 -9
- package/dist/esm/aya-pay/aya-pay.js +18 -14
- package/dist/esm/core/amount.d.ts +4 -3
- package/dist/esm/core/amount.js +13 -4
- package/dist/esm/core/callback.d.ts +14 -8
- package/dist/esm/core/callback.js +19 -11
- package/dist/esm/core/crypto.d.ts +6 -1
- package/dist/esm/core/crypto.js +17 -3
- package/dist/esm/core/env.d.ts +14 -5
- package/dist/esm/core/env.js +32 -9
- package/dist/esm/core/errors.d.ts +9 -3
- package/dist/esm/core/errors.js +12 -4
- package/dist/esm/core/http.d.ts +10 -11
- package/dist/esm/core/http.js +6 -8
- package/dist/esm/core/index.d.ts +2 -2
- package/dist/esm/core/index.js +2 -1
- package/dist/esm/core/json.d.ts +2 -2
- package/dist/esm/core/json.js +3 -3
- package/dist/esm/core/status.d.ts +3 -3
- package/dist/esm/core/status.js +2 -2
- package/dist/esm/core/values.d.ts +2 -0
- package/dist/esm/core/values.js +4 -0
- package/dist/esm/cyber-source/cyber-source.d.ts +12 -14
- package/dist/esm/cyber-source/cyber-source.js +41 -28
- package/dist/esm/kbz-pay/kbz-pay.d.ts +27 -11
- package/dist/esm/kbz-pay/kbz-pay.js +45 -22
- package/dist/esm/kbz-pay/signer.d.ts +4 -1
- package/dist/esm/kbz-pay/signer.js +8 -3
- package/dist/esm/wave-money/wave-money.d.ts +26 -13
- package/dist/esm/wave-money/wave-money.js +31 -31
- package/dist/esm/yoma-mmqr/yoma-mmqr.d.ts +17 -13
- package/dist/esm/yoma-mmqr/yoma-mmqr.js +23 -21
- package/package.json +2 -2
- package/skills/node-myanmar-payments/SKILL.md +26 -22
|
@@ -5,14 +5,17 @@ import { parseJsonObject, setKey, toPlainObject } from './json.js';
|
|
|
5
5
|
* {@link CallbackRequest.fromNodeRequest} or {@link CallbackRequest.fromWebRequest}.
|
|
6
6
|
*/
|
|
7
7
|
export class CallbackRequest {
|
|
8
|
-
/** The
|
|
8
|
+
/** The request body as text: a string body as given, bytes decoded as UTF-8. */
|
|
9
9
|
body;
|
|
10
|
+
/** The exact bytes received. A string body is encoded as UTF-8. */
|
|
11
|
+
rawBody;
|
|
10
12
|
/** The request headers, with lowercase names. Repeated headers are joined with `, `. */
|
|
11
13
|
headers;
|
|
12
14
|
/** The query string parameters (the first value of each). */
|
|
13
15
|
query;
|
|
14
16
|
constructor(init = {}) {
|
|
15
|
-
this.
|
|
17
|
+
this.rawBody = bodyBytes(init.body);
|
|
18
|
+
this.body = typeof init.body === 'string' ? init.body : new TextDecoder().decode(this.rawBody);
|
|
16
19
|
this.headers = Object.freeze(normalizeHeaders(init.headers));
|
|
17
20
|
this.query = Object.freeze(normalizeQuery(init.query));
|
|
18
21
|
}
|
|
@@ -31,10 +34,11 @@ export class CallbackRequest {
|
|
|
31
34
|
});
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
|
-
* Reads a Node `http.IncomingMessage` (also Express `req`,
|
|
35
|
-
* Reads the raw body from the stream, or from `rawBody`/`body` when middleware captured
|
|
36
|
-
* text or bytes. When a body parser already consumed the stream, the parsed `body` is
|
|
37
|
-
* again as JSON or a form.
|
|
37
|
+
* Reads a Node `http.IncomingMessage` (also Express `req`, or Koa `ctx.req` without a body
|
|
38
|
+
* parser). Reads the raw body from the stream, or from `rawBody`/`body` when middleware captured
|
|
39
|
+
* it as text or bytes. When a body parser already consumed the stream, the parsed `body` is
|
|
40
|
+
* encoded again as JSON or a form. Fastify parses the body before your handler runs: use
|
|
41
|
+
* {@link CallbackRequest.from} with the raw body there.
|
|
38
42
|
*/
|
|
39
43
|
static async fromNodeRequest(request) {
|
|
40
44
|
const headers = normalizeHeaders(request.headers);
|
|
@@ -67,7 +71,10 @@ export class CallbackRequest {
|
|
|
67
71
|
header(name) {
|
|
68
72
|
return this.headers[name.toLowerCase()];
|
|
69
73
|
}
|
|
70
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* The body decoded as JSON or as a urlencoded form. JSON numbers keep their exact text, as strings
|
|
76
|
+
* (`1000.50` stays `"1000.50"`).
|
|
77
|
+
*/
|
|
71
78
|
parsedBody() {
|
|
72
79
|
return toPlainObject(losslessBody(this));
|
|
73
80
|
}
|
|
@@ -206,14 +213,15 @@ export class PaymentStatusResult {
|
|
|
206
213
|
return this.status === 'successful';
|
|
207
214
|
}
|
|
208
215
|
}
|
|
209
|
-
function
|
|
216
|
+
function bodyBytes(body) {
|
|
210
217
|
if (body === undefined || body === null) {
|
|
211
|
-
return
|
|
218
|
+
return new Uint8Array();
|
|
212
219
|
}
|
|
213
220
|
if (typeof body === 'string') {
|
|
214
|
-
return body;
|
|
221
|
+
return new TextEncoder().encode(body);
|
|
215
222
|
}
|
|
216
|
-
|
|
223
|
+
// A copy, so later changes to the caller's buffer cannot alter what was verified.
|
|
224
|
+
return body instanceof ArrayBuffer ? new Uint8Array(body.slice(0)) : Uint8Array.from(body);
|
|
217
225
|
}
|
|
218
226
|
function rawBody(value) {
|
|
219
227
|
if (typeof value === 'string' || value instanceof Uint8Array || value instanceof ArrayBuffer) {
|
|
@@ -15,5 +15,10 @@ export declare function randomHex(bytes?: number): string;
|
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
17
|
export declare function queryEscape(value: string): string;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Decodes standard base64 (`A-Z a-z 0-9 + /`), either correctly padded or without any padding, to
|
|
20
|
+
* UTF-8 text. Partial padding, other characters and bytes that are not UTF-8 return `undefined`.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
19
24
|
export declare function decodeBase64(value: string): string | undefined;
|
package/dist/esm/core/crypto.js
CHANGED
|
@@ -32,10 +32,24 @@ export function queryEscape(value) {
|
|
|
32
32
|
.replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)
|
|
33
33
|
.replace(/%20/g, '+');
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
const UTF8 = new TextDecoder('utf-8', { fatal: true });
|
|
36
|
+
/**
|
|
37
|
+
* Decodes standard base64 (`A-Z a-z 0-9 + /`), either correctly padded or without any padding, to
|
|
38
|
+
* UTF-8 text. Partial padding, other characters and bytes that are not UTF-8 return `undefined`.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
36
42
|
export function decodeBase64(value) {
|
|
37
|
-
if (
|
|
43
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(value)) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
if (value.includes('=') ? value.length % 4 !== 0 : value.length % 4 === 1) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return UTF8.decode(Buffer.from(value, 'base64'));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
38
53
|
return undefined;
|
|
39
54
|
}
|
|
40
|
-
return Buffer.from(value, 'base64').toString('utf8');
|
|
41
55
|
}
|
package/dist/esm/core/env.d.ts
CHANGED
|
@@ -3,14 +3,23 @@ export type EnvSource = Readonly<Record<string, string | undefined>>;
|
|
|
3
3
|
/** The first non-empty value among `keys`, trimmed, or `''`. @internal */
|
|
4
4
|
export declare function envFirst(env: EnvSource, ...keys: string[]): string;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* A required whole number of seconds: an integer greater than 0, or text such as `'300'`. Unset
|
|
7
|
+
* or blank throws the missing {@link ConfigurationError}; anything else throws the invalid one.
|
|
8
8
|
*
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
|
-
export declare function
|
|
12
|
-
/**
|
|
13
|
-
export declare
|
|
11
|
+
export declare function requireSeconds(gateway: string, key: string, value: unknown): number;
|
|
12
|
+
/** The variable holding the HTTP timeout of every gateway that calls an API. @internal */
|
|
13
|
+
export declare const HTTP_TIMEOUT_VARIABLE = "MYANMAR_PAYMENTS_HTTP_TIMEOUT";
|
|
14
|
+
/** Seconds before the default HTTP client gives up on a request when no timeout is configured. */
|
|
15
|
+
export declare const DEFAULT_TIMEOUT_SECONDS = 30;
|
|
16
|
+
/**
|
|
17
|
+
* The HTTP timeout in seconds: {@link DEFAULT_TIMEOUT_SECONDS} when unset or blank, otherwise a
|
|
18
|
+
* whole number greater than 0 (or its text), or the invalid {@link ConfigurationError}.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveTimeout(gateway: string, value: unknown): number;
|
|
14
23
|
/** The trimmed value, or throws a {@link ConfigurationError} naming `key`. @internal */
|
|
15
24
|
export declare function requireSetting(gateway: string, key: string, value: unknown): string;
|
|
16
25
|
/** A trimmed optional string, `undefined` when blank. @internal */
|
package/dist/esm/core/env.js
CHANGED
|
@@ -10,19 +10,42 @@ export function envFirst(env, ...keys) {
|
|
|
10
10
|
return '';
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* A required whole number of seconds: an integer greater than 0, or text such as `'300'`. Unset
|
|
14
|
+
* or blank throws the missing {@link ConfigurationError}; anything else throws the invalid one.
|
|
15
15
|
*
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
|
-
export function
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
export function requireSeconds(gateway, key, value) {
|
|
19
|
+
if (value === undefined || value === null || (typeof value === 'string' && value.trim() === '')) {
|
|
20
|
+
throw new ConfigurationError(gateway, key);
|
|
21
|
+
}
|
|
22
|
+
let seconds;
|
|
23
|
+
if (typeof value === 'number' && Number.isSafeInteger(value)) {
|
|
24
|
+
seconds = value;
|
|
25
|
+
}
|
|
26
|
+
else if (typeof value === 'string' && /^[+-]?\d+$/.test(value.trim())) {
|
|
27
|
+
seconds = Number.parseInt(value.trim(), 10);
|
|
28
|
+
}
|
|
29
|
+
if (seconds === undefined || !Number.isSafeInteger(seconds) || seconds <= 0) {
|
|
30
|
+
throw new ConfigurationError(gateway, key, true);
|
|
31
|
+
}
|
|
32
|
+
return seconds;
|
|
21
33
|
}
|
|
22
|
-
/**
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
/** The variable holding the HTTP timeout of every gateway that calls an API. @internal */
|
|
35
|
+
export const HTTP_TIMEOUT_VARIABLE = 'MYANMAR_PAYMENTS_HTTP_TIMEOUT';
|
|
36
|
+
/** Seconds before the default HTTP client gives up on a request when no timeout is configured. */
|
|
37
|
+
export const DEFAULT_TIMEOUT_SECONDS = 30;
|
|
38
|
+
/**
|
|
39
|
+
* The HTTP timeout in seconds: {@link DEFAULT_TIMEOUT_SECONDS} when unset or blank, otherwise a
|
|
40
|
+
* whole number greater than 0 (or its text), or the invalid {@link ConfigurationError}.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export function resolveTimeout(gateway, value) {
|
|
45
|
+
if (value === undefined || value === null || (typeof value === 'string' && value.trim() === '')) {
|
|
46
|
+
return DEFAULT_TIMEOUT_SECONDS;
|
|
47
|
+
}
|
|
48
|
+
return requireSeconds(gateway, 'timeout_in_seconds', value);
|
|
26
49
|
}
|
|
27
50
|
/** The trimmed value, or throws a {@link ConfigurationError} naming `key`. @internal */
|
|
28
51
|
export function requireSetting(gateway, key, value) {
|
|
@@ -45,12 +45,18 @@ export declare class SignatureVerificationError extends PaymentError {
|
|
|
45
45
|
constructor(message: string, raw?: Record<string, unknown>);
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
* Thrown when a gateway is missing a credential or setting it needs
|
|
48
|
+
* Thrown when a gateway is missing a credential or setting it needs, or a whole-number setting
|
|
49
|
+
* is not a whole number greater than 0.
|
|
49
50
|
*/
|
|
50
51
|
export declare class ConfigurationError extends PaymentError {
|
|
51
52
|
/** The gateway, e.g. `kbz_pay`. */
|
|
52
53
|
readonly gateway: string;
|
|
53
|
-
/** The missing setting, e.g. `app_key`. */
|
|
54
|
+
/** The missing or invalid setting, e.g. `app_key`. */
|
|
54
55
|
readonly key: string;
|
|
55
|
-
|
|
56
|
+
/**
|
|
57
|
+
* @param invalid `true` when the setting is set but out of range; `false` (the default) when it
|
|
58
|
+
* is missing.
|
|
59
|
+
* @param requirement What a valid value is, used in the message when `invalid`.
|
|
60
|
+
*/
|
|
61
|
+
constructor(gateway: string, key: string, invalid?: boolean, requirement?: string);
|
|
56
62
|
}
|
package/dist/esm/core/errors.js
CHANGED
|
@@ -55,15 +55,23 @@ export class SignatureVerificationError extends PaymentError {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
* Thrown when a gateway is missing a credential or setting it needs
|
|
58
|
+
* Thrown when a gateway is missing a credential or setting it needs, or a whole-number setting
|
|
59
|
+
* is not a whole number greater than 0.
|
|
59
60
|
*/
|
|
60
61
|
export class ConfigurationError extends PaymentError {
|
|
61
62
|
/** The gateway, e.g. `kbz_pay`. */
|
|
62
63
|
gateway;
|
|
63
|
-
/** The missing setting, e.g. `app_key`. */
|
|
64
|
+
/** The missing or invalid setting, e.g. `app_key`. */
|
|
64
65
|
key;
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
* @param invalid `true` when the setting is set but out of range; `false` (the default) when it
|
|
68
|
+
* is missing.
|
|
69
|
+
* @param requirement What a valid value is, used in the message when `invalid`.
|
|
70
|
+
*/
|
|
71
|
+
constructor(gateway, key, invalid = false, requirement = 'a whole number greater than 0') {
|
|
72
|
+
super(invalid
|
|
73
|
+
? `The ${gateway} configuration [${key}] must be ${requirement}.`
|
|
74
|
+
: `The ${gateway} configuration is missing [${key}].`);
|
|
67
75
|
this.gateway = gateway;
|
|
68
76
|
this.key = key;
|
|
69
77
|
}
|
package/dist/esm/core/http.d.ts
CHANGED
|
@@ -27,29 +27,28 @@ export type FetchFunction = (input: string, init: RequestInit) => Promise<Respon
|
|
|
27
27
|
export interface FetchHttpClientOptions {
|
|
28
28
|
/** The `fetch` to call; defaults to the global `fetch`. */
|
|
29
29
|
fetch?: FetchFunction | undefined;
|
|
30
|
-
/** Milliseconds before a request is aborted
|
|
31
|
-
timeoutMs
|
|
30
|
+
/** Milliseconds before a request is aborted. `0` disables the timeout. */
|
|
31
|
+
timeoutMs: number;
|
|
32
32
|
}
|
|
33
|
-
/** The default request timeout: 30 seconds. */
|
|
34
|
-
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
35
33
|
/**
|
|
36
|
-
* The default {@link HttpClient}: the global `fetch` (or the one you pass) with
|
|
37
|
-
*
|
|
34
|
+
* The default {@link HttpClient}: the global `fetch` (or the one you pass) with the timeout you
|
|
35
|
+
* give it. Gateways build one with their `timeoutSeconds` setting when you pass no client.
|
|
38
36
|
*/
|
|
39
37
|
export declare class FetchHttpClient implements HttpClient {
|
|
40
38
|
private readonly fetchFunction;
|
|
41
39
|
private readonly timeoutMs;
|
|
42
|
-
constructor(options
|
|
40
|
+
constructor(options: FetchHttpClientOptions);
|
|
43
41
|
send(request: HttpRequest): Promise<HttpResponse>;
|
|
44
42
|
}
|
|
45
43
|
/** Options every gateway that calls an API accepts. */
|
|
46
44
|
export interface GatewayOptions {
|
|
47
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Sends the requests, with its own timeout. Takes precedence over `fetch`. Without one, the
|
|
47
|
+
* gateway uses a {@link FetchHttpClient} with the config's `timeoutSeconds`.
|
|
48
|
+
*/
|
|
48
49
|
httpClient?: HttpClient | undefined;
|
|
49
50
|
/** The `fetch` the default client calls, e.g. a mocked one in tests. */
|
|
50
51
|
fetch?: FetchFunction | undefined;
|
|
51
|
-
/** Milliseconds before the default client aborts a request; defaults to 30000. */
|
|
52
|
-
timeoutMs?: number | undefined;
|
|
53
52
|
}
|
|
54
53
|
/** Per-call options of every network method. */
|
|
55
54
|
export interface RequestOptions {
|
|
@@ -57,7 +56,7 @@ export interface RequestOptions {
|
|
|
57
56
|
signal?: AbortSignal | undefined;
|
|
58
57
|
}
|
|
59
58
|
/** @internal */
|
|
60
|
-
export declare function httpClientFrom(options
|
|
59
|
+
export declare function httpClientFrom(options: GatewayOptions, timeoutSeconds: number): HttpClient;
|
|
61
60
|
/** A decoded gateway response. @internal */
|
|
62
61
|
export declare class GatewayResponse {
|
|
63
62
|
readonly status: number;
|
package/dist/esm/core/http.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { ApiError, PaymentError } from './errors.js';
|
|
2
2
|
import { parseJsonObject } from './json.js';
|
|
3
|
-
/** The default request timeout: 30 seconds. */
|
|
4
|
-
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
5
3
|
/**
|
|
6
|
-
* The default {@link HttpClient}: the global `fetch` (or the one you pass) with
|
|
7
|
-
*
|
|
4
|
+
* The default {@link HttpClient}: the global `fetch` (or the one you pass) with the timeout you
|
|
5
|
+
* give it. Gateways build one with their `timeoutSeconds` setting when you pass no client.
|
|
8
6
|
*/
|
|
9
7
|
export class FetchHttpClient {
|
|
10
8
|
fetchFunction;
|
|
11
9
|
timeoutMs;
|
|
12
|
-
constructor(options
|
|
10
|
+
constructor(options) {
|
|
13
11
|
this.fetchFunction = options.fetch;
|
|
14
|
-
this.timeoutMs = options.timeoutMs
|
|
12
|
+
this.timeoutMs = options.timeoutMs;
|
|
15
13
|
}
|
|
16
14
|
async send(request) {
|
|
17
15
|
const fetchFunction = this.fetchFunction ?? globalThis.fetch;
|
|
@@ -38,9 +36,9 @@ export class FetchHttpClient {
|
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
/** @internal */
|
|
41
|
-
export function httpClientFrom(options
|
|
39
|
+
export function httpClientFrom(options, timeoutSeconds) {
|
|
42
40
|
return (options.httpClient ??
|
|
43
|
-
new FetchHttpClient({ fetch: options.fetch, timeoutMs:
|
|
41
|
+
new FetchHttpClient({ fetch: options.fetch, timeoutMs: timeoutSeconds * 1000 }));
|
|
44
42
|
}
|
|
45
43
|
/** A decoded gateway response. @internal */
|
|
46
44
|
export class GatewayResponse {
|
package/dist/esm/core/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { Amount, type AmountInput } from './amount.js';
|
|
2
2
|
export { MemoryTokenCache, type TokenCache } from './cache.js';
|
|
3
3
|
export { Acknowledgement, CallbackRequest, PaymentCallback, PaymentStatusResult, type AcknowledgementInit, type BodyInput, type CallbackRequestInit, type HeadersInput, type NodeRequestLike, type PaymentCallbackInit, type PaymentStatusResultInit, type QueryInput, type ServerResponseLike, type WebRequestLike, } from './callback.js';
|
|
4
|
-
export type
|
|
4
|
+
export { DEFAULT_TIMEOUT_SECONDS, type EnvSource } from './env.js';
|
|
5
5
|
export { ApiError, ConfigurationError, InvalidPaymentDataError, PaymentError, SignatureVerificationError, } from './errors.js';
|
|
6
|
-
export {
|
|
6
|
+
export { FetchHttpClient, type FetchFunction, type FetchHttpClientOptions, type GatewayOptions, type HttpClient, type HttpRequest, type HttpResponse, type RequestOptions, } from './http.js';
|
|
7
7
|
export { AppPayment, FormPayment, QrPayment, RedirectPayment, type FormField, type PaymentResult, } from './results.js';
|
|
8
8
|
export { PaymentFlow, PaymentStatus, resolveStatus } from './status.js';
|
package/dist/esm/core/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { Amount } from './amount.js';
|
|
2
2
|
export { MemoryTokenCache } from './cache.js';
|
|
3
3
|
export { Acknowledgement, CallbackRequest, PaymentCallback, PaymentStatusResult, } from './callback.js';
|
|
4
|
+
export { DEFAULT_TIMEOUT_SECONDS } from './env.js';
|
|
4
5
|
export { ApiError, ConfigurationError, InvalidPaymentDataError, PaymentError, SignatureVerificationError, } from './errors.js';
|
|
5
|
-
export {
|
|
6
|
+
export { FetchHttpClient, } from './http.js';
|
|
6
7
|
export { AppPayment, FormPayment, QrPayment, RedirectPayment, } from './results.js';
|
|
7
8
|
export { PaymentFlow, PaymentStatus, resolveStatus } from './status.js';
|
package/dist/esm/core/json.d.ts
CHANGED
|
@@ -32,8 +32,8 @@ export declare function parseJsonObject(text: string): LosslessObject | undefine
|
|
|
32
32
|
/** @internal */
|
|
33
33
|
export declare function isLosslessObject(value: unknown): value is LosslessObject;
|
|
34
34
|
/**
|
|
35
|
-
* Converts a lossless value to plain JavaScript values
|
|
36
|
-
*
|
|
35
|
+
* Converts a lossless value to plain JavaScript values for the `raw` fields of results. Numbers
|
|
36
|
+
* become their exact text as a string (`1000.50` stays `"1000.50"`), so no precision is lost.
|
|
37
37
|
*
|
|
38
38
|
* @internal
|
|
39
39
|
*/
|
package/dist/esm/core/json.js
CHANGED
|
@@ -46,14 +46,14 @@ export function isLosslessObject(value) {
|
|
|
46
46
|
!(value instanceof JsonNumber));
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* Converts a lossless value to plain JavaScript values
|
|
50
|
-
*
|
|
49
|
+
* Converts a lossless value to plain JavaScript values for the `raw` fields of results. Numbers
|
|
50
|
+
* become their exact text as a string (`1000.50` stays `"1000.50"`), so no precision is lost.
|
|
51
51
|
*
|
|
52
52
|
* @internal
|
|
53
53
|
*/
|
|
54
54
|
export function toPlain(value) {
|
|
55
55
|
if (value instanceof JsonNumber) {
|
|
56
|
-
return
|
|
56
|
+
return value.text;
|
|
57
57
|
}
|
|
58
58
|
if (Array.isArray(value)) {
|
|
59
59
|
return value.map(toPlain);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A gateway-independent payment status. Every gateway's own status values are mapped onto these.
|
|
3
3
|
*/
|
|
4
|
-
export type PaymentStatus = 'successful' | 'pending' | 'failed' | '
|
|
4
|
+
export type PaymentStatus = 'successful' | 'pending' | 'failed' | 'canceled' | 'expired' | 'unknown';
|
|
5
5
|
/**
|
|
6
6
|
* The payment statuses, plus helpers.
|
|
7
7
|
*
|
|
@@ -18,13 +18,13 @@ export declare const PaymentStatus: Readonly<{
|
|
|
18
18
|
/** The payment was attempted and failed or was rejected. */
|
|
19
19
|
Failed: "failed";
|
|
20
20
|
/** The payment or order was canceled or closed before completing. */
|
|
21
|
-
|
|
21
|
+
Canceled: "canceled";
|
|
22
22
|
/** The payment window ran out before the customer paid. */
|
|
23
23
|
Expired: "expired";
|
|
24
24
|
/** The gateway sent a status this package does not recognize. Inspect `gatewayStatus`. */
|
|
25
25
|
Unknown: "unknown";
|
|
26
26
|
/** Every status, in the order above. */
|
|
27
|
-
values: readonly ["successful", "pending", "failed", "
|
|
27
|
+
values: readonly ["successful", "pending", "failed", "canceled", "expired", "unknown"];
|
|
28
28
|
/** Whether the status will not change any more: `false` for `pending` and `unknown`. */
|
|
29
29
|
isFinal(status: PaymentStatus): boolean;
|
|
30
30
|
}>;
|
package/dist/esm/core/status.js
CHANGED
|
@@ -14,7 +14,7 @@ export const PaymentStatus = Object.freeze({
|
|
|
14
14
|
/** The payment was attempted and failed or was rejected. */
|
|
15
15
|
Failed: 'failed',
|
|
16
16
|
/** The payment or order was canceled or closed before completing. */
|
|
17
|
-
|
|
17
|
+
Canceled: 'canceled',
|
|
18
18
|
/** The payment window ran out before the customer paid. */
|
|
19
19
|
Expired: 'expired',
|
|
20
20
|
/** The gateway sent a status this package does not recognize. Inspect `gatewayStatus`. */
|
|
@@ -24,7 +24,7 @@ export const PaymentStatus = Object.freeze({
|
|
|
24
24
|
'successful',
|
|
25
25
|
'pending',
|
|
26
26
|
'failed',
|
|
27
|
-
'
|
|
27
|
+
'canceled',
|
|
28
28
|
'expired',
|
|
29
29
|
'unknown',
|
|
30
30
|
]),
|
|
@@ -14,3 +14,5 @@ export declare function optional(source: Record<string, unknown>, key: string):
|
|
|
14
14
|
export declare function trimmed(source: Record<string, unknown>, key: string): string;
|
|
15
15
|
/** The value at `key` when it is an object (not an array). @internal */
|
|
16
16
|
export declare function object(source: Record<string, unknown>, key: string): LosslessObject | undefined;
|
|
17
|
+
/** Whether `value` is an object or array, which a gateway never signs. @internal */
|
|
18
|
+
export declare function isNested(value: unknown): boolean;
|
package/dist/esm/core/values.js
CHANGED
|
@@ -36,3 +36,7 @@ export function object(source, key) {
|
|
|
36
36
|
const value = source[key];
|
|
37
37
|
return isLosslessObject(value) ? value : undefined;
|
|
38
38
|
}
|
|
39
|
+
/** Whether `value` is an object or array, which a gateway never signs. @internal */
|
|
40
|
+
export function isNested(value) {
|
|
41
|
+
return typeof value === 'object' && value !== null && !(value instanceof JsonNumber);
|
|
42
|
+
}
|
|
@@ -10,27 +10,24 @@ export interface CyberSourceConfigOptions {
|
|
|
10
10
|
accessKey: string;
|
|
11
11
|
/** The profile's secret key, which signs the fields. */
|
|
12
12
|
secretKey: string;
|
|
13
|
-
/**
|
|
14
|
-
sandbox?: boolean | undefined;
|
|
15
|
-
/** Overrides the Secure Acceptance base URL. */
|
|
13
|
+
/** Overrides the Secure Acceptance base URL, e.g. to point at the test environment. */
|
|
16
14
|
baseUrl?: string | undefined;
|
|
17
15
|
}
|
|
18
16
|
/**
|
|
19
|
-
* A CyberSource Secure Acceptance profile. A missing credential throws a `ConfigurationError`.
|
|
17
|
+
* A CyberSource Secure Acceptance profile. A missing credential throws a `ConfigurationError`. The
|
|
18
|
+
* URL defaults to production.
|
|
20
19
|
*/
|
|
21
20
|
export declare class CyberSourceConfig {
|
|
22
|
-
static readonly SANDBOX_URL = "https://testsecureacceptance.cybersource.com";
|
|
23
21
|
static readonly PRODUCTION_URL = "https://secureacceptance.cybersource.com";
|
|
24
22
|
readonly profileId: string;
|
|
25
23
|
readonly accessKey: string;
|
|
26
24
|
readonly secretKey: string;
|
|
27
|
-
readonly sandbox: boolean;
|
|
28
25
|
/** The base URL in use. */
|
|
29
26
|
readonly baseUrl: string;
|
|
30
27
|
constructor(options: CyberSourceConfigOptions);
|
|
31
28
|
/**
|
|
32
29
|
* Reads `CYBER_SOURCE_PROFILE_ID`, `CYBER_SOURCE_ACCESS_KEY`, `CYBER_SOURCE_SECRET_KEY`,
|
|
33
|
-
*
|
|
30
|
+
* and `CYBER_SOURCE_BASE_URL`.
|
|
34
31
|
*/
|
|
35
32
|
static fromEnv(env?: EnvSource): CyberSourceConfig;
|
|
36
33
|
}
|
|
@@ -61,12 +58,12 @@ export interface CyberSourcePaymentData {
|
|
|
61
58
|
returnUrl?: string | undefined;
|
|
62
59
|
/** The page shown on cancel (`override_custom_cancel_page`), at most 255 characters. */
|
|
63
60
|
cancelUrl?: string | undefined;
|
|
64
|
-
/** An ISO 4217 code
|
|
65
|
-
currency
|
|
66
|
-
/** What to do with the card
|
|
67
|
-
transactionType
|
|
68
|
-
/** The hosted page language, e.g. `en-us
|
|
69
|
-
locale
|
|
61
|
+
/** An ISO 4217 code, e.g. `MMK`. */
|
|
62
|
+
currency: string;
|
|
63
|
+
/** What to do with the card, e.g. `sale`. */
|
|
64
|
+
transactionType: CyberSourceTransactionType;
|
|
65
|
+
/** The hosted page language, e.g. `en-us`. */
|
|
66
|
+
locale: string;
|
|
70
67
|
}
|
|
71
68
|
/**
|
|
72
69
|
* CyberSource Secure Acceptance hosted checkout for card payments: signs the form and verifies the
|
|
@@ -87,7 +84,8 @@ export declare class CyberSource {
|
|
|
87
84
|
initiate(data: CyberSourcePaymentData): FormPayment;
|
|
88
85
|
/**
|
|
89
86
|
* Verifies CyberSource's result post. The same check works for the browser post to your receipt
|
|
90
|
-
* page.
|
|
87
|
+
* page. Only the fields listed in `signed_field_names` are trusted: `decision` and
|
|
88
|
+
* `req_reference_number` must be signed, and unsigned fields are left out of the result.
|
|
91
89
|
*/
|
|
92
90
|
handleCallback(request: CallbackRequest): PaymentCallback;
|
|
93
91
|
/** Signs the fields listed in `signed_field_names`; `undefined` when a listed field is missing. */
|