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

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 (39) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/dist/cjs/aya-pay/aya-pay.d.ts +10 -10
  3. package/dist/cjs/aya-pay/aya-pay.js +10 -11
  4. package/dist/cjs/core/env.d.ts +5 -12
  5. package/dist/cjs/core/env.js +20 -23
  6. package/dist/cjs/core/errors.d.ts +8 -3
  7. package/dist/cjs/core/errors.js +11 -4
  8. package/dist/cjs/core/http.d.ts +10 -11
  9. package/dist/cjs/core/http.js +7 -9
  10. package/dist/cjs/core/index.d.ts +1 -1
  11. package/dist/cjs/core/index.js +1 -2
  12. package/dist/cjs/cyber-source/cyber-source.d.ts +10 -16
  13. package/dist/cjs/cyber-source/cyber-source.js +13 -14
  14. package/dist/cjs/kbz-pay/kbz-pay.d.ts +10 -11
  15. package/dist/cjs/kbz-pay/kbz-pay.js +11 -13
  16. package/dist/cjs/wave-money/wave-money.d.ts +12 -13
  17. package/dist/cjs/wave-money/wave-money.js +14 -23
  18. package/dist/cjs/yoma-mmqr/yoma-mmqr.d.ts +14 -14
  19. package/dist/cjs/yoma-mmqr/yoma-mmqr.js +14 -15
  20. package/dist/esm/aya-pay/aya-pay.d.ts +10 -10
  21. package/dist/esm/aya-pay/aya-pay.js +11 -12
  22. package/dist/esm/core/env.d.ts +5 -12
  23. package/dist/esm/core/env.js +18 -20
  24. package/dist/esm/core/errors.d.ts +8 -3
  25. package/dist/esm/core/errors.js +11 -4
  26. package/dist/esm/core/http.d.ts +10 -11
  27. package/dist/esm/core/http.js +6 -8
  28. package/dist/esm/core/index.d.ts +1 -1
  29. package/dist/esm/core/index.js +1 -1
  30. package/dist/esm/cyber-source/cyber-source.d.ts +10 -16
  31. package/dist/esm/cyber-source/cyber-source.js +14 -15
  32. package/dist/esm/kbz-pay/kbz-pay.d.ts +10 -11
  33. package/dist/esm/kbz-pay/kbz-pay.js +12 -14
  34. package/dist/esm/wave-money/wave-money.d.ts +12 -13
  35. package/dist/esm/wave-money/wave-money.js +15 -24
  36. package/dist/esm/yoma-mmqr/yoma-mmqr.d.ts +14 -14
  37. package/dist/esm/yoma-mmqr/yoma-mmqr.js +15 -16
  38. package/package.json +1 -1
  39. package/skills/node-myanmar-payments/SKILL.md +7 -5
@@ -10,30 +10,24 @@ export interface CyberSourceConfigOptions {
10
10
  accessKey: string;
11
11
  /** The profile's secret key, which signs the fields. */
12
12
  secretKey: string;
13
- /**
14
- * Use the test environment (default `true`).
15
- * Text is read like a `*_SANDBOX` variable: `false`, `0`, `f`, `no` or `off` select production.
16
- */
17
- sandbox?: boolean | string | undefined;
18
- /** Overrides the Secure Acceptance base URL. */
13
+ /** Overrides the Secure Acceptance base URL, e.g. to point at the test environment. */
19
14
  baseUrl?: string | undefined;
20
15
  }
21
16
  /**
22
- * A CyberSource Secure Acceptance profile. A missing credential throws a `ConfigurationError`.
17
+ * A CyberSource Secure Acceptance profile. A missing credential throws a `ConfigurationError`. The
18
+ * URL defaults to production.
23
19
  */
