const fs = require('fs');
const path = require('path');
const moment = require('moment');
const log = require('loglevel');

const constants = require('../models/constants');
const constantsXml = require('../models/constants-xml');
const enums = require('../models/enums');
const enumsXml = require('../models/enums-xml');

const PaymentGatewayServ = require('../services/payment-gateway');

class PaymentGatewayCtrl {
    constructor () {
        this.service = new PaymentGatewayServ();
    }

    checkout = async (req, res) => {
        try {
            const checkout = req.body;

            const checkoutData = {
                transaction_type: 'C200',
                transaction_amount: (checkout.amount * Math.pow(10, global.currentPosData.currencyDecimal)).toString().padStart(12, '0'),
                command_identifier: checkout.commandId
            };

            let checkoutResponse = await this.service.checkout(checkoutData);

            res.status(200).json(checkoutResponse);
        } catch (err) {
            log.error(err);
            res.status(400).json({ error: err.message });
        }
    }

}

module.exports = PaymentGatewayCtrl;
