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!.

Advertisements
Categories: Uncategorized
  1. June 22, 2015 at 1:40 pm

    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);
    }

    ///

    /// Represents Stripe Fees
    ///

    private class stripeFee
    {
    ///

    /// Gets or sets the percent.
    ///

    ///
    /// The percent.
    ///
    public double Percent { get; set; }
    ///

    /// Gets or sets the fixed.
    ///

    ///
    /// The fixed.
    ///
    public double Fixed { get; set; }

    }

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: