Commit 099ce6f7f6c9fe82be75f56daead1be96c654bc2
1 parent
273862fe58
Exists in
master
transferBalance handler
Showing 3 changed files with 40 additions and 1 deletions Side-by-side Diff
lib/command-handler/index.js
... | ... | @@ -14,6 +14,7 @@ const handlerListDownline = require('./listdownline'); |
14 | 14 | const handlerDownlineInfo = require('./downlineinfo'); |
15 | 15 | const handlerAddDownline = require('./adddownline'); |
16 | 16 | const handlerAddBalance = require('./addbalance'); |
17 | +const handlerTransferBalance = require('./transferbalance'); | |
17 | 18 | |
18 | 19 | function execute(msg, params, cb) { |
19 | 20 | |
... | ... | @@ -35,6 +36,9 @@ function execute(msg, params, cb) { |
35 | 36 | else if (commandGroup === 'addbalance') { |
36 | 37 | handlerAddBalance(tokens, params, cb); |
37 | 38 | } |
39 | + else if (commandGroup === 'transferbalance') { | |
40 | + handlerTransferBalance(tokens, params, cb); | |
41 | + } | |
38 | 42 | else if (commandGroup === 'price') { |
39 | 43 | handlerPrice(tokens, params, cb); |
40 | 44 | } |
lib/command-handler/transferbalance.js
... | ... | @@ -0,0 +1,35 @@ |
1 | +"use strict"; | |
2 | + | |
3 | +const commandError = require('./error'); | |
4 | +const coreapi = require('../coreapi'); | |
5 | + | |
6 | +const coreEndpoint = '/stores/transfer-balance'; | |
7 | + | |
8 | +function help(keyword) { | |
9 | + return `Untuk transfer saldo ke downline, ketik perintah dengan format: ${ keyword.toUpperCase() }.<IDDOWNLINE>.<JUMLAH>.<PIN>`; | |
10 | +} | |
11 | + | |
12 | +function execute(tokens, params, cb) { | |
13 | + | |
14 | + if (!tokens || tokens.length < 4) { | |
15 | + const responseParams = { | |
16 | + body: `${ commandError.ERR_INVALID_FORMAT }. ${ help(tokens[0]) }` | |
17 | + } | |
18 | + | |
19 | + cb(null, null, responseParams); | |
20 | + return; | |
21 | + } | |
22 | + | |
23 | + const coreParams = { | |
24 | + asker_terminal_name: params.from, | |
25 | + destination_store_id: tokens[1], | |
26 | + amount: tokens[2], | |
27 | + asker_terminal_password: tokens[3], | |
28 | + additional_note: tokens.slice(4).join(' ') || '', | |
29 | + origin: params.origin | |
30 | + }; | |
31 | + | |
32 | + coreapi(coreEndpoint, coreParams, 'GET', cb); | |
33 | +} | |
34 | + | |
35 | +module.exports = execute; | |
0 | 36 | \ No newline at end of file |