102 lines
2.8 KiB
JavaScript
102 lines
2.8 KiB
JavaScript
import axios from "axios";
|
|
import dotenv from "dotenv"
|
|
import Bvn from "../model/bvnModel.js";
|
|
import https from "https";
|
|
export const deposit = async (req, res)=>{
|
|
try{
|
|
console.log("TRNS** STARTED REQ-----------------------------------------");
|
|
// console.log(req.body);
|
|
// console.log("BVN REQ=========================================");
|
|
|
|
|
|
const params = JSON.stringify({
|
|
"source": "balance",
|
|
"reason": "Calm down",
|
|
"amount":3700,
|
|
"recipient": "RCP_iycuaxuhxluj8o7"
|
|
})
|
|
|
|
const SECRET = "sk_test_e880ee5f37602e3f5d8703b1a691f3f800fcea68";
|
|
const options = {
|
|
hostname: 'api.paystack.co',
|
|
port: 443,
|
|
path: '/transfer',
|
|
method: 'POST',
|
|
headers: {
|
|
Authorization: `Bearer ${SECRET}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
}
|
|
|
|
const req = https.request(options, res => {
|
|
let data = ''
|
|
|
|
res.on('data', (chunk) => {
|
|
data += chunk
|
|
});
|
|
|
|
res.on('end', () => {
|
|
console.log(JSON.parse(data))
|
|
})
|
|
}).on('error', error => {
|
|
console.error(error)
|
|
})
|
|
|
|
req.write(params)
|
|
req.end()
|
|
res.status(200).json({result: "Transfer Result"});
|
|
|
|
}catch(error){
|
|
res.status(500).json({error: "Internal Server error"});
|
|
}
|
|
}
|
|
|
|
export const recipient = async (req, res)=>{
|
|
try{
|
|
console.log("TRNS** STARTED REQ-----------------------------------------");
|
|
// console.log(req.body);
|
|
// console.log("BVN REQ=========================================");
|
|
|
|
const params = JSON.stringify({
|
|
"type": "nuban",
|
|
"name": "Tolulope Robert",
|
|
"account_number": "0148618731",
|
|
"bank_code": "058",
|
|
"currency": "NGN"
|
|
})
|
|
const SECRET = "sk_test_e880ee5f37602e3f5d8703b1a691f3f800fcea68";
|
|
const options = {
|
|
hostname: 'api.paystack.co',
|
|
port: 443,
|
|
path: '/transferrecipient',
|
|
method: 'POST',
|
|
headers: {
|
|
Authorization: `Bearer ${SECRET}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
}
|
|
|
|
const req = https.request(options, res => {
|
|
let data = ''
|
|
|
|
res.on('data', (chunk) => {
|
|
data += chunk
|
|
});
|
|
|
|
res.on('end', () => {
|
|
console.log(JSON.parse(data))
|
|
})
|
|
}).on('error', error => {
|
|
console.error(error)
|
|
})
|
|
|
|
req.write(params)
|
|
req.end()
|
|
|
|
|
|
res.status(200).json({result: "Transfer Result"});
|
|
|
|
}catch(error){
|
|
res.status(500).json({error: "Internal Server error"});
|
|
}
|
|
} |