24
20
  export declare class CyberSourceConfig {
25
- static readonly SANDBOX_URL = "https://testsecureacceptance.cybersource.com";
26
21
  static readonly PRODUCTION_URL = "https://secureacceptance.cybersource.com";
27
22
  readonly profileId: string;
28
23
  readonly accessKey: string;
29
24
  readonly secretKey: string;
30
- readonly sandbox: boolean;
31
25
  /** The base URL in use. */
32
26
  readonly baseUrl: string;
33
27
  constructor(options: CyberSourceConfigOptions);
34
28
  /**
35
29
  * Reads `CYBER_SOURCE_PROFILE_ID`, `CYBER_SOURCE_ACCESS_KEY`, `CYBER_SOURCE_SECRET_KEY`,
36
- * `CYBER_SOURCE_SANDBOX` and `CYBER_SOURCE_BASE_URL`.
30
+ * and `CYBER_SOURCE_BASE_URL`.
37
31
  */
38
32
  static fromEnv(env?: EnvSource): CyberSourceConfig;
39
33
  }
@@ -64,12 +58,12 @@ export interface CyberSourcePaymentData {
64
58
  returnUrl?: string | undefined;
65
59
  /** The page shown on cancel (`override_custom_cancel_page`), at most 255 characters. */
66
60
  cancelUrl?: string | undefined;
67
- /** An ISO 4217 code (default `MMK`). */
68
- currency?: string | undefined;
69
- /** What to do with the card (default `sale`). */
70
- transactionType?: CyberSourceTransactionType | undefined;
71
- /** The hosted page language, e.g. `en-us` (the default). */
72
- locale?: string | undefined;
61
+ /** An ISO 4217 code, e.g. `MMK`. */
62
+ currency: string;
63
+ /** What to do with the card, e.g. `sale`. */
64
+ transactionType: CyberSourceTransactionType;
65
+ /** The hosted page language, e.g. `en-us`. */
66
+ locale: string;
73
67
  }
74
68
  /**
75
69
  * CyberSource Secure Acceptance hosted checkout for card payments: signs the form and verifies the
@@ -1,7 +1,7 @@
1
1
  import {} from '../core/amount.js';
2
2
  import { CallbackRequest, losslessInput, PaymentCallback } from '../core/callback.js';
3
3
  import { hmacSha256Base64, randomHex, safeEqual } from '../core/crypto.js';
4
- import { defaultEnv, envFirst, envSandbox, parseSandbox, optionalSetting, requireSetting, trimUrl, } from '../core/env.js';
4
+ import { defaultEnv, envFirst, optionalSetting, requireSetting, trimUrl, } from '../core/env.js';
5
5
  import { SignatureVerificationError } from '../core/errors.js';
6
6
  import { setKey, toPlainObject } from '../core/json.js';
7
7
  import { FormPayment } from '../core/results.js';
@@ -9,35 +9,31 @@ import { resolveStatus } from '../core/status.js';
9
9
  import { toAmount, Validator } from '../core/validate.js';
10
10
  import { get, optional, scalarString, trimmed } from '../core/values.js';
11
11
  /**
12
- * A CyberSource Secure Acceptance profile. A missing credential throws a `ConfigurationError`.
12
+ * A CyberSource Secure Acceptance profile. A missing credential throws a `ConfigurationError`. The
13
+ * URL defaults to production.
13
14
  */
14
15
  export class CyberSourceConfig {
15
- static SANDBOX_URL = 'https://testsecureacceptance.cybersource.com';
16
16
  static PRODUCTION_URL = 'https://secureacceptance.cybersource.com';
17
17
  profileId;
18
18
  accessKey;
19
19
  secretKey;
20
- sandbox;
21
20
  /** The base URL in use. */
22
21
  baseUrl;
23
22
  constructor(options) {
24
23
  this.profileId = requireSetting('cyber_source', 'profile_id', options.profileId);
25
24
  this.accessKey = requireSetting('cyber_source', 'access_key', options.accessKey);
26
25
  this.secretKey = requireSetting('cyber_source', 'secret_key', options.secretKey);
27
- this.sandbox = parseSandbox(options.sandbox);
28
- this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ??
29
- (this.sandbox ? CyberSourceConfig.SANDBOX_URL : CyberSourceConfig.PRODUCTION_URL));
26
+ this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ?? CyberSourceConfig.PRODUCTION_URL);
30
27
  }
