Skip to content

Instantly share code, notes, and snippets.

@tjconcept
Last active January 11, 2016 20:06
Show Gist options
  • Save tjconcept/e0ebd96277e0fbbc972f to your computer and use it in GitHub Desktop.
Save tjconcept/e0ebd96277e0fbbc972f to your computer and use it in GitHub Desktop.
Surcharge

If you wish to put the entire fee on your customer, remember that the customer must also pay the fee of collecting the fee itself.

r = 0.025 // (rate fee)
f = 0.25 // (flat fee)

O = 100 // original amount (the cost of some product)

Naive (wrong) approach:

R = O * r + f
  = 100 * 0.025 + 0.25
  = 2.75 // total fees

T = O + R
  = 100 + 2.75
  = 102.75 // total to pay by customer

The problem is that 2.75 is not what you are charged to make a 102.75 transaction. Instead you are charged 2.81875. Thus making you loose 0.07.

The correct approach is reached with some algebra:

R = (O + R) * r + f  // total fees (identical to former, but taking itself into account)

R                 = (O + R) * r + f        // subtract (O + R) * r
R - (O + R) * r   = f                      // lift parenthesis
R - O * r - R * r = f                      // add O * r
R - R * r         = f + O * r              // add parenthesis
R(1 - r)          = f + O * r              // divide by (1 - r)
R                 = (f + O * r) / (1 - r)

R = (f + O * r) / (1 - r)

// total fees
R = (f + O * r) / (1 - r)
  = (0.25 + 100 * 0.025) / (1 - 0.025)
  = 2.82051282051

T = O + R = 100 + 2.82 = 102.82 // total to pay by customer

And we can verify the approach easily: 100 + 102.82 * 0.025 + 0.25 ≈ 102.82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment