Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-Platform Chimoney Wallet #470

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions submissions/Cross-Platform-Wallet-Bot/chimoney/createWallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const axios = require("axios");
require('dotenv').config({ path: '../.env' });


async function createWallet(user_id) {
const CHIMONEY_BASE_URL = process.env.CHIMONEY_BASE_URL;

const url = `${CHIMONEY_BASE_URL}/multicurrency-wallets/create`;
const payload = { name: user_id };

const walResponse = await axios.post(url, payload, {
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"X-API-KEY": process.env.API_KEY
}
});

return walResponse.data;
}

module.exports = {
createWallet
};
37 changes: 37 additions & 0 deletions submissions/Cross-Platform-Wallet-Bot/chimoney/depositFund.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const axios = require("axios");
const fs = require("fs").promises;
require('dotenv').config({ path: '../.env' });


async function depositFund(accChiUid, amount) {
const CHIMONEY_BASE_URL = process.env.CHIMONEY_BASE_URL;

const url = `${CHIMONEY_BASE_URL}/multicurrency-wallets/transfer`;

const payload = {
amountToSend: amount,
originCurrency: "USD",
receiver: accChiUid,
destinationCurrency: "USD"
};


try {
const walResponse = await axios.post(url, payload, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"X-API-KEY": process.env.API_KEY,
},
});

return;
} catch (error) {
console.error("Error occurred:", error.response ? error.response.data : error.message);
throw error;
}
}

module.exports = {
depositFund,
};
66 changes: 66 additions & 0 deletions submissions/Cross-Platform-Wallet-Bot/chimoney/fundWallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const axios = require("axios");
const { platform } = require("os");
const fs = require("fs").promises;
require('dotenv').config({ path: '../.env' });


async function fundWallet(accChiUid, amount, firstName, userId, platform) {
const CHIMONEY_BASE_URL = process.env.CHIMONEY_BASE_URL;
const CHIMONEY_REDIRECT_URL = process.env.CHIMONEY_REDIRECT_URL;
const CHIMONEY_PAYMENT_EMAIL = process.env.CHIMONEY_PAYMENT_EMAIL;

const url = `${CHIMONEY_BASE_URL}/payment/initiate`;

const payload = {
valueInUSD: amount,
payerEmail: CHIMONEY_PAYMENT_EMAIL,
redirect_url: CHIMONEY_REDIRECT_URL,
// walletID: accChiUid,
narration: `Deposit of ${amount} by ${firstName}`,
// subAccount: accChiUid,
};


try {
const walResponse = await axios.post(url, payload, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"X-API-KEY": process.env.API_KEY,
},
});


const { id, valueInUSD, redeemData, issueID } = walResponse.data.data;

const transactionData = {
id,
amount: valueInUSD,
userId,
accChiId: accChiUid,
issueID,
platform: platform
};

let existingData = [];
try {
const data = await fs.readFile("transaction.json");
existingData = JSON.parse(data);
} catch (error) {
console.log("No existing transaction data found, starting fresh.");
}

existingData.push(transactionData);

await fs.writeFile("transaction.json", JSON.stringify(existingData, null, 2));

return walResponse.data;
} catch (error) {
console.error("Error occurred:", error.response ? error.response.data : error.message);
throw error;
}
}

module.exports = {
fundWallet,
};
30 changes: 30 additions & 0 deletions submissions/Cross-Platform-Wallet-Bot/chimoney/realName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const axios = require("axios");
require('dotenv').config({ path: '../.env' });


async function realName(accChiId, firstName, lastName) {
const CHIMONEY_BASE_URL = process.env.CHIMONEY_BASE_URL;

const url = `${CHIMONEY_BASE_URL}/multicurrency-wallets/update`;
const payload = {
"meta": { "newKey": "New Value" }, //I don't know what this is, but it's required
"id": accChiId,
"firstName": firstName,
"lastName": lastName
}
console.log(payload)

const walResponse = await axios.post(url, payload, {
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"X-API-KEY": process.env.API_KEY
}
});
console.log(walResponse.data);
return walResponse.data;
}

module.exports = {
realName
};
65 changes: 65 additions & 0 deletions submissions/Cross-Platform-Wallet-Bot/chimoney/sendFund.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const axios = require("axios");
const fs = require("fs").promises;
require('dotenv').config({ path: '../.env' });


async function sendFund(accChiUid, amount, receiverChiUid, platform, recId) {
const CHIMONEY_BASE_URL = process.env.CHIMONEY_BASE_URL;

const url = `${CHIMONEY_BASE_URL}/multicurrency-wallets/transfer`;


const payload = {
"sender": accChiUid,
"amountToSend": amount,
"originCurrency": "USD",
"destinationCurrency": "USD",
"receiver": receiverChiUid
}


try {
const walResponse = await axios.post(url, payload, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"X-API-KEY": process.env.API_KEY,
},
});




const { id, valueInUSD, redeemData, issueID } = walResponse.data.data;

const transactionData = {
id,
amount: amount,
userId: recId,
accChiId: "",
issueID,
platform: platform
};

let existingData = [];
try {
const data = await fs.readFile("transaction.json");
existingData = JSON.parse(data);
} catch (error) {
console.log("No existing transaction data found, starting fresh.");
}

existingData.push(transactionData);

await fs.writeFile("transaction.json", JSON.stringify(existingData, null, 2));

return;
} catch (error) {
console.error("Error occurred:", error.response ? error.response.data : error.message);
throw error;
}
}

module.exports = {
sendFund,
};
34 changes: 34 additions & 0 deletions submissions/Cross-Platform-Wallet-Bot/chimoney/updateBalance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const axios = require("axios");
const fs = require("fs").promises;
require('dotenv').config({ path: '../.env' });

async function updateBalance(accChiUid) {
const CHIMONEY_BASE_URL = process.env.CHIMONEY_BASE_URL;

const url = `${CHIMONEY_BASE_URL}/multicurrency-wallets/get?id=${accChiUid}`;

try {
const walResponse = await axios.get(url, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"X-API-KEY": process.env.API_KEY,
},
});

const jsonData = walResponse.data;

const chiWallet = jsonData.data.wallets.find(wallet => wallet.type === 'chi');
const chiBalance = chiWallet.balance;


return chiBalance;
} catch (error) {
console.error("Error occurred:", error.response ? error.response.data : error.message);
throw error;
}
}

module.exports = {
updateBalance,
};
Loading