const express = require('express');
// var https = require('follow-redirects').https;
const https= require('https');
const router = express.Router();
const request = require('request');
const bcrypt = require('bcryptjs');
var async = require('async');
const crypto = require('crypto');
var axios = require('axios');
const passport = require('passport');
// Load User model
const User = require('../models/User');
const Payment = require('../models/Payment');
const Contact = require('../models/Contact');


const { ensureAuthenticated, forwardAuthenticated } = require('../config/auth');

router.get('/airtime', (req, res)=>{
console.log('airtime')
var app_key = "103c193d-5425-42c9-8a93-b840e6b50670";
var app_token = "l4y0OhZ4xasFlwtjiVv6zJG8eC8YSBzT"
var rawNums = req.body.numbers;
var nums = rawNums.split(',');


for (let i = 0; i < nums.length; i++) {
var data = JSON.stringify({
  "recipients": [
    {
      "recipient": nums[i],
      "amount": 10
    }
  ]
});

var config = {
  method: 'post',
  url: 'https://quicksms.advantasms.com/api/v3/airtime/send',
  headers: { 
    'APP-Key': app_key, 
    'App-Token': app_token, 
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
.then(function (response) {
  // console.log(JSON.stringify(response.data));
  var res = JSON.stringify(response.data.message)


})

.catch(function (error) {
  console.log(error);
});
}
})

module.exports = router;