31
28
  /**
32
29
  * Reads `CYBER_SOURCE_PROFILE_ID`, `CYBER_SOURCE_ACCESS_KEY`, `CYBER_SOURCE_SECRET_KEY`,
33
- * `CYBER_SOURCE_SANDBOX` and `CYBER_SOURCE_BASE_URL`.
30
+ * and `CYBER_SOURCE_BASE_URL`.
34
31
  */
35
32
  static fromEnv(env = defaultEnv()) {
36
33
  return new CyberSourceConfig({
37
34
  profileId: envFirst(env, 'CYBER_SOURCE_PROFILE_ID'),
38
35
  accessKey: envFirst(env, 'CYBER_SOURCE_ACCESS_KEY'),
39
36
  secretKey: envFirst(env, 'CYBER_SOURCE_SECRET_KEY'),
40
- sandbox: envSandbox(env, 'CYBER_SOURCE_SANDBOX'),
41
37
  baseUrl: envFirst(env, 'CYBER_SOURCE_BASE_URL'),
42
38
  });
43
39
  }
@@ -110,9 +106,12 @@ export class CyberSource {
110
106
  .string('cancelUrl', data.cancelUrl)
111
107
  .url('cancelUrl', data.cancelUrl)
112
108
  .max('cancelUrl', data.cancelUrl, 255)
113
- .pattern('currency', String(data.currency || 'MMK'), /^[A-Z]{3}$/, 'a three letter ISO 4217 code')
114
- .pattern('locale', String(data.locale || 'en-us'), /^[a-z]{2}-[a-z]{2}$/, 'a locale code such as en-us')
115
- .when(!TRANSACTION_TYPES.includes(String(data.transactionType || 'sale')), 'transactionType', 'The transactionType field is not a supported transaction type.')
109
+ .required('currency', data.currency)
110
+ .pattern('currency', data.currency, /^[A-Z]{3}$/, 'a three letter ISO 4217 code')
111
+ .required('transactionType', data.transactionType)
112
+ .when(!TRANSACTION_TYPES.includes(String(data.transactionType)), 'transactionType', 'The transactionType field is not a supported transaction type.')
113
+ .required('locale', data.locale)
114
+ .pattern('locale', data.locale, /^[a-z]{2}-[a-z]{2}$/, 'a locale code such as en-us')
116
115
  .validate();
117
116
  }
118
117
  /**
@@ -127,11 +126,11 @@ export class CyberSource {
127
126
  transaction_uuid: randomHex(),
128
127
  signed_field_names: SIGNED_FIELDS.join(','),
129
128
  signed_date_time: new Date().toISOString().replace(/\.\d{3}Z$/, 'Z'),
130
- locale: data.locale || 'en-us',
131
- transaction_type: data.transactionType || 'sale',
129
+ locale: data.locale,
130
+ transaction_type: data.transactionType,
132
131
  reference_number: data.orderId,
133
132
  amount: String(toAmount(data.amount)),
134
- currency: data.currency || 'MMK',
133
+ currency: data.currency,
135
134
  override_custom_receipt_page: data.returnUrl ?? '',
136
135
  override_backoffice_post_url: data.callbackUrl,
137
136
  override_custom_cancel_page: data.cancelUrl ?? '',
@@ -13,36 +13,35 @@ export interface KbzPayConfigOptions {
13
13
  /** The `merch_code` KBZ issued. */
14
14
  merchantCode: string;
15
15
  /**
16
- * Use the UAT endpoints (default `true`). UAT and production issue separate
17
- * credentials. Text is read like a `*_SANDBOX` variable: `false`, `0`, `f`, `no` or `off`
18
- * select production.
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.
19
18
  */
20
- sandbox?: boolean | string | undefined;
21
- /** Overrides the API base URL, e.g. to go through a proxy. */
19
+ timeoutSeconds: number | string;
20
+ /** Overrides the API base URL, e.g. to point at UAT or go through a proxy. */
22
21
  apiUrl?: string | undefined;
23
22
  /** Overrides the PWA checkout URL. A trailing `#` or `#/` is normalized to `#/`. */
