Stripe fee calculation
Solution 1:
the easiest way is to add expand for balance transaction
$charge = \Stripe\Charge::create(array(
"amount" => $totalAmount,
"currency" => $currency_code,
"source" => $stripeToken,
"transfer_group" => $orderId,
"expand" => array("balance_transaction")
));
This will give you what stripe has charged as fee and then you can do remaining calculations
Solution 2:
for someone looking for the javascript code to calculate stripe fee (maybe to ask customers to cover the stripe fee). i wrote small script to do it
/**
* Calculate stripe fee from amount
* so you can charge stripe fee to customers
* lafif <[email protected]>
*/
var fees = {
USD: { Percent: 2.9, Fixed: 0.30 },
GBP: { Percent: 2.4, Fixed: 0.20 },
EUR: { Percent: 2.4, Fixed: 0.24 },
CAD: { Percent: 2.9, Fixed: 0.30 },
AUD: { Percent: 2.9, Fixed: 0.30 },
NOK: { Percent: 2.9, Fixed: 2 },
DKK: { Percent: 2.9, Fixed: 1.8 },
SEK: { Percent: 2.9, Fixed: 1.8 },
JPY: { Percent: 3.6, Fixed: 0 },
MXN: { Percent: 3.6, Fixed: 3 }
};
function calcFee(amount, currency) {
var _fee = fees[currency];
var amount = parseFloat(amount);
var total = (amount + parseFloat(_fee.Fixed)) / (1 - parseFloat(_fee.Percent) / 100);
var fee = total - amount;
return {
amount: amount,
fee: fee.toFixed(2),
total: total.toFixed(2)
};
}
var charge_data = calcFee(100, 'USD');
alert('You should ask: ' + charge_data.total + ' to customer, to cover ' + charge_data.fee + ' fee from ' + charge_data.amount );
console.log(charge_data);
https://gist.github.com/c3954950798ae14d6caabd6ba15b302b