@laranex/myanmar-payments 4.0.0-dev.7 → 4.0.0-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/dist/cjs/wave-money/wave-money.d.ts +10 -0
- package/dist/cjs/wave-money/wave-money.js +10 -3
- package/dist/esm/wave-money/wave-money.d.ts +10 -0
- package/dist/esm/wave-money/wave-money.js +10 -3
- package/package.json +1 -1
- package/skills/node-myanmar-payments/SKILL.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -31,3 +31,4 @@ Initial release. The version number matches the other Laranex Myanmar payments p
|
|
|
31
31
|
- Yoma MMQR caches its access token under `myanmar-payments.yoma-mmqr.token.<sha256 of base URL and client id>` (was `node-myanmar-payments.…`), the same key as the PHP, Go and Python SDKs, and reads `expires_in` from its leading digits.
|
|
32
32
|
- `Amount.equals()` compares by value, ignoring leading zeros too (`'01000'` equals `Amount.kyat(1000)`); text that is not plain digits with an optional fraction is never equal.
|
|
33
33
|
- `CallbackRequest.rawBody` holds the exact bytes received (a string body is encoded as UTF-8), next to `body` as text, like Python's `raw_body` and Go's `Body`.
|
|
34
|
+
- `WaveMoneyPaymentData` takes optional `merchantName` and `timeToLiveSeconds`, which override the configured `merchantName` and `timeToLiveSeconds` for one payment (request hash included); a blank `merchantName` or a `timeToLiveSeconds` that is not a whole number greater than 0 throws `InvalidPaymentDataError`, like the PHP SDK.
|
|
@@ -79,6 +79,16 @@ export interface WaveMoneyPaymentData {
|
|
|
79
79
|
* this.
|
|
80
80
|
*/
|
|
81
81
|
merchantReferenceId?: string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The business name shown on Wave's page for this payment. Defaults to the configured
|
|
84
|
+
* `merchantName` when unset.
|
|
85
|
+
*/
|
|
86
|
+
merchantName?: string | null | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* How long the customer has to pay this payment, in seconds: a whole number greater than 0.
|
|
89
|
+
* Defaults to the configured `timeToLiveSeconds` when unset.
|
|
90
|
+
*/
|
|
91
|
+
timeToLiveSeconds?: number | null | undefined;
|
|
82
92
|
}
|
|
83
93
|
/**
|
|
84
94
|
* Wave Money (WavePay payment gateway): redirect payments and callbacks. Wave has no status API,
|
|
@@ -127,7 +127,11 @@ class WaveMoney {
|
|
|
127
127
|
.url('returnUrl', data.returnUrl)
|
|
128
128
|
.required('description', data.description)
|
|
129
129
|
.when(items.length === 0, 'items', 'The items field must have at least one item.')
|
|
130
|
-
.string('merchantReferenceId', data.merchantReferenceId)
|
|
130
|
+
.string('merchantReferenceId', data.merchantReferenceId)
|
|
131
|
+
.string('merchantName', data.merchantName)
|
|
132
|
+
.when(typeof data.merchantName === 'string' && data.merchantName.trim() === '', 'merchantName', 'The merchantName field is required.')
|
|
133
|
+
.when(isSet(data.timeToLiveSeconds) && !Number.isInteger(data.timeToLiveSeconds), 'timeToLiveSeconds', 'The timeToLiveSeconds field must be an integer.')
|
|
134
|
+
.when(isSet(data.timeToLiveSeconds) && data.timeToLiveSeconds < 1, 'timeToLiveSeconds', 'The timeToLiveSeconds field must be greater than 0.');
|
|
131
135
|
items.forEach((item, index) => {
|
|
132
136
|
validator
|
|
133
137
|
.required(`items.${index}.name`, item?.name)
|
|
@@ -153,7 +157,7 @@ class WaveMoney {
|
|
|
153
157
|
data.merchantReferenceId = (0, crypto_js_1.randomHex)();
|
|
154
158
|
}
|
|
155
159
|
const amount = WaveMoney.resolvedAmount(data).toString();
|
|
156
|
-
const ttl = String(this.config.timeToLiveSeconds);
|
|
160
|
+
const ttl = String(data.timeToLiveSeconds ?? this.config.timeToLiveSeconds);
|
|
157
161
|
// Wave documents items as [{"name": "...", "amount": 1000}] with a numeric amount; the amount
|
|
158
162
|
// text is written as a JSON number without passing through a float.
|
|
159
163
|
const items = `[${data.items
|
|
@@ -168,7 +172,7 @@ class WaveMoney {
|
|
|
168
172
|
backend_result_url: data.callbackUrl,
|
|
169
173
|
amount,
|
|
170
174
|
payment_description: data.description,
|
|
171
|
-
merchant_name: this.config.merchantName,
|
|
175
|
+
merchant_name: data.merchantName ?? this.config.merchantName,
|
|
172
176
|
items,
|
|
173
177
|
hash: this.hash([
|
|
174
178
|
ttl,
|
|
@@ -226,6 +230,9 @@ class WaveMoney {
|
|
|
226
230
|
}
|
|
227
231
|
}
|
|
228
232
|
exports.WaveMoney = WaveMoney;
|
|
233
|
+
function isSet(value) {
|
|
234
|
+
return value !== undefined && value !== null;
|
|
235
|
+
}
|
|
229
236
|
function errorMessage(body) {
|
|
230
237
|
const errors = body.errors;
|
|
231
238
|
if ((0, json_js_1.isLosslessObject)(errors)) {
|
|
@@ -79,6 +79,16 @@ export interface WaveMoneyPaymentData {
|
|
|
79
79
|
* this.
|
|
80
80
|
*/
|
|
81
81
|
merchantReferenceId?: string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The business name shown on Wave's page for this payment. Defaults to the configured
|
|
84
|
+
* `merchantName` when unset.
|
|
85
|
+
*/
|
|
86
|
+
merchantName?: string | null | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* How long the customer has to pay this payment, in seconds: a whole number greater than 0.
|
|
89
|
+
* Defaults to the configured `timeToLiveSeconds` when unset.
|
|
90
|
+
*/
|
|
91
|
+
timeToLiveSeconds?: number | null | undefined;
|
|
82
92
|
}
|
|
83
93
|
/**
|
|
84
94
|
* Wave Money (WavePay payment gateway): redirect payments and callbacks. Wave has no status API,
|
|
@@ -123,7 +123,11 @@ export class WaveMoney {
|
|
|
123
123
|
.url('returnUrl', data.returnUrl)
|
|
124
124
|
.required('description', data.description)
|
|
125
125
|
.when(items.length === 0, 'items', 'The items field must have at least one item.')
|
|
126
|
-
.string('merchantReferenceId', data.merchantReferenceId)
|
|
126
|
+
.string('merchantReferenceId', data.merchantReferenceId)
|
|
127
|
+
.string('merchantName', data.merchantName)
|
|
128
|
+
.when(typeof data.merchantName === 'string' && data.merchantName.trim() === '', 'merchantName', 'The merchantName field is required.')
|
|
129
|
+
.when(isSet(data.timeToLiveSeconds) && !Number.isInteger(data.timeToLiveSeconds), 'timeToLiveSeconds', 'The timeToLiveSeconds field must be an integer.')
|
|
130
|
+
.when(isSet(data.timeToLiveSeconds) && data.timeToLiveSeconds < 1, 'timeToLiveSeconds', 'The timeToLiveSeconds field must be greater than 0.');
|
|
127
131
|
items.forEach((item, index) => {
|
|
128
132
|
validator
|
|
129
133
|
.required(`items.${index}.name`, item?.name)
|
|
@@ -149,7 +153,7 @@ export class WaveMoney {
|
|
|
149
153
|
data.merchantReferenceId = randomHex();
|
|
150
154
|
}
|
|
151
155
|
const amount = WaveMoney.resolvedAmount(data).toString();
|
|
152
|
-
const ttl = String(this.config.timeToLiveSeconds);
|
|
156
|
+
const ttl = String(data.timeToLiveSeconds ?? this.config.timeToLiveSeconds);
|
|
153
157
|
// Wave documents items as [{"name": "...", "amount": 1000}] with a numeric amount; the amount
|
|
154
158
|
// text is written as a JSON number without passing through a float.
|
|
155
159
|
const items = `[${data.items
|
|
@@ -164,7 +168,7 @@ export class WaveMoney {
|
|
|
164
168
|
backend_result_url: data.callbackUrl,
|
|
165
169
|
amount,
|
|
166
170
|
payment_description: data.description,
|
|
167
|
-
merchant_name: this.config.merchantName,
|
|
171
|
+
merchant_name: data.merchantName ?? this.config.merchantName,
|
|
168
172
|
items,
|
|
169
173
|
hash: this.hash([
|
|
170
174
|
ttl,
|
|
@@ -221,6 +225,9 @@ export class WaveMoney {
|
|
|
221
225
|
return hmacSha256Hex(this.config.secretKey, parts.join(''));
|
|
222
226
|
}
|
|
223
227
|
}
|
|
228
|
+
function isSet(value) {
|
|
229
|
+
return value !== undefined && value !== null;
|
|
230
|
+
}
|
|
224
231
|
function errorMessage(body) {
|
|
225
232
|
const errors = body.errors;
|
|
226
233
|
if (isLosslessObject(errors)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laranex/myanmar-payments",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
3
|
+
"version": "4.0.0-dev.8",
|
|
4
4
|
"description": "Node.js SDK for Myanmar payment gateways: KBZ Pay, Wave Money, AYA Pay, Yoma MMQR and CyberSource. Typed requests and results, exact amounts, no runtime dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"laranex",
|
|
@@ -58,7 +58,7 @@ const payment = await kbz.pwa({
|
|
|
58
58
|
res.writeHead(302, { Location: payment.url }).end();
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
- `RedirectPayment` (`url`) from `kbz.pwa(data)` and `wave.initiate(data)`. Wave fills `data.merchantReferenceId` when empty; store it.
|
|
61
|
+
- `RedirectPayment` (`url`) from `kbz.pwa(data)` and `wave.initiate(data)`. Wave fills `data.merchantReferenceId` when empty; store it. Pass `merchantName` or `timeToLiveSeconds` in Wave's payment data to override the configured `WAVE_MONEY_MERCHANT_NAME` or `WAVE_MONEY_TIME_TO_LIVE_IN_SECONDS` for that one payment (the settings stay required).
|
|
62
62
|
- `FormPayment` from `aya.initiate(data)` and `cyberSource.initiate(data)` (no network call): send `payment.toHtml()` as an auto-submitting page, or render `action`, `fields` and `enctype` yourself.
|
|
63
63
|
- `QrPayment` from `kbz.qr(data)` (encode `qrString`) and `yoma.initiate(data)` (`qrImageDataUri()`, `expiresAt`, `reference`). A Yoma QR lives `YomaMmqr.QR_LIFETIME_SECONDS` (120); renew it with `yoma.renewQr(orderId)`.
|
|
64
64
|
- `AppPayment` from `kbz.app(data)`: `res.json(payment)` sends `orderId`, `orderInfo`, `sign` and `signType` to your mobile app.
|