@laranex/myanmar-payments 4.0.0-dev.5 → 4.0.0-dev.7
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 +2 -2
- package/README.md +1 -1
- package/dist/cjs/aya-pay/aya-pay.d.ts +3 -2
- package/dist/cjs/aya-pay/aya-pay.js +1 -1
- package/dist/cjs/core/env.d.ts +9 -0
- package/dist/cjs/core/env.js +16 -1
- package/dist/cjs/core/index.d.ts +1 -1
- package/dist/cjs/core/index.js +3 -1
- package/dist/cjs/kbz-pay/kbz-pay.d.ts +3 -2
- package/dist/cjs/kbz-pay/kbz-pay.js +1 -1
- package/dist/cjs/wave-money/wave-money.d.ts +3 -2
- package/dist/cjs/wave-money/wave-money.js +1 -1
- package/dist/cjs/yoma-mmqr/yoma-mmqr.d.ts +3 -2
- package/dist/cjs/yoma-mmqr/yoma-mmqr.js +1 -1
- package/dist/esm/aya-pay/aya-pay.d.ts +3 -2
- package/dist/esm/aya-pay/aya-pay.js +2 -2
- package/dist/esm/core/env.d.ts +9 -0
- package/dist/esm/core/env.js +14 -0
- package/dist/esm/core/index.d.ts +1 -1
- package/dist/esm/core/index.js +1 -0
- package/dist/esm/kbz-pay/kbz-pay.d.ts +3 -2
- package/dist/esm/kbz-pay/kbz-pay.js +2 -2
- package/dist/esm/wave-money/wave-money.d.ts +3 -2
- package/dist/esm/wave-money/wave-money.js +2 -2
- package/dist/esm/yoma-mmqr/yoma-mmqr.d.ts +3 -2
- package/dist/esm/yoma-mmqr/yoma-mmqr.js +2 -2
- package/package.json +2 -2
- package/skills/node-myanmar-payments/SKILL.md +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -22,8 +22,8 @@ Initial release. The version number matches the other Laranex Myanmar payments p
|
|
|
22
22
|
- Requires Node.js 20 or higher.
|
|
23
23
|
|
|
24
24
|
### Changed since the pre-releases
|
|
25
|
-
- No sandbox switch: the sandbox setting (`sandbox`) and the `*_SANDBOX` variables are removed, and every gateway defaults to its production endpoints.
|
|
26
|
-
- In Node: config options `timeoutSeconds` (KBZ Pay, Wave Money, AYA Pay, Yoma MMQR),
|
|
25
|
+
- No sandbox switch: the sandbox setting (`sandbox`) and the `*_SANDBOX` variables are removed, and every gateway defaults to its production endpoints. The HTTP timeout (`timeout_in_seconds`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT`) of every gateway that calls an API is optional and defaults to 30 seconds. Every other setting is required: Wave Money's `time_to_live_in_seconds` and `merchant_name` (no `APP_NAME` fallback), Yoma MMQR's `api_version`, and CyberSource's `currency`, `locale` and `transactionType` on each payment. A missing setting throws the configuration error naming it; a time setting that is not a whole number greater than 0 throws `The <gateway> configuration [<key>] must be a whole number greater than 0.` Upgrading: delete `*_SANDBOX`; to keep testing against UAT, set the URL overrides to the UAT URLs listed in the docs; set the newly required settings.
|
|
26
|
+
- In Node: config options `timeToLiveSeconds` and `apiVersion` are required and take a whole number or its text; `timeoutSeconds` (KBZ Pay, Wave Money, AYA Pay, Yoma MMQR) is optional, takes a whole number or its text and defaults to the new `DEFAULT_TIMEOUT_SECONDS` (30) when unset or blank; the `SANDBOX_*`, `DEFAULT_TIME_TO_LIVE_SECONDS` and `DEFAULT_API_VERSION` constants are removed. `GatewayOptions.timeoutMs` (so also the `MyanmarPayments` option) and `DEFAULT_TIMEOUT_MS` are removed; `FetchHttpClient` requires `timeoutMs`. `ConfigurationError` takes a third `invalid` argument for the whole-number message.
|
|
27
27
|
- `PaymentStatus.Cancelled` is renamed to `PaymentStatus.Canceled` and its value from `'cancelled'` to `'canceled'` (American English), with no alias. Code or stored statuses from the `v4.0.0-dev` pre-releases need the new name; gateway status literals such as Wave Money's `PAYMENT_REQUEST_CANCELLED` are unchanged.
|
|
28
28
|
- Callback values that are JSON numbers are kept as their exact text, as strings, in `raw`, `parsedBody()`, `input()`, `queryInput()` and the `raw` of errors (`1000.50` is `'1000.50'`, not `1000.5`), like the PHP SDK.
|
|
29
29
|
- A nested value (object or array) in a signed or hashed callback field now fails verification: KBZ Pay (any callback field), Wave Money (the hashed fields), AYA Pay (the signed payload fields) and Yoma MMQR (`status`). Before, KBZ Pay skipped it, Wave Money hashed it as `null` and AYA Pay signed it as empty.
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://github.com/laranex/node-myanmar-payments/actions/workflows/tests.yml)
|
|
5
5
|
[](LICENSE.md)
|
|
6
6
|
|
|
7
|
-
Node.js SDK for Myanmar payment gateways: KBZ Pay, Wave Money, AYA Pay, Yoma MMQR and CyberSource. Typed
|
|
7
|
+
Node.js SDK for Myanmar payment gateways: KBZ Pay, Wave Money, AYA Pay, Yoma MMQR and CyberSource. Typed requests and results, exact amounts, no runtime dependencies. Built for humans and AI agents.
|
|
8
8
|
|
|
9
9
|
## Documentation
|
|
10
10
|
|
|
@@ -11,9 +11,10 @@ export interface AyaPayConfigOptions {
|
|
|
11
11
|
appSecret: string;
|
|
12
12
|
/**
|
|
13
13
|
* Seconds before the default HTTP client gives up on a request, a whole number greater than 0
|
|
14
|
-
* (or its text).
|
|
14
|
+
* (or its text). Defaults to 30 (`DEFAULT_TIMEOUT_SECONDS`) when unset or blank. A
|
|
15
|
+
* client you pass keeps its own timeout.
|
|
15
16
|
*/
|
|
16
|
-
timeoutSeconds
|
|
17
|
+
timeoutSeconds?: number | string | null | undefined;
|
|
17
18
|
/** Overrides the gateway base URL, e.g. to point at UAT. */
|
|
18
19
|
baseUrl?: string | undefined;
|
|
19
20
|
}
|
|
@@ -26,7 +26,7 @@ class AyaPayConfig {
|
|
|
26
26
|
constructor(options) {
|
|
27
27
|
this.appKey = (0, env_js_1.requireSetting)('aya_pay', 'app_key', options.appKey);
|
|
28
28
|
this.appSecret = (0, env_js_1.requireSetting)('aya_pay', 'app_secret', options.appSecret);
|
|
29
|
-
this.timeoutSeconds = (0, env_js_1.
|
|
29
|
+
this.timeoutSeconds = (0, env_js_1.resolveTimeout)('aya_pay', options.timeoutSeconds);
|
|
30
30
|
this.baseUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.baseUrl) ?? AyaPayConfig.PRODUCTION_URL);
|
|
31
31
|
}
|
|
32
32
|
/**
|
package/dist/cjs/core/env.d.ts
CHANGED
|
@@ -11,6 +11,15 @@ export declare function envFirst(env: EnvSource, ...keys: string[]): string;
|
|
|
11
11
|
export declare function requireSeconds(gateway: string, key: string, value: unknown): number;
|
|
12
12
|
/** The variable holding the HTTP timeout of every gateway that calls an API. @internal */
|
|
13
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/cjs/core/env.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HTTP_TIMEOUT_VARIABLE = void 0;
|
|
3
|
+
exports.DEFAULT_TIMEOUT_SECONDS = exports.HTTP_TIMEOUT_VARIABLE = void 0;
|
|
4
4
|
exports.envFirst = envFirst;
|
|
5
5
|
exports.requireSeconds = requireSeconds;
|
|
6
|
+
exports.resolveTimeout = resolveTimeout;
|
|
6
7
|
exports.requireSetting = requireSetting;
|
|
7
8
|
exports.optionalSetting = optionalSetting;
|
|
8
9
|
exports.trimUrl = trimUrl;
|
|
@@ -42,6 +43,20 @@ function requireSeconds(gateway, key, value) {
|
|
|
42
43
|
}
|
|
43
44
|
/** The variable holding the HTTP timeout of every gateway that calls an API. @internal */
|
|
44
45
|
exports.HTTP_TIMEOUT_VARIABLE = 'MYANMAR_PAYMENTS_HTTP_TIMEOUT';
|
|
46
|
+
/** Seconds before the default HTTP client gives up on a request when no timeout is configured. */
|
|
47
|
+
exports.DEFAULT_TIMEOUT_SECONDS = 30;
|
|
48
|
+
/**
|
|
49
|
+
* The HTTP timeout in seconds: {@link DEFAULT_TIMEOUT_SECONDS} when unset or blank, otherwise a
|
|
50
|
+
* whole number greater than 0 (or its text), or the invalid {@link ConfigurationError}.
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
function resolveTimeout(gateway, value) {
|
|
55
|
+
if (value === undefined || value === null || (typeof value === 'string' && value.trim() === '')) {
|
|
56
|
+
return exports.DEFAULT_TIMEOUT_SECONDS;
|
|
57
|
+
}
|
|
58
|
+
return requireSeconds(gateway, 'timeout_in_seconds', value);
|
|
59
|
+
}
|
|
45
60
|
/** The trimmed value, or throws a {@link ConfigurationError} naming `key`. @internal */
|
|
46
61
|
function requireSetting(gateway, key, value) {
|
|
47
62
|
if (typeof value !== 'string' || value.trim() === '') {
|
package/dist/cjs/core/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
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';
|
package/dist/cjs/core/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveStatus = exports.PaymentStatus = exports.PaymentFlow = exports.RedirectPayment = exports.QrPayment = exports.FormPayment = exports.AppPayment = exports.FetchHttpClient = exports.SignatureVerificationError = exports.PaymentError = exports.InvalidPaymentDataError = exports.ConfigurationError = exports.ApiError = exports.PaymentStatusResult = exports.PaymentCallback = exports.CallbackRequest = exports.Acknowledgement = exports.MemoryTokenCache = exports.Amount = void 0;
|
|
3
|
+
exports.resolveStatus = exports.PaymentStatus = exports.PaymentFlow = exports.RedirectPayment = exports.QrPayment = exports.FormPayment = exports.AppPayment = exports.FetchHttpClient = exports.SignatureVerificationError = exports.PaymentError = exports.InvalidPaymentDataError = exports.ConfigurationError = exports.ApiError = exports.DEFAULT_TIMEOUT_SECONDS = exports.PaymentStatusResult = exports.PaymentCallback = exports.CallbackRequest = exports.Acknowledgement = exports.MemoryTokenCache = exports.Amount = void 0;
|
|
4
4
|
var amount_js_1 = require("./amount.js");
|
|
5
5
|
Object.defineProperty(exports, "Amount", { enumerable: true, get: function () { return amount_js_1.Amount; } });
|
|
6
6
|
var cache_js_1 = require("./cache.js");
|
|
@@ -10,6 +10,8 @@ Object.defineProperty(exports, "Acknowledgement", { enumerable: true, get: funct
|
|
|
10
10
|
Object.defineProperty(exports, "CallbackRequest", { enumerable: true, get: function () { return callback_js_1.CallbackRequest; } });
|
|
11
11
|
Object.defineProperty(exports, "PaymentCallback", { enumerable: true, get: function () { return callback_js_1.PaymentCallback; } });
|
|
12
12
|
Object.defineProperty(exports, "PaymentStatusResult", { enumerable: true, get: function () { return callback_js_1.PaymentStatusResult; } });
|
|
13
|
+
var env_js_1 = require("./env.js");
|
|
14
|
+
Object.defineProperty(exports, "DEFAULT_TIMEOUT_SECONDS", { enumerable: true, get: function () { return env_js_1.DEFAULT_TIMEOUT_SECONDS; } });
|
|
13
15
|
var errors_js_1 = require("./errors.js");
|
|
14
16
|
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return errors_js_1.ApiError; } });
|
|
15
17
|
Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return errors_js_1.ConfigurationError; } });
|
|
@@ -14,9 +14,10 @@ export interface KbzPayConfigOptions {
|
|
|
14
14
|
merchantCode: string;
|
|
15
15
|
/**
|
|
16
16
|
* Seconds before the default HTTP client gives up on a request, a whole number greater than 0
|
|
17
|
-
* (or its text).
|
|
17
|
+
* (or its text). Defaults to 30 (`DEFAULT_TIMEOUT_SECONDS`) when unset or blank. A
|
|
18
|
+
* client you pass keeps its own timeout.
|
|
18
19
|
*/
|
|
19
|
-
timeoutSeconds
|
|
20
|
+
timeoutSeconds?: number | string | null | undefined;
|
|
20
21
|
/** Overrides the API base URL, e.g. to point at UAT or go through a proxy. */
|
|
21
22
|
apiUrl?: string | undefined;
|
|
22
23
|
/** Overrides the PWA checkout URL. A trailing `#` or `#/` is normalized to `#/`. */
|
|
@@ -32,7 +32,7 @@ class KbzPayConfig {
|
|
|
32
32
|
this.appId = (0, env_js_1.requireSetting)('kbz_pay', 'app_id', options.appId);
|
|
33
33
|
this.appKey = (0, env_js_1.requireSetting)('kbz_pay', 'app_key', options.appKey);
|
|
34
34
|
this.merchantCode = (0, env_js_1.requireSetting)('kbz_pay', 'merchant_code', options.merchantCode);
|
|
35
|
-
this.timeoutSeconds = (0, env_js_1.
|
|
35
|
+
this.timeoutSeconds = (0, env_js_1.resolveTimeout)('kbz_pay', options.timeoutSeconds);
|
|
36
36
|
this.apiUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.apiUrl) ?? KbzPayConfig.PRODUCTION_API_URL);
|
|
37
37
|
this.pwaUrl = `${(0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.pwaUrl) ?? KbzPayConfig.PRODUCTION_PWA_URL)}/`;
|
|
38
38
|
}
|
|
@@ -15,9 +15,10 @@ export interface WaveMoneyConfigOptions {
|
|
|
15
15
|
timeToLiveSeconds: number | string;
|
|
16
16
|
/**
|
|
17
17
|
* Seconds before the default HTTP client gives up on a request, a whole number greater than 0
|
|
18
|
-
* (or its text).
|
|
18
|
+
* (or its text). Defaults to 30 (`DEFAULT_TIMEOUT_SECONDS`) when unset or blank. A
|
|
19
|
+
* client you pass keeps its own timeout.
|
|
19
20
|
*/
|
|
20
|
-
timeoutSeconds
|
|
21
|
+
timeoutSeconds?: number | string | null | undefined;
|
|
21
22
|
/** Overrides the API base URL, e.g. to point at UAT. */
|
|
22
23
|
baseUrl?: string | undefined;
|
|
23
24
|
/** Overrides the host the customer is redirected to. Wave serves it without the API port. */
|
|
@@ -35,7 +35,7 @@ class WaveMoneyConfig {
|
|
|
35
35
|
this.secretKey = (0, env_js_1.requireSetting)('wave_money', 'secret_key', options.secretKey);
|
|
36
36
|
this.merchantName = (0, env_js_1.requireSetting)('wave_money', 'merchant_name', options.merchantName);
|
|
37
37
|
this.timeToLiveSeconds = (0, env_js_1.requireSeconds)('wave_money', 'time_to_live_in_seconds', options.timeToLiveSeconds);
|
|
38
|
-
this.timeoutSeconds = (0, env_js_1.
|
|
38
|
+
this.timeoutSeconds = (0, env_js_1.resolveTimeout)('wave_money', options.timeoutSeconds);
|
|
39
39
|
this.baseUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.baseUrl) ?? WaveMoneyConfig.PRODUCTION_URL);
|
|
40
40
|
this.authenticateUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.authenticateUrl) ?? WaveMoneyConfig.PRODUCTION_AUTHENTICATE_URL);
|
|
41
41
|
}
|
|
@@ -20,9 +20,10 @@ export interface YomaMmqrConfigOptions {
|
|
|
20
20
|
apiVersion: string;
|
|
21
21
|
/**
|
|
22
22
|
* Seconds before the default HTTP client gives up on a request, a whole number greater than 0
|
|
23
|
-
* (or its text).
|
|
23
|
+
* (or its text). Defaults to 30 (`DEFAULT_TIMEOUT_SECONDS`) when unset or blank. A
|
|
24
|
+
* client you pass keeps its own timeout.
|
|
24
25
|
*/
|
|
25
|
-
timeoutSeconds
|
|
26
|
+
timeoutSeconds?: number | string | null | undefined;
|
|
26
27
|
/** Overrides the API base URL, e.g. to point at UAT. */
|
|
27
28
|
baseUrl?: string | undefined;
|
|
28
29
|
}
|
|
@@ -35,7 +35,7 @@ class YomaMmqrConfig {
|
|
|
35
35
|
this.clientSecret = (0, env_js_1.requireSetting)('yoma_mmqr', 'client_secret', options.clientSecret);
|
|
36
36
|
this.webhookHashKey = (0, env_js_1.requireSetting)('yoma_mmqr', 'webhook_hashkey', options.webhookHashKey);
|
|
37
37
|
this.apiVersion = (0, env_js_1.requireSetting)('yoma_mmqr', 'api_version', options.apiVersion);
|
|
38
|
-
this.timeoutSeconds = (0, env_js_1.
|
|
38
|
+
this.timeoutSeconds = (0, env_js_1.resolveTimeout)('yoma_mmqr', options.timeoutSeconds);
|
|
39
39
|
this.webhookSecret = (0, env_js_1.optionalSetting)(options.webhookSecret);
|
|
40
40
|
this.baseUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.baseUrl) ?? YomaMmqrConfig.PRODUCTION_URL);
|
|
41
41
|
}
|
|
@@ -11,9 +11,10 @@ export interface AyaPayConfigOptions {
|
|
|
11
11
|
appSecret: string;
|
|
12
12
|
/**
|
|
13
13
|
* Seconds before the default HTTP client gives up on a request, a whole number greater than 0
|
|
14
|
-
* (or its text).
|
|
14
|
+
* (or its text). Defaults to 30 (`DEFAULT_TIMEOUT_SECONDS`) when unset or blank. A
|
|
15
|
+
* client you pass keeps its own timeout.
|
|
15
16
|
*/
|
|
16
|
-
timeoutSeconds
|
|
17
|
+
timeoutSeconds?: number | string | null | undefined;
|
|
17
18
|
/** Overrides the gateway base URL, e.g. to point at UAT. */
|
|
18
19
|
baseUrl?: string | undefined;
|
|
19
20
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {} from '../core/amount.js';
|
|
2
2
|
import { CallbackRequest, losslessInput, losslessQueryInput, PaymentCallback, PaymentStatusResult, } from '../core/callback.js';
|
|
3
3
|
import { decodeBase64, hmacSha256Hex, safeEqual } from '../core/crypto.js';
|
|
4
|
-
import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting,
|
|
4
|
+
import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting, requireSetting, resolveTimeout, trimUrl, } from '../core/env.js';
|
|
5
5
|
import { ApiError, SignatureVerificationError } from '../core/errors.js';
|
|
6
6
|
import { httpClientFrom, Transport, } from '../core/http.js';
|
|
7
7
|
import { isLosslessObject, parseJsonObject, toPlainObject, } from '../core/json.js';
|
|
@@ -24,7 +24,7 @@ export class AyaPayConfig {
|
|
|
24
24
|
constructor(options) {
|
|
25
25
|
this.appKey = requireSetting('aya_pay', 'app_key', options.appKey);
|
|
26
26
|
this.appSecret = requireSetting('aya_pay', 'app_secret', options.appSecret);
|
|
27
|
-
this.timeoutSeconds =
|
|
27
|
+
this.timeoutSeconds = resolveTimeout('aya_pay', options.timeoutSeconds);
|
|
28
28
|
this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ?? AyaPayConfig.PRODUCTION_URL);
|
|
29
29
|
}
|
|
30
30
|
/**
|
package/dist/esm/core/env.d.ts
CHANGED
|
@@ -11,6 +11,15 @@ export declare function envFirst(env: EnvSource, ...keys: string[]): string;
|
|
|
11
11
|
export declare function requireSeconds(gateway: string, key: string, value: unknown): number;
|
|
12
12
|
/** The variable holding the HTTP timeout of every gateway that calls an API. @internal */
|
|
13
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
|
@@ -33,6 +33,20 @@ export function requireSeconds(gateway, key, value) {
|
|
|
33
33
|
}
|
|
34
34
|
/** The variable holding the HTTP timeout of every gateway that calls an API. @internal */
|
|
35
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);
|
|
49
|
+
}
|
|
36
50
|
/** The trimmed value, or throws a {@link ConfigurationError} naming `key`. @internal */
|
|
37
51
|
export function requireSetting(gateway, key, value) {
|
|
38
52
|
if (typeof value !== 'string' || value.trim() === '') {
|
package/dist/esm/core/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
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';
|
package/dist/esm/core/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
6
|
export { FetchHttpClient, } from './http.js';
|
|
6
7
|
export { AppPayment, FormPayment, QrPayment, RedirectPayment, } from './results.js';
|
|
@@ -14,9 +14,10 @@ export interface KbzPayConfigOptions {
|
|
|
14
14
|
merchantCode: string;
|
|
15
15
|
/**
|
|
16
16
|
* Seconds before the default HTTP client gives up on a request, a whole number greater than 0
|
|
17
|
-
* (or its text).
|
|
17
|
+
* (or its text). Defaults to 30 (`DEFAULT_TIMEOUT_SECONDS`) when unset or blank. A
|
|
18
|
+
* client you pass keeps its own timeout.
|
|
18
19
|
*/
|
|
19
|
-
timeoutSeconds
|
|
20
|
+
timeoutSeconds?: number | string | null | undefined;
|
|
20
21
|
/** Overrides the API base URL, e.g. to point at UAT or go through a proxy. */
|
|
21
22
|
apiUrl?: string | undefined;
|
|
22
23
|
/** Overrides the PWA checkout URL. A trailing `#` or `#/` is normalized to `#/`. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {} from '../core/amount.js';
|
|
2
2
|
import { Acknowledgement, CallbackRequest, losslessBody, PaymentCallback, PaymentStatusResult, } from '../core/callback.js';
|
|
3
3
|
import { queryEscape, randomHex } from '../core/crypto.js';
|
|
4
|
-
import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting,
|
|
4
|
+
import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting, requireSetting, resolveTimeout, trimUrl, } from '../core/env.js';
|
|
5
5
|
import { ApiError, SignatureVerificationError } from '../core/errors.js';
|
|
6
6
|
import { httpClientFrom, Transport, } from '../core/http.js';
|
|
7
7
|
import { toPlainObject } from '../core/json.js';
|
|
@@ -30,7 +30,7 @@ export class KbzPayConfig {
|
|
|
30
30
|
this.appId = requireSetting('kbz_pay', 'app_id', options.appId);
|
|
31
31
|
this.appKey = requireSetting('kbz_pay', 'app_key', options.appKey);
|
|
32
32
|
this.merchantCode = requireSetting('kbz_pay', 'merchant_code', options.merchantCode);
|
|
33
|
-
this.timeoutSeconds =
|
|
33
|
+
this.timeoutSeconds = resolveTimeout('kbz_pay', options.timeoutSeconds);
|
|
34
34
|
this.apiUrl = trimUrl(optionalSetting(options.apiUrl) ?? KbzPayConfig.PRODUCTION_API_URL);
|
|
35
35
|
this.pwaUrl = `${trimUrl(optionalSetting(options.pwaUrl) ?? KbzPayConfig.PRODUCTION_PWA_URL)}/`;
|
|
36
36
|
}
|
|
@@ -15,9 +15,10 @@ export interface WaveMoneyConfigOptions {
|
|
|
15
15
|
timeToLiveSeconds: number | string;
|
|
16
16
|
/**
|
|
17
17
|
* Seconds before the default HTTP client gives up on a request, a whole number greater than 0
|
|
18
|
-
* (or its text).
|
|
18
|
+
* (or its text). Defaults to 30 (`DEFAULT_TIMEOUT_SECONDS`) when unset or blank. A
|
|
19
|
+
* client you pass keeps its own timeout.
|
|
19
20
|
*/
|
|
20
|
-
timeoutSeconds
|
|
21
|
+
timeoutSeconds?: number | string | null | undefined;
|
|
21
22
|
/** Overrides the API base URL, e.g. to point at UAT. */
|
|
22
23
|
baseUrl?: string | undefined;
|
|
23
24
|
/** Overrides the host the customer is redirected to. Wave serves it without the API port. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Amount } from '../core/amount.js';
|
|
2
2
|
import { CallbackRequest, losslessBody, PaymentCallback } from '../core/callback.js';
|
|
3
3
|
import { hmacSha256Hex, queryEscape, randomHex, safeEqual } from '../core/crypto.js';
|
|
4
|
-
import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting, requireSeconds, requireSetting, trimUrl, } from '../core/env.js';
|
|
4
|
+
import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting, requireSeconds, requireSetting, resolveTimeout, trimUrl, } from '../core/env.js';
|
|
5
5
|
import { ApiError, SignatureVerificationError } from '../core/errors.js';
|
|
6
6
|
import { httpClientFrom, Transport, } from '../core/http.js';
|
|
7
7
|
import { isLosslessObject, toPlainObject } from '../core/json.js';
|
|
@@ -32,7 +32,7 @@ export class WaveMoneyConfig {
|
|
|
32
32
|
this.secretKey = requireSetting('wave_money', 'secret_key', options.secretKey);
|
|
33
33
|
this.merchantName = requireSetting('wave_money', 'merchant_name', options.merchantName);
|
|
34
34
|
this.timeToLiveSeconds = requireSeconds('wave_money', 'time_to_live_in_seconds', options.timeToLiveSeconds);
|
|
35
|
-
this.timeoutSeconds =
|
|
35
|
+
this.timeoutSeconds = resolveTimeout('wave_money', options.timeoutSeconds);
|
|
36
36
|
this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ?? WaveMoneyConfig.PRODUCTION_URL);
|
|
37
37
|
this.authenticateUrl = trimUrl(optionalSetting(options.authenticateUrl) ?? WaveMoneyConfig.PRODUCTION_AUTHENTICATE_URL);
|
|
38
38
|
}
|
|
@@ -20,9 +20,10 @@ export interface YomaMmqrConfigOptions {
|
|
|
20
20
|
apiVersion: string;
|
|
21
21
|
/**
|
|
22
22
|
* Seconds before the default HTTP client gives up on a request, a whole number greater than 0
|
|
23
|
-
* (or its text).
|
|
23
|
+
* (or its text). Defaults to 30 (`DEFAULT_TIMEOUT_SECONDS`) when unset or blank. A
|
|
24
|
+
* client you pass keeps its own timeout.
|
|
24
25
|
*/
|
|
25
|
-
timeoutSeconds
|
|
26
|
+
timeoutSeconds?: number | string | null | undefined;
|
|
26
27
|
/** Overrides the API base URL, e.g. to point at UAT. */
|
|
27
28
|
baseUrl?: string | undefined;
|
|
28
29
|
}
|
|
@@ -2,7 +2,7 @@ import {} from '../core/amount.js';
|
|
|
2
2
|
import { MemoryTokenCache } from '../core/cache.js';
|
|
3
3
|
import { CallbackRequest, losslessBody, PaymentCallback, PaymentStatusResult, } from '../core/callback.js';
|
|
4
4
|
import { hmacSha256Hex, safeEqual, sha256Hex } from '../core/crypto.js';
|
|
5
|
-
import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting,
|
|
5
|
+
import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting, requireSetting, resolveTimeout, trimUrl, } from '../core/env.js';
|
|
6
6
|
import { ApiError, SignatureVerificationError } from '../core/errors.js';
|
|
7
7
|
import { httpClientFrom, Transport, } from '../core/http.js';
|
|
8
8
|
import { toPlainObject } from '../core/json.js';
|
|
@@ -33,7 +33,7 @@ export class YomaMmqrConfig {
|
|
|
33
33
|
this.clientSecret = requireSetting('yoma_mmqr', 'client_secret', options.clientSecret);
|
|
34
34
|
this.webhookHashKey = requireSetting('yoma_mmqr', 'webhook_hashkey', options.webhookHashKey);
|
|
35
35
|
this.apiVersion = requireSetting('yoma_mmqr', 'api_version', options.apiVersion);
|
|
36
|
-
this.timeoutSeconds =
|
|
36
|
+
this.timeoutSeconds = resolveTimeout('yoma_mmqr', options.timeoutSeconds);
|
|
37
37
|
this.webhookSecret = optionalSetting(options.webhookSecret);
|
|
38
38
|
this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ?? YomaMmqrConfig.PRODUCTION_URL);
|
|
39
39
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laranex/myanmar-payments",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
4
|
-
"description": "Node.js SDK for Myanmar payment gateways: KBZ Pay, Wave Money, AYA Pay, Yoma MMQR and CyberSource. Typed
|
|
3
|
+
"version": "4.0.0-dev.7",
|
|
4
|
+
"description": "Node.js SDK for Myanmar payment gateways: KBZ Pay, Wave Money, AYA Pay, Yoma MMQR and CyberSource. Typed requests and results, exact amounts, no runtime dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"laranex",
|
|
7
7
|
"node-myanmar-payments",
|
|
@@ -23,7 +23,7 @@ Requires Node.js 20+ and has no runtime dependencies (global `fetch`, `node:cryp
|
|
|
23
23
|
|
|
24
24
|
## Configure
|
|
25
25
|
|
|
26
|
-
`MyanmarPayments.fromEnv(process.env)` reads `KBZ_PAY_*`, `WAVE_MONEY_*`, `AYA_PAY_*` (or `AYA_PGW_*`), `YOMA_MMQR_*` and `CYBER_SOURCE_*` plus `MYANMAR_PAYMENTS_HTTP_TIMEOUT` (the same variables as the PHP, Go and Python SDKs). Every gateway defaults to its production URLs; to test against UAT, set the URL overrides (`KBZ_PAY_BASE_URL`, `KBZ_PAY_PWA_BASE_REDIRECT_URL`, `WAVE_MONEY_BASE_URL`, `WAVE_MONEY_AUTHENTICATE_URL`, `AYA_PAY_BASE_URL`, `YOMA_MMQR_BASE_URL`, `CYBER_SOURCE_BASE_URL`) to the gateway's UAT URLs.
|
|
26
|
+
`MyanmarPayments.fromEnv(process.env)` reads `KBZ_PAY_*`, `WAVE_MONEY_*`, `AYA_PAY_*` (or `AYA_PGW_*`), `YOMA_MMQR_*` and `CYBER_SOURCE_*` plus `MYANMAR_PAYMENTS_HTTP_TIMEOUT` (the same variables as the PHP, Go and Python SDKs). Every gateway defaults to its production URLs; to test against UAT, set the URL overrides (`KBZ_PAY_BASE_URL`, `KBZ_PAY_PWA_BASE_REDIRECT_URL`, `WAVE_MONEY_BASE_URL`, `WAVE_MONEY_AUTHENTICATE_URL`, `AYA_PAY_BASE_URL`, `YOMA_MMQR_BASE_URL`, `CYBER_SOURCE_BASE_URL`) to the gateway's UAT URLs. The HTTP timeout `timeoutSeconds` / `MYANMAR_PAYMENTS_HTTP_TIMEOUT` (seconds, for every gateway except CyberSource) is optional and defaults to 30 (`DEFAULT_TIMEOUT_SECONDS`); an explicit value must be a whole number greater than 0. Every other setting is required, with no defaults: credentials, Wave's `merchantName` and `timeToLiveSeconds`, and Yoma's `apiVersion` (e.g. `v1rc`).
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
29
|
import { MyanmarPayments } from '@laranex/myanmar-payments';
|
|
@@ -32,8 +32,8 @@ const payments = MyanmarPayments.fromEnv(process.env); // create once, share acr
|
|
|
32
32
|
const kbz = payments.kbzPay(); // also waveMoney(), ayaPay(), yomaMmqr(), cyberSource()
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
- Or build one gateway: `new KbzPay(new KbzPayConfig({ appId, appKey, merchantCode
|
|
36
|
-
- Or pass the settings directly: gateways and `new MyanmarPayments({ kbzPay: { appId, appKey, merchantCode
|
|
35
|
+
- Or build one gateway: `new KbzPay(new KbzPayConfig({ appId, appKey, merchantCode }))`, `KbzPay.fromEnv()` or `new KbzPay(KbzPayConfig.fromEnv(process.env))`.
|
|
36
|
+
- Or pass the settings directly: gateways and `new MyanmarPayments({ kbzPay: { appId, appKey, merchantCode } })` take config objects or plain option objects; whole-number settings also take text such as `'30'`.
|
|
37
37
|
- Options (second argument): `{ httpClient, fetch }`. Without `httpClient`, the gateway uses `fetch` with the config's `timeoutSeconds`; a client you pass keeps its own timeout. Yoma and the facade also take `tokenCache` (any `TokenCache`, default `MemoryTokenCache`; back it with Redis when you run several processes).
|
|
38
38
|
- A missing setting throws `ConfigurationError` (`gateway`, `key`); a time setting that is not a whole number greater than 0 throws it too.
|
|
39
39
|
|