Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

daugaard47's avatar

For Hire: Add Stripe Transaction Fees to Variable Amount Entered

I have a very small project I’m trying to complete, but stuck on a JS section. Willing to pay by PayPal. (Normally I would try and figure it out, but don't have the time at the moment and need to move forward with the project.)

It’s for a donation system. I need to give the donor the ability to GIFT the Stripe / PayPal transaction fees so the non-profit gets 100% of the donation.

I have the fees formula pieced together, but need help adding the fees to the total amount / variable amount being donated.

Here is the JSFiddle Please review. All is explained in the Fiddle.

Here is the code, so you can see what you're working with.

HTML:

<div class="input-field-container">
  <span>$</span>
  <input type="number" min="1.00" max="200000.00" step="0.01" value="60" id="other_amount" name="other_amount" class="p-goal">
  <span>USD</span>
</div>



  <input type="hidden" id="f-fixed" type="number" value="0.30">

  <input type="hidden" id="f-percent" type="number" value="2.9">

 
<p>Would you like to gift the transaction fee $<input size='5' id="p-charge" type="number" disabled>
  <br>so we can recieve 100% of your donation?
  <br>
  <input type="checkbox" value="yes" name="yes" /> Check box for yes
</p>

JS:

var Pgoal = document.querySelector('.p-goal');
var Ffixed = document.querySelector('#f-fixed');
var Fpercent = document.querySelector('#f-percent');
var Pcharge = document.querySelector('#p-charge');

function f(n) {
  return Number((+n).toFixed(10));
}

function calcPcharge(goal, fixed, percent) {
  return (goal + fixed) / (1 - percent);
}

function update() {
  var charge = calcPcharge(f(Pgoal.value), f(Ffixed.value), f(Fpercent.value / 100));
  Pcharge.value = (charge || 0).toFixed(2);
}

[].forEach.call(document.querySelectorAll('input'), function() {
  this.addEventListener('input', update);
});

0 likes
0 replies

Please or to participate in this conversation.