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].
# 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
| Variable | Module option | Required | Description |
|---|---|---|---|
MYANMAR_PAYMENTS_HTTP_TIMEOUT | timeoutSeconds of kbzPay, wavePay, wavePayMiniApp, ayaPay and yomaMmqr | No | Seconds 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_MINUTES | formLink.ttlMinutes | Yes | Minutes an auto-submit form link stays valid. Needed by AYA Pay and CyberSource while the form route is enabled |
MYANMAR_PAYMENTS_FORM_KEY | formLink.secret | No | Encrypts form links; falls back to APP_KEY. At least 32 bytes, e.g. base64: followed by 32 random bytes in base64 |
APP_URL | formLink.baseUrl | No | The scheme and host form links start with (http://localhost when unset) |
KBZ_PAY_APP_ID | kbzPay.appId | Yes | appid issued by KBZ |
KBZ_PAY_APP_KEY | kbzPay.appKey | Yes | Secret key used to sign requests |
KBZ_PAY_MERCHANT_CODE | kbzPay.merchantCode | Yes | merch_code issued by KBZ |
KBZ_PAY_BASE_URL | kbzPay.apiUrl | Yes | The API base URL, e.g. KbzPayConfig.PRODUCTION_API_URL |
KBZ_PAY_PWA_BASE_REDIRECT_URL | kbzPay.pwaUrl | Yes | The PWA checkout URL, e.g. KbzPayConfig.PRODUCTION_PWA_URL |
KBZ_PAY_TIME_TO_LIVE_IN_MINUTES | kbzPay.timeToLiveMinutes | Yes | Minutes the customer has to pay each order, 1 to 120. A payment can override it with KbzPayPaymentData's timeToLiveMinutes |
WAVE_PAY_MERCHANT_ID | wavePay.merchantId | Yes | Merchant ID issued by Wave |
WAVE_PAY_SECRET_KEY | wavePay.secretKey | Yes | Hash secret key issued by Wave |
WAVE_PAY_MERCHANT_NAME | wavePay.merchantName | Yes | Shown on Wave's payment page. A payment can override it with WavePayPaymentData's merchantName |
WAVE_PAY_BASE_URL | wavePay.baseUrl | Yes | The API base URL, e.g. WavePayConfig.PRODUCTION_URL. Payments are requested at its /payment |
WAVE_PAY_BASE_REDIRECT_URL | wavePay.baseRedirectUrl | Yes | The 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_SECONDS | wavePay.timeToLiveSeconds | Yes | Seconds the customer has to pay, greater than 0. A payment can override it with WavePayPaymentData's timeToLiveSeconds |
WAVE_PAY_MINI_APP_CLIENT_ID | wavePayMiniApp.clientId | Yes | Client ID issued by Wave, for the token endpoint |
WAVE_PAY_MINI_APP_CLIENT_SECRET | wavePayMiniApp.clientSecret | Yes | Client secret issued by Wave, for the token endpoint |
WAVE_PAY_MINI_APP_APP_ID | wavePayMiniApp.miniAppId | Yes | Your mini app ID (miniAppID) |
WAVE_PAY_MINI_APP_SECRET_KEY | wavePayMiniApp.secretKey | Yes | Hash secret key for payment and callback hashes |
WAVE_PAY_MINI_APP_BASE_URL | wavePayMiniApp.baseUrl | Yes | The API base URL, e.g. WavePayMiniAppConfig.PRODUCTION_URL. Tokens are requested at its /auth/v1/external-utility/token |
AYA_PAY_APP_KEY | ayaPay.appKey | Yes | Public application key |
AYA_PAY_APP_SECRET | ayaPay.appSecret | Yes | Secret used for checksums |
AYA_PAY_BASE_URL | ayaPay.baseUrl | Yes | The gateway base URL, e.g. AyaPayConfig.PRODUCTION_URL |
YOMA_MMQR_MERCHANT_ID | yomaMmqr.merchantId | Yes | Merchant ID issued by Yoma |
YOMA_MMQR_CLIENT_ID | yomaMmqr.clientId | Yes | OAuth client ID |
YOMA_MMQR_CLIENT_SECRET | yomaMmqr.clientSecret | Yes | OAuth client secret |
YOMA_MMQR_WEBHOOK_HASHKEY | yomaMmqr.webhookHashKey | Yes | Hash key issued by Yoma for verifying callbacks |
YOMA_MMQR_API_VERSION | yomaMmqr.apiVersion | Yes | The {version} segment of Yoma's API paths, e.g. v1rc |
YOMA_MMQR_WEBHOOK_SECRET | yomaMmqr.webhookSecret | Yes | Every callback must carry it in the X-Webhook-Secret header, compared in constant time |
YOMA_MMQR_BASE_URL | yomaMmqr.baseUrl | Yes | The API base URL, e.g. YomaMmqrConfig.PRODUCTION_URL |
CYBER_SOURCE_PROFILE_ID | cyberSource.profileId | Yes | Secure Acceptance profile ID |
CYBER_SOURCE_ACCESS_KEY | cyberSource.accessKey | Yes | Profile access key |
CYBER_SOURCE_SECRET_KEY | cyberSource.secretKey | Yes | Profile secret key used to sign fields |
CYBER_SOURCE_BASE_URL | cyberSource.baseUrl | Yes | The 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
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.comUAT Endpoints
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.comModule Options
forRoot
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:
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:
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
| Option | Meaning |
|---|---|
env | Where variables are read: process.env (default), a record, or anything with get(key) such as ConfigService |
kbzPay, wavePay, wavePayMiniApp, ayaPay, yomaMmqr, cyberSource | A 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 |
fetch | The fetch gateways call, e.g. a fake one in tests |
httpClient | An SDK HttpClient; takes precedence over fetch and keeps its own timeout (the config's timeoutSeconds only applies to the default client) |
tokenCache | An SDK TokenCache for the Yoma MMQR and Wave Pay Mini App access tokens |
useCacheManager | Use @nestjs/cache-manager for the tokens when it is available (default true) |
formLink | secret, ttlMinutes and baseUrl of the auto-submit form links |
Extras, given to forRoot() and forRootAsync() directly (never through a factory):
| Extra | Meaning |
|---|---|
isGlobal | Register 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.
| Setting | Meaning |
|---|---|
formRoute.enabled | Register the route (default true). When false, autoSubmitUrl() throws The form route is disabled (formRoute.enabled is false). |
formRoute.path | The route path (default myanmar-payments/form). The app's global prefix applies |
formRoute.guards | Guards 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.secret | Encrypts 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.ttlMinutes | Minutes 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.baseUrl | The 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.
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.