@laranex/myanmar-payments 4.0.0-dev.6 → 4.0.0-dev.8

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 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. Every other setting is required: the HTTP timeout (`timeout_in_seconds`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT`) for every gateway that calls an API, 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 `timeoutSeconds` (KBZ Pay, Wave Money, AYA Pay, Yoma MMQR), `timeToLiveSeconds` and `apiVersion` are required and take a whole number or its text; 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.
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.
@@ -31,3 +31,4 @@ Initial release. The version number matches the other Laranex Myanmar payments p
31
31
  - Yoma MMQR caches its access token under `myanmar-payments.yoma-mmqr.token.<sha256 of base URL and client id>` (was `node-myanmar-payments.…`), the same key as the PHP, Go and Python SDKs, and reads `expires_in` from its leading digits.
32
32
  - `Amount.equals()` compares by value, ignoring leading zeros too (`'01000'` equals `Amount.kyat(1000)`); text that is not plain digits with an optional fraction is never equal.
33
33
  - `CallbackRequest.rawBody` holds the exact bytes received (a string body is encoded as UTF-8), next to `body` as text, like Python's `raw_body` and Go's `Body`.
34
+ - `WaveMoneyPaymentData` takes optional `merchantName` and `timeToLiveSeconds`, which override the configured `merchantName` and `timeToLiveSeconds` for one payment (request hash included); a blank `merchantName` or a `timeToLiveSeconds` that is not a whole number greater than 0 throws `InvalidPaymentDataError`, like the PHP SDK.
@@ -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). A client you pass keeps its own timeout.
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: number | string;
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.requireSeconds)('aya_pay', 'timeout_in_seconds', options.timeoutSeconds);
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
  /**
@@ -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 */
@@ -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() === '') {
@@ -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 { EnvSource } from './env.js';
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';
@@ -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). A client you pass keeps its own timeout.
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: number | string;
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.requireSeconds)('kbz_pay', 'timeout_in_seconds', options.timeoutSeconds);
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). A client you pass keeps its own timeout.
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: number | string;
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. */
@@ -78,6 +79,16 @@ export interface WaveMoneyPaymentData {
78
79
  * this.
79
80
  */
80
81
  merchantReferenceId?: string | undefined;
82
+ /**
83
+ * The business name shown on Wave's page for this payment. Defaults to the configured
84
+ * `merchantName` when unset.
85
+ */
86
+ merchantName?: string | null | undefined;
87
+ /**
88
+ * How long the customer has to pay this payment, in seconds: a whole number greater than 0.
89
+ * Defaults to the configured `timeToLiveSeconds` when unset.
90
+ */
91
+ timeToLiveSeconds?: number | null | undefined;
81
92
  }
82
93
  /**
83
94
  * Wave Money (WavePay payment gateway): redirect payments and callbacks. Wave has no status API,
@@ -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.requireSeconds)('wave_money', 'timeout_in_seconds', options.timeoutSeconds);
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
  }
@@ -127,7 +127,11 @@ class WaveMoney {
127
127
  .url('returnUrl', data.returnUrl)
128
128
  .required('description', data.description)
129
129
  .when(items.length === 0, 'items', 'The items field must have at least one item.')
130
- .string('merchantReferenceId', data.merchantReferenceId);
130
+ .string('merchantReferenceId', data.merchantReferenceId)
131
+ .string('merchantName', data.merchantName)
132
+ .when(typeof data.merchantName === 'string' && data.merchantName.trim() === '', 'merchantName', 'The merchantName field is required.')
133
+ .when(isSet(data.timeToLiveSeconds) && !Number.isInteger(data.timeToLiveSeconds), 'timeToLiveSeconds', 'The timeToLiveSeconds field must be an integer.')
134
+ .when(isSet(data.timeToLiveSeconds) && data.timeToLiveSeconds < 1, 'timeToLiveSeconds', 'The timeToLiveSeconds field must be greater than 0.');
131
135
  items.forEach((item, index) => {
132
136
  validator
133
137
  .required(`items.${index}.name`, item?.name)
@@ -153,7 +157,7 @@ class WaveMoney {
153
157
  data.merchantReferenceId = (0, crypto_js_1.randomHex)();
154
158
  }
155
159
  const amount = WaveMoney.resolvedAmount(data).toString();
156
- const ttl = String(this.config.timeToLiveSeconds);
160
+ const ttl = String(data.timeToLiveSeconds ?? this.config.timeToLiveSeconds);
157
161
  // Wave documents items as [{"name": "...", "amount": 1000}] with a numeric amount; the amount
158
162
  // text is written as a JSON number without passing through a float.
159
163
  const items = `[${data.items
@@ -168,7 +172,7 @@ class WaveMoney {
168
172
  backend_result_url: data.callbackUrl,
169
173
  amount,
170
174
  payment_description: data.description,
171
- merchant_name: this.config.merchantName,
175
+ merchant_name: data.merchantName ?? this.config.merchantName,
172
176
  items,
173
177
  hash: this.hash([
174
178
  ttl,
@@ -226,6 +230,9 @@ class WaveMoney {
226
230
  }
227
231
  }
228
232
  exports.WaveMoney = WaveMoney;
233
+ function isSet(value) {
234
+ return value !== undefined && value !== null;
235
+ }
229
236
  function errorMessage(body) {
230
237
  const errors = body.errors;
231
238
  if ((0, json_js_1.isLosslessObject)(errors)) {
@@ -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). A client you pass keeps its own timeout.
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: number | string;
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.requireSeconds)('yoma_mmqr', 'timeout_in_seconds', options.timeoutSeconds);
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). A client you pass keeps its own timeout.
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: number | string;
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, requireSeconds, requireSetting, trimUrl, } from '../core/env.js';
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 = requireSeconds('aya_pay', 'timeout_in_seconds', options.timeoutSeconds);
27
+ this.timeoutSeconds = resolveTimeout('aya_pay', options.timeoutSeconds);
28
28
  this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ?? AyaPayConfig.PRODUCTION_URL);
29
29
  }
30
30
  /**
@@ -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 */
@@ -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() === '') {
@@ -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 { EnvSource } from './env.js';
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';
@@ -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). A client you pass keeps its own timeout.
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: number | string;
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, requireSeconds, requireSetting, trimUrl, } from '../core/env.js';
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 = requireSeconds('kbz_pay', 'timeout_in_seconds', options.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). A client you pass keeps its own timeout.
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: number | string;
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. */
@@ -78,6 +79,16 @@ export interface WaveMoneyPaymentData {
78
79
  * this.
79
80
  */
80
81
  merchantReferenceId?: string | undefined;
82
+ /**
83
+ * The business name shown on Wave's page for this payment. Defaults to the configured
84
+ * `merchantName` when unset.
85
+ */
86
+ merchantName?: string | null | undefined;
87
+ /**
88
+ * How long the customer has to pay this payment, in seconds: a whole number greater than 0.
89
+ * Defaults to the configured `timeToLiveSeconds` when unset.
90
+ */
91
+ timeToLiveSeconds?: number | null | undefined;
81
92
  }
