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

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/README.md +1 -1
  3. package/dist/cjs/aya-pay/aya-pay.d.ts +10 -10
  4. package/dist/cjs/aya-pay/aya-pay.js +10 -11
  5. package/dist/cjs/core/env.d.ts +5 -12
  6. package/dist/cjs/core/env.js +20 -23
  7. package/dist/cjs/core/errors.d.ts +8 -3
  8. package/dist/cjs/core/errors.js +11 -4
  9. package/dist/cjs/core/http.d.ts +10 -11
  10. package/dist/cjs/core/http.js +7 -9
  11. package/dist/cjs/core/index.d.ts +1 -1
  12. package/dist/cjs/core/index.js +1 -2
  13. package/dist/cjs/cyber-source/cyber-source.d.ts +10 -16
  14. package/dist/cjs/cyber-source/cyber-source.js +13 -14
  15. package/dist/cjs/kbz-pay/kbz-pay.d.ts +10 -11
  16. package/dist/cjs/kbz-pay/kbz-pay.js +11 -13
  17. package/dist/cjs/wave-money/wave-money.d.ts +12 -13
  18. package/dist/cjs/wave-money/wave-money.js +14 -23
  19. package/dist/cjs/yoma-mmqr/yoma-mmqr.d.ts +14 -14
  20. package/dist/cjs/yoma-mmqr/yoma-mmqr.js +14 -15
  21. package/dist/esm/aya-pay/aya-pay.d.ts +10 -10
  22. package/dist/esm/aya-pay/aya-pay.js +11 -12
  23. package/dist/esm/core/env.d.ts +5 -12
  24. package/dist/esm/core/env.js +18 -20
  25. package/dist/esm/core/errors.d.ts +8 -3
  26. package/dist/esm/core/errors.js +11 -4
  27. package/dist/esm/core/http.d.ts +10 -11
  28. package/dist/esm/core/http.js +6 -8
  29. package/dist/esm/core/index.d.ts +1 -1
  30. package/dist/esm/core/index.js +1 -1
  31. package/dist/esm/cyber-source/cyber-source.d.ts +10 -16
  32. package/dist/esm/cyber-source/cyber-source.js +14 -15
  33. package/dist/esm/kbz-pay/kbz-pay.d.ts +10 -11
  34. package/dist/esm/kbz-pay/kbz-pay.js +12 -14
  35. package/dist/esm/wave-money/wave-money.d.ts +12 -13
  36. package/dist/esm/wave-money/wave-money.js +15 -24
  37. package/dist/esm/yoma-mmqr/yoma-mmqr.d.ts +14 -14
  38. package/dist/esm/yoma-mmqr/yoma-mmqr.js +15 -16
  39. package/package.json +2 -2
  40. package/skills/node-myanmar-payments/SKILL.md +7 -5
@@ -13,17 +13,17 @@ const validate_js_1 = require("../core/validate.js");
13
13
  const values_js_1 = require("../core/values.js");
14
14
  const signer_js_1 = require("./signer.js");
15
15
  /**
16
- * KBZ Pay credentials and endpoints. A missing credential throws a `ConfigurationError`.
16
+ * KBZ Pay credentials and endpoints. A missing setting throws a `ConfigurationError`. The URLs
17
+ * default to production; UAT and production issue separate credentials.
17
18
  */
18
19
  class KbzPayConfig {
19
- static SANDBOX_API_URL = 'http://api-uat.kbzpay.com/payment/gateway/uat';
20
20
  static PRODUCTION_API_URL = 'https://api.kbzpay.com/payment/gateway';
21
- static SANDBOX_PWA_URL = 'https://static.kbzpay.com/pgw/uat/pwa/#/';
22
21
  static PRODUCTION_PWA_URL = 'https://wap.kbzpay.com/pgw/pwa/#/';
23
22
  appId;
24
23
  appKey;
25
24
  merchantCode;
26
- sandbox;
25
+ /** Seconds before the default HTTP client gives up on a request. */
26
+ timeoutSeconds;
27
27
  /** The API base URL in use. */
28
28
  apiUrl;
29
29
  /** The PWA checkout URL in use, always ending in `/`. */
@@ -32,22 +32,20 @@ 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.sandbox = (0, env_js_1.parseSandbox)(options.sandbox);
36
- this.apiUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.apiUrl) ??
37
- (this.sandbox ? KbzPayConfig.SANDBOX_API_URL : KbzPayConfig.PRODUCTION_API_URL));
38
- this.pwaUrl = `${(0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.pwaUrl) ??
39
- (this.sandbox ? KbzPayConfig.SANDBOX_PWA_URL : KbzPayConfig.PRODUCTION_PWA_URL))}/`;
35
+ this.timeoutSeconds = (0, env_js_1.requireSeconds)('kbz_pay', 'timeout_in_seconds', options.timeoutSeconds);
36
+ this.apiUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.apiUrl) ?? KbzPayConfig.PRODUCTION_API_URL);
37
+ this.pwaUrl = `${(0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.pwaUrl) ?? KbzPayConfig.PRODUCTION_PWA_URL)}/`;
40
38
  }
