Skip to content

Commit

Permalink
Payment: Moved Keys to separate file, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaykrishna1203 committed Oct 6, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9a59fd0 commit c5a5add
Showing 19 changed files with 14 additions and 205 deletions.
21 changes: 0 additions & 21 deletions functions/model/application/lib.js
Original file line number Diff line number Diff line change
@@ -158,7 +158,6 @@ exports.checkUpdateTime = function(lastUpdated) {
// for 1 day difference - 86400000
const currentTimeStamp = Date.now();
const diff = currentTimeStamp - lastUpdated;
console.log(currentTimeStamp, "-", lastUpdated, " = ", diff);
if (diff >= 60) {
return currentTimeStamp;
}
@@ -201,23 +200,3 @@ const today = new Date();
exports.currentDate = today.getFullYear()+"-"+(today.getMonth()+1)+"-"+today.getDate();
exports.currentTime = today.getHours()+"-"+today.getMinutes()+"-"+today.getSeconds();
exports.milliSeconds = today.getMilliseconds();

// const base62 = {
// charset: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// .split(""),
// encode: (integer) => {
// if (integer === 0) {
// return 0;
// }
// let s = [];
// while (integer > 0) {
// s = [base62.charset[integer % 62], ...s];
// integer = Math.floor(integer / 62);
// }
// return s.join("");
// },
// };

// exports.generateBase62Constant = function() {
// return base62.encode(milliSeconds);
// };
2 changes: 0 additions & 2 deletions functions/model/filters/lib.js
Original file line number Diff line number Diff line change
@@ -54,7 +54,6 @@ exports.setFilterProperties = function(orgDomain, teamName, docId, filterName, d
* @return {any}
*/
exports.getFilterById = function(orgDomain, teamName, docId) {
console.log(orgDomain, teamName, docId);
const getFilterById = db.collection("Organizations").doc(orgDomain).collection("Teams").doc(teamName).collection("CustomFilter").doc(docId).get().then((doc) => {
const data = doc.data();
return data;
@@ -70,7 +69,6 @@ exports.getFilterById = function(orgDomain, teamName, docId) {
* @return {any}
*/
exports.getFilters = function(orgDomain, teamName) {
console.log(orgDomain, teamName);
const getFilterPromise = db.collection("Organizations").doc(orgDomain).collection("Teams").doc(teamName).collection("CustomFilter").where("Status", "==", "OK").get().then((doc) => {
const data = [];
doc.forEach((filter) => {
2 changes: 0 additions & 2 deletions functions/model/meet/lib.js
Original file line number Diff line number Diff line change
@@ -132,10 +132,8 @@ exports.updateMeetDetails= function(updateJson) {
exports.getMeetDetails=function(uid) {
const query = db.collection("Users").doc(uid).collection("Meet");

// query = query.where("HostName", "==", "OK");
const promise = query.get().then((doc) => {
const data=[];
// console.log(doc);
doc.forEach((element) => {
if (element.exists) {
data.push( element.data());
3 changes: 1 addition & 2 deletions functions/model/milestone/lib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable valid-jsdoc */
/* eslint-disable linebreak-style */
/* eslint-disable valid-jsdoc */
/* eslint-disable object-curly-spacing */
/* eslint-disable eol-last */
/* eslint-disable indent */
@@ -109,7 +109,6 @@ exports.getAllMilestonesData = function(orgDomain, teamId="") {
* @return
*/
exports.addTask = function(milestoneId, taskId, orgDomain) {
console.log(milestoneId, taskId, orgDomain);
const promise =db.collection("Organizations").doc(orgDomain).collection("Tasks").doc(taskId).update({
MilestoneId: milestoneId,
});
1 change: 0 additions & 1 deletion functions/model/milestone/tark/addTask.js
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ const { addTask } = require("../lib");
* @return {any}
*/
exports.addTaskToMilestone = function(request, response) {
console.log( request.body.data);
const uid = request.body.data.Uid;
const milestoneId = request.body.data.MilestoneId;
const taskId = request.body.data.TaskId;
1 change: 0 additions & 1 deletion functions/model/organization/tark/changeMemberRole.js
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@
const {updateMember} = require("../lib");

exports.editRole = function(request, response) {
console.log("Reached here");
const orgDomain = request.body.data.OrgDomain;
const email = request.body.data.Email;
const isAdmin = request.body.data.IsAdmin;
69 changes: 0 additions & 69 deletions functions/model/payment/lib.js
Original file line number Diff line number Diff line change
@@ -19,30 +19,6 @@

const { db } = require("../application/lib");
const { currentTime, currentDate } = require("../application/lib");
// /**
// * Description
// * @param {any} amount
// * @param {any} userUid
// * @param {any} subscriptionId
// * @param {any} paymentId
// * @param {any} userEmailAddress
// * @param {any} paymentTime
// * @param {any} paymentDate
// * @return {any}
// */
// exports.setPayment = function(amount, userUid, subscriptionId, paymentId, userEmailAddress, paymentTime, paymentDate) {
// const addPaymentPromise = db.collection("Subscriptions").doc(orgDomain).collection("Payment").set({
// UserEmailAddress: userEmailAddress,
// Amount: amount,
// PaymentId: paymentId,
// PaymentCounter: 0,
// PaymentTime: paymentTime,
// PaymentDate: paymentDate,
// SubscriptionId: subscriptionId,
// UserUid: userUid,
// });
// return Promise.resolve(addPaymentPromise);
// };

const base62 = {
charset: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -72,7 +48,6 @@ exports.generatePaymentId = function() {
return "Pay" + base62.encode(miliSec);
};

// eslint-disable-next-line require-jsdoc

/**
* Description
@@ -97,30 +72,15 @@ exports.setRazorpayOrderDetails = function(uid, order, paymentId, subscriptionId
return Promise.resolve(p1);
};

// /**
// * Description
// * @param {any} Id
// * @param {any} order
// * @return {any}
// */
// exports.setEcommerceRazorDetails = function(Id, order) {
// const p1 = db.collection("Orders").doc(Id).update({
// RazorPayOrderDetails: order,
// });
// return Promise.resolve(p1);
// };

exports.setPaymentStatus = function(subscriptionId, paymentId) {
console.log("subscriptionId", subscriptionId);
console.log("paymentId", paymentId);
let data;

const p1 = db.collection("Subscriptions").doc(subscriptionId).collection("Payment").doc(paymentId).get().then((doc)=>{
data = doc.data();
data.RazorPayOrderDetails.amount_paid = data.RazorPayOrderDetails.amount_due;
data.RazorPayOrderDetails.amount_due = 0;
data.RazorPayOrderDetails.status = "paid";
console.log(currentTime, currentDate);
});
Promise.resolve(p1).then(()=>{
const promise = db.collection("Subscriptions").doc(subscriptionId).collection("Payment").doc(paymentId).update({
@@ -129,35 +89,6 @@ exports.setPaymentStatus = function(subscriptionId, paymentId) {
PaymentCreationTime: currentTime,
RazorPayOrderDetails: data.RazorPayOrderDetails,
});
// mailer(data.UserUid, "Payment_Complete", paymentId);
return Promise.resolve(promise);
});
};

// exports.setEcommercePaymentStatus = function(id) {
// console.log("reg id", id);
// let data;

// const p1 = db.collection("Orders").doc(id).get().then((doc)=>{
// data = doc.data();
// data.RazorPayOrderDetails.amount_paid = data.RazorPayOrderDetails.amount_due;
// data.RazorPayOrderDetails.amount_due = 0;
// data.RazorPayOrderDetails.status = "paid";
// });
// Promise.resolve(p1).then(()=>{
// const promise = db.collection("Orders").doc(id).update({
// PaymentStatus: "Complete",
// RazorPayOrderDetails: data.RazorPayOrderDetails,
// });
// mailer(data.UserUid, "Payment_Complete", id);
// return Promise.resolve(promise);
// });
// };

// exports.gerOrderData = function(paymentId) {
// const promise = db.collection("Subscriptions").doc(orgDomain).collection("Payment").doc(paymentId).get().then((doc)=>{
// if (doc.exists) return doc.data();
// else return;
// });
// return Promise.resolve(promise);
// };
16 changes: 4 additions & 12 deletions functions/model/payment/tark/generateRazorpayOrder.js
Original file line number Diff line number Diff line change
@@ -9,22 +9,16 @@ const { standardSubscription } = require("../../application/lib");
const { getSubscriptions } = require("../../subscriptions/lib");
const { setRazorpayOrderDetails, generateBase62Constant, generatePaymentId} = require("../lib");
const { currentTime, currentDate } = require("../../application/lib");

const { keyId, keySecret, orderKey} = require("../../../paymentKeys");
exports.generateRazorpayOrder = function(request, response) {
const Uid = request.body.data.Uid;
const SubscriptionId = request.body.data.SubscriptionId;
console.log("Uid", Uid);
console.log("SubscriptionId", SubscriptionId);
// const OrgDomain = request.body.data.OrgDomain;
getSubscriptions("", SubscriptionId).then((doc) => {
console.log(doc);
if (doc != undefined) {
// Test Credentials
console.log(doc);
const amount = standardSubscription.amount;
const razorpay = new RazorPay({
key_id: "rzp_test_nfhDfN6X5cgp42",
key_secret: "EjWL1pPedHeT4Z1C4laM3u1b",
key_id: keyId,
key_secret: keySecret,
});


@@ -47,17 +41,15 @@ exports.generateRazorpayOrder = function(request, response) {
// RazorPayOrderDetails: order,
// });
const paymentId = generatePaymentId();
console.log(paymentId);
const time = currentTime;
const date = currentDate;
setRazorpayOrderDetails(Uid, order, paymentId, SubscriptionId, date, time);
// Test credentials
order.key = "rzp_test_nfhDfN6X5cgp42";
order.key = orderKey;

order.receipt = generatedReceipt;
order.paymentId = paymentId;
const result = { data: order };
console.log(result);
return response.status(200).send(result);
});
}
19 changes: 3 additions & 16 deletions functions/model/payment/tark/paymentVerification.js
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ const crypto = require("crypto");
const { setPaymentStatus } = require("../lib");
const { standardSubscription, currentDate } = require("../../application/lib");
const { updateSubscription, getSubscriptions } = require("../../subscriptions/lib");
const { keySecret } = require("../../../paymentKeys");
exports.paymentVerification = function(request, response) {
try {
const orderId = request.body.data.OrderId;
@@ -29,27 +30,13 @@ exports.paymentVerification = function(request, response) {
const id = request.body.data.Id; // Subscription Id
const type = request.body.data.Type;
const paymentId = request.body.data.PId;

console.log("orderId: " + orderId);
console.log("rzpPaymentId: " + rzpPaymentId);
console.log("signature: " + signature);
console.log("Id: " + id);
console.log("type", type);
console.log("PaymentId", paymentId);

// Test Credentials
const keySecret = "EjWL1pPedHeT4Z1C4laM3u1b";

console.log("hit 1");
const secretKey = keySecret;
let generatedSignature = "";
generatedSignature = crypto.createHmac("sha256", keySecret).update((orderId + "|" + rzpPaymentId).toString()).digest("hex");

console.log("generated signature ", generatedSignature);
generatedSignature = crypto.createHmac("sha256", secretKey).update((orderId + "|" + rzpPaymentId).toString()).digest("hex");

if (generatedSignature === signature) {
const result = { data: "Payment verified successfully", status: 200 };
console.log("Payment successful");
console.log();
getSubscriptions("", id).then((data)=>{
let date;
if (data.ExpiresOn == "No limit") {
Original file line number Diff line number Diff line change
@@ -68,7 +68,6 @@ exports.getPerformanceChartData = function(request, response) {
responseData.push([i, doc[i]]);
}
}
console.log(responseData);
result = { data: { status: "OK", data: responseData } };
}
});
Original file line number Diff line number Diff line change
@@ -30,9 +30,7 @@ exports.updateSprintEvaluationGraphData = function(orgDomain, teamId, sprintId)
const inputJson = {};
const p1 = getTeamUseTeamId(orgDomain, teamId).then((data)=>{
const teamName = data.TeamName;
console.log(orgDomain, teamId, sprintId);
const p = getSprint(orgDomain, teamName, sprintId).then((sprintDoc) => {
console.log(sprintDoc);
storyPointArray = [parseInt(sprintDoc.StartStoryPoint), parseInt(sprintDoc.MidStoryPoint), parseInt(sprintDoc.EndStoryPoint)];
inputJson[sprintId] = storyPointArray;
const promise = getOrganizationsChartDetails(orgDomain, teamName, "SprintEvaluationGraph").then((data) => {
3 changes: 1 addition & 2 deletions functions/model/requestDemo/lib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-unused-vars */
/* eslint-disable linebreak-style */
/* eslint-disable no-unused-vars */
/* eslint-disable object-curly-spacing */
/* eslint-disable eol-last */
/* eslint-disable indent */
@@ -61,7 +61,6 @@ exports.getDemoRequestData = function() {
if (doc.exists) {
return doc.data();
} else {
console.log("else triggered");
return;
}
});
3 changes: 1 addition & 2 deletions functions/model/requestDemo/requestDemo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-unused-vars */
/* eslint-disable linebreak-style */
/* eslint-disable no-unused-vars */
/* eslint-disable object-curly-spacing */
/* eslint-disable eol-last */
/* eslint-disable indent */
@@ -28,7 +28,6 @@ const {addRequest} = require("./tark/addRequest");
* @returns {any}
*/
fastify.post("/addRequest", (req, res) => {
console.log("requestDemo triggered");
addRequest(req, res);
});

1 change: 0 additions & 1 deletion functions/model/socialPage/tark/deleteComment.js
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ exports.deleteComment = function(request, response) {
const uid = request.body.data.Uid;
const postId = request.body.data.PostId;
const commentId = request.body.data.CommentId;
console.log(postId, commentId);

let result;
let status = 200;
Loading

0 comments on commit c5a5add

Please sign in to comment.