partner.js 1.03 KB
"use strict";

const moment = require('moment');

const pull = require('./pull');
const logger = require('./logger').get();

var config;
var matrix;

function init(options) {
    config = options.config;
    matrix = options.matrix;
}

function _buy(task) {
    let destination = Number(task.destination);
    if (destination % 2) {
        let msg = 'Isi ' + task.remote_product + ' ke ' + task.destination + ' gagal karena nomor tujuan ganjil';
        pull.report(task.trx_id, '14', msg);
    } else {
        let sn = moment().format('YYYYMMDDHHmmssSSS')
        let msg = 'Isi ' + task.remote_product + ' ke ' + task.destination + ' berhasil karena nomor tujuan genap dengan SN=' + sn;
        pull.report(task.trx_id, '00', msg, sn);
    }
}

function buy(_task) {
    let task = JSON.parse(JSON.stringify(_task));

    logger.verbose('Buy on partner', {task: task});
    setTimeout(
        function() {
            _buy(task);
        },
        (config.max_result_timeout_ms || 2000) * Math.random()
    )
}

exports.init = init;
exports.buy = buy;