41
39
  /**
42
- * Reads `KBZ_PAY_APP_ID`, `KBZ_PAY_APP_KEY`, `KBZ_PAY_MERCHANT_CODE`, `KBZ_PAY_SANDBOX`,
43
- * `KBZ_PAY_BASE_URL` and `KBZ_PAY_PWA_BASE_REDIRECT_URL`.
40
+ * Reads `KBZ_PAY_APP_ID`, `KBZ_PAY_APP_KEY`, `KBZ_PAY_MERCHANT_CODE`,
41
+ * `MYANMAR_PAYMENTS_HTTP_TIMEOUT`, `KBZ_PAY_BASE_URL` and `KBZ_PAY_PWA_BASE_REDIRECT_URL`.
44
42
  */
45
43
  static fromEnv(env = (0, env_js_1.defaultEnv)()) {
46
44
  return new KbzPayConfig({
47
45
  appId: (0, env_js_1.envFirst)(env, 'KBZ_PAY_APP_ID'),
48
46
  appKey: (0, env_js_1.envFirst)(env, 'KBZ_PAY_APP_KEY'),
49
47
  merchantCode: (0, env_js_1.envFirst)(env, 'KBZ_PAY_MERCHANT_CODE'),
50
- sandbox: (0, env_js_1.envSandbox)(env, 'KBZ_PAY_SANDBOX'),
48
+ timeoutSeconds: (0, env_js_1.envFirst)(env, env_js_1.HTTP_TIMEOUT_VARIABLE),
51
49
  apiUrl: (0, env_js_1.envFirst)(env, 'KBZ_PAY_BASE_URL'),
52
50
  pwaUrl: (0, env_js_1.envFirst)(env, 'KBZ_PAY_PWA_BASE_REDIRECT_URL'),
53
51
  });
@@ -76,7 +74,7 @@ class KbzPay {
76
74
  constructor(config, options = {}) {
77
75
  this.config = config instanceof KbzPayConfig ? config : new KbzPayConfig(config);
78
76
  this.signer = new signer_js_1.KbzPaySigner(this.config.appKey);
79
- this.transport = new http_js_1.Transport((0, http_js_1.httpClientFrom)(options));
77
+ this.transport = new http_js_1.Transport((0, http_js_1.httpClientFrom)(options, this.config.timeoutSeconds));
80
78
  }
81
79
  /** A gateway configured from the `KBZ_PAY_*` environment variables. */
82
80
  static fromEnv(env = (0, env_js_1.defaultEnv)(), options = {}) {
@@ -11,41 +11,40 @@ export interface WaveMoneyConfigOptions {
11
11
  secretKey: string;
12
12
  /** Your business name, shown on Wave's payment page. */
13
13
  merchantName: string;
14
- /** How long the customer has to pay, in seconds (default 300). */
15
- timeToLiveSeconds?: number | undefined;
14
+ /** How long the customer has to pay, in seconds: a whole number greater than 0 (or its text). */
15
+ timeToLiveSeconds: number | string;
16
16
  /**
17
- * Use the test environment (default `true`).
18
- * Text is read like a `*_SANDBOX` variable: `false`, `0`, `f`, `no` or `off` select production.
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.
19
19
  */
20
- sandbox?: boolean | string | undefined;
21
- /** Overrides the API base URL. */
20
+ timeoutSeconds: number | string;
21
+ /** Overrides the API base URL, e.g. to point at UAT. */
22
22
  baseUrl?: string | undefined;
23
23
  /** Overrides the host the customer is redirected to. Wave serves it without the API port. */
24
24
  authenticateUrl?: string | undefined;
25
25
  }
26
26
  /**
27
- * Wave Money credentials and endpoints. A missing credential throws a `ConfigurationError`.
27
+ * Wave Money credentials and endpoints. A missing setting throws a `ConfigurationError`. The URLs
28
+ * default to production.
28
29
  */
29
30
  export declare class WaveMoneyConfig {
30
- static readonly SANDBOX_URL = "https://preprodpayments.wavemoney.io:8107";
31
31
  static readonly PRODUCTION_URL = "https://payments.wavemoney.io";
32
- static readonly SANDBOX_AUTHENTICATE_URL = "https://preprodpayments.wavemoney.io";
33
32
  static readonly PRODUCTION_AUTHENTICATE_URL = "https://payments.wavemoney.io";
34
- static readonly DEFAULT_TIME_TO_LIVE_SECONDS = 300;
35
33
  readonly merchantId: string;
36
34
  readonly secretKey: string;
37
35
  readonly merchantName: string;
38
36
  /** Seconds the customer has to pay. */
39
37
  readonly timeToLiveSeconds: number;
40
- readonly sandbox: boolean;
38
+ /** Seconds before the default HTTP client gives up on a request. */
39
+ readonly timeoutSeconds: number;
41
40
  /** The API base URL in use. */
42
41
  readonly baseUrl: string;
43
42
  /** The host the customer is redirected to. */
44
43
  readonly authenticateUrl: string;
45
44
  constructor(options: WaveMoneyConfigOptions);
46
45
  /**
47
- * Reads `WAVE_MONEY_MERCHANT_ID`, `WAVE_MONEY_SECRET_KEY`, `WAVE_MONEY_MERCHANT_NAME` (falling back
48
- * to `APP_NAME`), `WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS`, `WAVE_MONEY_SANDBOX`, `WAVE_MONEY_BASE_URL`
46
+ * Reads `WAVE_MONEY_MERCHANT_ID`, `WAVE_MONEY_SECRET_KEY`, `WAVE_MONEY_MERCHANT_NAME`,
47
+ * `WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT`, `WAVE_MONEY_BASE_URL`
49
48
  * and `WAVE_MONEY_AUTHENTICATE_URL`.
50
49
  */
51
50
  static fromEnv(env?: EnvSource): WaveMoneyConfig;
@@ -13,20 +13,19 @@ const status_js_1 = require("../core/status.js");
13
13
  const validate_js_1 = require("../core/validate.js");
14
14
  const values_js_1 = require("../core/values.js");
15
15
  /**
16
- * Wave Money credentials and endpoints. A missing credential throws a `ConfigurationError`.
16
+ * Wave Money credentials and endpoints. A missing setting throws a `ConfigurationError`. The URLs
17
+ * default to production.
17
18
  */
18
19
  class WaveMoneyConfig {
19
- static SANDBOX_URL = 'https://preprodpayments.wavemoney.io:8107';
20
20
  static PRODUCTION_URL = 'https://payments.wavemoney.io';
21
- static SANDBOX_AUTHENTICATE_URL = 'https://preprodpayments.wavemoney.io';
22
21
  static PRODUCTION_AUTHENTICATE_URL = 'https://payments.wavemoney.io';
23
- static DEFAULT_TIME_TO_LIVE_SECONDS = 300;
24
22
  merchantId;
25
23
  secretKey;
26
24
  merchantName;
27
25
  /** Seconds the customer has to pay. */
28
26
  timeToLiveSeconds;
29
- sandbox;
27
+ /** Seconds before the default HTTP client gives up on a request. */
28
+ timeoutSeconds;
30
29
  /** The API base URL in use. */
31
30
  baseUrl;
32
31
  /** The host the customer is redirected to. */
@@ -35,31 +34,23 @@ class WaveMoneyConfig {
35
34
  this.merchantId = (0, env_js_1.requireSetting)('wave_money', 'merchant_id', options.merchantId);
36
35
  this.secretKey = (0, env_js_1.requireSetting)('wave_money', 'secret_key', options.secretKey);
37
36
  this.merchantName = (0, env_js_1.requireSetting)('wave_money', 'merchant_name', options.merchantName);
38
- const ttl = options.timeToLiveSeconds;
39
- this.timeToLiveSeconds =
40
- ttl !== undefined && Number.isInteger(ttl) && ttl > 0
41
- ? ttl
42
- : WaveMoneyConfig.DEFAULT_TIME_TO_LIVE_SECONDS;
43
- this.sandbox = (0, env_js_1.parseSandbox)(options.sandbox);
44
- this.baseUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.baseUrl) ??
45
- (this.sandbox ? WaveMoneyConfig.SANDBOX_URL : WaveMoneyConfig.PRODUCTION_URL));
46
- this.authenticateUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.authenticateUrl) ??
47
- (this.sandbox
48
- ? WaveMoneyConfig.SANDBOX_AUTHENTICATE_URL
49
- : WaveMoneyConfig.PRODUCTION_AUTHENTICATE_URL));
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);
39
+ this.baseUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.baseUrl) ?? WaveMoneyConfig.PRODUCTION_URL);
40
+ this.authenticateUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.authenticateUrl) ?? WaveMoneyConfig.PRODUCTION_AUTHENTICATE_URL);
50
41
  }
