Skip to content

Configuration ​

Environment Variables ​

Add the keys of the gateways you use. Every setting of those gateways is required and has no default, except the HTTP timeout (MYANMAR_PAYMENTS_HTTP_TIMEOUT, 30 seconds when unset or blank). That includes the URLs, the time to live (KBZ_PAY_TIME_TO_LIVE_IN_MINUTES and WAVE_PAY_TIME_TO_LIVE_IN_SECONDS) and Yoma's webhook secret. A gateway is configured the first time you call it, and a missing or blank setting throws a ConfigurationError naming it, e.g. The kbz_pay configuration is missing [app_key].

env
# Every gateway that calls an API (all but CyberSource)
MYANMAR_PAYMENTS_HTTP_TIMEOUT=30      # optional, defaults to 30
# AYA Pay and CyberSource, while the form route is enabled
MYANMAR_PAYMENTS_FORM_TTL_MINUTES=30
# optional, encrypts form links, falls back to APP_KEY
MYANMAR_PAYMENTS_FORM_KEY=
# optional, scheme and host of form links
APP_URL=

# KBZ Pay
KBZ_PAY_APP_ID=
KBZ_PAY_APP_KEY=
KBZ_PAY_MERCHANT_CODE=
KBZ_PAY_BASE_URL=
KBZ_PAY_PWA_BASE_REDIRECT_URL=
KBZ_PAY_TIME_TO_LIVE_IN_MINUTES=15    # 1 to 120

# Wave Pay
WAVE_PAY_MERCHANT_ID=
WAVE_PAY_SECRET_KEY=
WAVE_PAY_MERCHANT_NAME=
WAVE_PAY_BASE_URL=
WAVE_PAY_BASE_REDIRECT_URL=
WAVE_PAY_TIME_TO_LIVE_IN_SECONDS=900   # greater than 0

# Wave Pay Mini App
WAVE_PAY_MINI_APP_CLIENT_ID=
WAVE_PAY_MINI_APP_CLIENT_SECRET=
WAVE_PAY_MINI_APP_APP_ID=
WAVE_PAY_MINI_APP_SECRET_KEY=
WAVE_PAY_MINI_APP_BASE_URL=

# AYA Payment Gateway
AYA_PAY_APP_KEY=
AYA_PAY_APP_SECRET=
AYA_PAY_BASE_URL=

# Yoma MMQR
YOMA_MMQR_MERCHANT_ID=
YOMA_MMQR_CLIENT_ID=
YOMA_MMQR_CLIENT_SECRET=
YOMA_MMQR_WEBHOOK_HASHKEY=
YOMA_MMQR_API_VERSION=v1rc
YOMA_MMQR_WEBHOOK_SECRET=             # every callback carries it in X-Webhook-Secret
YOMA_MMQR_BASE_URL=

# CyberSource Secure Acceptance
CYBER_SOURCE_PROFILE_ID=
CYBER_SOURCE_ACCESS_KEY=
CYBER_SOURCE_SECRET_KEY=
CYBER_SOURCE_BASE_URL=

Settings ​

