Skip to content

Instantly share code, notes, and snippets.

@ochui
Last active October 10, 2023 09:04
Show Gist options
  • Save ochui/ca968854f67dc450bfca999bd2154f9d to your computer and use it in GitHub Desktop.
Save ochui/ca968854f67dc450bfca999bd2154f9d to your computer and use it in GitHub Desktop.
fees.js
let transactionAmount = 100000
let amountPaid = 1000
// Parse the percentage fee from the environment variable
const escrowFeePercentage = 5;
let expected_fee = transactionAmount * (escrowFeePercentage / 100);
console.log("Expected fee: ", expected_fee);
let fee_from_amount_paid = amountPaid - transactionAmount;
console.log("Fee paid: ", fee_from_amount_paid);
let amount_to_pay = amountPaid - fee_from_amount_paid;
if (fee_from_amount_paid >= expected_fee) {
amount_to_pay = amountPaid - expected_fee;
}
if (fee_from_amount_paid < expected_fee) {
let fee_balance_amount_paid = expected_fee - fee_from_amount_paid;
console.log("Unpaid Fee: ", fee_balance_amount_paid);
// let fee_balance_amount_paid_percentage = (fee_balance_amount_paid / 100) * transactionAmount;
// console.log("Fee balance from amount paid percentage: ", fee_balance_amount_paid_percentage);
// let fee_from_amount_paid_percentage = (fee_from_amount_paid / 100) * transactionAmount;
// console.log("Fee from amount paid percentage: ", fee_from_amount_paid_percentage);
// let total_fee_percentage = fee_balance_amount_paid_percentage + fee_from_amount_paid_percentage;
// console.log("Total fee percentage: ", total_fee_percentage);
// amount_to_pay = (amountPaid - fee_from_amount_paid) - fee_balance_amount_paid_percentage
amount_to_pay = amountPaid - fee_balance_amount_paid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment