Merchant Fee Muncher (PHP Function)
Anyway, here's the code:
<?php
/*
Function Arguments
amount = Original transaction amount.
percent = Fee percentage taken by merchant per transaction.
fixed = Fixed rate amount taken by merchant per transcation.
nibble = Internal function use only!
*/
function fee_muncher($amount=100,$percent=2.9,$fixed=.3,$nibble=0)
{
global $history;
$munched = $amount * ((100-$percent) / 100) - $fixed;
$history[$nibble] = array('gross' => number_format($amount, 2, '.', ','),
'net' => number_format($munched, 2, '.', ','),
'fee' => number_format($amount - $munched, 2, '.', ','),
'transaction' => $nibble+1);
if ($munched > .1)
return (fee_muncher($munched,$percent,$fixed,$nibble+1));
else
return ($nibble+1);
}
/*
Example Usage:
*/
echo fee_muncher(5000,2.9,0.30); // Number of transactions before $5,000 USD is fully assimilated by merchant.
print_r($history); // Multi-dimensional array holding all the transaction info.
?>