51
42
  /**
52
- * Reads `WAVE_MONEY_MERCHANT_ID`, `WAVE_MONEY_SECRET_KEY`, `WAVE_MONEY_MERCHANT_NAME` (falling back
53
- * to `APP_NAME`), `WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS`, `WAVE_MONEY_SANDBOX`, `WAVE_MONEY_BASE_URL`
43
+ * Reads `WAVE_MONEY_MERCHANT_ID`, `WAVE_MONEY_SECRET_KEY`, `WAVE_MONEY_MERCHANT_NAME`,
44
+ * `WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT`, `WAVE_MONEY_BASE_URL`
54
45
  * and `WAVE_MONEY_AUTHENTICATE_URL`.
55
46
  */
56
47
  static fromEnv(env = (0, env_js_1.defaultEnv)()) {
57
48
  return new WaveMoneyConfig({
58
49
  merchantId: (0, env_js_1.envFirst)(env, 'WAVE_MONEY_MERCHANT_ID'),
59
50
  secretKey: (0, env_js_1.envFirst)(env, 'WAVE_MONEY_SECRET_KEY'),
60
- merchantName: (0, env_js_1.envFirst)(env, 'WAVE_MONEY_MERCHANT_NAME', 'APP_NAME'),
61
- timeToLiveSeconds: (0, env_js_1.envInt)(env, 'WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS'),
62
- sandbox: (0, env_js_1.envSandbox)(env, 'WAVE_MONEY_SANDBOX'),
51
+ merchantName: (0, env_js_1.envFirst)(env, 'WAVE_MONEY_MERCHANT_NAME'),
52
+ timeToLiveSeconds: (0, env_js_1.envFirst)(env, 'WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS'),
53
+ timeoutSeconds: (0, env_js_1.envFirst)(env, env_js_1.HTTP_TIMEOUT_VARIABLE),
63
54
  baseUrl: (0, env_js_1.envFirst)(env, 'WAVE_MONEY_BASE_URL'),
64
55
  authenticateUrl: (0, env_js_1.envFirst)(env, 'WAVE_MONEY_AUTHENTICATE_URL'),
65
56
  });
@@ -98,7 +89,7 @@ class WaveMoney {
98
89
  transport;
99
90
  constructor(config, options = {}) {
100
91
  this.config = config instanceof WaveMoneyConfig ? config : new WaveMoneyConfig(config);
101
- this.transport = new http_js_1.Transport((0, http_js_1.httpClientFrom)(options));
92
+ this.transport = new http_js_1.Transport((0, http_js_1.httpClientFrom)(options, this.config.timeoutSeconds));
102
93
  }
103
94
  /** A gateway configured from the `WAVE_MONEY_*` environment variables. */
104
95
  static fromEnv(env = (0, env_js_1.defaultEnv)(), options = {}) {
@@ -16,38 +16,38 @@ export interface YomaMmqrConfigOptions {
16
16
  webhookHashKey: string;
17
17
  /** The secret you shared with Yoma; when set, callbacks must carry it in `X-Webhook-Secret`. */
18
18
  webhookSecret?: string | undefined;
19
+ /** The `{version}` segment of the API paths, e.g. `v1rc`. */
20
+ apiVersion: string;
19
21
  /**
20
- * Use the UAT payment hub (default `true`).
21
- * Text is read like a `*_SANDBOX` variable: `false`, `0`, `f`, `no` or `off` select production.
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.
22
24
  */
23
- sandbox?: boolean | string | undefined;
24
- /** Overrides the API base URL. */
25
+ timeoutSeconds: number | string;
26
+ /** Overrides the API base URL, e.g. to point at UAT. */
25
27
  baseUrl?: string | undefined;
26
- /** The `{version}` segment of the API paths (default `v1rc`). */
27
- apiVersion?: string | undefined;
28
28
  }
29
29
  /**
30
- * Yoma MMQR credentials and endpoints. A missing credential throws a `ConfigurationError`.
30
+ * Yoma MMQR credentials and endpoints. A missing setting throws a `ConfigurationError`. The URL
31
+ * defaults to production.
31
32
  */
32
33
  export declare class YomaMmqrConfig {
33
- static readonly SANDBOX_URL = "https://devapi.yomabank.net";
34
34
  static readonly PRODUCTION_URL = "https://paymenthubapi.yomabank.com";
35
- static readonly DEFAULT_API_VERSION = "v1rc";
36
35
  readonly merchantId: string;
37
36
  readonly clientId: string;
38
37
  readonly clientSecret: string;
39
38
  readonly webhookHashKey: string;
40
39
  readonly webhookSecret: string | undefined;
41
- readonly sandbox: boolean;
40
+ /** The `{version}` segment of the API paths. */
41
+ readonly apiVersion: string;
42
+ /** Seconds before the default HTTP client gives up on a request. */
43
+ readonly timeoutSeconds: number;
42
44
  /** The base URL in use. */
43
45
  readonly baseUrl: string;
44
- /** The API version in use. */
45
- readonly apiVersion: string;
46
46
  constructor(options: YomaMmqrConfigOptions);
47
47
  /**
48
48
  * Reads `YOMA_MMQR_MERCHANT_ID`, `YOMA_MMQR_CLIENT_ID`, `YOMA_MMQR_CLIENT_SECRET`,
49
- * `YOMA_MMQR_WEBHOOK_HASHKEY`, `YOMA_MMQR_WEBHOOK_SECRET`, `YOMA_MMQR_SANDBOX`,
50
- * `YOMA_MMQR_BASE_URL` and `YOMA_MMQR_API_VERSION`.
49
+ * `YOMA_MMQR_WEBHOOK_HASHKEY`, `YOMA_MMQR_API_VERSION`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT`,
50
+ * `YOMA_MMQR_WEBHOOK_SECRET` and `YOMA_MMQR_BASE_URL`.
51
51
  */
52
52
  static fromEnv(env?: EnvSource): YomaMmqrConfig;
53
53
  }
@@ -13,37 +13,36 @@ const status_js_1 = require("../core/status.js");
13
13
  const validate_js_1 = require("../core/validate.js");
14
14
  const values_js_1 = require("../core/values.js");
15
15
  /**
16
- * Yoma MMQR credentials and endpoints. A missing credential throws a `ConfigurationError`.
16
+ * Yoma MMQR credentials and endpoints. A missing setting throws a `ConfigurationError`. The URL
17
+ * defaults to production.
17
18
  */
18
19
  class YomaMmqrConfig {
19
- static SANDBOX_URL = 'https://devapi.yomabank.net';
20
20
  static PRODUCTION_URL = 'https://paymenthubapi.yomabank.com';
21
- static DEFAULT_API_VERSION = 'v1rc';
22
21
  merchantId;
23
22
  clientId;
24
23
  clientSecret;
25
24
  webhookHashKey;
26
25
  webhookSecret;
27
- sandbox;
26
+ /** The `{version}` segment of the API paths. */
27
+ apiVersion;
28
+ /** Seconds before the default HTTP client gives up on a request. */
29
+ timeoutSeconds;
28
30
  /** The base URL in use. */
29
31
  baseUrl;
30
- /** The API version in use. */
31
- apiVersion;
32
32
  constructor(options) {
33
33
  this.merchantId = (0, env_js_1.requireSetting)('yoma_mmqr', 'merchant_id', options.merchantId);
34
34
  this.clientId = (0, env_js_1.requireSetting)('yoma_mmqr', 'client_id', options.clientId);
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
+ 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);
37
39
  this.webhookSecret = (0, env_js_1.optionalSetting)(options.webhookSecret);
38
- this.sandbox = (0, env_js_1.parseSandbox)(options.sandbox);
39
- this.baseUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.baseUrl) ??
40
- (this.sandbox ? YomaMmqrConfig.SANDBOX_URL : YomaMmqrConfig.PRODUCTION_URL));
41
- this.apiVersion = (0, env_js_1.optionalSetting)(options.apiVersion) ?? YomaMmqrConfig.DEFAULT_API_VERSION;
40
+ this.baseUrl = (0, env_js_1.trimUrl)((0, env_js_1.optionalSetting)(options.baseUrl) ?? YomaMmqrConfig.PRODUCTION_URL);
42
41
  }
43
42
  /**
44
43
  * Reads `YOMA_MMQR_MERCHANT_ID`, `YOMA_MMQR_CLIENT_ID`, `YOMA_MMQR_CLIENT_SECRET`,
45
- * `YOMA_MMQR_WEBHOOK_HASHKEY`, `YOMA_MMQR_WEBHOOK_SECRET`, `YOMA_MMQR_SANDBOX`,
46
- * `YOMA_MMQR_BASE_URL` and `YOMA_MMQR_API_VERSION`.
44
+ * `YOMA_MMQR_WEBHOOK_HASHKEY`, `YOMA_MMQR_API_VERSION`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT`,
45
+ * `YOMA_MMQR_WEBHOOK_SECRET` and `YOMA_MMQR_BASE_URL`.
47
46
  */
48
47
  static fromEnv(env = (0, env_js_1.defaultEnv)()) {
49
48
  return new YomaMmqrConfig({
@@ -51,10 +50,10 @@ class YomaMmqrConfig {
51
50
  clientId: (0, env_js_1.envFirst)(env, 'YOMA_MMQR_CLIENT_ID'),
52
51
  clientSecret: (0, env_js_1.envFirst)(env, 'YOMA_MMQR_CLIENT_SECRET'),
53
52
  webhookHashKey: (0, env_js_1.envFirst)(env, 'YOMA_MMQR_WEBHOOK_HASHKEY'),
53
+ apiVersion: (0, env_js_1.envFirst)(env, 'YOMA_MMQR_API_VERSION'),
54
+ timeoutSeconds: (0, env_js_1.envFirst)(env, env_js_1.HTTP_TIMEOUT_VARIABLE),
54
55
  webhookSecret: (0, env_js_1.envFirst)(env, 'YOMA_MMQR_WEBHOOK_SECRET'),
55
- sandbox: (0, env_js_1.envSandbox)(env, 'YOMA_MMQR_SANDBOX'),
56
56
  baseUrl: (0, env_js_1.envFirst)(env, 'YOMA_MMQR_BASE_URL'),
57
- apiVersion: (0, env_js_1.envFirst)(env, 'YOMA_MMQR_API_VERSION'),
58
57
  });
59
58
  }
60
59
  }
@@ -79,7 +78,7 @@ class YomaMmqr {
79
78
  pendingToken;
80
79
  constructor(config, options = {}) {
81
80
  this.config = config instanceof YomaMmqrConfig ? config : new YomaMmqrConfig(config);
82
- this.transport = new http_js_1.Transport((0, http_js_1.httpClientFrom)(options));
81
+ this.transport = new http_js_1.Transport((0, http_js_1.httpClientFrom)(options, this.config.timeoutSeconds));
83
82
  this.cache = options.tokenCache ?? new cache_js_1.MemoryTokenCache();
84
83
  }
85
84
  /** A gateway configured from the `YOMA_MMQR_*` environment variables. */
@@ -10,29 +10,29 @@ export interface AyaPayConfigOptions {
10
10
  /** The secret that signs requests and verifies callbacks. */
11
11
  appSecret: string;
12
12
  /**
13
- * Use the UAT environment (default `true`).
14
- * Text is read like a `*_SANDBOX` variable: `false`, `0`, `f`, `no` or `off` select production.
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.
15
15
  */
16
- sandbox?: boolean | string | undefined;
17
- /** Overrides the gateway base URL. */
16
+ timeoutSeconds: number | string;
17
+ /** Overrides the gateway base URL, e.g. to point at UAT. */
18
18
  baseUrl?: string | undefined;
19
19
  }
20
20
  /**
21
- * AYA Payment Gateway (APG) credentials and endpoints. A missing credential throws a
22
- * `ConfigurationError`.
21
+ * AYA Payment Gateway (APG) credentials and endpoints. A missing setting throws a
22
+ * `ConfigurationError`. The URL defaults to production.
23
23
  */
24
24
  export declare class AyaPayConfig {
25
- static readonly SANDBOX_URL = "https://uat-pgw.ayainnovation.com";
26
25
  static readonly PRODUCTION_URL = "https://pgw.ayainnovation.com";
27
26
  readonly appKey: string;
28
27
  readonly appSecret: string;
29
- readonly sandbox: boolean;
28
+ /** Seconds before the default HTTP client gives up on a request. */
29
+ readonly timeoutSeconds: number;
30
30
  /** The base URL in use. */
31
31
  readonly baseUrl: string;
32
32
  constructor(options: AyaPayConfigOptions);
33
33
  /**
34
- * Reads `AYA_PAY_APP_KEY`, `AYA_PAY_APP_SECRET`, `AYA_PAY_SANDBOX` and `AYA_PAY_BASE_URL`, falling
35
- * back to the `AYA_PGW_*` names.
34
+ * Reads `AYA_PAY_APP_KEY`, `AYA_PAY_APP_SECRET`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT` and
35
+ * `AYA_PAY_BASE_URL`, falling back to the `AYA_PGW_*` names.
36
36
  */
37
37
  static fromEnv(env?: EnvSource): AyaPayConfig;
38
38
  }
@@ -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, envSandbox, parseSandbox, optionalSetting, requireSetting, trimUrl, } from '../core/env.js';
4
+ import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting, requireSeconds, requireSetting, 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';
@@ -10,33 +10,32 @@ import { resolveStatus } from '../core/status.js';
10
10
  import { toAmount, Validator } from '../core/validate.js';
11
11
  import { get, isNested, object, optional, scalarString, trimmed } from '../core/values.js';
12
12
  /**
13
- * AYA Payment Gateway (APG) credentials and endpoints. A missing credential throws a
14
- * `ConfigurationError`.
13
+ * AYA Payment Gateway (APG) credentials and endpoints. A missing setting throws a
14
+ * `ConfigurationError`. The URL defaults to production.
15
15
  */
16
16
  export class AyaPayConfig {
17
- static SANDBOX_URL = 'https://uat-pgw.ayainnovation.com';
18
17
  static PRODUCTION_URL = 'https://pgw.ayainnovation.com';
19
18
  appKey;
20
19
  appSecret;
21
- sandbox;
20
+ /** Seconds before the default HTTP client gives up on a request. */
21
+ timeoutSeconds;
22
22
  /** The base URL in use. */
23
23
  baseUrl;
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.sandbox = parseSandbox(options.sandbox);
28
- this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ??
29
- (this.sandbox ? AyaPayConfig.SANDBOX_URL : AyaPayConfig.PRODUCTION_URL));
27
+ this.timeoutSeconds = requireSeconds('aya_pay', 'timeout_in_seconds', options.timeoutSeconds);
28
+ this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ?? AyaPayConfig.PRODUCTION_URL);
30
29
  }
