transferbalance.js
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const CORE_ENDPOINT = '/stores/transfer-balance';
const common = require('../common');
const commandError = require('./error');
const coreapi = require('../coreapi');
function help(keyword) {
return `
Untuk transfer saldo ke downline, ketik perintah dengan format:
${keyword.toUpperCase()}.#<IDDOWNLINE>.<JUMLAH>.<PIN>
atau
${keyword.toUpperCase()}.<TERMINALDOWNLINE>.<JUMLAH>.<PIN>
`.trim();
}
function execute(tokens, params, cb) {
if (!tokens || tokens.length < 4) {
const responseParams = {
body: `
${commandError.ERR_INVALID_FORMAT}: ${params.msg}
${ help(tokens[0]) }`.trim(),
}
cb(null, null, responseParams);
return;
}
let destinationStoreId;
let destinationTerminalName;
if (tokens[1].indexOf('#') === 0) {
destinationStoreId = tokens[1].replace(/^#/, '');
} else {
destinationTerminalName = tokens[1];
}
const coreParams = {
asker_terminal_name: params.from,
destination_store_id: destinationStoreId,
destination_terminal_name: destinationTerminalName,
amount: tokens[2],
asker_terminal_password: tokens[3],
additional_note: tokens.slice(4).join(' ') || '',
origin: params.origin
};
if (typeof coreParams.destination_terminal_name === 'string' && common.isPhoneNumber(coreParams.destination_terminal_name) && coreParams.destination_terminal_name.indexOf('0') === 0) {
coreParams.destination_terminal_name = coreParams.destination_terminal_name.replace(/^0/, '62');
}
coreapi(CORE_ENDPOINT, coreParams, 'GET', cb);
}
module.exports = execute;