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
Solution 3
From the Stripe Charge ID we can get the processing fee taken from the amount
stripe.Charge.retrieve("ch_1DBKfWECTOB5aCAKpzxm5VIW", expand=['balance_transaction'])
"id": "txn_1DBKfWECTOB5aCAKtwwLMCjd",
"net": 941,
"object": "balance_transaction",
"source": "ch_1DBKfWECTOB5aCAKpzxm5VIW",
"status": "pending",
"type": "charge"
"net": 941 is the amount credited to merchant account
Solution 4
Currently, Stripe's API does not have a way of computing the fees before creating the charge. You'd need to do this yourself.
If you want to pass the fees to the paying customer, the following support article will be very helpful: https://support.stripe.com/questions/can-i-charge-my-stripe-fees-to-my-customers
To process payments on behalf of another account, and optionally take a cut out of the transactions, you need to use Stripe Connect. You can read more in the documentation: https://stripe.com/docs/connect.
Solution 5
Just wanted to pop in and add to Harshal Lonare's answer, for sending Payment Intent confirmations you can get the balance transaction data back with:
"expand" => array("charges.data.balance_transaction")
sher bahadur
Updated on June 06, 2022Comments
-
sher bahadur almost 2 years
Regarding Stripe fee calculation, is there is any way to get the Stripe fee according to the amount provided.
We have to implement this in such away that, we have to pay x amount to one dealer and y amount to another.
1st case:
Let say we have $100 to pay to Stripe.
According to our needs, we want to calculate the Stripe fee first and then add that fee to the $100 amount.
e.g:
Amount to be Paid is $100 + $3 (Stripe fee) = $103 (Total) you need to cut from the customers account.
2nd Case:
We need to pay $95 to the dealer and the $5 left we want to keep in our account (excluding the Stripe fee).
If this is possible, how do we implement this?
-
sher bahadur almost 8 yearsI am using this formula to calcualte Stripe Fee. Say amaount = $100 (100 * 0.029) + 0.30 = 103.20 But On stripe it is displaying 103.29 instead of 103.20. Dont know what's going on?
-
Jim Smith about 6 yearsAre you sure the fees depend on the payment currency? I thought that was determined by the platform account's currency. So, for example: If your platform is in the US, every payment will be "Percent: 2.9, Fixed: 0.30" regardless of the payment currency.
-
Martin James over 5 yearsFrom what I can see on Stripe's website (December 23 2018), all EU fees are 1.4% + 0.20p and all non-EU fees are 2.9% + 20p.
-
w00t about 5 yearsNo, the fees depend on the origin of the card, not the currency of the transaction
-
tsdorsey almost 5 yearsYou're having to pay 2.9% on the $3.20 which is $0.09
-
tsdorsey almost 5 years(100 / (1 - 0.029)) + 0.30 = 103.28661174 which rounds to $103.29
-
FlorianB almost 5 yearsAnd if anyone is interested into how it should look like in the POST request, here it is: &expand%5B%5D=balance_transaction
-
Tsuna over 4 yearsThis formula is really helpful thanks a lot, but is it possible to have a formula for international charges? I know there's additional internation charges on top of this
-
ilyanaDev about 3 yearscan I use this to get the details (net amount and/or stripe fee) of a given customer charge?
-
zacoder about 2 yearsfor example once upon a time in future the fee in USA can change, so hard coded fees like USD: { Percent: 2.9, Fixed: 0.30 } needs to be updated. Is there any api for getting fee calculations? Such we ask for the appropriate fees then get a response from Stripe.