VariableModule optionRequiredDescription
MYANMAR_PAYMENTS_HTTP_TIMEOUTtimeoutSeconds of kbzPay, wavePay, wavePayMiniApp, ayaPay and yomaMmqrNoSeconds before a gateway call gives up. Read by every gateway except CyberSource; defaults to 30 when unset or blank, and an invalid one is reported as timeout_in_seconds
MYANMAR_PAYMENTS_FORM_TTL_MINUTESformLink.ttlMinutesYesMinutes an auto-submit form link stays valid. Needed by AYA Pay and CyberSource while the form route is enabled
MYANMAR_PAYMENTS_FORM_KEYformLink.secretNoEncrypts form links; falls back to APP_KEY. At least 32 bytes, e.g. base64: followed by 32 random bytes in base64
APP_URLformLink.baseUrlNoThe scheme and host form links start with (http://localhost when unset)
KBZ_PAY_APP_IDkbzPay.appIdYesappid issued by KBZ
KBZ_PAY_APP_KEYkbzPay.appKeyYesSecret key used to sign requests
KBZ_PAY_MERCHANT_CODEkbzPay.merchantCodeYesmerch_code issued by KBZ
KBZ_PAY_BASE_URLkbzPay.apiUrlYesThe API base URL, e.g. KbzPayConfig.PRODUCTION_API_URL
KBZ_PAY_PWA_BASE_REDIRECT_URLkbzPay.pwaUrlYesThe PWA checkout URL, e.g. KbzPayConfig.PRODUCTION_PWA_URL
KBZ_PAY_TIME_TO_LIVE_IN_MINUTESkbzPay.timeToLiveMinutesYesMinutes the customer has to pay each order, 1 to 120. A payment can override it with KbzPayPaymentData's timeToLiveMinutes
WAVE_PAY_MERCHANT_IDwavePay.merchantIdYesMerchant ID issued by Wave
WAVE_PAY_SECRET_KEYwavePay.secretKeyYesHash secret key issued by Wave
WAVE_PAY_MERCHANT_NAMEwavePay.merchantNameYesShown on Wave's payment page. A payment can override it with WavePayPaymentData's merchantName
WAVE_PAY_BASE_URLwavePay.baseUrlYesThe API base URL, e.g. WavePayConfig.PRODUCTION_URL. Payments are requested at its /payment
WAVE_PAY_BASE_REDIRECT_URLwavePay.baseRedirectUrlYesThe host the customer is sent to, e.g. WavePayConfig.PRODUCTION_URL. The customer approves the payment at its /authenticate
WAVE_PAY_TIME_TO_LIVE_IN_SECONDSwavePay.timeToLiveSecondsYesSeconds the customer has to pay, greater than 0. A payment can override it with WavePayPaymentData's timeToLiveSeconds
WAVE_PAY_MINI_APP_CLIENT_IDwavePayMiniApp.clientIdYesClient ID issued by Wave, for the token endpoint
WAVE_PAY_MINI_APP_CLIENT_SECRETwavePayMiniApp.clientSecretYesClient secret issued by Wave, for the token endpoint
WAVE_PAY_MINI_APP_APP_IDwavePayMiniApp.miniAppIdYesYour mini app ID (miniAppID)
WAVE_PAY_MINI_APP_SECRET_KEYwavePayMiniApp.secretKeyYesHash secret key for payment and callback hashes
WAVE_PAY_MINI_APP_BASE_URLwavePayMiniApp.baseUrlYesThe API base URL, e.g. WavePayMiniAppConfig.PRODUCTION_URL. Tokens are requested at its /auth/v1/external-utility/token
AYA_PAY_APP_KEYayaPay.appKeyYesPublic application key
AYA_PAY_APP_SECRETayaPay.appSecretYesSecret used for checksums
AYA_PAY_BASE_URLayaPay.baseUrlYesThe gateway base URL, e.g. AyaPayConfig.PRODUCTION_URL
YOMA_MMQR_MERCHANT_IDyomaMmqr.merchantIdYesMerchant ID issued by Yoma
YOMA_MMQR_CLIENT_IDyomaMmqr.clientIdYesOAuth client ID
YOMA_MMQR_CLIENT_SECRETyomaMmqr.clientSecretYesOAuth client secret
YOMA_MMQR_WEBHOOK_HASHKEYyomaMmqr.webhookHashKeyYesHash key issued by Yoma for verifying callbacks
YOMA_MMQR_API_VERSIONyomaMmqr.apiVersionYesThe {version} segment of Yoma's API paths, e.g. v1rc
YOMA_MMQR_WEBHOOK_SECRETyomaMmqr.webhookSecretYesEvery callback must carry it in the X-Webhook-Secret header, compared in constant time
YOMA_MMQR_BASE_URLyomaMmqr.baseUrlYesThe API base URL, e.g. YomaMmqrConfig.PRODUCTION_URL
CYBER_SOURCE_PROFILE_IDcyberSource.profileIdYesSecure Acceptance profile ID
CYBER_SOURCE_ACCESS_KEYcyberSource.accessKeyYesProfile access key
CYBER_SOURCE_SECRET_KEYcyberSource.secretKeyYesProfile secret key used to sign fields
CYBER_SOURCE_BASE_URLcyberSource.baseUrlYesThe Secure Acceptance base URL, e.g. CyberSourceConfig.PRODUCTION_URL

Endpoints ​

Every gateway URL is a required setting with no default. There is no switch between test and production: set production's URLs (see Production Endpoints) or the gateway's UAT ones (see UAT Endpoints), or a proxy's.

Production Endpoints ​

env
KBZ_PAY_BASE_URL=https://api.kbzpay.com/payment/gateway
KBZ_PAY_PWA_BASE_REDIRECT_URL="https://wap.kbzpay.com/pgw/pwa/#/"
WAVE_PAY_BASE_URL=https://payments.wavemoney.io
WAVE_PAY_BASE_REDIRECT_URL=https://payments.wavemoney.io
WAVE_PAY_MINI_APP_BASE_URL=https://api.wavemoney.io:8100
AYA_PAY_BASE_URL=https://pgw.ayainnovation.com
YOMA_MMQR_BASE_URL=https://paymenthubapi.yomabank.com
CYBER_SOURCE_BASE_URL=https://secureacceptance.cybersource.com

UAT Endpoints ​

env
KBZ_PAY_BASE_URL=http://api-uat.kbzpay.com/payment/gateway/uat
KBZ_PAY_PWA_BASE_REDIRECT_URL="https://static.kbzpay.com/pgw/uat/pwa/#/"
WAVE_PAY_BASE_URL=https://preprodpayments.wavemoney.io:8107
WAVE_PAY_BASE_REDIRECT_URL=https://preprodpayments.wavemoney.io:8107
WAVE_PAY_MINI_APP_BASE_URL=https://preprodnewapi.wavemoney.io
AYA_PAY_BASE_URL=https://uat-pgw.ayainnovation.com
YOMA_MMQR_BASE_URL=https://devapi.yomabank.net
CYBER_SOURCE_BASE_URL=https://testsecureacceptance.cybersource.com

Module Options ​

forRoot ​

ts
import { KbzPayConfig } from '@laranex/myanmar-payments';
import { MyanmarPaymentsModule } from '@laranex/nestjs-myanmar-payments';

MyanmarPaymentsModule.forRoot(); // process.env
MyanmarPaymentsModule.forRoot({
  env: {
    KBZ_PAY_APP_ID: '...',
    KBZ_PAY_APP_KEY: '...',
    KBZ_PAY_MERCHANT_CODE: '...',
    KBZ_PAY_BASE_URL: 'https://api.kbzpay.com/payment/gateway',
    KBZ_PAY_PWA_BASE_REDIRECT_URL: 'https://wap.kbzpay.com/pgw/pwa/#/',
    KBZ_PAY_TIME_TO_LIVE_IN_MINUTES: '15',
  },
});
MyanmarPaymentsModule.forRoot({
  isGlobal: true,
  kbzPay: {
    appId: '...',
    appKey: '...',
    merchantCode: '...',
    apiUrl: KbzPayConfig.PRODUCTION_API_URL,
    pwaUrl: KbzPayConfig.PRODUCTION_PWA_URL,
    timeToLiveMinutes: 15,
  },
});

forRootAsync ​

With @nestjs/config, hand the ConfigService to env; the package reads each variable through config.get(), so values from .env files, load factories and validation all apply:

ts
import { MyanmarPaymentsModule } from '@laranex/nestjs-myanmar-payments';
import { ConfigModule, ConfigService } from '@nestjs/config';

MyanmarPaymentsModule.forRootAsync({
  isGlobal: true,
  imports: [ConfigModule],
  inject: [ConfigService],
  useFactory: (config: ConfigService) => ({ env: config }),
});

useClass and useExisting take a class implementing MyanmarPaymentsOptionsFactory:

ts
import {
  MyanmarPaymentsModule,
  type MyanmarPaymentsModuleOptions,
  type MyanmarPaymentsOptionsFactory,
} from '@laranex/nestjs-myanmar-payments';
import { Injectable } from '@nestjs/common';

@Injectable()
class PaymentsConfig implements MyanmarPaymentsOptionsFactory {
  createMyanmarPaymentsOptions(): MyanmarPaymentsModuleOptions {
    return { env: process.env, formLink: { ttlMinutes: 15 } };
  }
}

MyanmarPaymentsModule.forRootAsync({ useClass: PaymentsConfig });

Options ​

OptionMeaning
envWhere variables are read: process.env (default), a record, or anything with get(key) such as ConfigService
kbzPay, wavePay, wavePayMiniApp, ayaPay, yomaMmqr, cyberSourceA gateway's settings ({ appId, appKey, ... }), merged with the environment per setting: a setting given here wins, every other one (including timeoutSeconds, from MYANMAR_PAYMENTS_HTTP_TIMEOUT) is read from its variable, so kbzPay: { appId } still reads KBZ_PAY_APP_KEY and the rest. An SDK config instance (new KbzPayConfig(...)) is used as it is. See the SDK's config options
fetchThe fetch gateways call, e.g. a fake one in tests
httpClientAn SDK HttpClient; takes precedence over fetch and keeps its own timeout (the config's timeoutSeconds only applies to the default client)
tokenCacheAn SDK TokenCache for the Yoma MMQR and Wave Pay Mini App access tokens
useCacheManagerUse @nestjs/cache-manager for the tokens when it is available (default true)
formLinksecret, ttlMinutes and baseUrl of the auto-submit form links

Extras, given to forRoot() and forRootAsync() directly (never through a factory):

ExtraMeaning
isGlobalRegister the module globally (default false)
formRoute{ enabled, path, guards, nonce } of the auto-submit form route (default { enabled: true, path: 'myanmar-payments/form' })

The options object is available under the MYANMAR_PAYMENTS_OPTIONS token.

HTTP Client ​

Gateway calls go through the SDK's fetch client with each gateway's timeoutSeconds: the option, else MYANMAR_PAYMENTS_HTTP_TIMEOUT (also for gateways given in the options), else 30 seconds. Pass fetch to replace the function it calls, for example a fake one in tests, or httpClient to send requests yourself (proxies, tracing, retries); see Testing. Redirects are never followed: a 3xx answer is handled like any other non-2xx one. When a gateway can't be reached, the call throws ApiError with httpStatus 0. Every network method takes an optional last argument { signal } to abort the call, e.g. kbzPay().status(orderId, { signal: AbortSignal.timeout(5000) }).

Auto-submit Form Route ​

AYA Pay and CyberSource need the customer's browser to POST a signed form. The module registers a GET myanmar-payments/form route that renders that form and submits it, and MyanmarPaymentsService.autoSubmitUrl(form) returns an encrypted link to it. Links expire after formLink.ttlMinutes; an invalid or expired link answers 410 Gone. The page is sent with Cache-Control: no-store and Referrer-Policy: strict-origin, so the gateway only sees your origin, never the encrypted link.

SettingMeaning
formRoute.enabledRegister the route (default true). When false, autoSubmitUrl() throws The form route is disabled (formRoute.enabled is false).
formRoute.pathThe route path (default myanmar-payments/form). The app's global prefix applies
formRoute.guardsGuards for the route, classes or instances, e.g. a rate-limiting ThrottlerGuard. Don't add authentication: the customer may be redirected from a gateway or another device
formRoute.nonce(request, response) => string | undefined returning the Content-Security-Policy nonce for the page's inline script. Defaults to helmet's nonce: res.locals.cspNonce on Express, reply.cspNonce.script on Fastify (@fastify/helmet). Without a nonce the script has none
formLink.secretEncrypts the links (AES-256-GCM, key derived with HKDF-SHA256). Defaults to MYANMAR_PAYMENTS_FORM_KEY, then APP_KEY; a base64: prefix is decoded first. Must be at least 32 bytes after decoding: a shorter one makes autoSubmitUrl() throw a ConfigurationError naming the setting it came from, e.g. The myanmar_payments configuration [MYANMAR_PAYMENTS_FORM_KEY] must be at least 32 bytes, e.g. base64: followed by 32 random bytes in base64.
formLink.ttlMinutesMinutes a link stays valid. Defaults to MYANMAR_PAYMENTS_FORM_TTL_MINUTES; required, no default. Without it autoSubmitUrl() throws The form_route configuration is missing [ttl_minutes]., and the invalid-value message for a value that is not a whole number greater than 0
formLink.baseUrlThe scheme and host links start with. Defaults to APP_URL, then http://localhost, so links are always absolute

ayaPay().initiate() and cyberSource().hostedCheckout() never need the route or the TTL: with the route disabled or the TTL missing they still return the FormPayment, and only autoSubmitUrl() throws. Set formRoute.enabled to false to drop the route and build the form yourself, see Form Payments.

Cache ​

Yoma MMQR and Wave Pay Mini App access tokens are reused until they expire. When @nestjs/cache-manager's CacheModule is registered globally, or passed in forRootAsync's imports, they are kept in that cache (CacheManagerTokenCache); otherwise each process keeps its own token in memory. Use a shared store (Redis, for example) when you run more than one server.

ts
import { MyanmarPaymentsModule } from '@laranex/nestjs-myanmar-payments';
import { CacheModule } from '@nestjs/cache-manager';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    CacheModule.register({ isGlobal: true }),
    MyanmarPaymentsModule.forRoot(),
  ],
})
export class AppModule {}

Pass useCacheManager: false to keep tokens in memory anyway, or tokenCache to use your own TokenCache.