82
93
  /**
83
94
  * Wave Money (WavePay payment gateway): redirect payments and callbacks. Wave has no status API,
@@ -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 = requireSeconds('wave_money', 'timeout_in_seconds', options.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
  }
@@ -123,7 +123,11 @@ export class WaveMoney {
123
123
  .url('returnUrl', data.returnUrl)
124
124
  .required('description', data.description)
125
125
  .when(items.length === 0, 'items', 'The items field must have at least one item.')
126
- .string('merchantReferenceId', data.merchantReferenceId);
126
+ .string('merchantReferenceId', data.merchantReferenceId)
127
+ .string('merchantName', data.merchantName)
128
+ .when(typeof data.merchantName === 'string' && data.merchantName.trim() === '', 'merchantName', 'The merchantName field is required.')
129
+ .when(isSet(data.timeToLiveSeconds) && !Number.isInteger(data.timeToLiveSeconds), 'timeToLiveSeconds', 'The timeToLiveSeconds field must be an integer.')
130
+ .when(isSet(data.timeToLiveSeconds) && data.timeToLiveSeconds < 1, 'timeToLiveSeconds', 'The timeToLiveSeconds field must be greater than 0.');
127
131
  items.forEach((item, index) => {
128
132
  validator
129
133
  .required(`items.${index}.name`, item?.name)
@@ -149,7 +153,7 @@ export class WaveMoney {
149
153
  data.merchantReferenceId = randomHex();
150
154
  }
151
155
  const amount = WaveMoney.resolvedAmount(data).toString();
152
- const ttl = String(this.config.timeToLiveSeconds);
156
+ const ttl = String(data.timeToLiveSeconds ?? this.config.timeToLiveSeconds);
153
157
  // Wave documents items as [{"name": "...", "amount": 1000}] with a numeric amount; the amount
154
158
  // text is written as a JSON number without passing through a float.
155
159
  const items = `[${data.items
@@ -164,7 +168,7 @@ export class WaveMoney {
164
168
  backend_result_url: data.callbackUrl,
165
169
  amount,
166
170
  payment_description: data.description,
167
- merchant_name: this.config.merchantName,
171
+ merchant_name: data.merchantName ?? this.config.merchantName,
168
172
  items,
169
173
  hash: this.hash([
170
174
  ttl,
@@ -221,6 +225,9 @@ export class WaveMoney {
221
225
  return hmacSha256Hex(this.config.secretKey, parts.join(''));
222
226
  }
223
227
  }
228
+ function isSet(value) {
229
+ return value !== undefined && value !== null;
230
+ }
224
231
  function errorMessage(body) {
225
232
  const errors = body.errors;
226
233
  if (isLosslessObject(errors)) {
@@ -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). A client you pass keeps its own timeout.
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: number | string;
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, requireSeconds, requireSetting, trimUrl, } from '../core/env.js';
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 = requireSeconds('yoma_mmqr', 'timeout_in_seconds', options.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@laranex/myanmar-payments",
3
- "version": "4.0.0-dev.6",
3
+ "version": "4.0.0-dev.8",
4
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",
@@ -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. Every other setting is required, with no defaults: credentials, `timeoutSeconds` (seconds, for every gateway except CyberSource), Wave's `merchantName` and `timeToLiveSeconds`, and Yoma's `apiVersion` (e.g. `v1rc`).
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, timeoutSeconds: 30 }))`, `KbzPay.fromEnv()` or `new KbzPay(KbzPayConfig.fromEnv(process.env))`.
36
- - Or pass the settings directly: gateways and `new MyanmarPayments({ kbzPay: { appId, appKey, merchantCode, timeoutSeconds } })` take config objects or plain option objects; whole-number settings also take text such as `'30'`.
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
 
@@ -58,7 +58,7 @@ const payment = await kbz.pwa({
58
58
  res.writeHead(302, { Location: payment.url }).end();
59
59
  ```
60
60
 
61
- - `RedirectPayment` (`url`) from `kbz.pwa(data)` and `wave.initiate(data)`. Wave fills `data.merchantReferenceId` when empty; store it.
61
+ - `RedirectPayment` (`url`) from `kbz.pwa(data)` and `wave.initiate(data)`. Wave fills `data.merchantReferenceId` when empty; store it. Pass `merchantName` or `timeToLiveSeconds` in Wave's payment data to override the configured `WAVE_MONEY_MERCHANT_NAME` or `WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS` for that one payment (the settings stay required).
62
62
  - `FormPayment` from `aya.initiate(data)` and `cyberSource.initiate(data)` (no network call): send `payment.toHtml()` as an auto-submitting page, or render `action`, `fields` and `enctype` yourself.
63
63
  - `QrPayment` from `kbz.qr(data)` (encode `qrString`) and `yoma.initiate(data)` (`qrImageDataUri()`, `expiresAt`, `reference`). A Yoma QR lives `YomaMmqr.QR_LIFETIME_SECONDS` (120); renew it with `yoma.renewQr(orderId)`.
64
64
  - `AppPayment` from `kbz.app(data)`: `res.json(payment)` sends `orderId`, `orderInfo`, `sign` and `signType` to your mobile app.