Home
> Uncategorized > Calculate Stripe fees using Javascript
Calculate Stripe fees using Javascript
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 addFee(amount, currency)
{
var fee = fees[currency];
return (amount + fee.Fixed) / (1 – fee.Percent/100);
}alert(addFee(100,”GBP”));
– and viola, your consumer pays your stripe fees!.
Categories: Uncategorized
and here’s the c= version
private double AddFees(double amount, string currency)
{
/*{ 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}};
*/
var fees = new Dictionary
{
{“USD”, new stripeFee { Percent = 2.9, Fixed = 0.3}},
{“GBP”, new stripeFee { Percent= 2.4, Fixed= 0.20}},
{“EUR”, new stripeFee { Percent= 2.4, Fixed= 0.24}},
{“CAD”, new stripeFee { Percent= 2.9, Fixed= 0.30}},
{“AUD”, new stripeFee { Percent= 2.9, Fixed= 0.30}},
{“NOK”, new stripeFee { Percent= 2.9, Fixed= 2}},
{“DKK”, new stripeFee { Percent= 2.9, Fixed= 1.8}},
{“SEK”, new stripeFee { Percent= 2.9, Fixed= 1.8}},
{“JPY”, new stripeFee { Percent= 3.6, Fixed= 0}},
{“MXN”, new stripeFee { Percent= 3.6, Fixed= 3}}
};
var fee = fees[currency];
return (amount + fee.Fixed) / (1 – fee.Percent / 100);
}
///
///
private class stripeFee
{
///
///
///
/// The percent.
///
public double Percent { get; set; }
///
///
///
/// The fixed.
///
public double Fixed { get; set; }
}
LikeLike