24
23
  pwaUrl?: string | undefined;
25
24
  }
26
25
  /**
27
- * KBZ Pay credentials and endpoints. A missing credential throws a `ConfigurationError`.
26
+ * KBZ Pay credentials and endpoints. A missing setting throws a `ConfigurationError`. The URLs
27
+ * default to production; UAT and production issue separate credentials.
28
28
  */
29
29
  export declare class KbzPayConfig {
30
- static readonly SANDBOX_API_URL = "http://api-uat.kbzpay.com/payment/gateway/uat";
31
30
  static readonly PRODUCTION_API_URL = "https://api.kbzpay.com/payment/gateway";
32
- static readonly SANDBOX_PWA_URL = "https://static.kbzpay.com/pgw/uat/pwa/#/";
33
31
  static readonly PRODUCTION_PWA_URL = "https://wap.kbzpay.com/pgw/pwa/#/";
34
32
  readonly appId: string;
35
33
  readonly appKey: string;
36
34
  readonly merchantCode: string;
37
- readonly sandbox: boolean;
35
+ /** Seconds before the default HTTP client gives up on a request. */
36
+ readonly timeoutSeconds: number;
38
37
  /** The API base URL in use. */
39
38
  readonly apiUrl: string;
40
39
  /** The PWA checkout URL in use, always ending in `/`. */
41
40
  readonly pwaUrl: string;
42
41
  constructor(options: KbzPayConfigOptions);
43
42
  /**
44
- * Reads `KBZ_PAY_APP_ID`, `KBZ_PAY_APP_KEY`, `KBZ_PAY_MERCHANT_CODE`, `KBZ_PAY_SANDBOX`,
45
- * `KBZ_PAY_BASE_URL` and `KBZ_PAY_PWA_BASE_REDIRECT_URL`.
43
+ * Reads `KBZ_PAY_APP_ID`, `KBZ_PAY_APP_KEY`, `KBZ_PAY_MERCHANT_CODE`,
44
+ * `MYANMAR_PAYMENTS_HTTP_TIMEOUT`, `KBZ_PAY_BASE_URL` and `KBZ_PAY_PWA_BASE_REDIRECT_URL`.
46
45
  */
47
46
  static fromEnv(env?: EnvSource): KbzPayConfig;
48
47
  }
@@ -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, 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 { toPlainObject } from '../core/json.js';
@@ -11,17 +11,17 @@ import { toAmount, Validator } from '../core/validate.js';
11
11
  import { get, object, optional, trimmed } from '../core/values.js';
12
12
  import { KbzPaySigner } from './signer.js';
13
13
  /**
14
- * KBZ Pay credentials and endpoints. A missing credential throws a `ConfigurationError`.
14
+ * KBZ Pay credentials and endpoints. A missing setting throws a `ConfigurationError`. The URLs
15
+ * default to production; UAT and production issue separate credentials.
15
16
  */
16
17
  export class KbzPayConfig {
17
- static SANDBOX_API_URL = 'http://api-uat.kbzpay.com/payment/gateway/uat';
18
18
  static PRODUCTION_API_URL = 'https://api.kbzpay.com/payment/gateway';
19
- static SANDBOX_PWA_URL = 'https://static.kbzpay.com/pgw/uat/pwa/#/';
20
19
  static PRODUCTION_PWA_URL = 'https://wap.kbzpay.com/pgw/pwa/#/';
21
20
  appId;
22
21
  appKey;
23
22
  merchantCode;
24
- sandbox;
23
+ /** Seconds before the default HTTP client gives up on a request. */
24
+ timeoutSeconds;
25
25
  /** The API base URL in use. */
26
26
  apiUrl;
27
27
  /** The PWA checkout URL in use, always ending in `/`. */
@@ -30,22 +30,20 @@ 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.sandbox = parseSandbox(options.sandbox);
34
- this.apiUrl = trimUrl(optionalSetting(options.apiUrl) ??
35
- (this.sandbox ? KbzPayConfig.SANDBOX_API_URL : KbzPayConfig.PRODUCTION_API_URL));
36
- this.pwaUrl = `${trimUrl(optionalSetting(options.pwaUrl) ??
37
- (this.sandbox ? KbzPayConfig.SANDBOX_PWA_URL : KbzPayConfig.PRODUCTION_PWA_URL))}/`;
33
+ this.timeoutSeconds = requireSeconds('kbz_pay', 'timeout_in_seconds', options.timeoutSeconds);
34
+ this.apiUrl = trimUrl(optionalSetting(options.apiUrl) ?? KbzPayConfig.PRODUCTION_API_URL);
35
+ this.pwaUrl = `${trimUrl(optionalSetting(options.pwaUrl) ?? KbzPayConfig.PRODUCTION_PWA_URL)}/`;
38
36
  }
