I’ve got what you want, so think in this way:
- you have original price
- you want to calculate final transferAmount
that:
transferAmount = originalPrice + fee
but fee here depends on transferAmount
fee = transferAmount * 0.029 + 2.25
now solve it:
transferAmount = originalPrice + transferAmount * 0.029 + 2.25
transferAmount*(1-0.029) = originalPrice + 2.25
transferAmount = (originalPrice + 2.25) / (1-0.029)
in php:
$price = 10;
$total = ($price + 2.25) / (1.0 - 0.029); // 12.615859938208033
$fee = $total - $price; // 2.6158599382080325
now you can verify:
12.615... * 0.029 + 2.25 = 2.615...
ie, merchant will take 2.615...
as fee and result is 10
7
solved PHP: How to create a linear function, calculating a credit card fee? [closed]