kage-baileys 25.4.18 → 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 +4 -4
- package/helpers/interactive-pay.js +7 -7
- package/lib/Utils/interactive-compat.cjs +13 -0
- package/lib/Utils/native-flow.d.ts +2 -0
- package/lib/Utils/native-flow.js +24 -6
- package/package.json +5 -4
- package/scripts/verify-native-flow-payments.mjs +43 -1
- 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` 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.
|
|
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
|
|
|
@@ -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` 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.
|
|
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 { normalizeReviewAndPayAmounts, 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) {
|
|
@@ -212,6 +212,19 @@ function createKageOrderDetails(parameters) {
|
|
|
212
212
|
if (expectedTotal <= 0n || expectedTotal > BigInt(Number.MAX_SAFE_INTEGER)) throw new RangeError('El total calculado está fuera del rango permitido');
|
|
213
213
|
if (total !== expectedTotal && strict) throw new TypeError('El total no coincide con subtotal + impuestos + envío - descuento');
|
|
214
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
|
+
}
|
|
215
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');
|
|
216
229
|
// Defaults útiles para review_and_pay
|
|
217
230
|
if (!p.payment_type) p.payment_type = 'upi';
|
|
@@ -15,3 +15,5 @@ export declare function parseNativeFlowButton(button: { name?: string; buttonPar
|
|
|
15
15
|
|
|
16
16
|
export declare function normalizeReviewAndPayAmounts<T extends Record<string, unknown>>(params: T, options?: { strict?: boolean }): T;
|
|
17
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);
|
|
@@ -314,18 +326,24 @@ export function prepareNativeFlowMessageForRelay(input) {
|
|
|
314
326
|
if (params.payment_settings != null && !Array.isArray(params.payment_settings)) {
|
|
315
327
|
throw new TypeError('review_and_pay payment_settings must be an array');
|
|
316
328
|
}
|
|
329
|
+
|
|
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
|
+
});
|
|
339
|
+
}
|
|
340
|
+
|
|
317
341
|
for (const [accountIndex, entry] of (params.payment_settings ?? []).entries()) {
|
|
318
342
|
const account = entry?.payment_account ?? entry?.paymentAccount;
|
|
319
343
|
const identifier = account?.identifier_value ?? account?.identifierValue;
|
|
320
344
|
if (typeof identifier !== 'string' || !identifier.trim()) {
|
|
321
345
|
throw new TypeError(`payment_settings[${accountIndex}] requires payment_account.identifier_value`);
|
|
322
346
|
}
|
|
323
|
-
if (/^\[[^\]]+\]$/.test(identifier.trim())) {
|
|
324
|
-
throw new TypeError(`payment_settings[${accountIndex}] still contains a placeholder identifier (${identifier}); replace it with a valid value or remove that payment account`);
|
|
325
|
-
}
|
|
326
|
-
if (/^\[[^\]]+\]$/.test(identifier.trim())) {
|
|
327
|
-
throw new TypeError(`payment_settings[${accountIndex}] still contains a placeholder identifier; remove it or replace it with a valid provider value`);
|
|
328
|
-
}
|
|
329
347
|
}
|
|
330
348
|
|
|
331
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, normalized Native Flow payment totals, and expanded WAProto compatibility",
|
|
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"
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"README.md",
|
|
26
26
|
"LICENSE",
|
|
27
27
|
"VALIDATION-REPORT-25.4.15.md",
|
|
28
|
-
"VALIDATION-REPORT-25.4.16.md"
|
|
28
|
+
"VALIDATION-REPORT-25.4.16.md",
|
|
29
|
+
"VALIDATION-REPORT-25.4.17.md"
|
|
29
30
|
],
|
|
30
31
|
"scripts": {
|
|
31
32
|
"build:all": "npm run check",
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
"gen:protobuf": "sh WAProto/GenerateStatics.sh",
|
|
38
39
|
"lint": "node ./scripts/verify-package.mjs",
|
|
39
40
|
"release": "release-it",
|
|
40
|
-
"test": "node ./scripts/verify-pairing-flow.mjs && node ./scripts/verify-native-flow-payments.mjs"
|
|
41
|
+
"test": "node ./scripts/verify-pairing-flow.mjs && node ./scripts/verify-native-flow-payments.mjs && node ./scripts/verify-placeholder-payment-accounts.mjs"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"@adiwajshing/keyed-db": "^0.2.4",
|
|
@@ -2,8 +2,10 @@ import assert from 'node:assert/strict';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import {
|
|
4
4
|
normalizeReviewAndPayAmounts,
|
|
5
|
-
prepareNativeFlowMessageForRelay
|
|
5
|
+
prepareNativeFlowMessageForRelay,
|
|
6
|
+
isPlaceholderPaymentIdentifier
|
|
6
7
|
} from '../lib/Utils/native-flow.js';
|
|
8
|
+
import { buildReviewAndPayMessage } from '../helpers/interactive-pay.js';
|
|
7
9
|
|
|
8
10
|
const require = createRequire(import.meta.url);
|
|
9
11
|
const { createKageOrderDetails } = require('../lib/Utils/interactive-compat.cjs');
|
|
@@ -122,4 +124,44 @@ const legacyParams = JSON.parse(legacy.buttonParamsJson);
|
|
|
122
124
|
check(legacyParams.total_amount.value === 138, 'CJS compatibility builder should normalize total_amount');
|
|
123
125
|
check(legacyParams.order.subtotal.value === 138, 'CJS compatibility builder should normalize subtotal');
|
|
124
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
|
+
|
|
125
166
|
console.log(`Native Flow payment validation: ${checks} checks passed.`);
|
|
167
|
+
|
|
@@ -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.');
|