39
37
  /**
40
- * Reads `KBZ_PAY_APP_ID`, `KBZ_PAY_APP_KEY`, `KBZ_PAY_MERCHANT_CODE`, `KBZ_PAY_SANDBOX`,
41
- * `KBZ_PAY_BASE_URL` and `KBZ_PAY_PWA_BASE_REDIRECT_URL`.
38
+ * Reads `KBZ_PAY_APP_ID`, `KBZ_PAY_APP_KEY`, `KBZ_PAY_MERCHANT_CODE`,
39
+ * `MYANMAR_PAYMENTS_HTTP_TIMEOUT`, `KBZ_PAY_BASE_URL` and `KBZ_PAY_PWA_BASE_REDIRECT_URL`.
42
40
  */
43
41
  static fromEnv(env = defaultEnv()) {
44
42
  return new KbzPayConfig({
45
43
  appId: envFirst(env, 'KBZ_PAY_APP_ID'),
46
44
  appKey: envFirst(env, 'KBZ_PAY_APP_KEY'),
47
45
  merchantCode: envFirst(env, 'KBZ_PAY_MERCHANT_CODE'),
48
- sandbox: envSandbox(env, 'KBZ_PAY_SANDBOX'),
46
+ timeoutSeconds: envFirst(env, HTTP_TIMEOUT_VARIABLE),
49
47
  apiUrl: envFirst(env, 'KBZ_PAY_BASE_URL'),
50
48
  pwaUrl: envFirst(env, 'KBZ_PAY_PWA_BASE_REDIRECT_URL'),
51
49
  });
@@ -73,7 +71,7 @@ export class KbzPay {
73
71
  constructor(config, options = {}) {
74
72
  this.config = config instanceof KbzPayConfig ? config : new KbzPayConfig(config);
75
73
  this.signer = new KbzPaySigner(this.config.appKey);
76
- this.transport = new Transport(httpClientFrom(options));
74
+ this.transport = new Transport(httpClientFrom(options, this.config.timeoutSeconds));
77
75
  }
78
76
  /** A gateway configured from the `KBZ_PAY_*` environment variables. */
79
77
  static fromEnv(env = 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;
@@ -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, envInt, 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, toPlainObject } from '../core/json.js';
@@ -10,20 +10,19 @@ import { resolveStatus } from '../core/status.js';
10
10
  import { toAmount, Validator } from '../core/validate.js';
11
11
  import { get, isNested, optional, scalarString, trimmed } from '../core/values.js';
12
12
  /**
13
- * Wave Money credentials and endpoints. A missing credential throws a `ConfigurationError`.
13
+ * Wave Money credentials and endpoints. A missing setting throws a `ConfigurationError`. The URLs
14
+ * default to production.
14
15
  */
15
16
  export class WaveMoneyConfig {
16
- static SANDBOX_URL = 'https://preprodpayments.wavemoney.io:8107';
17
17
  static PRODUCTION_URL = 'https://payments.wavemoney.io';
18
- static SANDBOX_AUTHENTICATE_URL = 'https://preprodpayments.wavemoney.io';
19
18
  static PRODUCTION_AUTHENTICATE_URL = 'https://payments.wavemoney.io';
20
- static DEFAULT_TIME_TO_LIVE_SECONDS = 300;
21
19
  merchantId;
22
20
  secretKey;
23
21
  merchantName;
24
22
  /** Seconds the customer has to pay. */
25
23
  timeToLiveSeconds;
26
- sandbox;
24
+ /** Seconds before the default HTTP client gives up on a request. */
25
+ timeoutSeconds;
27
26
  /** The API base URL in use. */
28
27
  baseUrl;
29
28
  /** The host the customer is redirected to. */
@@ -32,31 +31,23 @@ export class WaveMoneyConfig {
32
31
  this.merchantId = requireSetting('wave_money', 'merchant_id', options.merchantId);
33
32
  this.secretKey = requireSetting('wave_money', 'secret_key', options.secretKey);
34
33
  this.merchantName = requireSetting('wave_money', 'merchant_name', options.merchantName);
35
- const ttl = options.timeToLiveSeconds;
36
- this.timeToLiveSeconds =
37
- ttl !== undefined && Number.isInteger(ttl) && ttl > 0
38
- ? ttl
39
- : WaveMoneyConfig.DEFAULT_TIME_TO_LIVE_SECONDS;
40
- this.sandbox = parseSandbox(options.sandbox);
41
- this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ??
42
- (this.sandbox ? WaveMoneyConfig.SANDBOX_URL : WaveMoneyConfig.PRODUCTION_URL));
43
- this.authenticateUrl = trimUrl(optionalSetting(options.authenticateUrl) ??
44
- (this.sandbox
45
- ? WaveMoneyConfig.SANDBOX_AUTHENTICATE_URL
46
- : WaveMoneyConfig.PRODUCTION_AUTHENTICATE_URL));
34
+ this.timeToLiveSeconds = requireSeconds('wave_money', 'time_to_live_in_seconds', options.timeToLiveSeconds);
35
+ this.timeoutSeconds = requireSeconds('wave_money', 'timeout_in_seconds', options.timeoutSeconds);
36
+ this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ?? WaveMoneyConfig.PRODUCTION_URL);
37
+ this.authenticateUrl = trimUrl(optionalSetting(options.authenticateUrl) ?? WaveMoneyConfig.PRODUCTION_AUTHENTICATE_URL);
47
38
  }
48
39
  /**
49
- * Reads `WAVE_MONEY_MERCHANT_ID`, `WAVE_MONEY_SECRET_KEY`, `WAVE_MONEY_MERCHANT_NAME` (falling back
50
- * to `APP_NAME`), `WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS`, `WAVE_MONEY_SANDBOX`, `WAVE_MONEY_BASE_URL`
40
+ * Reads `WAVE_MONEY_MERCHANT_ID`, `WAVE_MONEY_SECRET_KEY`, `WAVE_MONEY_MERCHANT_NAME`,
41
+ * `WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT`, `WAVE_MONEY_BASE_URL`
51
42
  * and `WAVE_MONEY_AUTHENTICATE_URL`.
52
43
  */
53
44
  static fromEnv(env = defaultEnv()) {
54
45
  return new WaveMoneyConfig({
55
46
  merchantId: envFirst(env, 'WAVE_MONEY_MERCHANT_ID'),
56
47
  secretKey: envFirst(env, 'WAVE_MONEY_SECRET_KEY'),
57
- merchantName: envFirst(env, 'WAVE_MONEY_MERCHANT_NAME', 'APP_NAME'),
58
- timeToLiveSeconds: envInt(env, 'WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS'),
59
- sandbox: envSandbox(env, 'WAVE_MONEY_SANDBOX'),
48
+ merchantName: envFirst(env, 'WAVE_MONEY_MERCHANT_NAME'),
49
+ timeToLiveSeconds: envFirst(env, 'WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS'),
50
+ timeoutSeconds: envFirst(env, HTTP_TIMEOUT_VARIABLE),
60
51
  baseUrl: envFirst(env, 'WAVE_MONEY_BASE_URL'),
61
52
  authenticateUrl: envFirst(env, 'WAVE_MONEY_AUTHENTICATE_URL'),
62
53
  });
@@ -94,7 +85,7 @@ export class WaveMoney {
94
85
  transport;
95
86
  constructor(config, options = {}) {
96
87
  this.config = config instanceof WaveMoneyConfig ? config : new WaveMoneyConfig(config);
97
- this.transport = new Transport(httpClientFrom(options));
88
+ this.transport = new Transport(httpClientFrom(options, this.config.timeoutSeconds));
98
89
  }
99
90
  /** A gateway configured from the `WAVE_MONEY_*` environment variables. */
100
91
  static fromEnv(env = 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
  }
@@ -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, envSandbox, parseSandbox, optionalSetting, requireSetting, trimUrl, } from '../core/env.js';
5
+ import { defaultEnv, envFirst, HTTP_TIMEOUT_VARIABLE, optionalSetting, requireSeconds, requireSetting, 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';
@@ -11,37 +11,36 @@ import { resolveStatus } from '../core/status.js';
11
11
  import { toAmount, Validator } from '../core/validate.js';
12
12
  import { get, isNested, optional, trimmed } from '../core/values.js';
13
13
  /**
14
- * Yoma MMQR credentials and endpoints. A missing credential throws a `ConfigurationError`.
14
+ * Yoma MMQR credentials and endpoints. A missing setting throws a `ConfigurationError`. The URL
15
+ * defaults to production.
15
16
  */
16
17
  export class YomaMmqrConfig {
17
- static SANDBOX_URL = 'https://devapi.yomabank.net';
18
18
  static PRODUCTION_URL = 'https://paymenthubapi.yomabank.com';
19
- static DEFAULT_API_VERSION = 'v1rc';
20
19
  merchantId;
21
20
  clientId;
22
21
  clientSecret;
23
22
  webhookHashKey;
24
23
  webhookSecret;
25
- sandbox;
24
+ /** The `{version}` segment of the API paths. */
25
+ apiVersion;
26
+ /** Seconds before the default HTTP client gives up on a request. */
27
+ timeoutSeconds;
26
28
  /** The base URL in use. */
27
29
  baseUrl;
28
- /** The API version in use. */
29
- apiVersion;
30
30
  constructor(options) {
31
31
  this.merchantId = requireSetting('yoma_mmqr', 'merchant_id', options.merchantId);
32
32
  this.clientId = requireSetting('yoma_mmqr', 'client_id', options.clientId);
33
33
  this.clientSecret = requireSetting('yoma_mmqr', 'client_secret', options.clientSecret);
34
34
  this.webhookHashKey = requireSetting('yoma_mmqr', 'webhook_hashkey', options.webhookHashKey);
35
+ this.apiVersion = requireSetting('yoma_mmqr', 'api_version', options.apiVersion);
36
+ this.timeoutSeconds = requireSeconds('yoma_mmqr', 'timeout_in_seconds', options.timeoutSeconds);
35
37
  this.webhookSecret = optionalSetting(options.webhookSecret);
36
- this.sandbox = parseSandbox(options.sandbox);
37
- this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ??
38
- (this.sandbox ? YomaMmqrConfig.SANDBOX_URL : YomaMmqrConfig.PRODUCTION_URL));
39
- this.apiVersion = optionalSetting(options.apiVersion) ?? YomaMmqrConfig.DEFAULT_API_VERSION;
38
+ this.baseUrl = trimUrl(optionalSetting(options.baseUrl) ?? YomaMmqrConfig.PRODUCTION_URL);
40
39
  }
41
40
  /**
42
41
  * Reads `YOMA_MMQR_MERCHANT_ID`, `YOMA_MMQR_CLIENT_ID`, `YOMA_MMQR_CLIENT_SECRET`,
43
- * `YOMA_MMQR_WEBHOOK_HASHKEY`, `YOMA_MMQR_WEBHOOK_SECRET`, `YOMA_MMQR_SANDBOX`,
44
- * `YOMA_MMQR_BASE_URL` and `YOMA_MMQR_API_VERSION`.
42
+ * `YOMA_MMQR_WEBHOOK_HASHKEY`, `YOMA_MMQR_API_VERSION`, `MYANMAR_PAYMENTS_HTTP_TIMEOUT`,
43
+ * `YOMA_MMQR_WEBHOOK_SECRET` and `YOMA_MMQR_BASE_URL`.
45
44
  */
46
45
  static fromEnv(env = defaultEnv()) {
47
46
  return new YomaMmqrConfig({
@@ -49,10 +48,10 @@ export class YomaMmqrConfig {
49
48
  clientId: envFirst(env, 'YOMA_MMQR_CLIENT_ID'),
50
49
  clientSecret: envFirst(env, 'YOMA_MMQR_CLIENT_SECRET'),
51
50
  webhookHashKey: envFirst(env, 'YOMA_MMQR_WEBHOOK_HASHKEY'),
51
+ apiVersion: envFirst(env, 'YOMA_MMQR_API_VERSION'),
52
+ timeoutSeconds: envFirst(env, HTTP_TIMEOUT_VARIABLE),
52
53
  webhookSecret: envFirst(env, 'YOMA_MMQR_WEBHOOK_SECRET'),
53
- sandbox: envSandbox(env, 'YOMA_MMQR_SANDBOX'),
54
54
  baseUrl: envFirst(env, 'YOMA_MMQR_BASE_URL'),
55
- apiVersion: envFirst(env, 'YOMA_MMQR_API_VERSION'),
56
55
  });
57
56
  }
58
57
  }
@@ -76,7 +75,7 @@ export class YomaMmqr {
76
75
  pendingToken;
77
76
  constructor(config, options = {}) {
78
77
  this.config = config instanceof YomaMmqrConfig ? config : new YomaMmqrConfig(config);
79
- this.transport = new Transport(httpClientFrom(options));
78
+ this.transport = new Transport(httpClientFrom(options, this.config.timeoutSeconds));
80
79
  this.cache = options.tokenCache ?? new MemoryTokenCache();
81
80
  }
82
81
  /** A gateway configured from the `YOMA_MMQR_*` environment variables. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laranex/myanmar-payments",
3
- "version": "4.0.0-dev.4",
3
+ "version": "4.0.0-dev.5",
4
4
  "description": "Node.js SDK for Myanmar payment gateways: KBZ Pay, Wave Money, AYA Pay, Yoma MMQR and CyberSource. Typed TypeScript API, ESM and CommonJS, 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_*` (the same variables as the PHP, Go and Python SDKs). `sandbox` defaults to `true`; set `*_SANDBOX=false` (or `sandbox: false`) in production.
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`).
27
27
 
28
28
  ```ts
29
29
  import { MyanmarPayments } from '@laranex/myanmar-payments';
@@ -32,10 +32,10 @@ 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 }))`, `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; a string `sandbox` such as `'false'` is read like the variable.
37
- - Options (second argument): `{ httpClient, fetch, timeoutMs }` (default 30 seconds). Yoma and the facade also take `tokenCache` (any `TokenCache`, default `MemoryTokenCache`; back it with Redis when you run several processes).
38
- - A missing credential throws `ConfigurationError` (`gateway`, `key`).
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'`.
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
+ - A missing setting throws `ConfigurationError` (`gateway`, `key`); a time setting that is not a whole number greater than 0 throws it too.
39
39
 
40
40
  ## Use
41
41
 
@@ -65,6 +65,8 @@ res.writeHead(302, { Location: payment.url }).end();
65
65
 
66
66
  AYA needs a channel: `await aya.services()` lists `AyaPayService` entries (`key`, `supports(method)`), then `aya.initiate({ orderId: 'ORDER123', amount: 1000, channel: 'kbz_pay', method: AyaPayMethod.Qr })`. Every network method takes `{ signal }` as its last argument.
67
67
 
68
+ CyberSource has no payment defaults: pass `currency` (e.g. `'MMK'`), `transactionType` (e.g. `CyberSourceTransactionType.Sale`) and `locale` (e.g. `'en-us'`) on every `cyberSource.initiate(data)`.
69
+
68
70
  ### Handle the callback
69
71
 
70
72
  Build a `CallbackRequest` from the raw request, verify it, then reply: