kage-baileys 25.4.17 → 25.4.19
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/README.md +6 -6
- package/helpers/interactive-pay.js +13 -13
- package/lib/Utils/interactive-compat.cjs +24 -3
- package/lib/Utils/native-flow.d.ts +3 -0
- package/lib/Utils/native-flow.js +122 -51
- package/package.json +6 -4
- package/scripts/verify-native-flow-payments.mjs +167 -0
- package/scripts/verify-pairing-flow.mjs +2 -2
- package/scripts/verify-placeholder-payment-accounts.mjs +42 -0
package/README.md
CHANGED
|
@@ -1108,7 +1108,7 @@ await conn.sendReviewAndPay(m.chat, {
|
|
|
1108
1108
|
})
|
|
1109
1109
|
```
|
|
1110
1110
|
|
|
1111
|
-
`total_amount`
|
|
1111
|
+
`total_amount` se normaliza usando la suma de `order.items` (importe × cantidad), más impuestos y envío, menos descuentos; `subtotal` también se recalcula desde las líneas del pedido. Deben usarse importes válidos y un mismo `offset`. Para rechazar cualquier ajuste automático, configura `KAGE_STRICT_REVIEW_AND_PAY=1`. En el ejemplo, `137` con `offset: 100` representa PEN 1.37. Los marcadores de plantilla como `[NUMERO_PLIN]` se eliminan automáticamente de `payment_settings`; las cuentas reales se conservan. Configura solo datos de pago válidos que estés autorizado a utilizar. Que una cuenta bancaria o billetera figure en `payment_settings` no garantiza que WhatsApp la admita como proveedor de pago. Kage construye y transmite el mensaje, pero no procesa cobros ni confirma pagos. El renderizado depende del cliente, la cuenta, la región y las funciones habilitadas por WhatsApp. Para depurar, prueba primero sin miniatura ni cuentas de pago; WhatsApp puede ignorar flujos no habilitados en esa cuenta o cliente. **Disponibilidad regional:** el Centro de ayuda de WhatsApp lista India, Brasil, México e Indonesia para pagar a empresas registradas; fuera de esos países, la función no está disponible. Baileys no puede habilitarla desde el protocolo. En países no incluidos, usa un enlace externo de tu proveedor mediante `cta_url` en vez de `review_and_pay` (consulta https://faq.whatsapp.com/1293279751500598/).
|
|
1112
1112
|
|
|
1113
1113
|
### Helpers de fotos y perfil
|
|
1114
1114
|
|
|
@@ -2273,7 +2273,7 @@ This Kage build incorporates the compatible additions identified in the attached
|
|
|
2273
2273
|
|
|
2274
2274
|
### Native Flow `review_and_pay`
|
|
2275
2275
|
|
|
2276
|
-
`buildReviewAndPayMessage()` builds the protobuf-compatible `interactiveMessage` payload. `sendReviewAndPay()` wraps it with `generateWAMessageFromContent`, adds a message ID, and supplies the payment `biz` relay node. The core `relayMessage()` path normalizes `messageParamsJson` and `messageVersion`,
|
|
2276
|
+
`buildReviewAndPayMessage()` builds the protobuf-compatible `interactiveMessage` payload. `sendReviewAndPay()` wraps it with `generateWAMessageFromContent`, adds a message ID, and supplies the payment `biz` relay node. The core `relayMessage()` path normalizes `messageParamsJson` and `messageVersion`, reconciles subtotal/total against order lines and declared tax/shipping/discount, and adds the `biz` node with the `order_details` mapping for `review_and_pay`. Set `KAGE_STRICT_REVIEW_AND_PAY=1` to reject rather than reconcile mismatched totals. The library does not inject a `bot` marker into ordinary private chats. `buttonParamsJson` accepts a JSON string or object and is validated before transmission. Example:
|
|
2277
2277
|
|
|
2278
2278
|
```js
|
|
2279
2279
|
await conn.sendReviewAndPay(chatJid, {
|
|
@@ -2299,7 +2299,7 @@ await conn.sendReviewAndPay(chatJid, {
|
|
|
2299
2299
|
}, {});
|
|
2300
2300
|
```
|
|
2301
2301
|
|
|
2302
|
-
This sends a WhatsApp Native Flow payment-request payload only. It does not charge, settle or verify a payment, and rendering depends on WhatsApp client/account/region support and a payment provider activated for that business. The generic helper deliberately does not embed personal payment accounts. The
|
|
2302
|
+
This sends a WhatsApp Native Flow payment-request payload only. It does not charge, settle or verify a payment, and rendering depends on WhatsApp client/account/region support and a payment provider activated for that business. The generic helper deliberately does not embed personal payment accounts. The subtotal is derived from the line items and `total_amount` is normalized to subtotal plus tax and shipping minus discount. Set `KAGE_STRICT_REVIEW_AND_PAY=1` to reject mismatches instead of reconciling them. The core relay automatically attaches the required `biz` companion node even when the caller uses `conn.relayMessage()` directly. WhatsApp Help Center lists India, Brazil, Mexico and Indonesia as markets where customers can pay registered businesses; outside those markets the native payment feature is unavailable. For other countries, use a provider-hosted payment link with a regular `cta_url` button instead.
|
|
2303
2303
|
|
|
2304
2304
|
### Media status and view-once messages
|
|
2305
2305
|
|
|
@@ -2310,15 +2310,15 @@ Use `getMediaDownloadStatus(message)` to inspect ordinary media availability. It
|
|
|
2310
2310
|
The root package and `./Utils/*` subpaths now expose additional auth-state adapters (MongoDB, MySQL, PostgreSQL, Redis, SQLite, single-file and NekoDB), TTL cache, sender-key memory helpers, group metadata validation, username validation, modern message constructors, status sticker builders, social link preview helpers, HTML-app validation/multiplayer helpers, scheduled-message helpers and newsletter status helpers. Database drivers are optional peer dependencies and must be installed only when the relevant adapter is used.
|
|
2311
2311
|
|
|
2312
2312
|
|
|
2313
|
-
## Kage 25.4.
|
|
2313
|
+
## Kage 25.4.17: payment account placeholder cleanup
|
|
2314
2314
|
|
|
2315
2315
|
When `requestPairingCode(phoneNumber)` is called without a custom code, Kage generates `KAGE` followed by four cryptographically random characters from an unambiguous 32-character alphabet. The actual eight-character token has no space; display it with a space only for readability. Kage waits for WhatsApp to accept the `companion_hello` IQ request. The authoritative `link_code_pairing_ref` is then read from `primary_hello`, matching the established Kage Antigua / Baileys flow. A `rate-overlimit` response is a server-side 429 and cannot be bypassed by changing the code. Kage never retries automatically and activates a process-wide cooldown (15 minutes by default when WhatsApp supplies no retry time; configurable with `pairingRateLimitCooldownMs`). The cooldown is also stored in `authState.creds.pairingRateLimitedUntil` and is persisted when the application saves `creds.update`; this protects normal reconnects and process restarts that reuse the same saved session. If the application discards the auth state, WhatsApp's server-side limit may still remain active.
|
|
2316
2316
|
|
|
2317
|
-
For `review_and_pay`, `relayMessage()` adds the `biz` node with `native_flow_name="order_details"`, merges compatible custom `biz` nodes, and supplies `messageParamsJson` / `messageVersion` when missing. Before sending, it validates the payment JSON and JPEG thumbnail. `total_amount`
|
|
2317
|
+
For `review_and_pay`, `relayMessage()` adds the `biz` node with `native_flow_name="order_details"`, merges compatible custom `biz` nodes, and supplies `messageParamsJson` / `messageVersion` when missing. Before sending, it validates the payment JSON and JPEG thumbnail. `total_amount` is normalized to item subtotal plus tax and shipping minus discount. The subtotal is derived from the actual order lines. Set `KAGE_STRICT_REVIEW_AND_PAY=1` to reject mismatched amounts instead of normalizing them. Kage builds the UI payload; it does not process or confirm payments. Placeholder payment identifiers such as `[NUMERO_PLIN]` or `[ACCOUNT_NUMBER]` are filtered out automatically before relay; valid payment accounts are preserved.
|
|
2318
2318
|
|
|
2319
2319
|
The Native Flow helper constructs a payment-request message only. It does not process or verify transactions. WhatsApp's current Help Center lists registered-business payments in India, Brazil, Mexico and Indonesia; outside those countries, its in-app business-payment feature is not available. Use a legitimate hosted payment link for other regions. See [WhatsApp Help Center: participating countries](https://faq.whatsapp.com/1293279751500598/?locale=es_LA).
|
|
2320
2320
|
|
|
2321
2321
|
## Package validation
|
|
2322
2322
|
|
|
2323
|
-
The `test/` source folder and source maps are intentionally excluded from this clean distribution build. `npm test` runs focused pairing/reconnect and Native Flow assertions. `npm run check` validates syntax, imports, exports, WAProto, and the focused assertions. See `VALIDATION-REPORT-25.4.
|
|
2323
|
+
The `test/` source folder and source maps are intentionally excluded from this clean distribution build. `npm test` runs focused pairing/reconnect and Native Flow assertions. `npm run check` validates syntax, imports, exports, WAProto, and the focused assertions. See `VALIDATION-REPORT-25.4.17.md`.
|
|
2324
2324
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { normalizeThumbnail } from './media-thumb.js';
|
|
7
7
|
import { generateWAMessageFromContent } from '../lib/Utils/messages.js';
|
|
8
8
|
import { getBizBinaryNode } from '../lib/WABinary/index.js';
|
|
9
|
-
import { prepareNativeFlowMessageForRelay } from '../lib/Utils/native-flow.js';
|
|
9
|
+
import { isPlaceholderPaymentIdentifier, normalizeReviewAndPayAmounts, prepareNativeFlowMessageForRelay } from '../lib/Utils/native-flow.js';
|
|
10
10
|
|
|
11
11
|
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
12
12
|
const positiveInteger = (value, name) => {
|
|
@@ -27,17 +27,16 @@ const amountObject = (value, offset, name) => {
|
|
|
27
27
|
function normalizePaymentAccounts(accounts) {
|
|
28
28
|
if (accounts == null) return [];
|
|
29
29
|
if (!Array.isArray(accounts)) throw new TypeError('paymentAccounts must be an array');
|
|
30
|
-
|
|
30
|
+
const normalized = [];
|
|
31
|
+
for (const [index, entry] of accounts.entries()) {
|
|
31
32
|
if (!isObject(entry)) throw new TypeError(`paymentAccounts[${index}] must be an object`);
|
|
32
33
|
const paymentAccount = entry.payment_account ?? entry.paymentAccount;
|
|
33
34
|
if (!isObject(paymentAccount)) throw new TypeError(`paymentAccounts[${index}].payment_account is required`);
|
|
34
35
|
const identifier = paymentAccount.identifier_value ?? paymentAccount.identifierValue;
|
|
36
|
+
if (isPlaceholderPaymentIdentifier(identifier)) continue;
|
|
35
37
|
if (typeof identifier !== 'string' || !identifier.trim()) {
|
|
36
38
|
throw new TypeError(`paymentAccounts[${index}] needs a nonempty identifier_value`);
|
|
37
39
|
}
|
|
38
|
-
if (/^\[[^\]]+\]$/.test(identifier.trim())) {
|
|
39
|
-
throw new TypeError(`paymentAccounts[${index}].identifier_value is still a placeholder; replace it with a real value or omit that account`);
|
|
40
|
-
}
|
|
41
40
|
const result = { ...entry, type: entry.type || 'payment_account', payment_account: { ...paymentAccount } };
|
|
42
41
|
delete result.paymentAccount;
|
|
43
42
|
if (result.payment_account.identifierValue !== undefined && result.payment_account.identifier_value === undefined) {
|
|
@@ -60,8 +59,9 @@ function normalizePaymentAccounts(accounts) {
|
|
|
60
59
|
delete result.payment_account.identifierType;
|
|
61
60
|
delete result.payment_account.institutionName;
|
|
62
61
|
delete result.payment_account.beneficiaryName;
|
|
63
|
-
|
|
64
|
-
}
|
|
62
|
+
normalized.push(result);
|
|
63
|
+
}
|
|
64
|
+
return normalized;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
function normalizePaymentParams(options) {
|
|
@@ -110,8 +110,8 @@ function normalizePaymentParams(options) {
|
|
|
110
110
|
offset,
|
|
111
111
|
'total_amount'
|
|
112
112
|
);
|
|
113
|
-
if (normalizedTotal.offset !== offset
|
|
114
|
-
throw new TypeError('total_amount must
|
|
113
|
+
if (normalizedTotal.offset !== offset) {
|
|
114
|
+
throw new TypeError('total_amount.offset must match the order item offset');
|
|
115
115
|
}
|
|
116
116
|
const params = {
|
|
117
117
|
currency,
|
|
@@ -138,12 +138,12 @@ function normalizePaymentParams(options) {
|
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
if (!params.reference_id.trim()) throw new TypeError('referenceId cannot be empty');
|
|
141
|
+
let result = params;
|
|
141
142
|
if (supplied) {
|
|
142
|
-
|
|
143
|
-
if (isObject(supplied.order))
|
|
144
|
-
return merged;
|
|
143
|
+
result = { ...supplied, ...params };
|
|
144
|
+
if (isObject(supplied.order)) result.order = { ...supplied.order, ...params.order };
|
|
145
145
|
}
|
|
146
|
-
return
|
|
146
|
+
return normalizeReviewAndPayAmounts(result);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
function getRawButtonParamsJson(options) {
|
|
@@ -198,12 +198,33 @@ function createKageOrderDetails(parameters) {
|
|
|
198
198
|
if (p.order.subtotal == null) {
|
|
199
199
|
p.order.subtotal = { value: Number(sum), offset };
|
|
200
200
|
}
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
let subtotal = amount(p.order.subtotal,'order.subtotal');
|
|
202
|
+
const strict = process.env.KAGE_STRICT_REVIEW_AND_PAY === '1';
|
|
203
|
+
if (sum !== subtotal && strict) throw new TypeError('El subtotal no coincide con los productos');
|
|
204
|
+
if (sum !== subtotal) {
|
|
205
|
+
p.order.subtotal.value = Number(sum);
|
|
206
|
+
subtotal = sum;
|
|
207
|
+
}
|
|
203
208
|
const tax = p.order.tax ? amount(p.order.tax,'tax') : 0n;
|
|
204
209
|
const shipping = p.order.shipping ? amount(p.order.shipping,'shipping') : 0n;
|
|
205
210
|
const discount = p.order.discount ? amount(p.order.discount,'discount') : 0n;
|
|
206
|
-
|
|
211
|
+
const expectedTotal = subtotal + tax + shipping - discount;
|
|
212
|
+
if (expectedTotal <= 0n || expectedTotal > BigInt(Number.MAX_SAFE_INTEGER)) throw new RangeError('El total calculado está fuera del rango permitido');
|
|
213
|
+
if (total !== expectedTotal && strict) throw new TypeError('El total no coincide con subtotal + impuestos + envío - descuento');
|
|
214
|
+
if (total !== expectedTotal) p.total_amount.value = Number(expectedTotal);
|
|
215
|
+
// Remove only instructional placeholder identifiers such as [NUMERO_PLIN].
|
|
216
|
+
// Keep configured accounts and let the relay validator reject malformed entries.
|
|
217
|
+
if (Array.isArray(p.payment_settings)) {
|
|
218
|
+
p.payment_settings = p.payment_settings.filter(entry => {
|
|
219
|
+
const account = entry?.payment_account ?? entry?.paymentAccount;
|
|
220
|
+
const identifier = account?.identifier_value ?? account?.identifierValue;
|
|
221
|
+
if (typeof identifier !== 'string') return true;
|
|
222
|
+
const value = identifier.trim();
|
|
223
|
+
return !(/^\[[^\]]+\]$/.test(value) || /^<[^>]+>$/.test(value) || /^\{\{?[^{}]+\}\}?$/.test(value)
|
|
224
|
+
|| /^(?:NUMERO|NÚMERO|PHONE|TELEFONO|TELÉFONO|ACCOUNT|CUENTA|YOUR|REPLACE|PLACEHOLDER|INSERT|ENTER|CAMBIAR|PONER|EJEMPLO|EXAMPLE)(?:[\s_-]|$)/i.test(value)
|
|
225
|
+
|| /^(?:X{4,}|0{6,}|9{6,})$/i.test(value));
|
|
226
|
+
});
|
|
227
|
+
}
|
|
207
228
|
if (!p.payment_settings?.length && !p.native_payment_methods?.length && !p.payment_configuration) throw new TypeError('Falta una configuración de pago real; usa cta_url para enlaces externos');
|
|
208
229
|
// Defaults útiles para review_and_pay
|
|
209
230
|
if (!p.payment_type) p.payment_type = 'upi';
|
|
@@ -13,4 +13,7 @@ export declare function nativeFlowButtonsViolateConstraints(buttons?: Array<{ na
|
|
|
13
13
|
export declare function createNativeFlowButton(name: string, params?: Record<string, unknown> | string): { name: string; buttonParamsJson: string };
|
|
14
14
|
export declare function parseNativeFlowButton(button: { name?: string; buttonParamsJson: string }): Record<string, unknown>;
|
|
15
15
|
|
|
16
|
+
export declare function normalizeReviewAndPayAmounts<T extends Record<string, unknown>>(params: T, options?: { strict?: boolean }): T;
|
|
16
17
|
export declare function prepareNativeFlowMessageForRelay<T>(input: T): T;
|
|
18
|
+
|
|
19
|
+
export declare function isPlaceholderPaymentIdentifier(value: unknown): boolean;
|
package/lib/Utils/native-flow.js
CHANGED
|
@@ -86,6 +86,18 @@ export const NATIVE_FLOW_BUTTON_LIMIT = Object.freeze({ quickReply: 10, other: 3
|
|
|
86
86
|
|
|
87
87
|
export const getNativeFlowNameByButtonName = name => BUTTON_NAME_TO_FLOW[name];
|
|
88
88
|
|
|
89
|
+
/** True when a payment identifier is an instructional/template marker, not an account value. */
|
|
90
|
+
export function isPlaceholderPaymentIdentifier(value) {
|
|
91
|
+
if (typeof value !== 'string') return false;
|
|
92
|
+
const identifier = value.trim();
|
|
93
|
+
if (!identifier) return false;
|
|
94
|
+
if (/^\[[^\]]+\]$/.test(identifier) || /^<[^>]+>$/.test(identifier) || /^\{\{?[^{}]+\}\}?$/.test(identifier)) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return /^(?:NUMERO|NÚMERO|PHONE|TELEFONO|TELÉFONO|ACCOUNT|CUENTA|YOUR|REPLACE|PLACEHOLDER|INSERT|ENTER|CAMBIAR|PONER|EJEMPLO|EXAMPLE)(?:[\s_-]|$)/i.test(identifier)
|
|
98
|
+
|| /^(?:X{4,}|0{6,}|9{6,})$/i.test(identifier);
|
|
99
|
+
}
|
|
100
|
+
|
|
89
101
|
export const isWebSupportedButtonName = name => {
|
|
90
102
|
const flow = getNativeFlowNameByButtonName(name);
|
|
91
103
|
return flow !== undefined && WEB_SUPPORTED_INTERACTIVE_FLOWS.includes(flow);
|
|
@@ -120,6 +132,104 @@ export const checkNativeFlowButtons = buttons => {
|
|
|
120
132
|
|
|
121
133
|
export const nativeFlowButtonsViolateConstraints = buttons => !checkNativeFlowButtons(buttons).ok;
|
|
122
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Reconciles review_and_pay arithmetic against the actual order lines.
|
|
137
|
+
*
|
|
138
|
+
* WhatsApp expects total_amount = item subtotal + tax + shipping - discount.
|
|
139
|
+
* Older Kage forks did not validate this, which allowed malformed payloads to
|
|
140
|
+
* reach the relay layer. The safe default is to recompute subtotal/total from
|
|
141
|
+
* the line items and declared adjustments instead of crashing on a stale total.
|
|
142
|
+
* Set KAGE_STRICT_REVIEW_AND_PAY=1 to reject mismatches instead.
|
|
143
|
+
*/
|
|
144
|
+
export function normalizeReviewAndPayAmounts(params, options = {}) {
|
|
145
|
+
if (!params || typeof params !== 'object' || Array.isArray(params)) {
|
|
146
|
+
throw new TypeError('review_and_pay parameters must be an object');
|
|
147
|
+
}
|
|
148
|
+
if (!params.order || typeof params.order !== 'object' || !Array.isArray(params.order.items) || !params.order.items.length) {
|
|
149
|
+
throw new TypeError('review_and_pay requires at least one order.items entry');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const strict = options.strict ?? process.env.KAGE_STRICT_REVIEW_AND_PAY === '1';
|
|
153
|
+
const firstAmount = params.order.items[0]?.amount;
|
|
154
|
+
const offset = Number(params.total_amount?.offset ?? firstAmount?.offset);
|
|
155
|
+
if (!Number.isSafeInteger(offset) || offset <= 0) {
|
|
156
|
+
throw new TypeError('review_and_pay requires a positive safe integer amount offset');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const readAmount = (amount, label, allowZero = false) => {
|
|
160
|
+
if (!amount || typeof amount !== 'object' || Array.isArray(amount)) {
|
|
161
|
+
throw new TypeError(`${label} must contain value and offset`);
|
|
162
|
+
}
|
|
163
|
+
const value = Number(amount.value);
|
|
164
|
+
const amountOffset = Number(amount.offset);
|
|
165
|
+
if (!Number.isSafeInteger(value) || value < (allowZero ? 0 : 1)) {
|
|
166
|
+
throw new TypeError(`${label}.value must be a ${allowZero ? 'non-negative' : 'positive'} safe integer`);
|
|
167
|
+
}
|
|
168
|
+
if (!Number.isSafeInteger(amountOffset) || amountOffset <= 0) {
|
|
169
|
+
throw new TypeError(`${label}.offset must be a positive safe integer`);
|
|
170
|
+
}
|
|
171
|
+
if (amountOffset !== offset) {
|
|
172
|
+
throw new TypeError(`${label}.offset must match the order offset (${offset})`);
|
|
173
|
+
}
|
|
174
|
+
return BigInt(value);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const writeAmount = (current, value) => ({
|
|
178
|
+
...(current && typeof current === 'object' && !Array.isArray(current) ? current : {}),
|
|
179
|
+
value: typeof current?.value === 'string' ? value.toString() : Number(value),
|
|
180
|
+
offset: typeof current?.offset === 'string' ? String(offset) : offset
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
let itemSum = 0n;
|
|
184
|
+
for (const [itemIndex, item] of params.order.items.entries()) {
|
|
185
|
+
if (!item || typeof item !== 'object' || typeof item.name !== 'string' || !item.name.trim()) {
|
|
186
|
+
throw new TypeError(`order.items[${itemIndex}].name is required`);
|
|
187
|
+
}
|
|
188
|
+
const amount = readAmount(item.amount, `order.items[${itemIndex}].amount`);
|
|
189
|
+
const quantity = Number(item.quantity);
|
|
190
|
+
if (!Number.isSafeInteger(quantity) || quantity <= 0) {
|
|
191
|
+
throw new TypeError(`order.items[${itemIndex}].quantity must be a positive safe integer`);
|
|
192
|
+
}
|
|
193
|
+
itemSum += amount * BigInt(quantity);
|
|
194
|
+
}
|
|
195
|
+
if (itemSum > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
196
|
+
throw new RangeError('review_and_pay item total exceeds the safe integer range');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (params.order.subtotal != null) {
|
|
200
|
+
const suppliedSubtotal = readAmount(params.order.subtotal, 'order.subtotal', true);
|
|
201
|
+
if (suppliedSubtotal !== itemSum && strict) {
|
|
202
|
+
throw new TypeError('order.subtotal must equal the sum of order.items (amount × quantity)');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
params.order.subtotal = writeAmount(params.order.subtotal, itemSum);
|
|
206
|
+
|
|
207
|
+
const optionalOrderAmount = key => {
|
|
208
|
+
if (params.order[key] == null) return 0n;
|
|
209
|
+
return readAmount(params.order[key], `order.${key}`, true);
|
|
210
|
+
};
|
|
211
|
+
const expectedTotal = itemSum
|
|
212
|
+
+ optionalOrderAmount('tax')
|
|
213
|
+
+ optionalOrderAmount('shipping')
|
|
214
|
+
- optionalOrderAmount('discount');
|
|
215
|
+
|
|
216
|
+
if (expectedTotal <= 0n) {
|
|
217
|
+
throw new RangeError('review_and_pay calculated total must be greater than zero');
|
|
218
|
+
}
|
|
219
|
+
if (expectedTotal > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
220
|
+
throw new RangeError('review_and_pay calculated total exceeds the safe integer range');
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (params.total_amount != null) {
|
|
224
|
+
const suppliedTotal = readAmount(params.total_amount, 'total_amount');
|
|
225
|
+
if (suppliedTotal !== expectedTotal && strict) {
|
|
226
|
+
throw new TypeError(`review_and_pay total_amount (${suppliedTotal}) must equal subtotal + tax + shipping - discount (${expectedTotal})`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
params.total_amount = writeAmount(params.total_amount, expectedTotal);
|
|
230
|
+
return params;
|
|
231
|
+
}
|
|
232
|
+
|
|
123
233
|
|
|
124
234
|
/**
|
|
125
235
|
* Normalizes and validates Native Flow data immediately before relay.
|
|
@@ -211,68 +321,29 @@ export function prepareNativeFlowMessageForRelay(input) {
|
|
|
211
321
|
throw new TypeError('review_and_pay requires at least one order.items entry');
|
|
212
322
|
}
|
|
213
323
|
|
|
214
|
-
|
|
215
|
-
if (!amount || typeof amount !== 'object') throw new TypeError(`${label} must contain value and offset`);
|
|
216
|
-
const value = Number(amount.value);
|
|
217
|
-
const offset = Number(amount.offset);
|
|
218
|
-
if (!Number.isSafeInteger(value) || value < (allowZero ? 0 : 1)) {
|
|
219
|
-
throw new TypeError(`${label}.value must be a ${allowZero ? 'non-negative' : 'positive'} safe integer`);
|
|
220
|
-
}
|
|
221
|
-
if (!Number.isSafeInteger(offset) || offset <= 0) throw new TypeError(`${label}.offset must be a positive safe integer`);
|
|
222
|
-
if (commonOffset != null && offset !== commonOffset) throw new TypeError(`${label}.offset must match the order offset`);
|
|
223
|
-
return { value: BigInt(value), offset };
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
const total = readAmount(params.total_amount, 'total_amount');
|
|
227
|
-
const offset = total.offset;
|
|
228
|
-
let itemSum = 0n;
|
|
229
|
-
for (const [itemIndex, item] of params.order.items.entries()) {
|
|
230
|
-
if (!item || typeof item !== 'object' || typeof item.name !== 'string' || !item.name.trim()) {
|
|
231
|
-
throw new TypeError(`order.items[${itemIndex}].name is required`);
|
|
232
|
-
}
|
|
233
|
-
const amount = readAmount(item.amount, `order.items[${itemIndex}].amount`, offset);
|
|
234
|
-
const quantity = Number(item.quantity);
|
|
235
|
-
if (!Number.isSafeInteger(quantity) || quantity <= 0) {
|
|
236
|
-
throw new TypeError(`order.items[${itemIndex}].quantity must be a positive safe integer`);
|
|
237
|
-
}
|
|
238
|
-
itemSum += amount.value * BigInt(quantity);
|
|
239
|
-
}
|
|
240
|
-
if (itemSum > BigInt(Number.MAX_SAFE_INTEGER)) throw new RangeError('review_and_pay item total exceeds the safe integer range');
|
|
324
|
+
normalizeReviewAndPayAmounts(params);
|
|
241
325
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
subtotal = { value: Number(itemSum), offset };
|
|
245
|
-
params.order.subtotal = subtotal;
|
|
246
|
-
} else {
|
|
247
|
-
const parsed = readAmount(params.order.subtotal, 'order.subtotal', offset, true);
|
|
248
|
-
subtotal = { value: Number(parsed.value), offset };
|
|
249
|
-
if (parsed.value !== itemSum) throw new TypeError('order.subtotal must equal the sum of order.items (amount × quantity)');
|
|
326
|
+
if (params.payment_settings != null && !Array.isArray(params.payment_settings)) {
|
|
327
|
+
throw new TypeError('review_and_pay payment_settings must be an array');
|
|
250
328
|
}
|
|
251
329
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
330
|
+
// Template values such as [NUMERO_PLIN] are not payment accounts. Drop
|
|
331
|
+
// only those entries, preserve all real accounts, and keep rejecting
|
|
332
|
+
// malformed entries that do not contain an identifier at all.
|
|
333
|
+
if (Array.isArray(params.payment_settings)) {
|
|
334
|
+
params.payment_settings = params.payment_settings.filter(entry => {
|
|
335
|
+
const account = entry?.payment_account ?? entry?.paymentAccount;
|
|
336
|
+
const identifier = account?.identifier_value ?? account?.identifierValue;
|
|
337
|
+
return !isPlaceholderPaymentIdentifier(identifier);
|
|
338
|
+
});
|
|
259
339
|
}
|
|
260
340
|
|
|
261
|
-
if (params.payment_settings != null && !Array.isArray(params.payment_settings)) {
|
|
262
|
-
throw new TypeError('review_and_pay payment_settings must be an array');
|
|
263
|
-
}
|
|
264
341
|
for (const [accountIndex, entry] of (params.payment_settings ?? []).entries()) {
|
|
265
342
|
const account = entry?.payment_account ?? entry?.paymentAccount;
|
|
266
343
|
const identifier = account?.identifier_value ?? account?.identifierValue;
|
|
267
344
|
if (typeof identifier !== 'string' || !identifier.trim()) {
|
|
268
345
|
throw new TypeError(`payment_settings[${accountIndex}] requires payment_account.identifier_value`);
|
|
269
346
|
}
|
|
270
|
-
if (/^\[[^\]]+\]$/.test(identifier.trim())) {
|
|
271
|
-
throw new TypeError(`payment_settings[${accountIndex}] still contains a placeholder identifier (${identifier}); replace it with a valid value or remove that payment account`);
|
|
272
|
-
}
|
|
273
|
-
if (/^\[[^\]]+\]$/.test(identifier.trim())) {
|
|
274
|
-
throw new TypeError(`payment_settings[${accountIndex}] still contains a placeholder identifier; remove it or replace it with a valid provider value`);
|
|
275
|
-
}
|
|
276
347
|
}
|
|
277
348
|
|
|
278
349
|
const normalized = JSON.stringify(params);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kage-baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "25.4.
|
|
5
|
-
"description": "Kage Baileys with hardened pairing-code validation, WhatsApp 429 cooldown, resilient reconnect classification, Native Flow
|
|
4
|
+
"version": "25.4.19",
|
|
5
|
+
"description": "Kage Baileys with hardened pairing-code validation, WhatsApp 429 cooldown, resilient reconnect classification, normalized Native Flow payment totals, placeholder payment-account filtering, and expanded WAProto compatibility",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
8
8
|
"automation"
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"scripts/**/*",
|
|
25
25
|
"README.md",
|
|
26
26
|
"LICENSE",
|
|
27
|
-
"VALIDATION-REPORT-25.4.15.md"
|
|
27
|
+
"VALIDATION-REPORT-25.4.15.md",
|
|
28
|
+
"VALIDATION-REPORT-25.4.16.md",
|
|
29
|
+
"VALIDATION-REPORT-25.4.17.md"
|
|
28
30
|
],
|
|
29
31
|
"scripts": {
|
|
30
32
|
"build:all": "npm run check",
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
"gen:protobuf": "sh WAProto/GenerateStatics.sh",
|
|
37
39
|
"lint": "node ./scripts/verify-package.mjs",
|
|
38
40
|
"release": "release-it",
|
|
39
|
-
"test": "node ./scripts/verify-pairing-flow.mjs"
|
|
41
|
+
"test": "node ./scripts/verify-pairing-flow.mjs && node ./scripts/verify-native-flow-payments.mjs && node ./scripts/verify-placeholder-payment-accounts.mjs"
|
|
40
42
|
},
|
|
41
43
|
"dependencies": {
|
|
42
44
|
"@adiwajshing/keyed-db": "^0.2.4",
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import {
|
|
4
|
+
normalizeReviewAndPayAmounts,
|
|
5
|
+
prepareNativeFlowMessageForRelay,
|
|
6
|
+
isPlaceholderPaymentIdentifier
|
|
7
|
+
} from '../lib/Utils/native-flow.js';
|
|
8
|
+
import { buildReviewAndPayMessage } from '../helpers/interactive-pay.js';
|
|
9
|
+
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
const { createKageOrderDetails } = require('../lib/Utils/interactive-compat.cjs');
|
|
12
|
+
|
|
13
|
+
let checks = 0;
|
|
14
|
+
const check = (condition, message) => {
|
|
15
|
+
assert.ok(condition, message);
|
|
16
|
+
checks += 1;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const makeMessage = ({
|
|
20
|
+
total = 137,
|
|
21
|
+
item = 138,
|
|
22
|
+
quantity = 1,
|
|
23
|
+
subtotal = 137,
|
|
24
|
+
offset = 100,
|
|
25
|
+
tax,
|
|
26
|
+
shipping,
|
|
27
|
+
discount,
|
|
28
|
+
stringValues = false
|
|
29
|
+
} = {}) => {
|
|
30
|
+
const money = value => ({
|
|
31
|
+
value: stringValues ? String(value) : value,
|
|
32
|
+
offset: stringValues ? String(offset) : offset
|
|
33
|
+
});
|
|
34
|
+
const order = {
|
|
35
|
+
items: [{ name: 'Producto de prueba', amount: money(item), quantity }],
|
|
36
|
+
subtotal: money(subtotal)
|
|
37
|
+
};
|
|
38
|
+
if (tax !== undefined) order.tax = money(tax);
|
|
39
|
+
if (shipping !== undefined) order.shipping = money(shipping);
|
|
40
|
+
if (discount !== undefined) order.discount = money(discount);
|
|
41
|
+
|
|
42
|
+
const params = {
|
|
43
|
+
currency: 'PEN',
|
|
44
|
+
reference_id: 'KAGE_TEST_001',
|
|
45
|
+
type: 'physical-goods',
|
|
46
|
+
total_amount: money(total),
|
|
47
|
+
order
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
interactiveMessage: {
|
|
51
|
+
nativeFlowMessage: {
|
|
52
|
+
buttons: [{ name: 'review_and_pay', buttonParamsJson: JSON.stringify(params) }]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Regression for the user's exact exception: total 137 vs calculated 138.
|
|
59
|
+
const mismatched = makeMessage();
|
|
60
|
+
prepareNativeFlowMessageForRelay(mismatched);
|
|
61
|
+
let params = JSON.parse(mismatched.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
62
|
+
check(params.total_amount.value === 138, 'total_amount should be normalized from 137 to 138');
|
|
63
|
+
check(params.order.subtotal.value === 138, 'subtotal should match the item sum');
|
|
64
|
+
|
|
65
|
+
// String amounts are supported and keep their original JSON representation.
|
|
66
|
+
const stringPayload = makeMessage({ total: 137, item: 138, subtotal: 137, stringValues: true });
|
|
67
|
+
prepareNativeFlowMessageForRelay(stringPayload);
|
|
68
|
+
params = JSON.parse(stringPayload.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
69
|
+
check(params.total_amount.value === '138', 'string total_amount should remain a string after normalization');
|
|
70
|
+
check(params.order.subtotal.value === '138', 'string subtotal should remain a string after normalization');
|
|
71
|
+
|
|
72
|
+
// Tax, shipping and discount are included in the canonical total calculation.
|
|
73
|
+
const adjustments = makeMessage({ total: 144, item: 138, subtotal: 138, tax: 4, shipping: 5, discount: 2 });
|
|
74
|
+
prepareNativeFlowMessageForRelay(adjustments);
|
|
75
|
+
params = JSON.parse(adjustments.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
76
|
+
check(params.total_amount.value === 145, 'total should include tax + shipping - discount');
|
|
77
|
+
|
|
78
|
+
// A missing total is calculated from the order lines and adjustments.
|
|
79
|
+
const noTotal = makeMessage({ total: 137, item: 138 });
|
|
80
|
+
let missingParams = JSON.parse(noTotal.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
81
|
+
delete missingParams.total_amount;
|
|
82
|
+
noTotal.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson = JSON.stringify(missingParams);
|
|
83
|
+
prepareNativeFlowMessageForRelay(noTotal);
|
|
84
|
+
missingParams = JSON.parse(noTotal.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
85
|
+
check(missingParams.total_amount.value === 138, 'missing total_amount should be derived from order items');
|
|
86
|
+
|
|
87
|
+
// Strict mode remains available to deployments that prefer rejection.
|
|
88
|
+
assert.throws(() => normalizeReviewAndPayAmounts({
|
|
89
|
+
total_amount: { value: 137, offset: 100 },
|
|
90
|
+
order: {
|
|
91
|
+
items: [{ name: 'Producto', amount: { value: 138, offset: 100 }, quantity: 1 }],
|
|
92
|
+
subtotal: { value: 138, offset: 100 }
|
|
93
|
+
}
|
|
94
|
+
}, { strict: true }), /total_amount/);
|
|
95
|
+
checks += 1;
|
|
96
|
+
|
|
97
|
+
// Structural and currency-offset errors must still be rejected.
|
|
98
|
+
const malformed = makeMessage();
|
|
99
|
+
let malformedParams = JSON.parse(malformed.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
100
|
+
malformedParams.order.items[0].name = '';
|
|
101
|
+
malformed.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson = JSON.stringify(malformedParams);
|
|
102
|
+
assert.throws(() => prepareNativeFlowMessageForRelay(malformed), /name is required/);
|
|
103
|
+
checks += 1;
|
|
104
|
+
const wrongOffset = makeMessage({ total: 137, item: 138 });
|
|
105
|
+
let wrongParams = JSON.parse(wrongOffset.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
106
|
+
wrongParams.order.items[0].amount.offset = 10;
|
|
107
|
+
wrongOffset.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson = JSON.stringify(wrongParams);
|
|
108
|
+
assert.throws(() => prepareNativeFlowMessageForRelay(wrongOffset), /offset must match/);
|
|
109
|
+
checks += 1;
|
|
110
|
+
|
|
111
|
+
// The CommonJS compatibility builder uses the same arithmetic policy.
|
|
112
|
+
const legacy = createKageOrderDetails({
|
|
113
|
+
currency: 'PEN',
|
|
114
|
+
reference_id: 'KAGE_TEST_CJS',
|
|
115
|
+
type: 'physical-goods',
|
|
116
|
+
payment_configuration: 'merchant_account',
|
|
117
|
+
total_amount: { value: 137, offset: 100 },
|
|
118
|
+
order: {
|
|
119
|
+
subtotal: { value: 137, offset: 100 },
|
|
120
|
+
items: [{ name: 'Producto', amount: { value: 138, offset: 100 }, quantity: 1 }]
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const legacyParams = JSON.parse(legacy.buttonParamsJson);
|
|
124
|
+
check(legacyParams.total_amount.value === 138, 'CJS compatibility builder should normalize total_amount');
|
|
125
|
+
check(legacyParams.order.subtotal.value === 138, 'CJS compatibility builder should normalize subtotal');
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
// A placeholder identifier is removed from the settings array, while real entries survive.
|
|
129
|
+
const withPlaceholder = makeMessage();
|
|
130
|
+
let withPlaceholderParams = JSON.parse(withPlaceholder.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
131
|
+
withPlaceholderParams.payment_settings = [
|
|
132
|
+
{ type: 'payment_account', payment_account: { identifier_value: 'test-bank-001' } },
|
|
133
|
+
{ type: 'payment_account', payment_account: { identifier_value: 'test-bank-002' } },
|
|
134
|
+
{ type: 'payment_account', payment_account: { identifier_value: 'test-bank-003' } },
|
|
135
|
+
{ type: 'payment_account', payment_account: { identifier_value: '[NUMERO_PLIN]' } }
|
|
136
|
+
];
|
|
137
|
+
withPlaceholder.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson = JSON.stringify(withPlaceholderParams);
|
|
138
|
+
prepareNativeFlowMessageForRelay(withPlaceholder);
|
|
139
|
+
withPlaceholderParams = JSON.parse(withPlaceholder.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
140
|
+
check(withPlaceholderParams.payment_settings.length === 3, 'placeholder payment account should be removed');
|
|
141
|
+
check(withPlaceholderParams.payment_settings.every(entry => !/\[[^\]]+\]/.test(entry.payment_account.identifier_value)), 'valid payment accounts should be preserved');
|
|
142
|
+
check(isPlaceholderPaymentIdentifier('[NUMERO_PLIN]'), 'the reported PLIN marker should be recognized');
|
|
143
|
+
check(!isPlaceholderPaymentIdentifier('51987654321'), 'a concrete identifier should not be treated as a placeholder');
|
|
144
|
+
|
|
145
|
+
// The helper must also remove placeholders before constructing the raw Native Flow JSON.
|
|
146
|
+
const helperPayload = await buildReviewAndPayMessage({
|
|
147
|
+
currency: 'PEN',
|
|
148
|
+
referenceId: 'KAGE_TEST_HELPER',
|
|
149
|
+
items: [{ name: 'Producto', amount: { value: 500, offset: 100 }, quantity: 1 }],
|
|
150
|
+
paymentAccounts: [
|
|
151
|
+
{ payment_account: { identifier_value: '[NUMERO_PLIN]' } },
|
|
152
|
+
{ payment_account: { identifier_value: 'test-account-valid' } }
|
|
153
|
+
]
|
|
154
|
+
});
|
|
155
|
+
const helperParams = JSON.parse(helperPayload.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
156
|
+
check(helperParams.payment_settings.length === 1, 'payment helper should drop placeholder entries and keep valid entries');
|
|
157
|
+
|
|
158
|
+
// A malformed account with no identifier remains a hard error; only explicit template markers are filtered.
|
|
159
|
+
const missingIdentifier = makeMessage();
|
|
160
|
+
let missingIdentifierParams = JSON.parse(missingIdentifier.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
161
|
+
missingIdentifierParams.payment_settings = [{ payment_account: {} }];
|
|
162
|
+
missingIdentifier.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson = JSON.stringify(missingIdentifierParams);
|
|
163
|
+
assert.throws(() => prepareNativeFlowMessageForRelay(missingIdentifier), /requires payment_account.identifier_value/);
|
|
164
|
+
checks += 1;
|
|
165
|
+
|
|
166
|
+
console.log(`Native Flow payment validation: ${checks} checks passed.`);
|
|
167
|
+
|
|
@@ -74,8 +74,8 @@ assert.match(send, /getBizBinaryNode\(relayContent\)/,
|
|
|
74
74
|
'Native Flow relay must attach the biz companion node');
|
|
75
75
|
assert.match(send, /native_flow_name|order_details/,
|
|
76
76
|
'Native Flow relay must support order_details mapping');
|
|
77
|
-
assert.match(pay, /
|
|
78
|
-
'review_and_pay must
|
|
77
|
+
assert.match(pay, /normalizeReviewAndPayAmounts\(result\)/,
|
|
78
|
+
'review_and_pay helper must reconcile total/subtotal against order lines');
|
|
79
79
|
assert.match(pay, /placeholder/,
|
|
80
80
|
'review_and_pay must reject placeholder payment identifiers');
|
|
81
81
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { isPlaceholderPaymentIdentifier, prepareNativeFlowMessageForRelay } from '../lib/Utils/native-flow.js';
|
|
3
|
+
|
|
4
|
+
const amount = { value: 500, offset: 100 };
|
|
5
|
+
const params = {
|
|
6
|
+
currency: 'PEN',
|
|
7
|
+
reference_id: 'KAGE_PLACEHOLDER_REGRESSION',
|
|
8
|
+
type: 'physical-goods',
|
|
9
|
+
total_amount: amount,
|
|
10
|
+
order: {
|
|
11
|
+
subtotal: amount,
|
|
12
|
+
items: [{ name: 'Producto de prueba', amount, quantity: 1 }]
|
|
13
|
+
},
|
|
14
|
+
payment_settings: [
|
|
15
|
+
{ type: 'payment_account', payment_account: { identifier_value: 'test-bank-001' } },
|
|
16
|
+
{ type: 'payment_account', payment_account: { identifier_value: 'test-bank-002' } },
|
|
17
|
+
{ type: 'payment_account', payment_account: { identifier_value: 'test-bank-003' } },
|
|
18
|
+
{ type: 'payment_account', payment_account: { identifier_value: '[NUMERO_PLIN]' } }
|
|
19
|
+
]
|
|
20
|
+
};
|
|
21
|
+
const message = { interactiveMessage: { nativeFlowMessage: { buttons: [{ name: 'review_and_pay', buttonParamsJson: JSON.stringify(params) }] } } };
|
|
22
|
+
prepareNativeFlowMessageForRelay(message);
|
|
23
|
+
const result = JSON.parse(message.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
24
|
+
assert.equal(result.payment_settings.length, 3);
|
|
25
|
+
assert.deepEqual(result.payment_settings.map(item => item.payment_account.identifier_value), ['test-bank-001', 'test-bank-002', 'test-bank-003']);
|
|
26
|
+
assert.equal(isPlaceholderPaymentIdentifier('[NUMERO_PLIN]'), true);
|
|
27
|
+
assert.equal(isPlaceholderPaymentIdentifier('NUMERO_PLIN'), true);
|
|
28
|
+
assert.equal(isPlaceholderPaymentIdentifier('51987654321'), false);
|
|
29
|
+
|
|
30
|
+
const allPlaceholders = structuredClone(params);
|
|
31
|
+
allPlaceholders.payment_settings = [{ payment_account: { identifier_value: '[NUMERO_PLIN]' } }];
|
|
32
|
+
const allPlaceholderMessage = { interactiveMessage: { nativeFlowMessage: { buttons: [{ name: 'review_and_pay', buttonParamsJson: JSON.stringify(allPlaceholders) }] } } };
|
|
33
|
+
prepareNativeFlowMessageForRelay(allPlaceholderMessage);
|
|
34
|
+
const allPlaceholderResult = JSON.parse(allPlaceholderMessage.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson);
|
|
35
|
+
assert.deepEqual(allPlaceholderResult.payment_settings, []);
|
|
36
|
+
|
|
37
|
+
const malformed = structuredClone(params);
|
|
38
|
+
malformed.payment_settings = [{ payment_account: {} }];
|
|
39
|
+
const malformedMessage = { interactiveMessage: { nativeFlowMessage: { buttons: [{ name: 'review_and_pay', buttonParamsJson: JSON.stringify(malformed) }] } } };
|
|
40
|
+
assert.throws(() => prepareNativeFlowMessageForRelay(malformedMessage), /requires payment_account.identifier_value/);
|
|
41
|
+
|
|
42
|
+
console.log('Placeholder payment-account regression: 7 assertions passed.');
|