31
30
  /**
32
- * Reads `AYA_PAY_APP_KEY`, `AYA_PAY_APP_SECRET`, `AYA_PAY_SANDBOX` and `AYA_PAY_BASE_URL`, falling
33
- * back to the `AYA_PGW_*` names.
31
+ * Reads `AYA_PAY_APP_KEY`, `AYA_PAY_APP_SECRET`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT` and
32
+ * `AYA_PAY_BASE_URL`, falling back to the `AYA_PGW_*` names.
34
33
  */
35
34
  static fromEnv(env = defaultEnv()) {
36
35
  return new AyaPayConfig({
37
36
  appKey: envFirst(env, 'AYA_PAY_APP_KEY', 'AYA_PGW_APP_KEY'),
38
37
  appSecret: envFirst(env, 'AYA_PAY_APP_SECRET', 'AYA_PGW_APP_SECRET'),
39
- sandbox: envSandbox(env, 'AYA_PAY_SANDBOX'),
38
+ timeoutSeconds: envFirst(env, HTTP_TIMEOUT_VARIABLE),
40
39
  baseUrl: envFirst(env, 'AYA_PAY_BASE_URL', 'AYA_PGW_BASE_URL'),
41
40
  });
42
41
  }
@@ -119,7 +118,7 @@ export class AyaPay {
119
118
  transport;
120
119
  constructor(config, options = {}) {
121
120
  this.config = config instanceof AyaPayConfig ? config : new AyaPayConfig(config);
122
- this.transport = new Transport(httpClientFrom(options));
121
+ this.transport = new Transport(httpClientFrom(options, this.config.timeoutSeconds));
123
122
  }
124
123
  /** A gateway configured from the `AYA_PAY_*` (or `AYA_PGW_*`) environment variables. */
125
124
  static fromEnv(env = defaultEnv(), options = {}) {
@@ -3,21 +3,14 @@ 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
- * Reads a `*_SANDBOX` variable. Only `false`, `0`, `f`, `no` and `off` (any case) select
7
- * production; unset or unrecognized values mean sandbox.
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 envSandbox(env: EnvSource, key: string): boolean;
12
- /**
13
- * A `sandbox` setting: booleans as is, text parsed like a `*_SANDBOX` variable (`false`, `0`, `f`,
14
- * `no` and `off` in any case select production; anything else means sandbox), unset means sandbox.
15
- *
16
- * @internal
17
- */
18
- export declare function parseSandbox(value: boolean | string | undefined | null): boolean;
19
- /** An integer variable, or `undefined` when unset or not an integer. @internal */
20
- export declare function envInt(env: EnvSource, key: string): number | undefined;
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";
21
14
  /** The trimmed value, or throws a {@link ConfigurationError} naming `key`. @internal */
22
15
  export declare function requireSetting(gateway: string, key: string, value: unknown): string;
23
16
  /** A trimmed optional string, `undefined` when blank. @internal */
@@ -10,31 +10,29 @@ export function envFirst(env, ...keys) {
10
10
  return '';
11
11
  }
12
12
  /**
13
- * Reads a `*_SANDBOX` variable. Only `false`, `0`, `f`, `no` and `off` (any case) select
14
- * production; unset or unrecognized values mean sandbox.
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 envSandbox(env, key) {
19
- return parseSandbox(env[key] ?? '');
20
- }
21
- /**
22
- * A `sandbox` setting: booleans as is, text parsed like a `*_SANDBOX` variable (`false`, `0`, `f`,
23
- * `no` and `off` in any case select production; anything else means sandbox), unset means sandbox.
24
- *
25
- * @internal
26
- */
27
- export function parseSandbox(value) {
28
- if (typeof value === 'boolean') {
29
- return value;
18
+ export function requireSeconds(gateway, key, value) {
19
+ if (value === undefined || value === null || (typeof value === 'string' && value.trim() === '')) {
20
+ throw new ConfigurationError(gateway, key);
30
21
  }
31
- return !['false', '0', 'f', 'no', 'off'].includes((value ?? '').trim().toLowerCase());
32
- }
33
- /** An integer variable, or `undefined` when unset or not an integer. @internal */
34
- export function envInt(env, key) {
35
- const value = env[key]?.trim() ?? '';
36
- return /^[+-]?\d+$/.test(value) ? Number.parseInt(value, 10) : undefined;
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;
37
33
  }
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';
38
36
  /** The trimmed value, or throws a {@link ConfigurationError} naming `key`. @internal */
39
37
  export function requireSetting(gateway, key, value) {
40
38
  if (typeof value !== 'string' || value.trim() === '') {
@@ -45,12 +45,17 @@ 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
- constructor(gateway: string, key: string);
56
+ /**
57
+ * @param invalid `true` when the setting is set but is not a whole number greater than 0;
58
+ * `false` (the default) when it is missing.
59
+ */
60
+ constructor(gateway: string, key: string, invalid?: boolean);
56
61
  }
@@ -55,15 +55,22 @@ 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
- constructor(gateway, key) {
66
- super(`The ${gateway} configuration is missing [${key}].`);
66
+ /**
67
+ * @param invalid `true` when the setting is set but is not a whole number greater than 0;
68
+ * `false` (the default) when it is missing.
69
+ */
70
+ constructor(gateway, key, invalid = false) {
71
+ super(invalid
72
+ ? `The ${gateway} configuration [${key}] must be a whole number greater than 0.`
73
+ : `The ${gateway} configuration is missing [${key}].`);
67
74
  this.gateway = gateway;
68
75
  this.key = key;
69
76
  }
@@ -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; defaults to 30000. `0` disables the timeout. */
31
- timeoutMs?: number | undefined;
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 a 30 second
37
- * timeout.
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?: FetchHttpClientOptions);
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
- /** Sends the requests. Takes precedence over `fetch` and `timeoutMs`. */
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?: GatewayOptions): HttpClient;
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;
@@ -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 a 30 second
7
- * timeout.
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 ?? DEFAULT_TIMEOUT_MS;
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: options.timeoutMs }));
41
+ new FetchHttpClient({ fetch: options.fetch, timeoutMs: timeoutSeconds * 1000 }));
44
42
  }
45
43
  /** A decoded gateway response. @internal */
46
44
  export class GatewayResponse {